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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 55 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
56 OnUnregistered) | 56 OnUnregistered) |
57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
58 OnRegistrationError) | 58 OnRegistrationError) |
59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
60 OnServiceWorkerStateChanged) | 60 OnServiceWorkerStateChanged) |
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetInstallingServiceWorker, | 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetInstallingServiceWorker, |
62 OnSetInstallingServiceWorker) | 62 OnSetInstallingServiceWorker) |
63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetWaitingServiceWorker, | 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetWaitingServiceWorker, |
64 OnSetWaitingServiceWorker) | 64 OnSetWaitingServiceWorker) |
| 65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetActiveServiceWorker, |
| 66 OnSetActiveServiceWorker) |
65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, | 67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, |
66 OnSetControllerServiceWorker) | 68 OnSetControllerServiceWorker) |
67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, | 69 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, |
68 OnPostMessage) | 70 OnPostMessage) |
69 IPC_MESSAGE_UNHANDLED(handled = false) | 71 IPC_MESSAGE_UNHANDLED(handled = false) |
70 IPC_END_MESSAGE_MAP() | 72 IPC_END_MESSAGE_MAP() |
71 DCHECK(handled) << "Unhandled message:" << msg.type(); | 73 DCHECK(handled) << "Unhandled message:" << msg.type(); |
72 } | 74 } |
73 | 75 |
74 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { | 76 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 provider_contexts_[provider_id] = provider_context; | 127 provider_contexts_[provider_id] = provider_context; |
126 } | 128 } |
127 | 129 |
128 void ServiceWorkerDispatcher::RemoveProviderContext( | 130 void ServiceWorkerDispatcher::RemoveProviderContext( |
129 ServiceWorkerProviderContext* provider_context) { | 131 ServiceWorkerProviderContext* provider_context) { |
130 DCHECK(provider_context); | 132 DCHECK(provider_context); |
131 DCHECK(ContainsKey(provider_contexts_, provider_context->provider_id())); | 133 DCHECK(ContainsKey(provider_contexts_, provider_context->provider_id())); |
132 provider_contexts_.erase(provider_context->provider_id()); | 134 provider_contexts_.erase(provider_context->provider_id()); |
133 worker_to_provider_.erase(provider_context->installing_handle_id()); | 135 worker_to_provider_.erase(provider_context->installing_handle_id()); |
134 worker_to_provider_.erase(provider_context->waiting_handle_id()); | 136 worker_to_provider_.erase(provider_context->waiting_handle_id()); |
| 137 worker_to_provider_.erase(provider_context->active_handle_id()); |
135 worker_to_provider_.erase(provider_context->controller_handle_id()); | 138 worker_to_provider_.erase(provider_context->controller_handle_id()); |
136 } | 139 } |
137 | 140 |
138 void ServiceWorkerDispatcher::AddScriptClient( | 141 void ServiceWorkerDispatcher::AddScriptClient( |
139 int provider_id, | 142 int provider_id, |
140 blink::WebServiceWorkerProviderClient* client) { | 143 blink::WebServiceWorkerProviderClient* client) { |
141 DCHECK(client); | 144 DCHECK(client); |
142 DCHECK(!ContainsKey(script_clients_, provider_id)); | 145 DCHECK(!ContainsKey(script_clients_, provider_id)); |
143 script_clients_[provider_id] = client; | 146 script_clients_[provider_id] = client; |
144 } | 147 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 worker_to_provider_[info.handle_id] = provider->second; | 309 worker_to_provider_[info.handle_id] = provider->second; |
307 } | 310 } |
308 | 311 |
309 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 312 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
310 if (found != script_clients_.end()) { | 313 if (found != script_clients_.end()) { |
311 // Populate the .waiting field with the new worker object. | 314 // Populate the .waiting field with the new worker object. |
312 found->second->setWaiting(GetServiceWorker(info, false)); | 315 found->second->setWaiting(GetServiceWorker(info, false)); |
313 } | 316 } |
314 } | 317 } |
315 | 318 |
| 319 void ServiceWorkerDispatcher::OnSetActiveServiceWorker( |
| 320 int thread_id, |
| 321 int provider_id, |
| 322 const ServiceWorkerObjectInfo& info) { |
| 323 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 324 if (provider != provider_contexts_.end()) { |
| 325 int existing_active_id = provider->second->active_handle_id(); |
| 326 if (existing_active_id != info.handle_id && |
| 327 existing_active_id != kInvalidServiceWorkerHandleId) { |
| 328 WorkerToProviderMap::iterator associated_provider = |
| 329 worker_to_provider_.find(existing_active_id); |
| 330 DCHECK(associated_provider != worker_to_provider_.end()); |
| 331 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 332 worker_to_provider_.erase(associated_provider); |
| 333 } |
| 334 provider->second->OnSetActiveServiceWorker(provider_id, info); |
| 335 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 336 worker_to_provider_[info.handle_id] = provider->second; |
| 337 } |
| 338 |
| 339 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
| 340 if (found != script_clients_.end()) { |
| 341 // Populate the .active field with the new worker object. |
| 342 found->second->setActive(GetServiceWorker(info, false)); |
| 343 } |
| 344 } |
| 345 |
316 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( | 346 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( |
317 int thread_id, | 347 int thread_id, |
318 int provider_id, | 348 int provider_id, |
319 const ServiceWorkerObjectInfo& info) { | 349 const ServiceWorkerObjectInfo& info) { |
320 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 350 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
321 if (provider != provider_contexts_.end()) { | 351 if (provider != provider_contexts_.end()) { |
322 provider->second->OnSetControllerServiceWorker(provider_id, info); | 352 provider->second->OnSetControllerServiceWorker(provider_id, info); |
323 worker_to_provider_[info.handle_id] = provider->second; | 353 worker_to_provider_[info.handle_id] = provider->second; |
324 } | 354 } |
325 | 355 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 DCHECK(!ContainsKey(service_workers_, handle_id)); | 395 DCHECK(!ContainsKey(service_workers_, handle_id)); |
366 service_workers_[handle_id] = worker; | 396 service_workers_[handle_id] = worker; |
367 } | 397 } |
368 | 398 |
369 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 399 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
370 DCHECK(ContainsKey(service_workers_, handle_id)); | 400 DCHECK(ContainsKey(service_workers_, handle_id)); |
371 service_workers_.erase(handle_id); | 401 service_workers_.erase(handle_id); |
372 } | 402 } |
373 | 403 |
374 } // namespace content | 404 } // namespace content |
OLD | NEW |