Chromium Code Reviews| Index: content/browser/service_worker/service_worker_dispatcher_host.cc |
| diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| index 98e4d7aad4c50c24578001c2f15a1bc69171731f..79b9406d37604ab39d4272519ae958a931480296 100644 |
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| @@ -5,29 +5,53 @@ |
| #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| #include "base/strings/utf_string_conversions.h" |
| -#include "content/browser/service_worker/service_worker_context.h" |
| +#include "content/browser/service_worker/service_worker_context_core.h" |
| +#include "content/browser/service_worker/service_worker_context_wrapper.h" |
| #include "content/common/service_worker_messages.h" |
| #include "ipc/ipc_message_macros.h" |
| #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
| #include "url/gurl.h" |
| -using blink::WebServiceWorkerError; |
| - |
| namespace content { |
| -ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| - int render_process_id, |
| - ServiceWorkerContext* context) : context_(context) {} |
| - |
| -ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {} |
| - |
| namespace { |
| + |
| +const char kDisabledErrorMessage[] = |
| + "ServiceWorker is disabled"; |
| const char kDomainMismatchErrorMessage[] = |
| "Scope and scripts do not have the same origin"; |
| + |
| +// TODO(alecflett): Store the service_worker_id keyed by (domain+pattern, |
| +// script) so we don't always return a new service worker id. |
| +int64 NextWorkerId() { |
| + static int64 service_worker_id = 0; |
| + return service_worker_id++; |
| +} |
| + |
| +} // namespace |
| + |
| +ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| + int render_process_id) { |
|
kinuko
2013/11/09 09:39:56
Oh, we don't use this process_id yet..
michaeln
2013/11/11 16:40:25
i was surprised by that too
|
| +} |
| + |
| +ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() { |
| } |
| -bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| - bool* message_was_ok) { |
| +void ServiceWorkerDispatcherHost::Init( |
| + ServiceWorkerContextWrapper* context_wrapper) { |
| + if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&ServiceWorkerDispatcherHost::Init, |
| + this, context_wrapper)); |
| + return; |
| + } |
| + context_ = context_wrapper->context()->AsWeakPtr(); |
| +} |
| + |
| +bool ServiceWorkerDispatcherHost::OnMessageReceived( |
| + const IPC::Message& message, |
| + bool* message_was_ok) { |
| if (IPC_MESSAGE_CLASS(message) != ServiceWorkerMsgStart) |
| return false; |
| @@ -44,24 +68,17 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(const IPC::Message& message, |
| return handled; |
| } |
| -// TODO(alecflett): Store the service_worker_id keyed by (domain+pattern, |
| -// script) so we don't always return a new service worker id. |
| -static int64 NextWorkerId() { |
| - static int64 service_worker_id = 0; |
| - return service_worker_id++; |
| -} |
| - |
| void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| int32 thread_id, |
| int32 request_id, |
| const GURL& scope, |
| const GURL& script_url) { |
| - if (!context_->IsEnabled()) { |
| + if (!context_ || !context_->IsEnabled()) { |
| Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| thread_id, |
| request_id, |
| blink::WebServiceWorkerError::DisabledError, |
| - ASCIIToUTF16("ServiceWorker is disabled"))); |
| + ASCIIToUTF16(kDisabledErrorMessage))); |
| return; |
| } |
| @@ -87,12 +104,12 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(int32 thread_id, |
| // TODO(alecflett): This check is insufficient for release. Add a |
| // ServiceWorker-specific policy query in |
| // ChildProcessSecurityImpl. See http://crbug.com/311631. |
| - if (!context_->IsEnabled()) { |
| + if (!context_ || !context_->IsEnabled()) { |
| Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| thread_id, |
| request_id, |
| - WebServiceWorkerError::DisabledError, |
| - ASCIIToUTF16("ServiceWorker is disabled"))); |
| + blink::WebServiceWorkerError::DisabledError, |
| + ASCIIToUTF16(kDisabledErrorMessage))); |
| return; |
| } |