I am following the guidance
from this doc to try to get some help.
I have a change (
WIP here), where I am trying to open a file and return it through a mojo callback. When posting a task to open the file through a ThreadPool, some part of my code is marking my code as blocking even after adding task traits to indicate that this operation MayBlock.
Sample run output here with the full error.
Relevant code part:
void AccessibilityServiceClient::Load(const base::FilePath& path,
LoadCallback callback) {
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock()}, base::BindOnce(&LoadFile, path),
base::BindOnce(&OnFileLoaded, std::move(callback)));
}
Where LoadFile is implemented as:
base::File LoadFile(base::FilePath path) {
DCHECK(!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK);
base::FilePath resources_path;
if (!base::PathService::Get(chrome::DIR_RESOURCES, &resources_path)) {
NOTREACHED();
}
base::FilePath accessibility_file_path =
resources_path.Append(extension_misc::kAccessibilityCommonExtensionPath)
.Append(path);
LOG(INFO) << accessibility_file_path.MaybeAsASCII();
base::File file(accessibility_file_path,
base::File::FLAG_OPEN | base::File::FLAG_READ);
return file;
}
And OnFileLoaded is implemented as:
void OnFileLoaded(
AccessibilityServiceClient::LoadCallback callback,
base::File file) {
std::move(callback).Run(std::move(file));
}
Where:
- To open a file I am posting the task to the ThreadPool, and marking through traits that this may block;
- Callback must run in the same sequence in which the mojo InterfacePtr is bound (that's why it is passed to the on result parameter of PostTask above);
- So the base::File is the result of the task run.
I suspect that the presence of the base::File in the function signature for OnFileLoaded is causing the scheduler to think that the second function may block, although I am just trying to run the callback sending the resultt (which is the file already opened).
I tried to use base::ScopedAllowBlocking in the function body of OnFileLoaded with no success.
I ran out of ideas of what could be, so I am asking for help.
Thanks.