diff options
author | mek <mek@chromium.org> | 2015-07-16 11:30:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-16 18:30:55 +0000 |
commit | 27c9d745b80924002ac4c053fe77f6d9be0f1089 (patch) | |
tree | aae867e393f673ad7871de2ba738846c8ea74d74 /content/browser/service_worker | |
parent | 8671e55a378e1dba2b065cca7b4ed3895a0b62e5 (diff) | |
download | chromium_src-27c9d745b80924002ac4c053fe77f6d9be0f1089.zip chromium_src-27c9d745b80924002ac4c053fe77f6d9be0f1089.tar.gz chromium_src-27c9d745b80924002ac4c053fe77f6d9be0f1089.tar.bz2 |
Add a mojo ServiceRegistry to embedded workers.
This sets up a pair of linked ServiceRegistry instances between the
EmbeddedWorkerInstance in the browser and ServiceWorkerContextClient
in the renderer. These ServiceRegistries can be used to use mojo to
dispatch events to a serviceworker, avoiding any need for
thread-hopping.
This is used in https://codereview.chromium.org/1210643002 to implement
the new navigator.services.onconnect event and in
https://codereview.chromium.org/1220943003 for the background sync event.
BUG=426458
Review URL: https://codereview.chromium.org/1221503003
Cr-Commit-Position: refs/heads/master@{#339082}
Diffstat (limited to 'content/browser/service_worker')
-rw-r--r-- | content/browser/service_worker/embedded_worker_instance.cc | 36 | ||||
-rw-r--r-- | content/browser/service_worker/embedded_worker_instance.h | 7 |
2 files changed, 43 insertions, 0 deletions
diff --git a/content/browser/service_worker/embedded_worker_instance.cc b/content/browser/service_worker/embedded_worker_instance.cc index 64f122f..c79fdfe 100644 --- a/content/browser/service_worker/embedded_worker_instance.cc +++ b/content/browser/service_worker/embedded_worker_instance.cc @@ -15,7 +15,9 @@ #include "content/browser/service_worker/embedded_worker_registry.h" #include "content/browser/service_worker/service_worker_context_core.h" #include "content/common/content_switches_internal.h" +#include "content/common/mojo/service_registry_impl.h" #include "content/common/service_worker/embedded_worker_messages.h" +#include "content/common/service_worker/embedded_worker_setup.mojom.h" #include "content/common/service_worker/service_worker_types.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" @@ -83,6 +85,20 @@ void RegisterToWorkerDevToolsManagerOnUI( base::Bind(callback, worker_devtools_agent_route_id, wait_for_debugger)); } +void SetupMojoOnUIThread(int process_id, + int thread_id, + mojo::InterfaceRequest<mojo::ServiceProvider> services, + mojo::ServiceProviderPtr exposed_services) { + RenderProcessHost* rph = RenderProcessHost::FromID(process_id); + // |rph| may be NULL in unit tests. + if (!rph) + return; + EmbeddedWorkerSetupPtr setup; + rph->GetServiceRegistry()->ConnectToRemoteService(mojo::GetProxy(&setup)); + setup->ExchangeServiceProviders(thread_id, services.Pass(), + exposed_services.Pass()); +} + } // namespace // Lives on IO thread, proxies notifications to DevToolsManager that lives on @@ -145,6 +161,7 @@ void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, status_ = STARTING; starting_phase_ = ALLOCATING_PROCESS; network_accessed_for_script_ = false; + service_registry_.reset(new ServiceRegistryImpl()); FOR_EACH_OBSERVER(Listener, listener_list_, OnStarting()); scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( new EmbeddedWorkerMsg_StartWorker_Params()); @@ -202,6 +219,11 @@ ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( thread_id_, embedded_worker_id_, message)); } +ServiceRegistry* EmbeddedWorkerInstance::GetServiceRegistry() { + DCHECK(status_ == STARTING || status_ == RUNNING) << status_; + return service_registry_.get(); +} + EmbeddedWorkerInstance::EmbeddedWorkerInstance( base::WeakPtr<ServiceWorkerContextCore> context, int embedded_worker_id) @@ -257,6 +279,7 @@ void EmbeddedWorkerInstance::ProcessAllocated( if (status != SERVICE_WORKER_OK) { Status old_status = status_; status_ = STOPPED; + service_registry_.reset(); callback.Run(status); FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped(old_status)); return; @@ -344,6 +367,18 @@ void EmbeddedWorkerInstance::OnScriptLoaded(int thread_id) { } thread_id_ = thread_id; FOR_EACH_OBSERVER(Listener, listener_list_, OnScriptLoaded()); + + mojo::ServiceProviderPtr exposed_services; + service_registry_->Bind(GetProxy(&exposed_services)); + mojo::ServiceProviderPtr services; + mojo::InterfaceRequest<mojo::ServiceProvider> services_request = + GetProxy(&services); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(SetupMojoOnUIThread, process_id_, thread_id_, + base::Passed(&services_request), + base::Passed(&exposed_services))); + service_registry_->BindRemoteServiceProvider(services.Pass()); } void EmbeddedWorkerInstance::OnScriptLoadFailed() { @@ -449,6 +484,7 @@ void EmbeddedWorkerInstance::ReleaseProcess() { status_ = STOPPED; process_id_ = -1; thread_id_ = -1; + service_registry_.reset(); start_callback_.Reset(); } diff --git a/content/browser/service_worker/embedded_worker_instance.h b/content/browser/service_worker/embedded_worker_instance.h index f0f3431..5993a40 100644 --- a/content/browser/service_worker/embedded_worker_instance.h +++ b/content/browser/service_worker/embedded_worker_instance.h @@ -37,6 +37,8 @@ namespace content { class EmbeddedWorkerRegistry; class MessagePortMessageFilter; +class ServiceRegistry; +class ServiceRegistryImpl; class ServiceWorkerContextCore; struct ServiceWorkerFetchRequest; @@ -118,6 +120,10 @@ class CONTENT_EXPORT EmbeddedWorkerInstance { // status. ServiceWorkerStatusCode SendMessage(const IPC::Message& message); + // Returns the ServiceRegistry for this worker. It is invalid to call this + // when the worker is not in STARTING or RUNNING status. + ServiceRegistry* GetServiceRegistry(); + int embedded_worker_id() const { return embedded_worker_id_; } Status status() const { return status_; } StartingPhase starting_phase() const { @@ -235,6 +241,7 @@ class CONTENT_EXPORT EmbeddedWorkerInstance { // Current running information. -1 indicates the worker is not running. int process_id_; int thread_id_; + scoped_ptr<ServiceRegistryImpl> service_registry_; // Whether devtools is attached or not. bool devtools_attached_; |