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..8fbd97374bb3b2a0f6ab3b7db48c4bf27c424409 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 the active worker can claim clients."; |
| + |
| +const char kClaimClientsShutdownErrorMesage[] = |
| + "Failed to claim clients due to Service Worker system shutdown."; |
| + |
| void RunSoon(const base::Closure& callback) { |
| if (!callback.is_null()) |
| base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| @@ -158,6 +165,7 @@ ServiceWorkerVersion::ServiceWorkerVersion( |
| script_cache_map_(this, context), |
| is_doomed_(false), |
| skip_waiting_(false), |
| + claiming_clients_(false), |
| weak_factory_(this) { |
| DCHECK(context_); |
| DCHECK(registration); |
| @@ -800,6 +808,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 +1115,30 @@ 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; |
|
falken
2015/01/29 15:10:37
nullptr
xiang
2015/01/30 07:18:57
Done.
|
| + if (!context_ || |
| + !(registration = context_->GetLiveRegistration(registration_id_))) { |
| + embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError( |
| + request_id, blink::WebServiceWorkerError::ErrorTypeAbort, |
| + base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage))); |
| + return; |
| + } |
| + |
| + DCHECK_EQ(this, registration->active_version()); |
| + claiming_clients_ = true; |
| + registration->ClaimClients(); |
| + claiming_clients_ = false; |
| + embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id)); |
| +} |
| + |
| void ServiceWorkerVersion::DidGetClientInfo( |
| int client_id, |
| scoped_refptr<GetClientDocumentsCallback> callback, |