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

Unified Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 1221503003: Add a mojo ServiceRegistry to embedded workers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: copy content/common/*.mojom OWNERS to service_worker subdirectory Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/embedded_worker_instance.cc
diff --git a/content/browser/service_worker/embedded_worker_instance.cc b/content/browser/service_worker/embedded_worker_instance.cc
index 64f122f45e5c4f489abb264814848b27414de1b2..9866014e2e905319a41b8e3e26cd31b874d107c8 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
@@ -202,6 +218,10 @@ ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage(
thread_id_, embedded_worker_id_, message));
}
+ServiceRegistry* EmbeddedWorkerInstance::GetServiceRegistry() {
michaeln 2015/07/15 02:34:22 Maybe DCHECK its either STARTING or RUNNING and se
Marijn Kruisselbrink 2015/07/15 18:13:28 I added the DCHECK and moved the creating of the s
+ return service_registry_.get();
+}
+
EmbeddedWorkerInstance::EmbeddedWorkerInstance(
base::WeakPtr<ServiceWorkerContextCore> context,
int embedded_worker_id)
@@ -344,6 +364,19 @@ void EmbeddedWorkerInstance::OnScriptLoaded(int thread_id) {
}
thread_id_ = thread_id;
FOR_EACH_OBSERVER(Listener, listener_list_, OnScriptLoaded());
+
+ service_registry_.reset(new ServiceRegistryImpl());
+ 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() {
@@ -376,6 +409,7 @@ void EmbeddedWorkerInstance::OnStarted() {
void EmbeddedWorkerInstance::OnStopped() {
Status old_status = status_;
ReleaseProcess();
+ service_registry_.reset();
FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped(old_status));
}

Powered by Google App Engine
This is Rietveld 408576698