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..64f2b28927c77b0827df2f44bade25d9b06b631b 100644 |
--- a/mojo/public/cpp/system/watcher.cc |
+++ b/mojo/public/cpp/system/watcher.cc |
@@ -56,6 +56,10 @@ Watcher::~Watcher() { |
Cancel(); |
} |
+void Watcher::SetAllowSyncDispatch(bool allowed) { |
+ allow_sync_dispatch_ = allowed; |
+} |
+ |
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->allow_sync_dispatch_) { |
+ watcher->OnHandleReady(result); |
+ } else { |
+ watcher->task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); |
+ } |
} |
} // namespace mojo |