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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CountFeature, OnCountFeature) | 113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CountFeature, OnCountFeature) |
114 IPC_MESSAGE_UNHANDLED(handled = false) | 114 IPC_MESSAGE_UNHANDLED(handled = false) |
115 IPC_END_MESSAGE_MAP() | 115 IPC_END_MESSAGE_MAP() |
116 DCHECK(handled) << "Unhandled message:" << msg.type(); | 116 DCHECK(handled) << "Unhandled message:" << msg.type(); |
117 } | 117 } |
118 | 118 |
119 void ServiceWorkerDispatcher::RegisterServiceWorker( | 119 void ServiceWorkerDispatcher::RegisterServiceWorker( |
120 int provider_id, | 120 int provider_id, |
121 const GURL& pattern, | 121 const GURL& pattern, |
122 const GURL& script_url, | 122 const GURL& script_url, |
| 123 blink::WebServiceWorkerUpdateViaCache update_via_cache, |
123 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { | 124 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { |
124 DCHECK(callbacks); | 125 DCHECK(callbacks); |
125 | 126 |
126 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || | 127 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || |
127 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 128 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
128 std::string error_message(kServiceWorkerRegisterErrorPrefix); | 129 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
129 error_message += "The provided scriptURL or scope is too long."; | 130 error_message += "The provided scriptURL or scope is too long."; |
130 callbacks->OnError( | 131 callbacks->OnError( |
131 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeSecurity, | 132 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeSecurity, |
132 blink::WebString::FromASCII(error_message))); | 133 blink::WebString::FromASCII(error_message))); |
133 return; | 134 return; |
134 } | 135 } |
135 | 136 |
136 int request_id = pending_registration_callbacks_.Add(std::move(callbacks)); | 137 int request_id = pending_registration_callbacks_.Add(std::move(callbacks)); |
137 ServiceWorkerRegistrationOptions options(pattern); | 138 ServiceWorkerRegistrationOptions options(pattern, update_via_cache); |
138 | 139 |
139 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 140 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
140 "ServiceWorkerDispatcher::RegisterServiceWorker", | 141 "ServiceWorkerDispatcher::RegisterServiceWorker", |
141 request_id, | 142 request_id, |
142 "Scope", pattern.spec(), | 143 "Scope", pattern.spec(), |
143 "Script URL", script_url.spec()); | 144 "Script URL", script_url.spec()); |
144 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 145 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
145 CurrentWorkerId(), request_id, provider_id, script_url, options)); | 146 CurrentWorkerId(), request_id, provider_id, script_url, options)); |
146 } | 147 } |
147 | 148 |
(...skipping 30 matching lines...) Expand all Loading... |
178 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); | 179 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
179 error_message += "The provided documentURL is too long."; | 180 error_message += "The provided documentURL is too long."; |
180 callbacks->OnError( | 181 callbacks->OnError( |
181 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeSecurity, | 182 WebServiceWorkerError(WebServiceWorkerError::kErrorTypeSecurity, |
182 blink::WebString::FromASCII(error_message))); | 183 blink::WebString::FromASCII(error_message))); |
183 return; | 184 return; |
184 } | 185 } |
185 | 186 |
186 int request_id = | 187 int request_id = |
187 pending_get_registration_callbacks_.Add(std::move(callbacks)); | 188 pending_get_registration_callbacks_.Add(std::move(callbacks)); |
| 189 |
188 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 190 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
189 "ServiceWorkerDispatcher::GetRegistration", | 191 "ServiceWorkerDispatcher::GetRegistration", |
190 request_id, | 192 request_id, |
191 "Document URL", document_url.spec()); | 193 "Document URL", document_url.spec()); |
192 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | 194 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
193 CurrentWorkerId(), request_id, provider_id, document_url)); | 195 CurrentWorkerId(), request_id, provider_id, document_url)); |
194 } | 196 } |
195 | 197 |
196 void ServiceWorkerDispatcher::GetRegistrations( | 198 void ServiceWorkerDispatcher::GetRegistrations( |
197 int provider_id, | 199 int provider_id, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration_ref = | 367 std::unique_ptr<ServiceWorkerRegistrationHandleReference> registration_ref = |
366 Adopt(info); | 368 Adopt(info); |
367 std::unique_ptr<ServiceWorkerHandleReference> installing_ref = | 369 std::unique_ptr<ServiceWorkerHandleReference> installing_ref = |
368 Adopt(attrs.installing); | 370 Adopt(attrs.installing); |
369 std::unique_ptr<ServiceWorkerHandleReference> waiting_ref = | 371 std::unique_ptr<ServiceWorkerHandleReference> waiting_ref = |
370 Adopt(attrs.waiting); | 372 Adopt(attrs.waiting); |
371 std::unique_ptr<ServiceWorkerHandleReference> active_ref = | 373 std::unique_ptr<ServiceWorkerHandleReference> active_ref = |
372 Adopt(attrs.active); | 374 Adopt(attrs.active); |
373 | 375 |
374 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); | 376 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); |
375 if (found != registrations_.end()) | 377 if (found != registrations_.end()) { |
| 378 if (found->second->UpdateViaCache() != registration_ref->update_via_cache()) |
| 379 found->second->SetRegistrationHandleReference( |
| 380 std::move(registration_ref)); |
376 return found->second; | 381 return found->second; |
| 382 } |
377 | 383 |
378 // WebServiceWorkerRegistrationImpl constructor calls | 384 // WebServiceWorkerRegistrationImpl constructor calls |
379 // AddServiceWorkerRegistration. | 385 // AddServiceWorkerRegistration. |
380 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( | 386 scoped_refptr<WebServiceWorkerRegistrationImpl> registration( |
381 new WebServiceWorkerRegistrationImpl(std::move(registration_ref))); | 387 new WebServiceWorkerRegistrationImpl(std::move(registration_ref))); |
382 registration->SetInstalling( | 388 registration->SetInstalling( |
383 GetOrCreateServiceWorker(std::move(installing_ref))); | 389 GetOrCreateServiceWorker(std::move(installing_ref))); |
384 registration->SetWaiting(GetOrCreateServiceWorker(std::move(waiting_ref))); | 390 registration->SetWaiting(GetOrCreateServiceWorker(std::move(waiting_ref))); |
385 registration->SetActive(GetOrCreateServiceWorker(std::move(active_ref))); | 391 registration->SetActive(GetOrCreateServiceWorker(std::move(active_ref))); |
386 return registration; | 392 return registration; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 return ServiceWorkerRegistrationHandleReference::Adopt( | 930 return ServiceWorkerRegistrationHandleReference::Adopt( |
925 info, thread_safe_sender_.get()); | 931 info, thread_safe_sender_.get()); |
926 } | 932 } |
927 | 933 |
928 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 934 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
929 const ServiceWorkerObjectInfo& info) { | 935 const ServiceWorkerObjectInfo& info) { |
930 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 936 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
931 } | 937 } |
932 | 938 |
933 } // namespace content | 939 } // namespace content |
OLD | NEW |