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

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 871853002: ServiceWorker: add ServiceWorkerClients.claim() support (2/3). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change error type Created 5 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_version.h" 5 #include "content/browser/service_worker/service_worker_version.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/message_port_message_filter.h" 12 #include "content/browser/message_port_message_filter.h"
12 #include "content/browser/message_port_service.h" 13 #include "content/browser/message_port_service.h"
13 #include "content/browser/service_worker/embedded_worker_instance.h" 14 #include "content/browser/service_worker/embedded_worker_instance.h"
14 #include "content/browser/service_worker/embedded_worker_registry.h" 15 #include "content/browser/service_worker/embedded_worker_registry.h"
15 #include "content/browser/service_worker/service_worker_context_core.h" 16 #include "content/browser/service_worker/service_worker_context_core.h"
16 #include "content/browser/service_worker/service_worker_registration.h" 17 #include "content/browser/service_worker/service_worker_registration.h"
17 #include "content/browser/service_worker/service_worker_utils.h" 18 #include "content/browser/service_worker/service_worker_utils.h"
18 #include "content/common/service_worker/service_worker_messages.h" 19 #include "content/common/service_worker/service_worker_messages.h"
19 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // (Note that if all references to the version is dropped the worker 65 // (Note that if all references to the version is dropped the worker
65 // is also stopped without delay) 66 // is also stopped without delay)
66 const int64 kStopWorkerDelay = 30; // 30 secs. 67 const int64 kStopWorkerDelay = 30; // 30 secs.
67 68
68 // Delay for attempting to stop a doomed worker with in-flight requests. 69 // Delay for attempting to stop a doomed worker with in-flight requests.
69 const int64 kStopDoomedWorkerDelay = 5; // 5 secs. 70 const int64 kStopDoomedWorkerDelay = 5; // 5 secs.
70 71
71 // Default delay for scheduled update. 72 // Default delay for scheduled update.
72 const int kUpdateDelaySeconds = 1; 73 const int kUpdateDelaySeconds = 1;
73 74
75 const char kClaimClientsStateErrorMesage[] =
76 "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.
77
78 const char kClaimClientsShutdownErrorMesage[] =
79 "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.
80
74 void RunSoon(const base::Closure& callback) { 81 void RunSoon(const base::Closure& callback) {
75 if (!callback.is_null()) 82 if (!callback.is_null())
76 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 83 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
77 } 84 }
78 85
79 template <typename CallbackArray, typename Arg> 86 template <typename CallbackArray, typename Arg>
80 void RunCallbacks(ServiceWorkerVersion* version, 87 void RunCallbacks(ServiceWorkerVersion* version,
81 CallbackArray* callbacks_ptr, 88 CallbackArray* callbacks_ptr,
82 const Arg& arg) { 89 const Arg& arg) {
83 CallbackArray callbacks; 90 CallbackArray callbacks;
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument, 800 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToDocument,
794 OnPostMessageToDocument) 801 OnPostMessageToDocument)
795 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, 802 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient,
796 OnFocusClient) 803 OnFocusClient)
797 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientInfoSuccess, 804 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientInfoSuccess,
798 OnGetClientInfoSuccess) 805 OnGetClientInfoSuccess)
799 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientInfoError, 806 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetClientInfoError,
800 OnGetClientInfoError) 807 OnGetClientInfoError)
801 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, 808 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting,
802 OnSkipWaiting) 809 OnSkipWaiting)
810 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients,
811 OnClaimClients)
803 IPC_MESSAGE_UNHANDLED(handled = false) 812 IPC_MESSAGE_UNHANDLED(handled = false)
804 IPC_END_MESSAGE_MAP() 813 IPC_END_MESSAGE_MAP()
805 return handled; 814 return handled;
806 } 815 }
807 816
808 void ServiceWorkerVersion::OnStartMessageSent( 817 void ServiceWorkerVersion::OnStartMessageSent(
809 ServiceWorkerStatusCode status) { 818 ServiceWorkerStatusCode status) {
810 if (status != SERVICE_WORKER_OK) 819 if (status != SERVICE_WORKER_OK)
811 RunCallbacks(this, &start_callbacks_, status); 820 RunCallbacks(this, &start_callbacks_, status);
812 } 821 }
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 pending_skip_waiting_requests_.push_back(request_id); 1107 pending_skip_waiting_requests_.push_back(request_id);
1099 if (pending_skip_waiting_requests_.size() == 1) 1108 if (pending_skip_waiting_requests_.size() == 1)
1100 registration->ActivateWaitingVersionWhenReady(); 1109 registration->ActivateWaitingVersionWhenReady();
1101 } 1110 }
1102 1111
1103 void ServiceWorkerVersion::DidSkipWaiting(int request_id) { 1112 void ServiceWorkerVersion::DidSkipWaiting(int request_id) {
1104 if (running_status() == STARTING || running_status() == RUNNING) 1113 if (running_status() == STARTING || running_status() == RUNNING)
1105 embedded_worker_->SendMessage(ServiceWorkerMsg_DidSkipWaiting(request_id)); 1114 embedded_worker_->SendMessage(ServiceWorkerMsg_DidSkipWaiting(request_id));
1106 } 1115 }
1107 1116
1117 void ServiceWorkerVersion::OnClaimClients(int request_id) {
1118 if (status_ != ACTIVATING && status_ != ACTIVATED) {
1119 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError(
1120 request_id, blink::WebServiceWorkerError::ErrorTypeState,
1121 base::ASCIIToUTF16(kClaimClientsStateErrorMesage)));
1122 return;
1123 }
1124
1125 ServiceWorkerRegistration* registration = NULL;
1126 if (!context_ ||
1127 !(registration = context_->GetLiveRegistration(registration_id_))) {
1128 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError(
1129 request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
1130 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage)));
1131 return;
1132 }
falken 2015/01/26 08:45:13 maybe add DCHECK_EQ(this, registration->active_ver
xiang 2015/01/28 05:38:35 Done.
1133 registration->ClaimClients();
1134 embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id));
1135 }
1136
1108 void ServiceWorkerVersion::DidGetClientInfo( 1137 void ServiceWorkerVersion::DidGetClientInfo(
1109 int client_id, 1138 int client_id,
1110 scoped_refptr<GetClientDocumentsCallback> callback, 1139 scoped_refptr<GetClientDocumentsCallback> callback,
1111 ServiceWorkerStatusCode status, 1140 ServiceWorkerStatusCode status,
1112 const ServiceWorkerClientInfo& info) { 1141 const ServiceWorkerClientInfo& info) {
1113 if (status == SERVICE_WORKER_OK) 1142 if (status == SERVICE_WORKER_OK)
1114 callback->AddClientInfo(client_id, info); 1143 callback->AddClientInfo(client_id, info);
1115 } 1144 }
1116 1145
1117 void ServiceWorkerVersion::ScheduleStopWorker() { 1146 void ServiceWorkerVersion::ScheduleStopWorker() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 int request_id) { 1201 int request_id) {
1173 callbacks->Remove(request_id); 1202 callbacks->Remove(request_id);
1174 if (is_doomed_) { 1203 if (is_doomed_) {
1175 // The stop should be already scheduled, but try to stop immediately, in 1204 // The stop should be already scheduled, but try to stop immediately, in
1176 // order to release worker resources soon. 1205 // order to release worker resources soon.
1177 StopWorkerIfIdle(); 1206 StopWorkerIfIdle();
1178 } 1207 }
1179 } 1208 }
1180 1209
1181 } // namespace content 1210 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698