Chromium Code Reviews| Index: content/renderer/service_worker/embedded_worker_context_client.cc |
| diff --git a/content/renderer/service_worker/embedded_worker_context_client.cc b/content/renderer/service_worker/embedded_worker_context_client.cc |
| index eef9919b339070677665fea74d012ab203724b90..69ab6a729205dbe4f01a3929365d614cf335e17c 100644 |
| --- a/content/renderer/service_worker/embedded_worker_context_client.cc |
| +++ b/content/renderer/service_worker/embedded_worker_context_client.cc |
| @@ -15,7 +15,12 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/threading/thread_local.h" |
| #include "content/child/request_extra_data.h" |
| +#include "content/child/service_worker/service_worker_dispatcher.h" |
| #include "content/child/service_worker/service_worker_network_provider.h" |
| +#include "content/child/service_worker/service_worker_provider_context.h" |
| +#include "content/child/service_worker/service_worker_registration_handle_reference.h" |
| +#include "content/child/service_worker/web_service_worker_impl.h" |
| +#include "content/child/service_worker/web_service_worker_registration_impl.h" |
| #include "content/child/thread_safe_sender.h" |
| #include "content/child/worker_task_runner.h" |
| #include "content/child/worker_thread_task_runner.h" |
| @@ -176,6 +181,8 @@ void EmbeddedWorkerContextClient::workerContextStarted( |
| g_worker_client_tls.Pointer()->Set(this); |
| script_context_.reset(new ServiceWorkerScriptContext(this, proxy)); |
| + SetRegistrationInServiceWorkerGlobalScope(); |
| + |
| Send(new EmbeddedWorkerHostMsg_WorkerScriptLoaded( |
| embedded_worker_id_, |
| WorkerTaskRunner::Instance()->CurrentWorkerId())); |
| @@ -348,10 +355,13 @@ void EmbeddedWorkerContextClient::didHandleCrossOriginConnectEvent( |
| blink::WebServiceWorkerNetworkProvider* |
| EmbeddedWorkerContextClient::createServiceWorkerNetworkProvider( |
| blink::WebDataSource* data_source) { |
| + DCHECK(main_thread_proxy_->RunsTasksOnCurrentThread()); |
| + |
| // Create a content::ServiceWorkerNetworkProvider for this data source so |
| // we can observe its requests. |
| scoped_ptr<ServiceWorkerNetworkProvider> provider( |
| new ServiceWorkerNetworkProvider(MSG_ROUTING_NONE)); |
| + provider_context_ = provider->context(); |
| // Tell the network provider about which version to load. |
| provider->SetServiceWorkerVersionId(service_worker_version_id_); |
| @@ -415,4 +425,32 @@ void EmbeddedWorkerContextClient::SendWorkerStarted() { |
| Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_)); |
| } |
| +void EmbeddedWorkerContextClient::SetRegistrationInServiceWorkerGlobalScope() { |
| + DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| + DCHECK(provider_context_); |
| + DCHECK(script_context_); |
| + |
| + ServiceWorkerDispatcher* dispatcher = |
| + ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| + thread_safe_sender()); |
| + |
| + // Register a registration with the dispatcher living on the worker thread. |
| + scoped_ptr<WebServiceWorkerRegistrationImpl> registration( |
| + dispatcher->CreateServiceWorkerRegistration( |
| + provider_context_->registration()->info(), false)); |
| + |
| + // Register workers with the dispatcher living on the worker thread. |
| + ServiceWorkerVersionAttributes attrs = |
| + provider_context_->GetVersionAttributes(); |
|
kinuko
2015/01/22 08:05:44
It feels it's a bit odd to call two locked methods
nhiroki
2015/01/22 09:09:16
Agree. I'll make a followup patch (probably we can
|
| + registration->SetInstalling( |
| + dispatcher->GetServiceWorker(attrs.installing, false)); |
| + registration->SetWaiting( |
| + dispatcher->GetServiceWorker(attrs.waiting, false)); |
| + registration->SetActive( |
| + dispatcher->GetServiceWorker(attrs.active, false)); |
| + |
| + script_context_->SetRegistrationInServiceWorkerGlobalScope( |
| + registration.Pass()); |
| +} |
| + |
| } // namespace content |