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

Side by Side Diff: mojo/edk/js/waiting_callback.cc

Issue 2725133002: Mojo: Armed Watchers (Closed)
Patch Set: rebase Created 3 years, 9 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 #include "mojo/edk/js/waiting_callback.h" 5 #include "mojo/edk/js/waiting_callback.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "gin/per_context_data.h" 9 #include "gin/per_context_data.h"
10 10
(...skipping 14 matching lines...) Expand all
25 25
26 // static 26 // static
27 gin::Handle<WaitingCallback> WaitingCallback::Create( 27 gin::Handle<WaitingCallback> WaitingCallback::Create(
28 v8::Isolate* isolate, 28 v8::Isolate* isolate,
29 v8::Handle<v8::Function> callback, 29 v8::Handle<v8::Function> callback,
30 gin::Handle<HandleWrapper> handle_wrapper, 30 gin::Handle<HandleWrapper> handle_wrapper,
31 MojoHandleSignals signals, 31 MojoHandleSignals signals,
32 bool one_shot) { 32 bool one_shot) {
33 gin::Handle<WaitingCallback> waiting_callback = gin::CreateHandle( 33 gin::Handle<WaitingCallback> waiting_callback = gin::CreateHandle(
34 isolate, new WaitingCallback(isolate, callback, one_shot)); 34 isolate, new WaitingCallback(isolate, callback, one_shot));
35 MojoResult result = waiting_callback->watcher_.Start( 35 MojoResult result = waiting_callback->watcher_.Watch(
36 handle_wrapper->get(), signals, 36 handle_wrapper->get(), signals,
37 base::Bind(&WaitingCallback::OnHandleReady, 37 base::Bind(&WaitingCallback::OnHandleReady,
38 base::Unretained(waiting_callback.get()))); 38 base::Unretained(waiting_callback.get())));
39 39
40 // The signals may already be unsatisfiable. 40 // The signals may already be unsatisfiable.
41 if (result == MOJO_RESULT_FAILED_PRECONDITION) 41 if (result == MOJO_RESULT_FAILED_PRECONDITION)
42 waiting_callback->OnHandleReady(MOJO_RESULT_FAILED_PRECONDITION); 42 waiting_callback->OnHandleReady(MOJO_RESULT_FAILED_PRECONDITION);
43 43
44 return waiting_callback; 44 return waiting_callback;
45 } 45 }
46 46
47 void WaitingCallback::Cancel() { 47 void WaitingCallback::Cancel() {
48 if (watcher_.IsWatching()) 48 if (watcher_.IsWatching())
49 watcher_.Cancel(); 49 watcher_.Cancel();
50 } 50 }
51 51
52 WaitingCallback::WaitingCallback(v8::Isolate* isolate, 52 WaitingCallback::WaitingCallback(v8::Isolate* isolate,
53 v8::Handle<v8::Function> callback, 53 v8::Handle<v8::Function> callback,
54 bool one_shot) 54 bool one_shot)
55 : one_shot_(one_shot), 55 : one_shot_(one_shot),
56 watcher_(FROM_HERE), 56 watcher_(FROM_HERE, SimpleWatcher::ArmingPolicy::AUTOMATIC),
57 weak_factory_(this) { 57 weak_factory_(this) {
58 v8::Handle<v8::Context> context = isolate->GetCurrentContext(); 58 v8::Handle<v8::Context> context = isolate->GetCurrentContext();
59 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); 59 runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
60 GetWrapper(isolate) 60 GetWrapper(isolate)
61 ->SetPrivate(context, GetHiddenPropertyName(isolate), callback) 61 ->SetPrivate(context, GetHiddenPropertyName(isolate), callback)
62 .FromJust(); 62 .FromJust();
63 } 63 }
64 64
65 WaitingCallback::~WaitingCallback() { 65 WaitingCallback::~WaitingCallback() {
66 Cancel(); 66 Cancel();
(...skipping 19 matching lines...) Expand all
86 86
87 if (one_shot_ || result == MOJO_RESULT_CANCELLED) { 87 if (one_shot_ || result == MOJO_RESULT_CANCELLED) {
88 runner_.reset(); 88 runner_.reset();
89 Cancel(); 89 Cancel();
90 } 90 }
91 } 91 }
92 92
93 } // namespace js 93 } // namespace js
94 } // namespace edk 94 } // namespace edk
95 } // namespace mojo 95 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698