| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { | 51 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 52 bool handled = true; | 52 bool handled = true; |
| 53 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) | 53 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) |
| 54 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 54 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
| 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, |
| 62 OnSetInstallingServiceWorker) |
| 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetWaitingServiceWorker, | 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetWaitingServiceWorker, |
| 62 OnSetWaitingServiceWorker) | 64 OnSetWaitingServiceWorker) |
| 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, | 65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, |
| 64 OnSetControllerServiceWorker) | 66 OnSetControllerServiceWorker) |
| 65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, | 67 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, |
| 66 OnPostMessage) | 68 OnPostMessage) |
| 67 IPC_MESSAGE_UNHANDLED(handled = false) | 69 IPC_MESSAGE_UNHANDLED(handled = false) |
| 68 IPC_END_MESSAGE_MAP() | 70 IPC_END_MESSAGE_MAP() |
| 69 DCHECK(handled) << "Unhandled message:" << msg.type(); | 71 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 70 } | 72 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 int provider_id = provider_context->provider_id(); | 123 int provider_id = provider_context->provider_id(); |
| 122 DCHECK(!ContainsKey(provider_contexts_, provider_id)); | 124 DCHECK(!ContainsKey(provider_contexts_, provider_id)); |
| 123 provider_contexts_[provider_id] = provider_context; | 125 provider_contexts_[provider_id] = provider_context; |
| 124 } | 126 } |
| 125 | 127 |
| 126 void ServiceWorkerDispatcher::RemoveProviderContext( | 128 void ServiceWorkerDispatcher::RemoveProviderContext( |
| 127 ServiceWorkerProviderContext* provider_context) { | 129 ServiceWorkerProviderContext* provider_context) { |
| 128 DCHECK(provider_context); | 130 DCHECK(provider_context); |
| 129 DCHECK(ContainsKey(provider_contexts_, provider_context->provider_id())); | 131 DCHECK(ContainsKey(provider_contexts_, provider_context->provider_id())); |
| 130 provider_contexts_.erase(provider_context->provider_id()); | 132 provider_contexts_.erase(provider_context->provider_id()); |
| 133 worker_to_provider_.erase(provider_context->installing_handle_id()); |
| 131 worker_to_provider_.erase(provider_context->waiting_handle_id()); | 134 worker_to_provider_.erase(provider_context->waiting_handle_id()); |
| 132 worker_to_provider_.erase(provider_context->controller_handle_id()); | 135 worker_to_provider_.erase(provider_context->controller_handle_id()); |
| 133 } | 136 } |
| 134 | 137 |
| 135 void ServiceWorkerDispatcher::AddScriptClient( | 138 void ServiceWorkerDispatcher::AddScriptClient( |
| 136 int provider_id, | 139 int provider_id, |
| 137 blink::WebServiceWorkerProviderClient* client) { | 140 blink::WebServiceWorkerProviderClient* client) { |
| 138 DCHECK(client); | 141 DCHECK(client); |
| 139 DCHECK(!ContainsKey(script_clients_, provider_id)); | 142 DCHECK(!ContainsKey(script_clients_, provider_id)); |
| 140 script_clients_[provider_id] = client; | 143 script_clients_[provider_id] = client; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 blink::WebServiceWorkerState state) { | 252 blink::WebServiceWorkerState state) { |
| 250 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 253 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
| 251 if (worker != service_workers_.end()) | 254 if (worker != service_workers_.end()) |
| 252 worker->second->OnStateChanged(state); | 255 worker->second->OnStateChanged(state); |
| 253 | 256 |
| 254 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); | 257 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); |
| 255 if (provider != worker_to_provider_.end()) | 258 if (provider != worker_to_provider_.end()) |
| 256 provider->second->OnServiceWorkerStateChanged(handle_id, state); | 259 provider->second->OnServiceWorkerStateChanged(handle_id, state); |
| 257 } | 260 } |
| 258 | 261 |
| 262 void ServiceWorkerDispatcher::OnSetInstallingServiceWorker( |
| 263 int thread_id, |
| 264 int provider_id, |
| 265 const ServiceWorkerObjectInfo& info) { |
| 266 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 267 if (provider != provider_contexts_.end()) { |
| 268 int existing_installing_id = provider->second->installing_handle_id(); |
| 269 if (existing_installing_id != info.handle_id && |
| 270 existing_installing_id != kInvalidServiceWorkerHandleId) { |
| 271 WorkerToProviderMap::iterator associated_provider = |
| 272 worker_to_provider_.find(existing_installing_id); |
| 273 DCHECK(associated_provider != worker_to_provider_.end()); |
| 274 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 275 worker_to_provider_.erase(associated_provider); |
| 276 } |
| 277 provider->second->OnSetInstallingServiceWorker(provider_id, info); |
| 278 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 279 worker_to_provider_[info.handle_id] = provider->second; |
| 280 } |
| 281 |
| 282 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
| 283 if (found != script_clients_.end()) { |
| 284 // Populate the .installing field with the new worker object. |
| 285 found->second->setInstalling(GetServiceWorker(info, false)); |
| 286 } |
| 287 } |
| 288 |
| 259 void ServiceWorkerDispatcher::OnSetWaitingServiceWorker( | 289 void ServiceWorkerDispatcher::OnSetWaitingServiceWorker( |
| 260 int thread_id, | 290 int thread_id, |
| 261 int provider_id, | 291 int provider_id, |
| 262 const ServiceWorkerObjectInfo& info) { | 292 const ServiceWorkerObjectInfo& info) { |
| 263 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 293 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 264 if (provider != provider_contexts_.end()) { | 294 if (provider != provider_contexts_.end()) { |
| 265 int existing_waiting_id = provider->second->waiting_handle_id(); | 295 int existing_waiting_id = provider->second->waiting_handle_id(); |
| 266 if (existing_waiting_id != info.handle_id && | 296 if (existing_waiting_id != info.handle_id && |
| 267 existing_waiting_id != kInvalidServiceWorkerHandleId) { | 297 existing_waiting_id != kInvalidServiceWorkerHandleId) { |
| 268 WorkerToProviderMap::iterator associated_provider = | 298 WorkerToProviderMap::iterator associated_provider = |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 DCHECK(!ContainsKey(service_workers_, handle_id)); | 365 DCHECK(!ContainsKey(service_workers_, handle_id)); |
| 336 service_workers_[handle_id] = worker; | 366 service_workers_[handle_id] = worker; |
| 337 } | 367 } |
| 338 | 368 |
| 339 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 369 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
| 340 DCHECK(ContainsKey(service_workers_, handle_id)); | 370 DCHECK(ContainsKey(service_workers_, handle_id)); |
| 341 service_workers_.erase(handle_id); | 371 service_workers_.erase(handle_id); |
| 342 } | 372 } |
| 343 | 373 |
| 344 } // namespace content | 374 } // namespace content |
| OLD | NEW |