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