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

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: DISALLOW_COPY_AND_ASSIGN 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/handle_close_observer.h » ('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 "mojo/bindings/js/handle_close_observer.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(HandleCloseObserver* observer) {
27 close_observers_.AddObserver(observer);
28 }
29
30 void HandleWrapper::RemoveCloseObserver(HandleCloseObserver* observer) {
31 close_observers_.RemoveObserver(observer);
32 }
33
34 void HandleWrapper::NotifyCloseObservers() {
35 if (!handle_.is_valid())
36 return;
37
38 FOR_EACH_OBSERVER(HandleCloseObserver, close_observers_, OnWillCloseHandle());
16 } 39 }
17 40
18 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate, 41 v8::Handle<v8::Value> Converter<mojo::Handle>::ToV8(v8::Isolate* isolate,
19 const mojo::Handle& val) { 42 const mojo::Handle& val) {
20 if (!val.is_valid()) 43 if (!val.is_valid())
21 return v8::Null(isolate); 44 return v8::Null(isolate);
22 return HandleWrapper::Create(isolate, val.value()).ToV8(); 45 return HandleWrapper::Create(isolate, val.value()).ToV8();
23 } 46 }
24 47
25 bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate, 48 bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate,
26 v8::Handle<v8::Value> val, 49 v8::Handle<v8::Value> val,
27 mojo::Handle* out) { 50 mojo::Handle* out) {
28 if (val->IsNull()) { 51 if (val->IsNull()) {
29 *out = mojo::Handle(); 52 *out = mojo::Handle();
30 return true; 53 return true;
31 } 54 }
32 55
33 gin::Handle<HandleWrapper> handle; 56 gin::Handle<HandleWrapper> handle;
34 if (!Converter<gin::Handle<HandleWrapper> >::FromV8(isolate, val, &handle)) 57 if (!Converter<gin::Handle<HandleWrapper> >::FromV8(isolate, val, &handle))
35 return false; 58 return false;
36 59
37 *out = handle->get(); 60 *out = handle->get();
38 return true; 61 return true;
39 } 62 }
40 63
41 } // namespace gin 64 } // namespace gin
OLDNEW
« no previous file with comments | « mojo/bindings/js/handle.h ('k') | mojo/bindings/js/handle_close_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698