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

Side by Side Diff: mojo/bindings/js/handle.h

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 | « no previous file | mojo/bindings/js/handle.cc » ('j') | mojo/bindings/js/handle.cc » ('J')
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 #ifndef MOJO_BINDINGS_JS_HANDLE_H_ 5 #ifndef MOJO_BINDINGS_JS_HANDLE_H_
6 #define MOJO_BINDINGS_JS_HANDLE_H_ 6 #define MOJO_BINDINGS_JS_HANDLE_H_
7 7
8 #include <set>
9
8 #include "gin/converter.h" 10 #include "gin/converter.h"
9 #include "gin/handle.h" 11 #include "gin/handle.h"
10 #include "gin/wrappable.h" 12 #include "gin/wrappable.h"
11 #include "mojo/public/cpp/system/core.h" 13 #include "mojo/public/cpp/system/core.h"
12 14
13 namespace gin { 15 namespace gin {
14 16
15 // Wrapper for mojo Handles exposed to JavaScript. This ensures the Handle 17 // Wrapper for mojo Handles exposed to JavaScript. This ensures the Handle
16 // is Closed when its JS object is garbage collected. 18 // is Closed when its JS object is garbage collected.
17 class HandleWrapper : public gin::Wrappable<HandleWrapper> { 19 class HandleWrapper : public gin::Wrappable<HandleWrapper> {
18 public: 20 public:
21 class CloseObserver {
22 public:
23 virtual ~CloseObserver() {}
24 virtual void OnHandleClosed() = 0;
25 };
19 static gin::WrapperInfo kWrapperInfo; 26 static gin::WrapperInfo kWrapperInfo;
20 27
21 static gin::Handle<HandleWrapper> Create(v8::Isolate* isolate, 28 static gin::Handle<HandleWrapper> Create(v8::Isolate* isolate,
22 MojoHandle handle) { 29 MojoHandle handle) {
23 return gin::CreateHandle(isolate, new HandleWrapper(handle)); 30 return gin::CreateHandle(isolate, new HandleWrapper(handle));
24 } 31 }
25 32
26 mojo::Handle get() const { return handle_.get(); } 33 mojo::Handle get() const { return handle_.get(); }
27 mojo::Handle release() { return handle_.release(); } 34 mojo::Handle release() { return handle_.release(); }
28 void Close() { handle_.reset(); } 35 void Close();
36
37 void AddCloseObserver(CloseObserver* observer);
38 void RemoveCloseObserver(CloseObserver* observer);
29 39
30 protected: 40 protected:
31 HandleWrapper(MojoHandle handle); 41 HandleWrapper(MojoHandle handle);
32 virtual ~HandleWrapper(); 42 virtual ~HandleWrapper();
43 void NotifyCloseObservers();
33 mojo::ScopedHandle handle_; 44 mojo::ScopedHandle handle_;
45 std::set<CloseObserver*> observers_;
34 }; 46 };
35 47
36 // Note: It's important to use this converter rather than the one for 48 // Note: It's important to use this converter rather than the one for
37 // MojoHandle, since that will do a simple int32 conversion. It's unfortunate 49 // MojoHandle, since that will do a simple int32 conversion. It's unfortunate
38 // there's no way to prevent against accidental use. 50 // there's no way to prevent against accidental use.
39 // TODO(mpcomplete): define converters for all Handle subtypes. 51 // TODO(mpcomplete): define converters for all Handle subtypes.
40 template<> 52 template<>
41 struct Converter<mojo::Handle> { 53 struct Converter<mojo::Handle> {
42 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate, 54 static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
43 const mojo::Handle& val); 55 const mojo::Handle& val);
(...skipping 22 matching lines...) Expand all
66 return false; 78 return false;
67 } 79 }
68 *out = gin::Handle<gin::HandleWrapper>(val, object); 80 *out = gin::Handle<gin::HandleWrapper>(val, object);
69 return true; 81 return true;
70 } 82 }
71 }; 83 };
72 84
73 } // namespace gin 85 } // namespace gin
74 86
75 #endif // MOJO_BINDINGS_JS_HANDLE_H_ 87 #endif // MOJO_BINDINGS_JS_HANDLE_H_
OLDNEW
« no previous file with comments | « no previous file | mojo/bindings/js/handle.cc » ('j') | mojo/bindings/js/handle.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698