| 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/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 129 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
| 130 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 130 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void ServiceWorkerDispatcher::UpdateServiceWorker(int provider_id, | 133 void ServiceWorkerDispatcher::UpdateServiceWorker(int provider_id, |
| 134 int64 registration_id) { | 134 int64 registration_id) { |
| 135 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UpdateServiceWorker( | 135 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UpdateServiceWorker( |
| 136 provider_id, registration_id)); | 136 provider_id, registration_id)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 139 void ServiceWorkerDispatcher::DeprecatedUnregisterServiceWorker( |
| 140 int provider_id, | 140 int provider_id, |
| 141 const GURL& pattern, | 141 const GURL& pattern, |
| 142 WebServiceWorkerUnregistrationCallbacks* callbacks) { | 142 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
| 143 DCHECK(callbacks); | 143 DCHECK(callbacks); |
| 144 | 144 |
| 145 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { | 145 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| 146 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> | 146 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> |
| 147 owned_callbacks(callbacks); | 147 owned_callbacks(callbacks); |
| 148 std::string error_message(kServiceWorkerUnregisterErrorPrefix); | 148 std::string error_message(kServiceWorkerUnregisterErrorPrefix); |
| 149 error_message += "The provided scope is too long."; | 149 error_message += "The provided scope is too long."; |
| 150 scoped_ptr<WebServiceWorkerError> error( | 150 scoped_ptr<WebServiceWorkerError> error( |
| 151 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 151 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 152 blink::WebString::fromUTF8(error_message))); | 152 blink::WebString::fromUTF8(error_message))); |
| 153 callbacks->onError(error.release()); | 153 callbacks->onError(error.release()); |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 | 156 |
| 157 int request_id = pending_unregistration_callbacks_.Add(callbacks); | 157 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
| 158 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 158 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 159 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 159 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 160 request_id, | 160 request_id, |
| 161 "Scope", pattern.spec()); | 161 "Scope", pattern.spec()); |
| 162 thread_safe_sender_->Send( |
| 163 new ServiceWorkerHostMsg_DeprecatedUnregisterServiceWorker( |
| 164 CurrentWorkerId(), request_id, provider_id, pattern)); |
| 165 } |
| 166 |
| 167 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
| 168 int provider_id, |
| 169 int64 registration_id, |
| 170 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
| 171 DCHECK(callbacks); |
| 172 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
| 173 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 174 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 175 request_id, "Registration ID", registration_id); |
| 162 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 176 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
| 163 CurrentWorkerId(), request_id, provider_id, pattern)); | 177 CurrentWorkerId(), request_id, provider_id, registration_id)); |
| 164 } | 178 } |
| 165 | 179 |
| 166 void ServiceWorkerDispatcher::GetRegistration( | 180 void ServiceWorkerDispatcher::GetRegistration( |
| 167 int provider_id, | 181 int provider_id, |
| 168 const GURL& document_url, | 182 const GURL& document_url, |
| 169 WebServiceWorkerRegistrationCallbacks* callbacks) { | 183 WebServiceWorkerRegistrationCallbacks* callbacks) { |
| 170 DCHECK(callbacks); | 184 DCHECK(callbacks); |
| 171 | 185 |
| 172 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | 186 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| 173 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 187 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 bool adopt_handle = true; | 786 bool adopt_handle = true; |
| 773 WebServiceWorkerRegistrationImpl* registration = | 787 WebServiceWorkerRegistrationImpl* registration = |
| 774 CreateServiceWorkerRegistration(info, adopt_handle); | 788 CreateServiceWorkerRegistration(info, adopt_handle); |
| 775 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); | 789 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); |
| 776 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); | 790 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); |
| 777 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); | 791 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); |
| 778 return registration; | 792 return registration; |
| 779 } | 793 } |
| 780 | 794 |
| 781 } // namespace content | 795 } // namespace content |
| OLD | NEW |