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

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

Issue 1350023003: Add a Mojo EDK for Chrome that uses one OS pipe per message pipe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanup Created 5 years, 2 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 "third_party/mojo/src/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 #include "mojo/public/cpp/environment/environment.h" 10 #include "mojo/public/cpp/environment/environment.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace js { 13 namespace edk {
14 14
15 namespace { 15 namespace {
16 16
17 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) { 17 v8::Handle<v8::String> GetHiddenPropertyName(v8::Isolate* isolate) {
18 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback"); 18 return gin::StringToSymbol(isolate, "::mojo::js::WaitingCallback");
19 } 19 }
20 20
21 } // namespace 21 } // namespace
22 22
23 gin::WrapperInfo WaitingCallback::kWrapperInfo = { gin::kEmbedderNativeGin }; 23 gin::WrapperInfo WaitingCallback::kWrapperInfo = { gin::kEmbedderNativeGin };
24 24
25 // static 25 // static
26 gin::Handle<WaitingCallback> WaitingCallback::Create( 26 gin::Handle<WaitingCallback> WaitingCallback::Create(
27 v8::Isolate* isolate, 27 v8::Isolate* isolate,
28 v8::Handle<v8::Function> callback, 28 v8::Handle<v8::Function> callback,
29 gin::Handle<HandleWrapper> handle_wrapper, 29 gin::Handle<HandleWrapper> handle_wrapper,
30 MojoHandleSignals signals) { 30 MojoHandleSignals signals) {
31 gin::Handle<WaitingCallback> waiting_callback = gin::CreateHandle( 31 gin::Handle<WaitingCallback> waiting_callback = gin::CreateHandle(
32 isolate, new WaitingCallback(isolate, callback, handle_wrapper)); 32 isolate, new WaitingCallback(isolate, callback, handle_wrapper));
33 waiting_callback->wait_id_ = Environment::GetDefaultAsyncWaiter()->AsyncWait( 33 waiting_callback->wait_id_ = Environment::GetDefaultAsyncWaiter()->AsyncWait(
34 3, handle_wrapper->get().value(), signals, MOJO_DEADLINE_INDEFINITE, 34 handle_wrapper->get().value(),
35 &WaitingCallback::CallOnHandleReady, waiting_callback.get()); 35 signals,
36 MOJO_DEADLINE_INDEFINITE,
37 &WaitingCallback::CallOnHandleReady,
38 waiting_callback.get());
36 return waiting_callback; 39 return waiting_callback;
37 } 40 }
38 41
39 void WaitingCallback::Cancel() { 42 void WaitingCallback::Cancel() {
40 if (!wait_id_) 43 if (!wait_id_)
41 return; 44 return;
42 45
43 handle_wrapper_->RemoveCloseObserver(this); 46 handle_wrapper_->RemoveCloseObserver(this);
44 handle_wrapper_ = NULL; 47 handle_wrapper_ = NULL;
45 Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_); 48 Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 104
102 // This may be called from GC, so we can't execute Javascript now, call 105 // This may be called from GC, so we can't execute Javascript now, call
103 // ClearWaitId explicitly, and CallCallback asynchronously. 106 // ClearWaitId explicitly, and CallCallback asynchronously.
104 ClearWaitId(); 107 ClearWaitId();
105 base::MessageLoop::current()->PostTask( 108 base::MessageLoop::current()->PostTask(
106 FROM_HERE, 109 FROM_HERE,
107 base::Bind(&WaitingCallback::CallCallback, weak_factory_.GetWeakPtr(), 110 base::Bind(&WaitingCallback::CallCallback, weak_factory_.GetWeakPtr(),
108 MOJO_RESULT_INVALID_ARGUMENT)); 111 MOJO_RESULT_INVALID_ARGUMENT));
109 } 112 }
110 113
111 } // namespace js 114 } // namespace edk
112 } // namespace mojo 115 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/js/waiting_callback.h ('k') | mojo/edk/mojo_edk.gni » ('j') | mojo/edk/system/core.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698