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

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 517493002: ServiceWorker: Update the install sequence as per the latest spec (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/child/service_worker/service_worker_dispatcher.h" 5 #include "content/child/service_worker/service_worker_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/threading/thread_local.h" 9 #include "base/threading/thread_local.h"
10 #include "content/child/child_thread.h" 10 #include "content/child/child_thread.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) 55 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg)
56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) 56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered)
57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered,
58 OnUnregistered) 58 OnUnregistered)
59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, 59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
60 OnRegistrationError) 60 OnRegistrationError)
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
62 OnServiceWorkerStateChanged) 62 OnServiceWorkerStateChanged)
63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
64 OnSetVersionAttributes) 64 OnSetVersionAttributes)
65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
66 OnUpdateFound)
65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
66 OnSetControllerServiceWorker) 68 OnSetControllerServiceWorker)
67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
68 OnPostMessage) 70 OnPostMessage)
69 IPC_MESSAGE_UNHANDLED(handled = false) 71 IPC_MESSAGE_UNHANDLED(handled = false)
70 IPC_END_MESSAGE_MAP() 72 IPC_END_MESSAGE_MAP()
71 DCHECK(handled) << "Unhandled message:" << msg.type(); 73 DCHECK(handled) << "Unhandled message:" << msg.type();
72 } 74 }
73 75
74 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { 76 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 info, thread_safe_sender_.get()); 233 info, thread_safe_sender_.get());
232 234
233 // WebServiceWorkerRegistrationImpl constructor calls 235 // WebServiceWorkerRegistrationImpl constructor calls
234 // AddServiceWorkerRegistration. 236 // AddServiceWorkerRegistration.
235 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); 237 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass());
236 } 238 }
237 239
238 void ServiceWorkerDispatcher::OnRegistered( 240 void ServiceWorkerDispatcher::OnRegistered(
239 int thread_id, 241 int thread_id,
240 int request_id, 242 int request_id,
241 const ServiceWorkerRegistrationObjectInfo& info) { 243 const ServiceWorkerRegistrationObjectInfo& info,
244 const ServiceWorkerVersionAttributes& attrs) {
242 WebServiceWorkerRegistrationCallbacks* callbacks = 245 WebServiceWorkerRegistrationCallbacks* callbacks =
243 pending_callbacks_.Lookup(request_id); 246 pending_callbacks_.Lookup(request_id);
244 DCHECK(callbacks); 247 DCHECK(callbacks);
245 if (!callbacks) 248 if (!callbacks)
246 return; 249 return;
247 250
248 callbacks->onSuccess(GetServiceWorkerRegistration(info, true)); 251 WebServiceWorkerRegistrationImpl* registration =
252 GetServiceWorkerRegistration(info, true);
253
254 ChangedVersionAttributesMask mask(attrs.changed_mask);
255 if (mask.installing_changed())
256 registration->SetInstalling(GetServiceWorker(attrs.installing, true));
257 if (mask.waiting_changed())
258 registration->SetWaiting(GetServiceWorker(attrs.waiting, true));
259 if (mask.active_changed())
260 registration->SetActive(GetServiceWorker(attrs.active, true));
261
262 callbacks->onSuccess(registration);
249 pending_callbacks_.Remove(request_id); 263 pending_callbacks_.Remove(request_id);
250 } 264 }
251 265
252 void ServiceWorkerDispatcher::OnUnregistered( 266 void ServiceWorkerDispatcher::OnUnregistered(
253 int thread_id, 267 int thread_id,
254 int request_id) { 268 int request_id) {
255 WebServiceWorkerRegistrationCallbacks* callbacks = 269 WebServiceWorkerRegistrationCallbacks* callbacks =
256 pending_callbacks_.Lookup(request_id); 270 pending_callbacks_.Lookup(request_id);
257 DCHECK(callbacks); 271 DCHECK(callbacks);
258 if (!callbacks) 272 if (!callbacks)
(...skipping 30 matching lines...) Expand all
289 303
290 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); 304 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id);
291 if (provider != worker_to_provider_.end()) 305 if (provider != worker_to_provider_.end())
292 provider->second->OnServiceWorkerStateChanged(handle_id, state); 306 provider->second->OnServiceWorkerStateChanged(handle_id, state);
293 } 307 }
294 308
295 void ServiceWorkerDispatcher::OnSetVersionAttributes( 309 void ServiceWorkerDispatcher::OnSetVersionAttributes(
296 int thread_id, 310 int thread_id,
297 int provider_id, 311 int provider_id,
298 int registration_handle_id, 312 int registration_handle_id,
299 int changed_mask, 313 const ServiceWorkerVersionAttributes& attrs) {
300 const ServiceWorkerVersionAttributes& attributes) { 314 ChangedVersionAttributesMask mask(attrs.changed_mask);
301 ChangedVersionAttributesMask mask(changed_mask);
302 if (mask.installing_changed()) { 315 if (mask.installing_changed()) {
303 SetInstallingServiceWorker(provider_id, 316 SetInstallingServiceWorker(provider_id,
304 registration_handle_id, 317 registration_handle_id,
305 attributes.installing); 318 attrs.installing);
306 } 319 }
307 if (mask.waiting_changed()) { 320 if (mask.waiting_changed()) {
308 SetWaitingServiceWorker(provider_id, 321 SetWaitingServiceWorker(provider_id,
309 registration_handle_id, 322 registration_handle_id,
310 attributes.waiting); 323 attrs.waiting);
311 } 324 }
312 if (mask.active_changed()) { 325 if (mask.active_changed()) {
313 SetActiveServiceWorker(provider_id, 326 SetActiveServiceWorker(provider_id,
314 registration_handle_id, 327 registration_handle_id,
315 attributes.active); 328 attrs.active);
316 } 329 }
317 } 330 }
318 331
332 void ServiceWorkerDispatcher::OnUpdateFound(
333 int thread_id,
334 const ServiceWorkerRegistrationObjectInfo& info) {
335 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id);
336 if (found != registrations_.end())
337 found->second->OnUpdateFound();
338 }
339
319 void ServiceWorkerDispatcher::SetInstallingServiceWorker( 340 void ServiceWorkerDispatcher::SetInstallingServiceWorker(
320 int provider_id, 341 int provider_id,
321 int registration_handle_id, 342 int registration_handle_id,
322 const ServiceWorkerObjectInfo& info) { 343 const ServiceWorkerObjectInfo& info) {
323 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); 344 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id);
324 if (provider != provider_contexts_.end()) { 345 if (provider != provider_contexts_.end()) {
325 int existing_installing_id = provider->second->installing_handle_id(); 346 int existing_installing_id = provider->second->installing_handle_id();
326 if (existing_installing_id != info.handle_id && 347 if (existing_installing_id != info.handle_id &&
327 existing_installing_id != kInvalidServiceWorkerHandleId) { 348 existing_installing_id != kInvalidServiceWorkerHandleId) {
328 WorkerToProviderMap::iterator associated_provider = 349 WorkerToProviderMap::iterator associated_provider =
329 worker_to_provider_.find(existing_installing_id); 350 worker_to_provider_.find(existing_installing_id);
330 DCHECK(associated_provider != worker_to_provider_.end()); 351 DCHECK(associated_provider != worker_to_provider_.end());
331 DCHECK(associated_provider->second->provider_id() == provider_id); 352 DCHECK(associated_provider->second->provider_id() == provider_id);
332 worker_to_provider_.erase(associated_provider); 353 worker_to_provider_.erase(associated_provider);
333 } 354 }
334 provider->second->OnSetInstallingServiceWorker(provider_id, info); 355 provider->second->OnSetInstallingServiceWorker(provider_id, info);
335 if (info.handle_id != kInvalidServiceWorkerHandleId) 356 if (info.handle_id != kInvalidServiceWorkerHandleId)
336 worker_to_provider_[info.handle_id] = provider->second; 357 worker_to_provider_[info.handle_id] = provider->second;
337 } 358 }
338 359
339 RegistrationObjectMap::iterator found = 360 RegistrationObjectMap::iterator found =
340 registrations_.find(registration_handle_id); 361 registrations_.find(registration_handle_id);
341 if (found != registrations_.end()) { 362 if (found != registrations_.end()) {
342 // Populate the .installing field with the new worker object. 363 // Populate the .installing field with the new worker object.
343 found->second->SetInstalling(GetServiceWorker(info, false)); 364 found->second->SetInstalling(GetServiceWorker(info, false));
344 if (info.handle_id != kInvalidServiceWorkerHandleId)
345 found->second->OnUpdateFound();
346 } 365 }
347 } 366 }
348 367
349 void ServiceWorkerDispatcher::SetWaitingServiceWorker( 368 void ServiceWorkerDispatcher::SetWaitingServiceWorker(
350 int provider_id, 369 int provider_id,
351 int registration_handle_id, 370 int registration_handle_id,
352 const ServiceWorkerObjectInfo& info) { 371 const ServiceWorkerObjectInfo& info) {
353 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); 372 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id);
354 if (provider != provider_contexts_.end()) { 373 if (provider != provider_contexts_.end()) {
355 int existing_waiting_id = provider->second->waiting_handle_id(); 374 int existing_waiting_id = provider->second->waiting_handle_id();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 registrations_[registration_handle_id] = registration; 486 registrations_[registration_handle_id] = registration;
468 } 487 }
469 488
470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( 489 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration(
471 int registration_handle_id) { 490 int registration_handle_id) {
472 DCHECK(ContainsKey(registrations_, registration_handle_id)); 491 DCHECK(ContainsKey(registrations_, registration_handle_id));
473 registrations_.erase(registration_handle_id); 492 registrations_.erase(registration_handle_id);
474 } 493 }
475 494
476 } // namespace content 495 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698