OLD | NEW |
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_WAITING_CALLBACK_H_ | 5 #ifndef MOJO_BINDINGS_JS_WAITING_CALLBACK_H_ |
6 #define MOJO_BINDINGS_JS_WAITING_CALLBACK_H_ | 6 #define MOJO_BINDINGS_JS_WAITING_CALLBACK_H_ |
7 | 7 |
8 #include "gin/handle.h" | 8 #include "gin/handle.h" |
9 #include "gin/runner.h" | 9 #include "gin/runner.h" |
10 #include "gin/wrappable.h" | 10 #include "gin/wrappable.h" |
| 11 #include "mojo/bindings/js/handle.h" |
| 12 #include "mojo/bindings/js/handle_close_observer.h" |
11 #include "mojo/public/c/environment/async_waiter.h" | 13 #include "mojo/public/c/environment/async_waiter.h" |
12 #include "mojo/public/cpp/system/core.h" | 14 #include "mojo/public/cpp/system/core.h" |
13 | 15 |
14 namespace mojo { | 16 namespace mojo { |
15 namespace js { | 17 namespace js { |
16 | 18 |
17 class WaitingCallback : public gin::Wrappable<WaitingCallback> { | 19 class WaitingCallback : public gin::Wrappable<WaitingCallback>, |
| 20 public gin::HandleCloseObserver { |
18 public: | 21 public: |
19 static gin::WrapperInfo kWrapperInfo; | 22 static gin::WrapperInfo kWrapperInfo; |
20 | 23 |
21 // Creates a new WaitingCallback. | 24 // Creates a new WaitingCallback. |
22 static gin::Handle<WaitingCallback> Create( | 25 static gin::Handle<WaitingCallback> Create( |
23 v8::Isolate* isolate, | 26 v8::Isolate* isolate, |
24 v8::Handle<v8::Function> callback, | 27 v8::Handle<v8::Function> callback, |
25 mojo::Handle handle, | 28 gin::Handle<gin::HandleWrapper> handle_wrapper, |
26 MojoHandleSignals signals); | 29 MojoHandleSignals signals); |
27 | 30 |
28 // Cancels the callback. Does nothing if a callback is not pending. This is | 31 // Cancels the callback. Does nothing if a callback is not pending. This is |
29 // implicitly invoked from the destructor but can be explicitly invoked as | 32 // implicitly invoked from the destructor but can be explicitly invoked as |
30 // necessary. | 33 // necessary. |
31 void Cancel(); | 34 void Cancel(); |
32 | 35 |
33 private: | 36 private: |
34 WaitingCallback(v8::Isolate* isolate, v8::Handle<v8::Function> callback); | 37 WaitingCallback(v8::Isolate* isolate, |
| 38 v8::Handle<v8::Function> callback, |
| 39 gin::Handle<gin::HandleWrapper> handle_wrapper); |
35 virtual ~WaitingCallback(); | 40 virtual ~WaitingCallback(); |
36 | 41 |
37 // Callback from MojoAsyncWaiter. |closure| is the WaitingCallback. | 42 // Callback from MojoAsyncWaiter. |closure| is the WaitingCallback. |
38 static void CallOnHandleReady(void* closure, MojoResult result); | 43 static void CallOnHandleReady(void* closure, MojoResult result); |
39 | 44 |
40 // Invoked from CallOnHandleReady() (CallOnHandleReady() must be static). | 45 // Invoked from CallOnHandleReady() (CallOnHandleReady() must be static). |
41 void OnHandleReady(MojoResult result); | 46 void OnHandleReady(MojoResult result); |
42 | 47 |
| 48 // Invoked by the HandleWrapper if the handle is closed while this wait is |
| 49 // still in progress. |
| 50 virtual void OnWillCloseHandle() OVERRIDE; |
| 51 |
43 base::WeakPtr<gin::Runner> runner_; | 52 base::WeakPtr<gin::Runner> runner_; |
44 MojoAsyncWaitID wait_id_; | 53 MojoAsyncWaitID wait_id_; |
45 | 54 |
| 55 gin::HandleWrapper* handle_wrapper_; |
| 56 |
46 DISALLOW_COPY_AND_ASSIGN(WaitingCallback); | 57 DISALLOW_COPY_AND_ASSIGN(WaitingCallback); |
47 }; | 58 }; |
48 | 59 |
49 } // namespace js | 60 } // namespace js |
50 } // namespace mojo | 61 } // namespace mojo |
51 | 62 |
52 #endif // MOJO_BINDINGS_JS_WAITING_CALLBACK_H_ | 63 #endif // MOJO_BINDINGS_JS_WAITING_CALLBACK_H_ |
OLD | NEW |