Chromium Code Reviews| Index: content/browser/service_worker/service_worker_version.cc |
| diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc |
| index 09cd6f3ea2f6c3f317a795b65c6859a75188fd90..58e7972b4dc2da5b37227f4724a021f6c7a391d2 100644 |
| --- a/content/browser/service_worker/service_worker_version.cc |
| +++ b/content/browser/service_worker/service_worker_version.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/memory/ref_counted.h" |
| #include "base/stl_util.h" |
| #include "base/strings/string16.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "content/browser/message_port_message_filter.h" |
| #include "content/browser/message_port_service.h" |
| #include "content/browser/service_worker/embedded_worker_instance.h" |
| @@ -71,6 +72,12 @@ const int64 kStopDoomedWorkerDelay = 5; // 5 secs. |
| // Default delay for scheduled update. |
| const int kUpdateDelaySeconds = 1; |
| +const char kClaimClientsStateErrorMesage[] = |
| + "Only active worker can claim clients."; |
|
falken
2015/01/26 08:45:13
s/Only active/Only the active/
xiang
2015/01/28 05:38:35
Done.
|
| + |
| +const char kClaimClientsShutdownErrorMesage[] = |
| + "Failed to claim clients due to ServiceWorker system shutdown."; |
|
falken
2015/01/26 08:45:13
s/ServiceWorker/Service Worker/
xiang
2015/01/28 05:38:35
Done.
|
| + |
| void RunSoon(const base::Closure& callback) { |
| if (!callback.is_null()) |
| base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| @@ -800,6 +807,8 @@ bool ServiceWorkerVersion::OnMessageReceived(const IPC::Message& message) { |
| OnGetClientInfoError) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, |
| OnSkipWaiting) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, |
| + OnClaimClients) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -1105,6 +1114,26 @@ void ServiceWorkerVersion::DidSkipWaiting(int request_id) { |
| embedded_worker_->SendMessage(ServiceWorkerMsg_DidSkipWaiting(request_id)); |
| } |
| +void ServiceWorkerVersion::OnClaimClients(int request_id) { |
| + if (status_ != ACTIVATING && status_ != ACTIVATED) { |
| + embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError( |
| + request_id, blink::WebServiceWorkerError::ErrorTypeState, |
| + base::ASCIIToUTF16(kClaimClientsStateErrorMesage))); |
| + return; |
| + } |
| + |
| + ServiceWorkerRegistration* registration = NULL; |
| + if (!context_ || |
| + !(registration = context_->GetLiveRegistration(registration_id_))) { |
| + embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError( |
| + request_id, blink::WebServiceWorkerError::ErrorTypeAbort, |
| + base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); |
| + return; |
| + } |
|
falken
2015/01/26 08:45:13
maybe add DCHECK_EQ(this, registration->active_ver
xiang
2015/01/28 05:38:35
Done.
|
| + registration->ClaimClients(); |
| + embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id)); |
| +} |
| + |
| void ServiceWorkerVersion::DidGetClientInfo( |
| int client_id, |
| scoped_refptr<GetClientDocumentsCallback> callback, |