Chromium Code Reviews| 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" |
|
yzshen1
2016/03/08 23:02:42
nit: This is not needed anymore.
| |
| 15 #include "mojo/message_pump/handle_watcher.h" | |
| 16 #include "mojo/public/cpp/system/core.h" | 15 #include "mojo/public/cpp/system/core.h" |
| 16 #include "mojo/public/cpp/system/watcher.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 { | |
| 24 public: | 23 public: |
| 25 static gin::WrapperInfo kWrapperInfo; | 24 static gin::WrapperInfo kWrapperInfo; |
| 26 | 25 |
| 27 // Creates a new WaitingCallback. | 26 // Creates a new WaitingCallback. |
| 27 // | |
| 28 // If |one_shot| is true, the callback will only ever be called at most once. | |
| 29 // If false, the callback may be called any number of times until the | |
| 30 // WaitingCallback is explicitly cancelled. | |
| 28 static gin::Handle<WaitingCallback> Create( | 31 static gin::Handle<WaitingCallback> Create( |
| 29 v8::Isolate* isolate, | 32 v8::Isolate* isolate, |
| 30 v8::Handle<v8::Function> callback, | 33 v8::Handle<v8::Function> callback, |
| 31 gin::Handle<HandleWrapper> handle_wrapper, | 34 gin::Handle<HandleWrapper> handle_wrapper, |
| 32 MojoHandleSignals signals); | 35 MojoHandleSignals signals, |
| 36 bool one_shot); | |
| 33 | 37 |
| 34 // Cancels the callback. Does nothing if a callback is not pending. This is | 38 // 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 | 39 // implicitly invoked from the destructor but can be explicitly invoked as |
| 36 // necessary. | 40 // necessary. |
| 37 void Cancel(); | 41 void Cancel(); |
| 38 | 42 |
| 39 private: | 43 private: |
| 40 WaitingCallback(v8::Isolate* isolate, | 44 WaitingCallback(v8::Isolate* isolate, |
| 41 v8::Handle<v8::Function> callback, | 45 v8::Handle<v8::Function> callback, |
| 42 gin::Handle<HandleWrapper> handle_wrapper); | 46 bool one_shot); |
| 43 ~WaitingCallback() override; | 47 ~WaitingCallback() override; |
| 44 | 48 |
| 45 // Callback from common::HandleWatcher. | 49 // Callback from the Watcher. |
| 46 void OnHandleReady(MojoResult result); | 50 void OnHandleReady(MojoResult result); |
| 47 | 51 |
| 48 // Invoked by the HandleWrapper if the handle is closed while this wait is | |
| 49 // still in progress. | |
| 50 void OnWillCloseHandle() override; | |
| 51 | |
| 52 void RemoveHandleCloseObserver(); | |
| 53 void CallCallback(MojoResult result); | 52 void CallCallback(MojoResult result); |
| 54 | 53 |
| 54 // Indicates whether this is a one-shot callback or not. If so, it uses the | |
| 55 // deprecated HandleWatcher to wait for signals; otherwise it uses the new | |
| 56 // system Watcher API. | |
| 57 const bool one_shot_; | |
| 58 | |
| 55 base::WeakPtr<gin::Runner> runner_; | 59 base::WeakPtr<gin::Runner> runner_; |
| 56 | 60 Watcher watcher_; |
| 57 common::HandleWatcher handle_watcher_; | |
| 58 | |
| 59 HandleWrapper* handle_wrapper_; | |
| 60 base::WeakPtrFactory<WaitingCallback> weak_factory_; | 61 base::WeakPtrFactory<WaitingCallback> weak_factory_; |
| 61 | 62 |
| 62 DISALLOW_COPY_AND_ASSIGN(WaitingCallback); | 63 DISALLOW_COPY_AND_ASSIGN(WaitingCallback); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 } // namespace js | 66 } // namespace js |
| 66 } // namespace edk | 67 } // namespace edk |
| 67 } // namespace mojo | 68 } // namespace mojo |
| 68 | 69 |
| 69 #endif // MOJO_EDK_JS_WAITING_CALLBACK_H_ | 70 #endif // MOJO_EDK_JS_WAITING_CALLBACK_H_ |
| OLD | NEW |