Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Unified Diff: mojo/public/cpp/system/watcher.cc

Issue 1811433002: [mojo-edk] Expose notification source to MojoWatch callbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698