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