diff options
author | yzshen <yzshen@chromium.org> | 2016-02-23 17:27:55 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-24 01:29:19 +0000 |
commit | 418e6f8be0b625b4141380169ed07f5724032ac3 (patch) | |
tree | 01d6a0e5794eb7922e345db86c5ca87818596f53 | |
parent | 7915ae0dd753d281344d748789818dab97c39a37 (diff) | |
download | chromium_src-418e6f8be0b625b4141380169ed07f5724032ac3.zip chromium_src-418e6f8be0b625b4141380169ed07f5724032ac3.tar.gz chromium_src-418e6f8be0b625b4141380169ed07f5724032ac3.tar.bz2 |
Mojo bindings environment: remove usage in mojo/edk/js
BUG=585942
Review URL: https://codereview.chromium.org/1722543003
Cr-Commit-Position: refs/heads/master@{#377178}
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | components/message_port.gypi | 2 | ||||
-rw-r--r-- | content/content_child.gypi | 2 | ||||
-rw-r--r-- | content/content_utility.gypi | 2 | ||||
-rw-r--r-- | mojo/edk/js/BUILD.gn | 2 | ||||
-rw-r--r-- | mojo/edk/js/drain_data.cc | 19 | ||||
-rw-r--r-- | mojo/edk/js/drain_data.h | 9 | ||||
-rw-r--r-- | mojo/edk/js/test/run_js_tests.cc | 1 | ||||
-rw-r--r-- | mojo/edk/js/waiting_callback.cc | 42 | ||||
-rw-r--r-- | mojo/edk/js/waiting_callback.h | 12 | ||||
-rw-r--r-- | mojo/message_pump/handle_watcher.h | 2 | ||||
-rw-r--r-- | mojo/mojo_base.gyp | 31 | ||||
-rw-r--r-- | mojo/mojo_edk.gyp | 1 | ||||
-rw-r--r-- | mojo/mojo_edk_tests.gyp | 2 | ||||
-rw-r--r-- | mojo/mojo_public.gyp | 25 |
15 files changed, 66 insertions, 88 deletions
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2a2e7e2..bb7c1f7 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3347,11 +3347,11 @@ '../mojo/mojo_base.gyp:mojo_application_base', '../mojo/mojo_base.gyp:mojo_common_lib', '../mojo/mojo_base.gyp:mojo_environment_chromium', - '../mojo/mojo_base.gyp:mojo_message_pump_lib', '../mojo/mojo_base.gyp:mojo_url_type_converters', '../mojo/mojo_edk.gyp:mojo_system_impl', '../mojo/mojo_public.gyp:mojo_cpp_bindings', '../mojo/mojo_public.gyp:mojo_js_bindings', + '../mojo/mojo_public.gyp:mojo_message_pump_lib', '../net/net.gyp:net_extras', '../net/net.gyp:net_with_v8', '../storage/storage_browser.gyp:storage', diff --git a/components/message_port.gypi b/components/message_port.gypi index 232782c..4acee9c 100644 --- a/components/message_port.gypi +++ b/components/message_port.gypi @@ -9,7 +9,7 @@ 'type': 'static_library', 'dependencies': [ '../base/base.gyp:base', - '../mojo/mojo_base.gyp:mojo_message_pump_lib', + '../mojo/mojo_public.gyp:mojo_message_pump_lib', '../mojo/mojo_public.gyp:mojo_system_cpp_headers', '../third_party/WebKit/public/blink.gyp:blink', ], diff --git a/content/content_child.gypi b/content/content_child.gypi index d1b0a8f..37fad58 100644 --- a/content/content_child.gypi +++ b/content/content_child.gypi @@ -12,7 +12,7 @@ '../ipc/ipc.gyp:ipc', '../mojo/mojo_base.gyp:mojo_environment_chromium', '../mojo/mojo_base.gyp:mojo_common_lib', - '../mojo/mojo_base.gyp:mojo_message_pump_lib', + '../mojo/mojo_public.gyp:mojo_message_pump_lib', '../skia/skia.gyp:skia', '../storage/storage_common.gyp:storage_common', '../third_party/WebKit/public/blink.gyp:blink', diff --git a/content/content_utility.gypi b/content/content_utility.gypi index c1980da..a826636 100644 --- a/content/content_utility.gypi +++ b/content/content_utility.gypi @@ -9,8 +9,8 @@ '../mojo/mojo_base.gyp:mojo_application_base', '../mojo/mojo_base.gyp:mojo_application_bindings', '../mojo/mojo_base.gyp:mojo_common_lib', - '../mojo/mojo_base.gyp:mojo_message_pump_lib', '../mojo/mojo_public.gyp:mojo_cpp_bindings', + '../mojo/mojo_public.gyp:mojo_message_pump_lib', '../mojo/mojo_shell.gyp:mojo_shell_lib', '../url/url.gyp:url_lib', ], diff --git a/mojo/edk/js/BUILD.gn b/mojo/edk/js/BUILD.gn index 5c28a24..005416d 100644 --- a/mojo/edk/js/BUILD.gn +++ b/mojo/edk/js/BUILD.gn @@ -42,7 +42,7 @@ source_set("js") { ] deps = [ - "//mojo/public/cpp/environment", + "//mojo/message_pump", "//mojo/public/cpp/system", ] } diff --git a/mojo/edk/js/drain_data.cc b/mojo/edk/js/drain_data.cc index bc5d223..3b0a195 100644 --- a/mojo/edk/js/drain_data.cc +++ b/mojo/edk/js/drain_data.cc @@ -7,12 +7,12 @@ #include <stddef.h> #include <stdint.h> +#include "base/bind.h" #include "gin/array_buffer.h" #include "gin/converter.h" #include "gin/dictionary.h" #include "gin/per_context_data.h" #include "gin/per_isolate_data.h" -#include "mojo/public/cpp/environment/environment.h" #include "mojo/public/cpp/system/core.h" namespace mojo { @@ -20,10 +20,7 @@ namespace edk { namespace js { DrainData::DrainData(v8::Isolate* isolate, mojo::Handle handle) - : isolate_(isolate), - handle_(DataPipeConsumerHandle(handle.value())), - wait_id_(0) { - + : isolate_(isolate), handle_(DataPipeConsumerHandle(handle.value())) { v8::Handle<v8::Context> context(isolate_->GetCurrentContext()); runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); @@ -39,22 +36,16 @@ v8::Handle<v8::Value> DrainData::GetPromise() { } DrainData::~DrainData() { - if (wait_id_) - Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_); resolver_.Reset(); } void DrainData::WaitForData() { - wait_id_ = Environment::GetDefaultAsyncWaiter()->AsyncWait( - handle_.get().value(), - MOJO_HANDLE_SIGNAL_READABLE, - MOJO_DEADLINE_INDEFINITE, - &DrainData::WaitCompleted, - this); + handle_watcher_.Start( + handle_.get(), MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, + base::Bind(&DrainData::DataReady, base::Unretained(this))); } void DrainData::DataReady(MojoResult result) { - wait_id_ = 0; if (result != MOJO_RESULT_OK) { DeliverData(result); return; diff --git a/mojo/edk/js/drain_data.h b/mojo/edk/js/drain_data.h index 9fcdba2..13af286 100644 --- a/mojo/edk/js/drain_data.h +++ b/mojo/edk/js/drain_data.h @@ -7,7 +7,7 @@ #include "base/memory/scoped_vector.h" #include "gin/runner.h" -#include "mojo/public/c/environment/async_waiter.h" +#include "mojo/message_pump/handle_watcher.h" #include "mojo/public/cpp/system/core.h" #include "v8/include/v8.h" @@ -34,11 +34,8 @@ class DrainData { private: ~DrainData(); - // Registers an "async waiter" that calls DataReady() via WaitCompleted(). + // Waits for data to be available. DataReady() will be notified. void WaitForData(); - static void WaitCompleted(void* self, MojoResult result) { - static_cast<DrainData*>(self)->DataReady(result); - } // Use ReadData() to read whatever is availble now on handle_ and save // it in data_buffers_. @@ -53,7 +50,7 @@ class DrainData { v8::Isolate* isolate_; ScopedDataPipeConsumerHandle handle_; - MojoAsyncWaitID wait_id_; + common::HandleWatcher handle_watcher_; base::WeakPtr<gin::Runner> runner_; v8::UniquePersistent<v8::Promise::Resolver> resolver_; ScopedVector<DataBuffer> data_buffers_; diff --git a/mojo/edk/js/test/run_js_tests.cc b/mojo/edk/js/test/run_js_tests.cc index eb41b89..d0e8edc 100644 --- a/mojo/edk/js/test/run_js_tests.cc +++ b/mojo/edk/js/test/run_js_tests.cc @@ -11,7 +11,6 @@ #include "gin/test/gtest.h" #include "mojo/edk/js/core.h" #include "mojo/edk/js/support.h" -#include "mojo/public/cpp/environment/environment.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { diff --git a/mojo/edk/js/waiting_callback.cc b/mojo/edk/js/waiting_callback.cc index a28791c..af34d87 100644 --- a/mojo/edk/js/waiting_callback.cc +++ b/mojo/edk/js/waiting_callback.cc @@ -7,7 +7,6 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "gin/per_context_data.h" -#include "mojo/public/cpp/environment/environment.h" namespace mojo { namespace edk { @@ -32,29 +31,27 @@ gin::Handle<WaitingCallback> WaitingCallback::Create( MojoHandleSignals signals) { gin::Handle<WaitingCallback> waiting_callback = gin::CreateHandle( isolate, new WaitingCallback(isolate, callback, handle_wrapper)); - waiting_callback->wait_id_ = Environment::GetDefaultAsyncWaiter()->AsyncWait( - handle_wrapper->get().value(), - signals, - MOJO_DEADLINE_INDEFINITE, - &WaitingCallback::CallOnHandleReady, - waiting_callback.get()); + + waiting_callback->handle_watcher_.Start( + handle_wrapper->get(), signals, MOJO_DEADLINE_INDEFINITE, + base::Bind(&WaitingCallback::OnHandleReady, + base::Unretained(waiting_callback.get()))); return waiting_callback; } void WaitingCallback::Cancel() { - if (!wait_id_) + if (!handle_watcher_.is_watching()) return; - handle_wrapper_->RemoveCloseObserver(this); - handle_wrapper_ = NULL; - Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_); - wait_id_ = 0; + RemoveHandleCloseObserver(); + handle_watcher_.Stop(); } WaitingCallback::WaitingCallback(v8::Isolate* isolate, v8::Handle<v8::Function> callback, gin::Handle<HandleWrapper> handle_wrapper) - : wait_id_(0), handle_wrapper_(handle_wrapper.get()), weak_factory_(this) { + : handle_wrapper_(handle_wrapper.get()), + weak_factory_(this) { handle_wrapper_->AddCloseObserver(this); v8::Handle<v8::Context> context = isolate->GetCurrentContext(); runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); @@ -67,25 +64,18 @@ WaitingCallback::~WaitingCallback() { Cancel(); } -// static -void WaitingCallback::CallOnHandleReady(void* closure, MojoResult result) { - static_cast<WaitingCallback*>(closure)->OnHandleReady(result); -} - -void WaitingCallback::ClearWaitId() { - wait_id_ = 0; +void WaitingCallback::RemoveHandleCloseObserver() { handle_wrapper_->RemoveCloseObserver(this); handle_wrapper_ = nullptr; } void WaitingCallback::OnHandleReady(MojoResult result) { - ClearWaitId(); + RemoveHandleCloseObserver(); CallCallback(result); } void WaitingCallback::CallCallback(MojoResult result) { - // ClearWaitId must already have been called. - DCHECK(!wait_id_); + DCHECK(!handle_watcher_.is_watching()); DCHECK(!handle_wrapper_); if (!runner_) @@ -107,11 +97,11 @@ void WaitingCallback::CallCallback(MojoResult result) { } void WaitingCallback::OnWillCloseHandle() { - Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id_); + handle_watcher_.Stop(); // This may be called from GC, so we can't execute Javascript now, call - // ClearWaitId explicitly, and CallCallback asynchronously. - ClearWaitId(); + // RemoveHandleCloseObserver explicitly, and CallCallback asynchronously. + RemoveHandleCloseObserver(); base::MessageLoop::current()->PostTask( FROM_HERE, base::Bind(&WaitingCallback::CallCallback, weak_factory_.GetWeakPtr(), diff --git a/mojo/edk/js/waiting_callback.h b/mojo/edk/js/waiting_callback.h index b11fcc3..f2554bc 100644 --- a/mojo/edk/js/waiting_callback.h +++ b/mojo/edk/js/waiting_callback.h @@ -12,7 +12,7 @@ #include "gin/wrappable.h" #include "mojo/edk/js/handle.h" #include "mojo/edk/js/handle_close_observer.h" -#include "mojo/public/c/environment/async_waiter.h" +#include "mojo/message_pump/handle_watcher.h" #include "mojo/public/cpp/system/core.h" namespace mojo { @@ -42,21 +42,19 @@ class WaitingCallback : public gin::Wrappable<WaitingCallback>, gin::Handle<HandleWrapper> handle_wrapper); ~WaitingCallback() override; - // Callback from MojoAsyncWaiter. |closure| is the WaitingCallback. - static void CallOnHandleReady(void* closure, MojoResult result); - - // Invoked from CallOnHandleReady() (CallOnHandleReady() must be static). + // Callback from common::HandleWatcher. void OnHandleReady(MojoResult result); // Invoked by the HandleWrapper if the handle is closed while this wait is // still in progress. void OnWillCloseHandle() override; - void ClearWaitId(); + void RemoveHandleCloseObserver(); void CallCallback(MojoResult result); base::WeakPtr<gin::Runner> runner_; - MojoAsyncWaitID wait_id_; + + common::HandleWatcher handle_watcher_; HandleWrapper* handle_wrapper_; base::WeakPtrFactory<WaitingCallback> weak_factory_; diff --git a/mojo/message_pump/handle_watcher.h b/mojo/message_pump/handle_watcher.h index d855e45..18211ca 100644 --- a/mojo/message_pump/handle_watcher.h +++ b/mojo/message_pump/handle_watcher.h @@ -45,6 +45,8 @@ class MOJO_MESSAGE_PUMP_EXPORT HandleWatcher { // Stops listening. Does nothing if not in the process of listening. void Stop(); + bool is_watching() const { return !!state_; } + private: class StateBase; class SameThreadWatchingState; diff --git a/mojo/mojo_base.gyp b/mojo/mojo_base.gyp index 8f54076..890ab41 100644 --- a/mojo/mojo_base.gyp +++ b/mojo/mojo_base.gyp @@ -36,31 +36,6 @@ 'type': 'none', }, { - # GN version: //mojo/message_pump - 'target_name': 'mojo_message_pump_lib', - 'type': '<(component)', - 'defines': [ - 'MOJO_MESSAGE_PUMP_IMPLEMENTATION', - ], - 'dependencies': [ - '../base/base.gyp:base', - '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', - '<(mojo_system_for_component)', - ], - 'export_dependent_settings': [ - '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', - ], - 'sources': [ - 'message_pump/handle_watcher.cc', - 'message_pump/handle_watcher.h', - 'message_pump/message_pump_mojo.cc', - 'message_pump/message_pump_mojo.h', - 'message_pump/message_pump_mojo_handler.h', - 'message_pump/time_helper.cc', - 'message_pump/time_helper.h', - ], - }, - { # GN version: //mojo/common 'target_name': 'mojo_common_lib', 'type': '<(component)', @@ -135,8 +110,8 @@ 'mojo_edk.gyp:mojo_common_test_support', 'mojo_edk.gyp:mojo_run_all_unittests', 'mojo_environment_chromium', - 'mojo_message_pump_lib', 'mojo_public.gyp:mojo_cpp_bindings', + 'mojo_public.gyp:mojo_message_pump_lib', 'mojo_public.gyp:mojo_public_test_utils', 'mojo_url_type_converters', ], @@ -182,7 +157,7 @@ 'dependencies': [ '../base/base.gyp:base', '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', - 'mojo_message_pump_lib', + 'mojo_public.gyp:mojo_message_pump_lib', '<(mojo_system_for_component)', ], 'sources': [ @@ -244,7 +219,7 @@ 'dependencies': [ '../base/base.gyp:base_i18n', 'mojo_application_bindings', - 'mojo_message_pump_lib', + 'mojo_public.gyp:mojo_message_pump_lib', 'mojo_services.gyp:network_type_converters', ], }, diff --git a/mojo/mojo_edk.gyp b/mojo/mojo_edk.gyp index 989e503..144d8c0 100644 --- a/mojo/mojo_edk.gyp +++ b/mojo/mojo_edk.gyp @@ -150,6 +150,7 @@ '../base/base.gyp:base', '../gin/gin.gyp:gin', '../v8/tools/gyp/v8.gyp:v8', + 'mojo_public.gyp:mojo_message_pump_lib', ], 'export_dependent_settings': [ '../base/base.gyp:base', diff --git a/mojo/mojo_edk_tests.gyp b/mojo/mojo_edk_tests.gyp index e55389c..03e60d3 100644 --- a/mojo/mojo_edk_tests.gyp +++ b/mojo/mojo_edk_tests.gyp @@ -48,9 +48,9 @@ 'dependencies': [ '../testing/gtest.gyp:gtest', 'mojo_base.gyp:mojo_environment_chromium', - 'mojo_base.gyp:mojo_message_pump_lib', 'mojo_edk.gyp:mojo_run_all_unittests', 'mojo_public.gyp:mojo_cpp_bindings', + 'mojo_public.gyp:mojo_message_pump_lib', 'mojo_public.gyp:mojo_public_bindings_test_utils', 'mojo_public.gyp:mojo_public_test_associated_interfaces', 'mojo_public.gyp:mojo_public_test_interfaces', diff --git a/mojo/mojo_public.gyp b/mojo/mojo_public.gyp index d833edd..3017df8 100644 --- a/mojo/mojo_public.gyp +++ b/mojo/mojo_public.gyp @@ -188,6 +188,31 @@ ], }, { + # GN version: //mojo/message_pump + 'target_name': 'mojo_message_pump_lib', + 'type': '<(component)', + 'defines': [ + 'MOJO_MESSAGE_PUMP_IMPLEMENTATION', + ], + 'dependencies': [ + '../base/base.gyp:base', + '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + '<(mojo_system_for_component)', + ], + 'export_dependent_settings': [ + '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + ], + 'sources': [ + 'message_pump/handle_watcher.cc', + 'message_pump/handle_watcher.h', + 'message_pump/message_pump_mojo.cc', + 'message_pump/message_pump_mojo.h', + 'message_pump/message_pump_mojo_handler.h', + 'message_pump/time_helper.cc', + 'message_pump/time_helper.h', + ], + }, + { # GN version: //mojo/public/js 'target_name': 'mojo_js_bindings', 'type': 'static_library', |