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/public/c/environment/async_waiter.h"
12 #include "mojo/public/cpp/system/core.h"
17 class WaitingCallback : public gin::Wrappable<WaitingCallback> {
19 static gin::WrapperInfo kWrapperInfo;
21 // Creates a new WaitingCallback.
22 static gin::Handle<WaitingCallback> Create(
24 v8::Handle<v8::Function> callback,
26 MojoHandleSignals signals);
28 // 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
34 WaitingCallback(v8::Isolate* isolate, v8::Handle<v8::Function> callback);
35 virtual ~WaitingCallback();
37 // Callback from MojoAsyncWaiter. |closure| is the WaitingCallback.
38 static void CallOnHandleReady(void* closure, MojoResult result);
40 // Invoked from CallOnHandleReady() (CallOnHandleReady() must be static).
41 void OnHandleReady(MojoResult result);
43 base::WeakPtr<gin::Runner> runner_;
44 MojoAsyncWaitID wait_id_;
46 DISALLOW_COPY_AND_ASSIGN(WaitingCallback);
52 #endif // MOJO_BINDINGS_JS_WAITING_CALLBACK_H_