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

Unified Diff: mojo/public/cpp/bindings/lib/sync_handle_registry.cc

Issue 1900953002: Mojo C++ bindings: make SyncHandleRegistry a ref-counted object. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/bindings/lib/sync_handle_registry.cc
diff --git a/mojo/public/cpp/bindings/lib/sync_handle_registry.cc b/mojo/public/cpp/bindings/lib/sync_handle_registry.cc
index 3d88ec96da7c8270d92c5855de9118da103dc9b2..e4b495579377fe4297f7639a40f2990fe27f303a 100644
--- a/mojo/public/cpp/bindings/lib/sync_handle_registry.cc
+++ b/mojo/public/cpp/bindings/lib/sync_handle_registry.cc
@@ -20,11 +20,12 @@ base::LazyInstance<base::ThreadLocalPointer<SyncHandleRegistry>>
} // namespace
// static
-SyncHandleRegistry* SyncHandleRegistry::current() {
- SyncHandleRegistry* result = g_current_sync_handle_watcher.Pointer()->Get();
+scoped_refptr<SyncHandleRegistry> SyncHandleRegistry::current() {
+ scoped_refptr<SyncHandleRegistry> result(
+ g_current_sync_handle_watcher.Pointer()->Get());
if (!result) {
result = new SyncHandleRegistry();
- DCHECK_EQ(result, g_current_sync_handle_watcher.Pointer()->Get());
+ DCHECK_EQ(result.get(), g_current_sync_handle_watcher.Pointer()->Get());
}
return result;
}
@@ -66,10 +67,8 @@ bool SyncHandleRegistry::WatchAllHandles(const bool* should_stop[],
MojoHandle ready_handle;
MojoResult ready_handle_result;
- // This object may be destroyed during a callback. So we have to preserve
- // the boolean.
- scoped_refptr<base::RefCountedData<bool>> destroyed = destroyed_;
- while (!destroyed->data) {
+ scoped_refptr<SyncHandleRegistry> preserver(this);
+ while (true) {
for (size_t i = 0; i < count; ++i)
if (*should_stop[i])
return true;
@@ -96,8 +95,7 @@ bool SyncHandleRegistry::WatchAllHandles(const bool* should_stop[],
return false;
}
-SyncHandleRegistry::SyncHandleRegistry()
- : destroyed_(new base::RefCountedData<bool>(false)) {
+SyncHandleRegistry::SyncHandleRegistry() {
MojoHandle handle;
MojoResult result = MojoCreateWaitSet(&handle);
CHECK_EQ(MOJO_RESULT_OK, result);
@@ -106,24 +104,12 @@ SyncHandleRegistry::SyncHandleRegistry()
DCHECK(!g_current_sync_handle_watcher.Pointer()->Get());
g_current_sync_handle_watcher.Pointer()->Set(this);
-
- base::MessageLoop::current()->AddDestructionObserver(this);
}
SyncHandleRegistry::~SyncHandleRegistry() {
DCHECK(thread_checker_.CalledOnValidThread());
- destroyed_->data = true;
g_current_sync_handle_watcher.Pointer()->Set(nullptr);
}
-void SyncHandleRegistry::WillDestroyCurrentMessageLoop() {
- DCHECK(thread_checker_.CalledOnValidThread());
- DCHECK_EQ(this, g_current_sync_handle_watcher.Pointer()->Get());
-
- base::MessageLoop::current()->RemoveDestructionObserver(this);
-
- delete this;
-}
-
} // namespace internal
} // namespace mojo
« no previous file with comments | « mojo/public/cpp/bindings/lib/sync_handle_registry.h ('k') | mojo/public/cpp/bindings/lib/sync_handle_watcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698