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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { | 49 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { |
50 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 50 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
51 } | 51 } |
52 | 52 |
53 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { | 53 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
54 bool handled = true; | 54 bool handled = true; |
55 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) | 55 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) |
56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
58 OnUnregistered) | 58 OnUnregistered) |
59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, | |
60 OnDidGetRegistration) | |
59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
60 OnRegistrationError) | 62 OnRegistrationError) |
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
62 OnServiceWorkerStateChanged) | 64 OnServiceWorkerStateChanged) |
63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, | 65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
64 OnSetVersionAttributes) | 66 OnSetVersionAttributes) |
65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, | 67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, |
66 OnUpdateFound) | 68 OnUpdateFound) |
67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, | 69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, |
68 OnSetControllerServiceWorker) | 70 OnSetControllerServiceWorker) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | 114 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); |
113 callbacks->onError(error.release()); | 115 callbacks->onError(error.release()); |
114 return; | 116 return; |
115 } | 117 } |
116 | 118 |
117 int request_id = pending_callbacks_.Add(callbacks); | 119 int request_id = pending_callbacks_.Add(callbacks); |
118 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 120 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
119 CurrentWorkerId(), request_id, provider_id, pattern)); | 121 CurrentWorkerId(), request_id, provider_id, pattern)); |
120 } | 122 } |
121 | 123 |
124 void ServiceWorkerDispatcher::GetRegistration( | |
125 int provider_id, | |
126 const GURL& document_url, | |
127 WebServiceWorkerRegistrationCallbacks* callbacks) { | |
128 DCHECK(callbacks); | |
129 | |
130 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { | |
131 scoped_ptr<WebServiceWorkerRegistrationCallbacks> | |
132 owned_callbacks(callbacks); | |
133 scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( | |
134 WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); | |
135 callbacks->onError(error.release()); | |
136 return; | |
137 } | |
138 | |
139 int request_id = pending_callbacks_.Add(callbacks); | |
140 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | |
141 CurrentWorkerId(), request_id, provider_id, document_url)); | |
142 } | |
143 | |
122 void ServiceWorkerDispatcher::AddProviderContext( | 144 void ServiceWorkerDispatcher::AddProviderContext( |
123 ServiceWorkerProviderContext* provider_context) { | 145 ServiceWorkerProviderContext* provider_context) { |
124 DCHECK(provider_context); | 146 DCHECK(provider_context); |
125 int provider_id = provider_context->provider_id(); | 147 int provider_id = provider_context->provider_id(); |
126 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 148 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
127 provider_contexts_[provider_id] = provider_context; | 149 provider_contexts_[provider_id] = provider_context; |
128 } | 150 } |
129 | 151 |
130 void ServiceWorkerDispatcher::RemoveProviderContext( | 152 void ServiceWorkerDispatcher::RemoveProviderContext( |
131 ServiceWorkerProviderContext* provider_context) { | 153 ServiceWorkerProviderContext* provider_context) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 WebServiceWorkerRegistrationCallbacks* callbacks = | 286 WebServiceWorkerRegistrationCallbacks* callbacks = |
265 pending_callbacks_.Lookup(request_id); | 287 pending_callbacks_.Lookup(request_id); |
266 DCHECK(callbacks); | 288 DCHECK(callbacks); |
267 if (!callbacks) | 289 if (!callbacks) |
268 return; | 290 return; |
269 | 291 |
270 callbacks->onSuccess(NULL); | 292 callbacks->onSuccess(NULL); |
271 pending_callbacks_.Remove(request_id); | 293 pending_callbacks_.Remove(request_id); |
272 } | 294 } |
273 | 295 |
296 void ServiceWorkerDispatcher::OnDidGetRegistration( | |
297 int thread_id, | |
298 int request_id, | |
299 const ServiceWorkerRegistrationObjectInfo& info, | |
300 const ServiceWorkerVersionAttributes& attrs) { | |
301 WebServiceWorkerRegistrationCallbacks* callbacks = | |
302 pending_callbacks_.Lookup(request_id); | |
303 DCHECK(callbacks); | |
304 if (!callbacks) | |
305 return; | |
306 | |
307 WebServiceWorkerRegistrationImpl* registration = | |
308 GetServiceWorkerRegistration(info, true); | |
309 if (registration) { | |
310 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); | |
311 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); | |
312 registration->SetActive(GetServiceWorker(attrs.active, true)); | |
313 } | |
314 callbacks->onSuccess(registration); | |
nhiroki
2014/09/05 04:55:09
I guess this could be resolved with 'null' if a re
Kunihiko Sakamoto
2014/09/09 07:28:10
Done (in Blink side).
| |
315 pending_callbacks_.Remove(request_id); | |
316 } | |
317 | |
274 void ServiceWorkerDispatcher::OnRegistrationError( | 318 void ServiceWorkerDispatcher::OnRegistrationError( |
275 int thread_id, | 319 int thread_id, |
276 int request_id, | 320 int request_id, |
277 WebServiceWorkerError::ErrorType error_type, | 321 WebServiceWorkerError::ErrorType error_type, |
278 const base::string16& message) { | 322 const base::string16& message) { |
279 WebServiceWorkerRegistrationCallbacks* callbacks = | 323 WebServiceWorkerRegistrationCallbacks* callbacks = |
280 pending_callbacks_.Lookup(request_id); | 324 pending_callbacks_.Lookup(request_id); |
281 DCHECK(callbacks); | 325 DCHECK(callbacks); |
282 if (!callbacks) | 326 if (!callbacks) |
283 return; | 327 return; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 registrations_[registration_handle_id] = registration; | 526 registrations_[registration_handle_id] = registration; |
483 } | 527 } |
484 | 528 |
485 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 529 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
486 int registration_handle_id) { | 530 int registration_handle_id) { |
487 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 531 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
488 registrations_.erase(registration_handle_id); | 532 registrations_.erase(registration_handle_id); |
489 } | 533 } |
490 | 534 |
491 } // namespace content | 535 } // namespace content |
OLD | NEW |