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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 const ServiceWorkerRegistrationObjectInfo& info, | 308 const ServiceWorkerRegistrationObjectInfo& info, |
309 const ServiceWorkerVersionAttributes& attrs) { | 309 const ServiceWorkerVersionAttributes& attrs) { |
310 return CreateRegistrationInternal( | 310 return CreateRegistrationInternal( |
311 ServiceWorkerRegistrationHandleReference::Adopt( | 311 ServiceWorkerRegistrationHandleReference::Adopt( |
312 info, thread_safe_sender_.get()), | 312 info, thread_safe_sender_.get()), |
313 attrs, true /* adopt_handle */); | 313 attrs, true /* adopt_handle */); |
314 } | 314 } |
315 | 315 |
316 // We can assume that this message handler is called before the worker context | 316 // We can assume that this message handler is called before the worker context |
317 // starts because script loading happens after this association. | 317 // starts because script loading happens after this association. |
318 // TODO(nhiroki): This association information could be pushed into | |
319 // EmbeddedWorkerMsg_StartWorker message and handed over to the worker thread | |
320 // without a lock in ServiceWorkerProviderContext. | |
321 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker( | 318 void ServiceWorkerDispatcher::OnAssociateRegistrationWithServiceWorker( |
322 int thread_id, | 319 int thread_id, |
323 int provider_id, | 320 int provider_id, |
324 const ServiceWorkerRegistrationObjectInfo& info, | 321 const ServiceWorkerRegistrationObjectInfo& info, |
325 const ServiceWorkerVersionAttributes& attrs) { | 322 const ServiceWorkerVersionAttributes& attrs) { |
326 DCHECK_EQ(kDocumentMainThreadId, thread_id); | 323 DCHECK_EQ(kDocumentMainThreadId, thread_id); |
327 | 324 |
328 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); | 325 ProviderContextMap::iterator context = provider_contexts_.find(provider_id); |
329 if (context == provider_contexts_.end()) | 326 if (context == provider_contexts_.end()) |
330 return; | 327 return; |
331 context->second->OnAssociateRegistration(info, attrs); | 328 context->second->OnAssociateRegistration(info, attrs); |
332 | |
333 // We don't have to add entries into |worker_to_provider_| because state | |
334 // change events for the workers will be notified on the worker thread. | |
335 } | 329 } |
336 | 330 |
337 void ServiceWorkerDispatcher::OnAssociateRegistration( | 331 void ServiceWorkerDispatcher::OnAssociateRegistration( |
338 int thread_id, | 332 int thread_id, |
339 int provider_id, | 333 int provider_id, |
340 const ServiceWorkerRegistrationObjectInfo& info, | 334 const ServiceWorkerRegistrationObjectInfo& info, |
341 const ServiceWorkerVersionAttributes& attrs) { | 335 const ServiceWorkerVersionAttributes& attrs) { |
342 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 336 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
343 if (provider == provider_contexts_.end()) | 337 if (provider == provider_contexts_.end()) |
344 return; | 338 return; |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 // AddServiceWorkerRegistration. | 738 // AddServiceWorkerRegistration. |
745 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( | 739 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( |
746 new WebServiceWorkerRegistrationImpl(handle_ref.Pass())); | 740 new WebServiceWorkerRegistrationImpl(handle_ref.Pass())); |
747 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); | 741 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); |
748 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); | 742 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); |
749 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); | 743 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); |
750 return registration.Pass(); | 744 return registration.Pass(); |
751 } | 745 } |
752 | 746 |
753 } // namespace content | 747 } // namespace content |
OLD | NEW |