Chromium Code Reviews| 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/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 10 #include "content/child/child_thread.h" | 10 #include "content/child/child_thread.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || | 85 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || |
| 86 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | 86 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| 87 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 87 scoped_ptr<WebServiceWorkerRegistrationCallbacks> |
| 88 owned_callbacks(callbacks); | 88 owned_callbacks(callbacks); |
| 89 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 89 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( |
| 90 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 90 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
| 91 callbacks->onError(error.release()); | 91 callbacks->onError(error.release()); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 | 94 |
| 95 int request_id = pending_callbacks_.Add(callbacks); | 95 int request_id = pending_registration_callbacks_.Add(callbacks); |
| 96 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 96 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
| 97 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 97 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 100 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
| 101 int provider_id, | 101 int provider_id, |
| 102 const GURL& pattern, | 102 const GURL& pattern, |
| 103 WebServiceWorkerRegistrationCallbacks* callbacks) { | 103 WebServiceWorkerUnregistrationCallbacks* callbacks) { |
| 104 DCHECK(callbacks); | 104 DCHECK(callbacks); |
| 105 | 105 |
| 106 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { | 106 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars()) { |
| 107 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | 107 scoped_ptr<WebServiceWorkerUnregistrationCallbacks> |
| 108 owned_callbacks(callbacks); | 108 owned_callbacks(callbacks); |
| 109 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | 109 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( |
| 110 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 110 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
| 111 callbacks->onError(error.release()); | 111 callbacks->onError(error.release()); |
| 112 return; | 112 return; |
| 113 } | 113 } |
| 114 | 114 |
| 115 int request_id = pending_callbacks_.Add(callbacks); | 115 int request_id = pending_unregistration_callbacks_.Add(callbacks); |
| 116 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 116 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
| 117 CurrentWorkerId(), request_id, provider_id, pattern)); | 117 CurrentWorkerId(), request_id, provider_id, pattern)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void ServiceWorkerDispatcher::AddProviderContext( | 120 void ServiceWorkerDispatcher::AddProviderContext( |
| 121 ServiceWorkerProviderContext* provider_context) { | 121 ServiceWorkerProviderContext* provider_context) { |
| 122 DCHECK(provider_context); | 122 DCHECK(provider_context); |
| 123 int provider_id = provider_context->provider_id(); | 123 int provider_id = provider_context->provider_id(); |
| 124 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 124 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
| 125 provider_contexts_[provider_id] = provider_context; | 125 provider_contexts_[provider_id] = provider_context; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 // WebServiceWorkerRegistrationImpl constructor calls | 233 // WebServiceWorkerRegistrationImpl constructor calls |
| 234 // AddServiceWorkerRegistration. | 234 // AddServiceWorkerRegistration. |
| 235 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); | 235 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void ServiceWorkerDispatcher::OnRegistered( | 238 void ServiceWorkerDispatcher::OnRegistered( |
| 239 int thread_id, | 239 int thread_id, |
| 240 int request_id, | 240 int request_id, |
| 241 const ServiceWorkerRegistrationObjectInfo& info) { | 241 const ServiceWorkerRegistrationObjectInfo& info) { |
| 242 WebServiceWorkerRegistrationCallbacks* callbacks = | 242 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 243 pending_callbacks_.Lookup(request_id); | 243 pending_registration_callbacks_.Lookup(request_id); |
| 244 DCHECK(callbacks); | 244 DCHECK(callbacks); |
| 245 if (!callbacks) | 245 if (!callbacks) |
| 246 return; | 246 return; |
| 247 | 247 |
| 248 callbacks->onSuccess(GetServiceWorkerRegistration(info, true)); | 248 callbacks->onSuccess(GetServiceWorkerRegistration(info, true)); |
| 249 pending_callbacks_.Remove(request_id); | 249 pending_registration_callbacks_.Remove(request_id); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void ServiceWorkerDispatcher::OnUnregistered( | 252 void ServiceWorkerDispatcher::OnUnregistered( |
| 253 int thread_id, | 253 int thread_id, |
| 254 int request_id) { | 254 int request_id) { |
| 255 WebServiceWorkerRegistrationCallbacks* callbacks = | 255 WebServiceWorkerUnregistrationCallbacks* callbacks = |
| 256 pending_callbacks_.Lookup(request_id); | 256 pending_unregistration_callbacks_.Lookup(request_id); |
| 257 DCHECK(callbacks); | 257 DCHECK(callbacks); |
| 258 if (!callbacks) | 258 if (!callbacks) |
| 259 return; | 259 return; |
| 260 | 260 #ifdef DISABLE_SERVICEWORKER_UNREGISTER_RESOLVE_TO_BOOLEAN |
| 261 callbacks->onSuccess(NULL); | 261 callbacks->onSuccess(NULL); |
| 262 pending_callbacks_.Remove(request_id); | 262 #else |
| 263 bool is_success = true; | |
| 264 callbacks->onSuccess(&is_success); | |
| 265 #endif | |
| 266 pending_unregistration_callbacks_.Remove(request_id); | |
| 263 } | 267 } |
| 264 | 268 |
| 265 void ServiceWorkerDispatcher::OnRegistrationError( | 269 void ServiceWorkerDispatcher::OnRegistrationError( |
| 266 int thread_id, | 270 int thread_id, |
| 267 int request_id, | 271 int request_id, |
| 268 WebServiceWorkerError::ErrorType error_type, | 272 WebServiceWorkerError::ErrorType error_type, |
| 269 const base::string16& message) { | 273 const base::string16& message) { |
| 270 WebServiceWorkerRegistrationCallbacks* callbacks = | 274 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 271 pending_callbacks_.Lookup(request_id); | 275 pending_registration_callbacks_.Lookup(request_id); |
|
nhiroki
2014/08/29 07:27:29
Probably we can reach here when the unregisteratio
shimazu
2014/09/01 05:35:34
Done.
| |
| 272 DCHECK(callbacks); | 276 DCHECK(callbacks); |
| 273 if (!callbacks) | 277 if (!callbacks) |
| 274 return; | 278 return; |
| 275 | 279 |
| 276 scoped_ptr<WebServiceWorkerError> error( | 280 scoped_ptr<WebServiceWorkerError> error( |
| 277 new WebServiceWorkerError(error_type, message)); | 281 new WebServiceWorkerError(error_type, message)); |
| 278 callbacks->onError(error.release()); | 282 callbacks->onError(error.release()); |
| 279 pending_callbacks_.Remove(request_id); | 283 pending_registration_callbacks_.Remove(request_id); |
| 280 } | 284 } |
| 281 | 285 |
| 282 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( | 286 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( |
| 283 int thread_id, | 287 int thread_id, |
| 284 int handle_id, | 288 int handle_id, |
| 285 blink::WebServiceWorkerState state) { | 289 blink::WebServiceWorkerState state) { |
| 286 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 290 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
| 287 if (worker != service_workers_.end()) | 291 if (worker != service_workers_.end()) |
| 288 worker->second->OnStateChanged(state); | 292 worker->second->OnStateChanged(state); |
| 289 | 293 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 registrations_[registration_handle_id] = registration; | 471 registrations_[registration_handle_id] = registration; |
| 468 } | 472 } |
| 469 | 473 |
| 470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 474 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
| 471 int registration_handle_id) { | 475 int registration_handle_id) { |
| 472 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 476 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
| 473 registrations_.erase(registration_handle_id); | 477 registrations_.erase(registration_handle_id); |
| 474 } | 478 } |
| 475 | 479 |
| 476 } // namespace content | 480 } // namespace content |
| OLD | NEW |