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/web_service_worker_provider_impl.h" | 5 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "content/child/service_worker/service_worker_dispatcher.h" | 9 #include "content/child/service_worker/service_worker_dispatcher.h" |
10 #include "content/child/service_worker/service_worker_handle_reference.h" | 10 #include "content/child/service_worker/service_worker_handle_reference.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // the single provider context across threads. (http://crbug.com/366538 | 47 // the single provider context across threads. (http://crbug.com/366538 |
48 // for more context) | 48 // for more context) |
49 GetDispatcher()->AddProviderClient(provider_id_, client); | 49 GetDispatcher()->AddProviderClient(provider_id_, client); |
50 | 50 |
51 ServiceWorkerRegistrationObjectInfo info; | 51 ServiceWorkerRegistrationObjectInfo info; |
52 ServiceWorkerVersionAttributes attrs; | 52 ServiceWorkerVersionAttributes attrs; |
53 if (!context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs)) { | 53 if (!context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs)) { |
54 // This provider is not associated with any registration. | 54 // This provider is not associated with any registration. |
55 return; | 55 return; |
56 } | 56 } |
57 | |
58 // Set .ready if the associated registration has the active service worker. | |
59 if (context_->active_handle_id() != kInvalidServiceWorkerHandleId) { | |
60 WebServiceWorkerRegistrationImpl* registration = | |
61 GetDispatcher()->FindServiceWorkerRegistration(info, false); | |
62 if (!registration) { | |
63 registration = | |
64 GetDispatcher()->CreateServiceWorkerRegistration(info, false); | |
65 registration->SetInstalling( | |
66 GetDispatcher()->GetServiceWorker(attrs.installing, false)); | |
67 registration->SetWaiting( | |
68 GetDispatcher()->GetServiceWorker(attrs.waiting, false)); | |
69 registration->SetActive( | |
70 GetDispatcher()->GetServiceWorker(attrs.active, false)); | |
71 } | |
72 client->setReadyRegistration(registration); | |
73 } | |
74 | |
75 if (context_->controller_handle_id() != kInvalidServiceWorkerHandleId) { | 57 if (context_->controller_handle_id() != kInvalidServiceWorkerHandleId) { |
76 client->setController(GetDispatcher()->GetServiceWorker( | 58 client->setController(GetDispatcher()->GetServiceWorker( |
77 context_->controller()->info(), false), | 59 context_->controller()->info(), false), |
78 false /* shouldNotifyControllerChange */); | 60 false /* shouldNotifyControllerChange */); |
79 } | 61 } |
80 } | 62 } |
81 | 63 |
82 void WebServiceWorkerProviderImpl::registerServiceWorker( | 64 void WebServiceWorkerProviderImpl::registerServiceWorker( |
83 const WebURL& pattern, | 65 const WebURL& pattern, |
84 const WebURL& script_url, | 66 const WebURL& script_url, |
85 WebServiceWorkerRegistrationCallbacks* callbacks) { | 67 WebServiceWorkerRegistrationCallbacks* callbacks) { |
86 GetDispatcher()->RegisterServiceWorker( | 68 GetDispatcher()->RegisterServiceWorker( |
87 provider_id_, pattern, script_url, callbacks); | 69 provider_id_, pattern, script_url, callbacks); |
88 } | 70 } |
89 | 71 |
90 void WebServiceWorkerProviderImpl::unregisterServiceWorker( | 72 void WebServiceWorkerProviderImpl::unregisterServiceWorker( |
91 const WebURL& pattern, | 73 const WebURL& pattern, |
92 WebServiceWorkerUnregistrationCallbacks* callbacks) { | 74 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
93 GetDispatcher()->UnregisterServiceWorker( | 75 GetDispatcher()->UnregisterServiceWorker( |
94 provider_id_, pattern, callbacks); | 76 provider_id_, pattern, callbacks); |
95 } | 77 } |
96 | 78 |
97 void WebServiceWorkerProviderImpl::getRegistration( | 79 void WebServiceWorkerProviderImpl::getRegistration( |
98 const blink::WebURL& document_url, | 80 const blink::WebURL& document_url, |
99 WebServiceWorkerRegistrationCallbacks* callbacks) { | 81 WebServiceWorkerRegistrationCallbacks* callbacks) { |
100 GetDispatcher()->GetRegistration(provider_id_, document_url, callbacks); | 82 GetDispatcher()->GetRegistration(provider_id_, document_url, callbacks); |
101 } | 83 } |
102 | 84 |
| 85 void WebServiceWorkerProviderImpl::getRegistrationForReady( |
| 86 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { |
| 87 GetDispatcher()->GetRegistrationForReady(provider_id_, callbacks); |
| 88 } |
| 89 |
103 void WebServiceWorkerProviderImpl::RemoveProviderClient() { | 90 void WebServiceWorkerProviderImpl::RemoveProviderClient() { |
104 // Remove the provider client, but only if the dispatcher is still there. | 91 // Remove the provider client, but only if the dispatcher is still there. |
105 // (For cleanup path we don't need to bother creating a new dispatcher) | 92 // (For cleanup path we don't need to bother creating a new dispatcher) |
106 ServiceWorkerDispatcher* dispatcher = | 93 ServiceWorkerDispatcher* dispatcher = |
107 ServiceWorkerDispatcher::GetThreadSpecificInstance(); | 94 ServiceWorkerDispatcher::GetThreadSpecificInstance(); |
108 if (dispatcher) | 95 if (dispatcher) |
109 dispatcher->RemoveProviderClient(provider_id_); | 96 dispatcher->RemoveProviderClient(provider_id_); |
110 } | 97 } |
111 | 98 |
112 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { | 99 ServiceWorkerDispatcher* WebServiceWorkerProviderImpl::GetDispatcher() { |
113 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( | 100 return ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
114 thread_safe_sender_.get()); | 101 thread_safe_sender_.get()); |
115 } | 102 } |
116 | 103 |
117 } // namespace content | 104 } // namespace content |
OLD | NEW |