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

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

Issue 896533004: [WONT COMMIT] ServiceWorker: Move unregister function from WebSWProvider to WebSWRegistration (2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // We are instructed to adopt a handle but we already have one, so 278 // We are instructed to adopt a handle but we already have one, so
279 // adopt and destroy a handle ref. 279 // adopt and destroy a handle ref.
280 ServiceWorkerRegistrationHandleReference::Adopt( 280 ServiceWorkerRegistrationHandleReference::Adopt(
281 info, thread_safe_sender_.get()); 281 info, thread_safe_sender_.get());
282 } 282 }
283 return registration->second; 283 return registration->second;
284 } 284 }
285 285
286 WebServiceWorkerRegistrationImpl* 286 WebServiceWorkerRegistrationImpl*
287 ServiceWorkerDispatcher::CreateServiceWorkerRegistration( 287 ServiceWorkerDispatcher::CreateServiceWorkerRegistration(
288 int provider_id,
288 const ServiceWorkerRegistrationObjectInfo& info, 289 const ServiceWorkerRegistrationObjectInfo& info,
289 bool adopt_handle) { 290 bool adopt_handle) {
290 DCHECK(!FindServiceWorkerRegistration(info, adopt_handle)); 291 DCHECK(!FindServiceWorkerRegistration(info, adopt_handle));
291 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) 292 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId)
292 return NULL; 293 return NULL;
293 294
294 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = 295 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref =
295 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( 296 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt(
296 info, thread_safe_sender_.get()) 297 info, thread_safe_sender_.get())
297 : ServiceWorkerRegistrationHandleReference::Create( 298 : ServiceWorkerRegistrationHandleReference::Create(
298 info, thread_safe_sender_.get()); 299 info, thread_safe_sender_.get());
299 300
300 // WebServiceWorkerRegistrationImpl constructor calls 301 // WebServiceWorkerRegistrationImpl constructor calls
301 // AddServiceWorkerRegistration. 302 // AddServiceWorkerRegistration.
302 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); 303 return new WebServiceWorkerRegistrationImpl(provider_id, handle_ref.Pass());
303 } 304 }
304 305
305 // We can assume that this message handler is called before the worker context 306 // We can assume that this message handler is called before the worker context
306 // starts because script loading happens after this association. 307 // starts because script loading happens after this association.
307 // TODO(nhiroki): This association information could be pushed into 308 // TODO(nhiroki): This association information could be pushed into
308 // EmbeddedWorkerMsg_StartWorker message and handed over to the worker thread 309 // EmbeddedWorkerMsg_StartWorker message and handed over to the worker thread
309 // without a lock in ServiceWorkerProviderContext. 310 // without a lock in ServiceWorkerProviderContext.
310 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker( 311 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker(
311 int thread_id, 312 int thread_id,
312 int provider_id, 313 int provider_id,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 provider->second->OnDisassociateRegistration(); 350 provider->second->OnDisassociateRegistration();
350 worker_to_provider_.erase(provider->second->installing_handle_id()); 351 worker_to_provider_.erase(provider->second->installing_handle_id());
351 worker_to_provider_.erase(provider->second->waiting_handle_id()); 352 worker_to_provider_.erase(provider->second->waiting_handle_id());
352 worker_to_provider_.erase(provider->second->active_handle_id()); 353 worker_to_provider_.erase(provider->second->active_handle_id());
353 worker_to_provider_.erase(provider->second->controller_handle_id()); 354 worker_to_provider_.erase(provider->second->controller_handle_id());
354 } 355 }
355 356
356 void ServiceWorkerDispatcher::OnRegistered( 357 void ServiceWorkerDispatcher::OnRegistered(
357 int thread_id, 358 int thread_id,
358 int request_id, 359 int request_id,
360 int provider_id,
359 const ServiceWorkerRegistrationObjectInfo& info, 361 const ServiceWorkerRegistrationObjectInfo& info,
360 const ServiceWorkerVersionAttributes& attrs) { 362 const ServiceWorkerVersionAttributes& attrs) {
361 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", 363 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker",
362 "ServiceWorkerDispatcher::RegisterServiceWorker", 364 "ServiceWorkerDispatcher::RegisterServiceWorker",
363 request_id, 365 request_id,
364 "OnRegistered"); 366 "OnRegistered");
365 TRACE_EVENT_ASYNC_END0("ServiceWorker", 367 TRACE_EVENT_ASYNC_END0("ServiceWorker",
366 "ServiceWorkerDispatcher::RegisterServiceWorker", 368 "ServiceWorkerDispatcher::RegisterServiceWorker",
367 request_id); 369 request_id);
368 WebServiceWorkerRegistrationCallbacks* callbacks = 370 WebServiceWorkerRegistrationCallbacks* callbacks =
369 pending_registration_callbacks_.Lookup(request_id); 371 pending_registration_callbacks_.Lookup(request_id);
370 DCHECK(callbacks); 372 DCHECK(callbacks);
371 if (!callbacks) 373 if (!callbacks)
372 return; 374 return;
373 375
374 callbacks->onSuccess(FindOrCreateRegistration(info, attrs)); 376 callbacks->onSuccess(FindOrCreateRegistration(provider_id, info, attrs));
375 pending_registration_callbacks_.Remove(request_id); 377 pending_registration_callbacks_.Remove(request_id);
376 } 378 }
377 379
378 void ServiceWorkerDispatcher::OnUnregistered(int thread_id, 380 void ServiceWorkerDispatcher::OnUnregistered(int thread_id,
379 int request_id, 381 int request_id,
380 bool is_success) { 382 bool is_success) {
381 TRACE_EVENT_ASYNC_STEP_INTO0( 383 TRACE_EVENT_ASYNC_STEP_INTO0(
382 "ServiceWorker", 384 "ServiceWorker",
383 "ServiceWorkerDispatcher::UnregisterServiceWorker", 385 "ServiceWorkerDispatcher::UnregisterServiceWorker",
384 request_id, 386 request_id,
385 "OnUnregistered"); 387 "OnUnregistered");
386 TRACE_EVENT_ASYNC_END0("ServiceWorker", 388 TRACE_EVENT_ASYNC_END0("ServiceWorker",
387 "ServiceWorkerDispatcher::UnregisterServiceWorker", 389 "ServiceWorkerDispatcher::UnregisterServiceWorker",
388 request_id); 390 request_id);
389 WebServiceWorkerUnregistrationCallbacks* callbacks = 391 WebServiceWorkerUnregistrationCallbacks* callbacks =
390 pending_unregistration_callbacks_.Lookup(request_id); 392 pending_unregistration_callbacks_.Lookup(request_id);
391 DCHECK(callbacks); 393 DCHECK(callbacks);
392 if (!callbacks) 394 if (!callbacks)
393 return; 395 return;
394 callbacks->onSuccess(&is_success); 396 callbacks->onSuccess(&is_success);
395 pending_unregistration_callbacks_.Remove(request_id); 397 pending_unregistration_callbacks_.Remove(request_id);
396 } 398 }
397 399
398 void ServiceWorkerDispatcher::OnDidGetRegistration( 400 void ServiceWorkerDispatcher::OnDidGetRegistration(
399 int thread_id, 401 int thread_id,
400 int request_id, 402 int request_id,
403 int provider_id,
401 const ServiceWorkerRegistrationObjectInfo& info, 404 const ServiceWorkerRegistrationObjectInfo& info,
402 const ServiceWorkerVersionAttributes& attrs) { 405 const ServiceWorkerVersionAttributes& attrs) {
403 TRACE_EVENT_ASYNC_STEP_INTO0( 406 TRACE_EVENT_ASYNC_STEP_INTO0(
404 "ServiceWorker", 407 "ServiceWorker",
405 "ServiceWorkerDispatcher::GetRegistration", 408 "ServiceWorkerDispatcher::GetRegistration",
406 request_id, 409 request_id,
407 "OnDidGetRegistration"); 410 "OnDidGetRegistration");
408 TRACE_EVENT_ASYNC_END0("ServiceWorker", 411 TRACE_EVENT_ASYNC_END0("ServiceWorker",
409 "ServiceWorkerDispatcher::GetRegistration", 412 "ServiceWorkerDispatcher::GetRegistration",
410 request_id); 413 request_id);
411 WebServiceWorkerRegistrationCallbacks* callbacks = 414 WebServiceWorkerRegistrationCallbacks* callbacks =
412 pending_get_registration_callbacks_.Lookup(request_id); 415 pending_get_registration_callbacks_.Lookup(request_id);
413 DCHECK(callbacks); 416 DCHECK(callbacks);
414 if (!callbacks) 417 if (!callbacks)
415 return; 418 return;
416 419
417 WebServiceWorkerRegistrationImpl* registration = NULL; 420 WebServiceWorkerRegistrationImpl* registration = NULL;
418 if (info.handle_id != kInvalidServiceWorkerHandleId) 421 if (info.handle_id != kInvalidServiceWorkerHandleId)
419 registration = FindOrCreateRegistration(info, attrs); 422 registration = FindOrCreateRegistration(provider_id, info, attrs);
420 423
421 callbacks->onSuccess(registration); 424 callbacks->onSuccess(registration);
422 pending_get_registration_callbacks_.Remove(request_id); 425 pending_get_registration_callbacks_.Remove(request_id);
423 } 426 }
424 427
425 void ServiceWorkerDispatcher::OnRegistrationError( 428 void ServiceWorkerDispatcher::OnRegistrationError(
426 int thread_id, 429 int thread_id,
427 int request_id, 430 int request_id,
428 WebServiceWorkerError::ErrorType error_type, 431 WebServiceWorkerError::ErrorType error_type,
429 const base::string16& message) { 432 const base::string16& message) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 590
588 ServiceWorkerRegistrationObjectInfo info; 591 ServiceWorkerRegistrationObjectInfo info;
589 ServiceWorkerVersionAttributes attrs; 592 ServiceWorkerVersionAttributes attrs;
590 bool found = 593 bool found =
591 provider->second->GetRegistrationInfoAndVersionAttributes(&info, &attrs); 594 provider->second->GetRegistrationInfoAndVersionAttributes(&info, &attrs);
592 DCHECK(found); 595 DCHECK(found);
593 596
594 WebServiceWorkerRegistrationImpl* registration = 597 WebServiceWorkerRegistrationImpl* registration =
595 FindServiceWorkerRegistration(info, false); 598 FindServiceWorkerRegistration(info, false);
596 if (!registration) { 599 if (!registration) {
597 registration = CreateServiceWorkerRegistration(info, false); 600 registration = CreateServiceWorkerRegistration(provider_id, info, false);
598 registration->SetInstalling(GetServiceWorker(attrs.installing, false)); 601 registration->SetInstalling(GetServiceWorker(attrs.installing, false));
599 registration->SetWaiting(GetServiceWorker(attrs.waiting, false)); 602 registration->SetWaiting(GetServiceWorker(attrs.waiting, false));
600 registration->SetActive(GetServiceWorker(attrs.active, false)); 603 registration->SetActive(GetServiceWorker(attrs.active, false));
601 } 604 }
602 605
603 // Resolve the .ready promise with the registration object. 606 // Resolve the .ready promise with the registration object.
604 client->second->setReadyRegistration(registration); 607 client->second->setReadyRegistration(registration);
605 } 608 }
606 609
607 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( 610 void ServiceWorkerDispatcher::OnSetControllerServiceWorker(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 } 709 }
707 710
708 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( 711 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration(
709 int registration_handle_id) { 712 int registration_handle_id) {
710 DCHECK(ContainsKey(registrations_, registration_handle_id)); 713 DCHECK(ContainsKey(registrations_, registration_handle_id));
711 registrations_.erase(registration_handle_id); 714 registrations_.erase(registration_handle_id);
712 } 715 }
713 716
714 WebServiceWorkerRegistrationImpl* 717 WebServiceWorkerRegistrationImpl*
715 ServiceWorkerDispatcher::FindOrCreateRegistration( 718 ServiceWorkerDispatcher::FindOrCreateRegistration(
719 int provider_id,
716 const ServiceWorkerRegistrationObjectInfo& info, 720 const ServiceWorkerRegistrationObjectInfo& info,
717 const ServiceWorkerVersionAttributes& attrs) { 721 const ServiceWorkerVersionAttributes& attrs) {
718 WebServiceWorkerRegistrationImpl* registration = 722 WebServiceWorkerRegistrationImpl* registration =
719 FindServiceWorkerRegistration(info, true); 723 FindServiceWorkerRegistration(info, true);
720 if (!registration) { 724 if (!registration) {
721 registration = CreateServiceWorkerRegistration(info, true); 725 registration = CreateServiceWorkerRegistration(provider_id, info, true);
722 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); 726 registration->SetInstalling(GetServiceWorker(attrs.installing, true));
723 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); 727 registration->SetWaiting(GetServiceWorker(attrs.waiting, true));
724 registration->SetActive(GetServiceWorker(attrs.active, true)); 728 registration->SetActive(GetServiceWorker(attrs.active, true));
725 } else { 729 } else {
726 // |registration| must already have version attributes, so adopt and destroy 730 // |registration| must already have version attributes, so adopt and destroy
727 // handle refs for them. 731 // handle refs for them.
728 ServiceWorkerHandleReference::Adopt( 732 ServiceWorkerHandleReference::Adopt(
729 attrs.installing, thread_safe_sender_.get()); 733 attrs.installing, thread_safe_sender_.get());
730 ServiceWorkerHandleReference::Adopt( 734 ServiceWorkerHandleReference::Adopt(
731 attrs.waiting, thread_safe_sender_.get()); 735 attrs.waiting, thread_safe_sender_.get());
732 ServiceWorkerHandleReference::Adopt( 736 ServiceWorkerHandleReference::Adopt(
733 attrs.active, thread_safe_sender_.get()); 737 attrs.active, thread_safe_sender_.get());
734 } 738 }
735 return registration; 739 return registration;
736 } 740 }
737 741
738 } // namespace content 742 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698