Commit 34fa00c8 authored by Leo Zhang's avatar Leo Zhang Committed by Commit Bot

Add main task runner for Mojo message output

IME decoder shared library has its own threads. In order to make sure
all the child theads post message via mojo safely, we must post all of
these tasks to MainTaskRunner.

Bug: 837156
Change-Id: I564662bfae078844da47628ad95560bdc160e6a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1868532
Commit-Queue: Leo Zhang <googleo@chromium.org>
Auto-Submit: Leo Zhang <googleo@chromium.org>
Reviewed-by: default avatarMarti Wong <martiw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707288}
parent 9f787eef
...@@ -33,7 +33,8 @@ enum SimpleDownloadError { ...@@ -33,7 +33,8 @@ enum SimpleDownloadError {
} // namespace } // namespace
ImeService::ImeService(mojo::PendingReceiver<mojom::ImeService> receiver) ImeService::ImeService(mojo::PendingReceiver<mojom::ImeService> receiver)
: receiver_(this, std::move(receiver)) { : receiver_(this, std::move(receiver)),
main_task_runner_(base::SequencedTaskRunnerHandle::Get()) {
input_engine_ = chromeos::features::IsImeDecoderWithSandboxEnabled() input_engine_ = chromeos::features::IsImeDecoderWithSandboxEnabled()
? std::make_unique<DecoderEngine>(this) ? std::make_unique<DecoderEngine>(this)
: std::make_unique<InputEngine>(); : std::make_unique<InputEngine>();
...@@ -77,7 +78,7 @@ const char* ImeService::GetImeBundleDir() { ...@@ -77,7 +78,7 @@ const char* ImeService::GetImeBundleDir() {
} }
const char* ImeService::GetImeGlobalDir() { const char* ImeService::GetImeGlobalDir() {
// Global IME data dir will not be supported yet. // Global IME data is supported yet.
return ""; return "";
} }
...@@ -86,10 +87,11 @@ const char* ImeService::GetImeUserHomeDir() { ...@@ -86,10 +87,11 @@ const char* ImeService::GetImeUserHomeDir() {
} }
void ImeService::RunInMainSequence(ImeSequencedTask task, int task_id) { void ImeService::RunInMainSequence(ImeSequencedTask task, int task_id) {
// Always run tasks on current SequencedTaskRunner. // This helps ensure that tasks run in the **main** SequencedTaskRunner.
// It's necessary for making any call on a bound Mojo Remote. // E.g. the Mojo Remotes are bound on the main_task_runner_, so that any task
base::SequencedTaskRunnerHandle::Get()->PostTask( // invoked Mojo call from other threads (sequences) should be posted to
FROM_HERE, base::BindOnce(task, task_id)); // main_task_runner_ by this function.
main_task_runner_->PostTask(FROM_HERE, base::BindOnce(task, task_id));
} }
int ImeService::SimpleDownloadToFile(const char* url, int ImeService::SimpleDownloadToFile(const char* url,
......
...@@ -60,6 +60,7 @@ class ImeService : public mojom::ImeService, ...@@ -60,6 +60,7 @@ class ImeService : public mojom::ImeService,
const base::FilePath& file); const base::FilePath& file);
mojo::Receiver<mojom::ImeService> receiver_; mojo::Receiver<mojom::ImeService> receiver_;
scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
// For the duration of this service lifetime, there should be only one // For the duration of this service lifetime, there should be only one
// input engine instance. // input engine instance.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment