| OLD | NEW |
| 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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 scoped_ptr<ServiceWorkerHandleReference> handle_ref = | 268 scoped_ptr<ServiceWorkerHandleReference> handle_ref = |
| 269 adopt_handle | 269 adopt_handle |
| 270 ? ServiceWorkerHandleReference::Adopt(info, sender_.get()) | 270 ? ServiceWorkerHandleReference::Adopt(info, sender_.get()) |
| 271 : ServiceWorkerHandleReference::Create(info, sender_.get()); | 271 : ServiceWorkerHandleReference::Create(info, sender_.get()); |
| 272 // WebServiceWorkerImpl constructor calls AddServiceWorker. | 272 // WebServiceWorkerImpl constructor calls AddServiceWorker. |
| 273 return new WebServiceWorkerImpl(handle_ref.Pass(), sender_.get()); | 273 return new WebServiceWorkerImpl(handle_ref.Pass(), sender_.get()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 WebServiceWorkerRegistrationImpl* | 276 WebServiceWorkerRegistrationImpl* |
| 277 ServiceWorkerDispatcher::FindServiceWorkerRegistration( | |
| 278 const ServiceWorkerRegistrationObjectInfo& info, | |
| 279 bool adopt_handle) { | |
| 280 RegistrationObjectMap::iterator registration = | |
| 281 registrations_.find(info.handle_id); | |
| 282 if (registration == registrations_.end()) | |
| 283 return NULL; | |
| 284 if (adopt_handle) { | |
| 285 // We are instructed to adopt a handle but we already have one, so | |
| 286 // adopt and destroy a handle ref. | |
| 287 ServiceWorkerRegistrationHandleReference::Adopt(info, sender_.get()); | |
| 288 } | |
| 289 return registration->second; | |
| 290 } | |
| 291 | |
| 292 WebServiceWorkerRegistrationImpl* | |
| 293 ServiceWorkerDispatcher::CreateServiceWorkerRegistration( | 277 ServiceWorkerDispatcher::CreateServiceWorkerRegistration( |
| 294 const ServiceWorkerRegistrationObjectInfo& info, | 278 const ServiceWorkerRegistrationObjectInfo& info, |
| 295 bool adopt_handle) { | 279 bool adopt_handle) { |
| 296 DCHECK(!FindServiceWorkerRegistration(info, adopt_handle)); | 280 DCHECK(!ContainsKey(registrations_, info.handle_id)); |
| 297 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) | 281 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) |
| 298 return NULL; | 282 return NULL; |
| 299 | 283 |
| 300 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = | 284 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = |
| 301 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( | 285 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( |
| 302 info, sender_.get()) | 286 info, sender_.get()) |
| 303 : ServiceWorkerRegistrationHandleReference::Create( | 287 : ServiceWorkerRegistrationHandleReference::Create( |
| 304 info, sender_.get()); | 288 info, sender_.get()); |
| 305 | 289 |
| 306 // WebServiceWorkerRegistrationImpl constructor calls | 290 // WebServiceWorkerRegistrationImpl constructor calls |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 660 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
| 677 int registration_handle_id) { | 661 int registration_handle_id) { |
| 678 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 662 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
| 679 registrations_.erase(registration_handle_id); | 663 registrations_.erase(registration_handle_id); |
| 680 } | 664 } |
| 681 | 665 |
| 682 WebServiceWorkerRegistrationImpl* | 666 WebServiceWorkerRegistrationImpl* |
| 683 ServiceWorkerDispatcher::FindOrCreateRegistration( | 667 ServiceWorkerDispatcher::FindOrCreateRegistration( |
| 684 const ServiceWorkerRegistrationObjectInfo& info, | 668 const ServiceWorkerRegistrationObjectInfo& info, |
| 685 const ServiceWorkerVersionAttributes& attrs) { | 669 const ServiceWorkerVersionAttributes& attrs) { |
| 686 WebServiceWorkerRegistrationImpl* registration = | 670 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); |
| 687 FindServiceWorkerRegistration(info, true); | 671 if (found != registrations_.end()) { |
| 688 if (!registration) { | 672 ServiceWorkerRegistrationHandleReference::Adopt(info, sender_.get()); |
| 689 registration = CreateServiceWorkerRegistration(info, true); | |
| 690 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); | |
| 691 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); | |
| 692 registration->SetActive(GetServiceWorker(attrs.active, true)); | |
| 693 } else { | |
| 694 // |registration| must already have version attributes, so adopt and destroy | |
| 695 // handle refs for them. | |
| 696 ServiceWorkerHandleReference::Adopt(attrs.installing, sender_.get()); | 673 ServiceWorkerHandleReference::Adopt(attrs.installing, sender_.get()); |
| 697 ServiceWorkerHandleReference::Adopt(attrs.waiting, sender_.get()); | 674 ServiceWorkerHandleReference::Adopt(attrs.waiting, sender_.get()); |
| 698 ServiceWorkerHandleReference::Adopt(attrs.active, sender_.get()); | 675 ServiceWorkerHandleReference::Adopt(attrs.active, sender_.get()); |
| 676 return found->second; |
| 699 } | 677 } |
| 678 |
| 679 bool adopt_handle = true; |
| 680 WebServiceWorkerRegistrationImpl* registration = |
| 681 CreateServiceWorkerRegistration(info, adopt_handle); |
| 682 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); |
| 683 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); |
| 684 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); |
| 700 return registration; | 685 return registration; |
| 701 } | 686 } |
| 702 | 687 |
| 703 } // namespace content | 688 } // namespace content |
| OLD | NEW |