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

Unified Diff: mojo/bindings/js/handle.cc

Issue 534953002: Mojo: Cancel WaitingCallbacks when their HandleWrappers are closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « mojo/bindings/js/handle.h ('k') | mojo/bindings/js/support.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/bindings/js/handle.cc
diff --git a/mojo/bindings/js/handle.cc b/mojo/bindings/js/handle.cc
index e1d0fb04b60c063466536c04f48502c7b1423179..5273adc9e0ff7ac13b1652777f6c036a5a34b54d 100644
--- a/mojo/bindings/js/handle.cc
+++ b/mojo/bindings/js/handle.cc
@@ -4,6 +4,8 @@
#include "mojo/bindings/js/handle.h"
+#include "base/logging.h"
+
namespace gin {
gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin };
@@ -13,6 +15,30 @@ HandleWrapper::HandleWrapper(MojoHandle handle)
}
HandleWrapper::~HandleWrapper() {
+ NotifyCloseObservers();
+}
+
+void HandleWrapper::Close() {
+ NotifyCloseObservers();
+ handle_.reset();
+}
+
+void HandleWrapper::AddCloseObserver(CloseObserver* observer) {
+ bool inserted = observers_.insert(observer).second;
+ DCHECK(inserted);
+}
+
+void HandleWrapper::RemoveCloseObserver(CloseObserver* observer) {
+ size_t removed = observers_.erase(observer);
+ DCHECK_EQ(removed, 1u);
+}
+
+void HandleWrapper::NotifyCloseObservers() {
+ for (std::set<CloseObserver*>::iterator it = observers_.begin();
+ it != observers_.end();) {
+ (*it++)->OnHandleClosed();
abarth-chromium 2014/09/03 05:21:55 What if observers_ is modified during this iterati
Sam McNally 2014/09/03 05:37:27 Done.
+ }
+ observers_.clear();
}
v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate,
« no previous file with comments | « mojo/bindings/js/handle.h ('k') | mojo/bindings/js/support.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698