| 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/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 bool adopt_handle = true; | 342 bool adopt_handle = true; |
| 343 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); | 343 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); |
| 344 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); | 344 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); |
| 345 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); | 345 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); |
| 346 return registration.Pass(); | 346 return registration.Pass(); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // We can assume that this message handler is called before the worker context | 349 // We can assume that this message handler is called before the worker context |
| 350 // starts because script loading happens after this association. | 350 // starts because script loading happens after this association. |
| 351 // TODO(nhiroki): This association information could be pushed into | |
| 352 // EmbeddedWorkerMsg_StartWorker message and handed over to the worker thread | |
| 353 // without a lock in ServiceWorkerProviderContext. | |
| 354 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker( | 351 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker( |
| 355 int thread_id, | 352 int thread_id, |
| 356 int provider_id, | 353 int provider_id, |
| 357 const ServiceWorkerRegistrationObjectInfo& info, | 354 const ServiceWorkerRegistrationObjectInfo& info, |
| 358 const ServiceWorkerVersionAttributes& attrs) { | 355 const ServiceWorkerVersionAttributes& attrs) { |
| 359 DCHECK_EQ(kDocumentMainThreadId, thread_id); | 356 DCHECK_EQ(kDocumentMainThreadId, thread_id); |
| 360 | 357 |
| 361 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); | 358 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); |
| 362 if (context == provider_contexts_.end()) | 359 if (context == provider_contexts_.end()) |
| 363 return; | 360 return; |
| 364 context->second->OnAssociateRegistration(info, attrs); | 361 context->second->OnAssociateRegistration(info, attrs); |
| 365 | |
| 366 // We don't have to add entries into |worker_to_provider_| because state | |
| 367 // change events for the workers will be notified on the worker thread. | |
| 368 } | 362 } |
| 369 | 363 |
| 370 void ServiceWorkerDispatcher::OnAssociateRegistration( | 364 void ServiceWorkerDispatcher::OnAssociateRegistration( |
| 371 int thread_id, | 365 int thread_id, |
| 372 int provider_id, | 366 int provider_id, |
| 373 const ServiceWorkerRegistrationObjectInfo& info, | 367 const ServiceWorkerRegistrationObjectInfo& info, |
| 374 const ServiceWorkerVersionAttributes& attrs) { | 368 const ServiceWorkerVersionAttributes& attrs) { |
| 375 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 369 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 376 if (provider == provider_contexts_.end()) | 370 if (provider == provider_contexts_.end()) |
| 377 return; | 371 return; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 registrations_[registration_handle_id] = registration; | 756 registrations_[registration_handle_id] = registration; |
| 763 } | 757 } |
| 764 | 758 |
| 765 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 759 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
| 766 int registration_handle_id) { | 760 int registration_handle_id) { |
| 767 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 761 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
| 768 registrations_.erase(registration_handle_id); | 762 registrations_.erase(registration_handle_id); |
| 769 } | 763 } |
| 770 | 764 |
| 771 } // namespace content | 765 } // namespace content |
| OLD | NEW |