Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: mojo/bindings/js/waiting_callback.h

Issue 534953002: Mojo: Cancel WaitingCallbacks when their HandleWrappers are closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ObserverList Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "mojo/public/c/environment/async_waiter.h" 12 #include "mojo/public/c/environment/async_waiter.h"
12 #include "mojo/public/cpp/system/core.h" 13 #include "mojo/public/cpp/system/core.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace js { 16 namespace js {
16 17
17 class WaitingCallback : public gin::Wrappable<WaitingCallback> { 18 class WaitingCallback : public gin::Wrappable<WaitingCallback>,
19 public gin::HandleWrapper::CloseObserver {
18 public: 20 public:
19 static gin::WrapperInfo kWrapperInfo; 21 static gin::WrapperInfo kWrapperInfo;
20 22
21 // Creates a new WaitingCallback. 23 // Creates a new WaitingCallback.
22 static gin::Handle<WaitingCallback> Create( 24 static gin::Handle<WaitingCallback> Create(
23 v8::Isolate* isolate, 25 v8::Isolate* isolate,
24 v8::Handle<v8::Function> callback, 26 v8::Handle<v8::Function> callback,
25 mojo::Handle handle, 27 gin::Handle<gin::HandleWrapper> handle_wrapper,
26 MojoHandleSignals signals); 28 MojoHandleSignals signals);
27 29
28 // Cancels the callback. Does nothing if a callback is not pending. This is 30 // 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 31 // implicitly invoked from the destructor but can be explicitly invoked as
30 // necessary. 32 // necessary.
31 void Cancel(); 33 void Cancel();
32 34
33 private: 35 private:
34 WaitingCallback(v8::Isolate* isolate, v8::Handle<v8::Function> callback); 36 WaitingCallback(v8::Isolate* isolate,
37 v8::Handle<v8::Function> callback,
38 gin::Handle<gin::HandleWrapper> handle_wrapper);
35 virtual ~WaitingCallback(); 39 virtual ~WaitingCallback();
36 40
37 // Callback from MojoAsyncWaiter. |closure| is the WaitingCallback. 41 // Callback from MojoAsyncWaiter. |closure| is the WaitingCallback.
38 static void CallOnHandleReady(void* closure, MojoResult result); 42 static void CallOnHandleReady(void* closure, MojoResult result);
39 43
40 // Invoked from CallOnHandleReady() (CallOnHandleReady() must be static). 44 // Invoked from CallOnHandleReady() (CallOnHandleReady() must be static).
41 void OnHandleReady(MojoResult result); 45 void OnHandleReady(MojoResult result);
42 46
47 // Invoked by the HandleWrapper if the handle is closed while this wait is
48 // still in progress.
49 virtual void OnHandleClosed() OVERRIDE;
50
43 base::WeakPtr<gin::Runner> runner_; 51 base::WeakPtr<gin::Runner> runner_;
44 MojoAsyncWaitID wait_id_; 52 MojoAsyncWaitID wait_id_;
45 53
54 gin::HandleWrapper* handle_wrapper_;
55
46 DISALLOW_COPY_AND_ASSIGN(WaitingCallback); 56 DISALLOW_COPY_AND_ASSIGN(WaitingCallback);
47 }; 57 };
48 58
49 } // namespace js 59 } // namespace js
50 } // namespace mojo 60 } // namespace mojo
51 61
52 #endif // MOJO_BINDINGS_JS_WAITING_CALLBACK_H_ 62 #endif // MOJO_BINDINGS_JS_WAITING_CALLBACK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698