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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « mojo/bindings/js/handle.h ('k') | mojo/bindings/js/support.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/bindings/js/handle.h" 5 #include "mojo/bindings/js/handle.h"
6 6
7 #include "base/logging.h"
8
7 namespace gin { 9 namespace gin {
8 10
9 gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin }; 11 gin::WrapperInfo HandleWrapper::kWrapperInfo = { gin::kEmbedderNativeGin };
10 12
11 HandleWrapper::HandleWrapper(MojoHandle handle) 13 HandleWrapper::HandleWrapper(MojoHandle handle)
12 : handle_(mojo::Handle(handle)) { 14 : handle_(mojo::Handle(handle)) {
13 } 15 }
14 16
15 HandleWrapper::~HandleWrapper() { 17 HandleWrapper::~HandleWrapper() {
18 NotifyCloseObservers();
19 }
20
21 void HandleWrapper::Close() {
22 NotifyCloseObservers();
23 handle_.reset();
24 }
25
26 void HandleWrapper::AddCloseObserver(CloseObserver* observer) {
27 bool inserted = observers_.insert(observer).second;
28 DCHECK(inserted);
29 }
30
31 void HandleWrapper::RemoveCloseObserver(CloseObserver* observer) {
32 size_t removed = observers_.erase(observer);
33 DCHECK_EQ(removed, 1u);
34 }
35
36 void HandleWrapper::NotifyCloseObservers() {
37 for (std::set<CloseObserver*>::iterator it = observers_.begin();
38 it != observers_.end();) {
39 (*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.
40 }
41 observers_.clear();
16 } 42 }
17 43
18 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate, 44 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate,
19 const mojo::Handle& val) { 45 const mojo::Handle& val) {
20 if (!val.is_valid()) 46 if (!val.is_valid())
21 return v8::Null(isolate); 47 return v8::Null(isolate);
22 return HandleWrapper::Create(isolate, val.value()).ToV8(); 48 return HandleWrapper::Create(isolate, val.value()).ToV8();
23 } 49 }
24 50
25 bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate, 51 bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate,
26 v8::Handle<v8::Value> val, 52 v8::Handle<v8::Value> val,
27 mojo::Handle* out) { 53 mojo::Handle* out) {
28 if (val->IsNull()) { 54 if (val->IsNull()) {
29 *out = mojo::Handle(); 55 *out = mojo::Handle();
30 return true; 56 return true;
31 } 57 }
32 58
33 gin::Handle<HandleWrapper> handle; 59 gin::Handle<HandleWrapper> handle;
34 if (!Converter<gin::Handle<HandleWrapper> >::FromV8(isolate, val, &handle)) 60 if (!Converter<gin::Handle<HandleWrapper> >::FromV8(isolate, val, &handle))
35 return false; 61 return false;
36 62
37 *out = handle->get(); 63 *out = handle->get();
38 return true; 64 return true;
39 } 65 }
40 66
41 } // namespace gin 67 } // namespace gin
OLDNEW
« 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