| Index: mojo/public/cpp/system/watcher.cc
|
| diff --git a/mojo/public/cpp/system/watcher.cc b/mojo/public/cpp/system/watcher.cc
|
| index 57235338fe98c5f58ef05d4c44957dfc95add000..c9757b241471cb006ff928a61a860eb264479c89 100644
|
| --- a/mojo/public/cpp/system/watcher.cc
|
| +++ b/mojo/public/cpp/system/watcher.cc
|
| @@ -56,6 +56,10 @@ Watcher::~Watcher() {
|
| Cancel();
|
| }
|
|
|
| +void Watcher::EnableImmediateDispatchOfEventsFromSameThread(bool enabled) {
|
| + sync_dispatch_enabled_ = enabled;
|
| +}
|
| +
|
| bool Watcher::IsWatching() const {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| return handle_.is_valid();
|
| @@ -128,9 +132,15 @@ void Watcher::CallOnHandleReady(uintptr_t context,
|
| // TODO: Maybe we should also expose |signals_state| throught he Watcher API.
|
| // Current HandleWatcher users have no need for it, so it's omitted here.
|
| Watcher* watcher = reinterpret_cast<Watcher*>(context);
|
| - watcher->task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result));
|
| +
|
| + if (watcher->task_runner_->RunsTasksOnCurrentThread() &&
|
| + watcher->sync_dispatch_enabled_) {
|
| + watcher->OnHandleReady(result);
|
| + } else {
|
| + watcher->task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result));
|
| + }
|
| }
|
|
|
| } // namespace mojo
|
|
|