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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { | 52 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
53 bool handled = true; | 53 bool handled = true; |
54 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) | 54 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) |
55 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 55 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 56 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
57 OnUnregistered) | 57 OnUnregistered) |
58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
59 OnRegistrationError) | 59 OnRegistrationError) |
60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
61 OnServiceWorkerStateChanged) | 61 OnServiceWorkerStateChanged) |
62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetInstallingServiceWorker, | 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
63 OnSetInstallingServiceWorker) | 63 OnSetVersionAttributes) |
64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetWaitingServiceWorker, | |
65 OnSetWaitingServiceWorker) | |
66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetActiveServiceWorker, | |
67 OnSetActiveServiceWorker) | |
68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, | 64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, |
69 OnSetControllerServiceWorker) | 65 OnSetControllerServiceWorker) |
70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, | 66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, |
71 OnPostMessage) | 67 OnPostMessage) |
72 IPC_MESSAGE_UNHANDLED(handled = false) | 68 IPC_MESSAGE_UNHANDLED(handled = false) |
73 IPC_END_MESSAGE_MAP() | 69 IPC_END_MESSAGE_MAP() |
74 DCHECK(handled) << "Unhandled message:" << msg.type(); | 70 DCHECK(handled) << "Unhandled message:" << msg.type(); |
75 } | 71 } |
76 | 72 |
77 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { | 73 bool ServiceWorkerDispatcher::Send(IPC::Message* msg) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 blink::WebServiceWorkerState state) { | 256 blink::WebServiceWorkerState state) { |
261 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); | 257 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); |
262 if (worker != service_workers_.end()) | 258 if (worker != service_workers_.end()) |
263 worker->second->OnStateChanged(state); | 259 worker->second->OnStateChanged(state); |
264 | 260 |
265 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); | 261 WorkerToProviderMap::iterator provider = worker_to_provider_.find(handle_id); |
266 if (provider != worker_to_provider_.end()) | 262 if (provider != worker_to_provider_.end()) |
267 provider->second->OnServiceWorkerStateChanged(handle_id, state); | 263 provider->second->OnServiceWorkerStateChanged(handle_id, state); |
268 } | 264 } |
269 | 265 |
270 void ServiceWorkerDispatcher::OnSetInstallingServiceWorker( | 266 void ServiceWorkerDispatcher::OnSetVersionAttributes( |
271 int thread_id, | 267 int thread_id, |
272 int provider_id, | 268 int provider_id, |
| 269 int changed_mask, |
| 270 const ServiceWorkerVersionAttributes& attributes) { |
| 271 ChangedVersionAttributesMask mask(changed_mask); |
| 272 if (mask.installing_changed()) |
| 273 SetInstallingServiceWorker(provider_id, attributes.installing); |
| 274 if (mask.waiting_changed()) |
| 275 SetWaitingServiceWorker(provider_id, attributes.waiting); |
| 276 if (mask.active_changed()) |
| 277 SetActiveServiceWorker(provider_id, attributes.active); |
| 278 } |
| 279 |
| 280 void ServiceWorkerDispatcher::SetInstallingServiceWorker( |
| 281 int provider_id, |
273 const ServiceWorkerObjectInfo& info) { | 282 const ServiceWorkerObjectInfo& info) { |
274 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 283 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
275 if (provider != provider_contexts_.end()) { | 284 if (provider != provider_contexts_.end()) { |
276 int existing_installing_id = provider->second->installing_handle_id(); | 285 int existing_installing_id = provider->second->installing_handle_id(); |
277 if (existing_installing_id != info.handle_id && | 286 if (existing_installing_id != info.handle_id && |
278 existing_installing_id != kInvalidServiceWorkerHandleId) { | 287 existing_installing_id != kInvalidServiceWorkerHandleId) { |
279 WorkerToProviderMap::iterator associated_provider = | 288 WorkerToProviderMap::iterator associated_provider = |
280 worker_to_provider_.find(existing_installing_id); | 289 worker_to_provider_.find(existing_installing_id); |
281 DCHECK(associated_provider != worker_to_provider_.end()); | 290 DCHECK(associated_provider != worker_to_provider_.end()); |
282 DCHECK(associated_provider->second->provider_id() == provider_id); | 291 DCHECK(associated_provider->second->provider_id() == provider_id); |
283 worker_to_provider_.erase(associated_provider); | 292 worker_to_provider_.erase(associated_provider); |
284 } | 293 } |
285 provider->second->OnSetInstallingServiceWorker(provider_id, info); | 294 provider->second->OnSetInstallingServiceWorker(provider_id, info); |
286 if (info.handle_id != kInvalidServiceWorkerHandleId) | 295 if (info.handle_id != kInvalidServiceWorkerHandleId) |
287 worker_to_provider_[info.handle_id] = provider->second; | 296 worker_to_provider_[info.handle_id] = provider->second; |
288 } | 297 } |
289 | 298 |
290 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 299 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
291 if (found != script_clients_.end()) { | 300 if (found != script_clients_.end()) { |
292 // Populate the .installing field with the new worker object. | 301 // Populate the .installing field with the new worker object. |
293 found->second->setInstalling(GetServiceWorker(info, false)); | 302 found->second->setInstalling(GetServiceWorker(info, false)); |
294 } | 303 } |
295 } | 304 } |
296 | 305 |
297 void ServiceWorkerDispatcher::OnSetWaitingServiceWorker( | 306 void ServiceWorkerDispatcher::SetWaitingServiceWorker( |
298 int thread_id, | |
299 int provider_id, | 307 int provider_id, |
300 const ServiceWorkerObjectInfo& info) { | 308 const ServiceWorkerObjectInfo& info) { |
301 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 309 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
302 if (provider != provider_contexts_.end()) { | 310 if (provider != provider_contexts_.end()) { |
303 int existing_waiting_id = provider->second->waiting_handle_id(); | 311 int existing_waiting_id = provider->second->waiting_handle_id(); |
304 if (existing_waiting_id != info.handle_id && | 312 if (existing_waiting_id != info.handle_id && |
305 existing_waiting_id != kInvalidServiceWorkerHandleId) { | 313 existing_waiting_id != kInvalidServiceWorkerHandleId) { |
306 WorkerToProviderMap::iterator associated_provider = | 314 WorkerToProviderMap::iterator associated_provider = |
307 worker_to_provider_.find(existing_waiting_id); | 315 worker_to_provider_.find(existing_waiting_id); |
308 DCHECK(associated_provider != worker_to_provider_.end()); | 316 DCHECK(associated_provider != worker_to_provider_.end()); |
309 DCHECK(associated_provider->second->provider_id() == provider_id); | 317 DCHECK(associated_provider->second->provider_id() == provider_id); |
310 worker_to_provider_.erase(associated_provider); | 318 worker_to_provider_.erase(associated_provider); |
311 } | 319 } |
312 provider->second->OnSetWaitingServiceWorker(provider_id, info); | 320 provider->second->OnSetWaitingServiceWorker(provider_id, info); |
313 if (info.handle_id != kInvalidServiceWorkerHandleId) | 321 if (info.handle_id != kInvalidServiceWorkerHandleId) |
314 worker_to_provider_[info.handle_id] = provider->second; | 322 worker_to_provider_[info.handle_id] = provider->second; |
315 } | 323 } |
316 | 324 |
317 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 325 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
318 if (found != script_clients_.end()) { | 326 if (found != script_clients_.end()) { |
319 // Populate the .waiting field with the new worker object. | 327 // Populate the .waiting field with the new worker object. |
320 found->second->setWaiting(GetServiceWorker(info, false)); | 328 found->second->setWaiting(GetServiceWorker(info, false)); |
321 } | 329 } |
322 } | 330 } |
323 | 331 |
324 void ServiceWorkerDispatcher::OnSetActiveServiceWorker( | 332 void ServiceWorkerDispatcher::SetActiveServiceWorker( |
325 int thread_id, | |
326 int provider_id, | 333 int provider_id, |
327 const ServiceWorkerObjectInfo& info) { | 334 const ServiceWorkerObjectInfo& info) { |
328 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 335 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
329 if (provider != provider_contexts_.end()) { | 336 if (provider != provider_contexts_.end()) { |
330 int existing_active_id = provider->second->active_handle_id(); | 337 int existing_active_id = provider->second->active_handle_id(); |
331 if (existing_active_id != info.handle_id && | 338 if (existing_active_id != info.handle_id && |
332 existing_active_id != kInvalidServiceWorkerHandleId) { | 339 existing_active_id != kInvalidServiceWorkerHandleId) { |
333 WorkerToProviderMap::iterator associated_provider = | 340 WorkerToProviderMap::iterator associated_provider = |
334 worker_to_provider_.find(existing_active_id); | 341 worker_to_provider_.find(existing_active_id); |
335 DCHECK(associated_provider != worker_to_provider_.end()); | 342 DCHECK(associated_provider != worker_to_provider_.end()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 DCHECK(!ContainsKey(service_workers_, handle_id)); | 407 DCHECK(!ContainsKey(service_workers_, handle_id)); |
401 service_workers_[handle_id] = worker; | 408 service_workers_[handle_id] = worker; |
402 } | 409 } |
403 | 410 |
404 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { | 411 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { |
405 DCHECK(ContainsKey(service_workers_, handle_id)); | 412 DCHECK(ContainsKey(service_workers_, handle_id)); |
406 service_workers_.erase(handle_id); | 413 service_workers_.erase(handle_id); |
407 } | 414 } |
408 | 415 |
409 } // namespace content | 416 } // namespace content |
OLD | NEW |