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_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_ServiceWorkerRegistrationError, | 59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
60 OnRegistrationError) | 60 OnRegistrationError) |
61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
62 OnServiceWorkerStateChanged) | 62 OnServiceWorkerStateChanged) |
63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, | 63 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
64 OnSetVersionAttributes) | 64 OnSetVersionAttributes) |
| 65 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, |
| 66 OnUpdateFound) |
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 info, thread_safe_sender_.get()); | 233 info, thread_safe_sender_.get()); |
232 | 234 |
233 // WebServiceWorkerRegistrationImpl constructor calls | 235 // WebServiceWorkerRegistrationImpl constructor calls |
234 // AddServiceWorkerRegistration. | 236 // AddServiceWorkerRegistration. |
235 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); | 237 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); |
236 } | 238 } |
237 | 239 |
238 void ServiceWorkerDispatcher::OnRegistered( | 240 void ServiceWorkerDispatcher::OnRegistered( |
239 int thread_id, | 241 int thread_id, |
240 int request_id, | 242 int request_id, |
241 const ServiceWorkerRegistrationObjectInfo& info) { | 243 const ServiceWorkerRegistrationObjectInfo& info, |
| 244 const ServiceWorkerVersionAttributes& attrs) { |
242 WebServiceWorkerRegistrationCallbacks* callbacks = | 245 WebServiceWorkerRegistrationCallbacks* callbacks = |
243 pending_callbacks_.Lookup(request_id); | 246 pending_callbacks_.Lookup(request_id); |
244 DCHECK(callbacks); | 247 DCHECK(callbacks); |
245 if (!callbacks) | 248 if (!callbacks) |
246 return; | 249 return; |
247 | 250 |
248 callbacks->onSuccess(GetServiceWorkerRegistration(info, true)); | 251 WebServiceWorkerRegistrationImpl* registration = |
| 252 GetServiceWorkerRegistration(info, true); |
| 253 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); |
| 254 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); |
| 255 registration->SetActive(GetServiceWorker(attrs.active, true)); |
| 256 |
| 257 callbacks->onSuccess(registration); |
249 pending_callbacks_.Remove(request_id); | 258 pending_callbacks_.Remove(request_id); |
250 } | 259 } |
251 | 260 |
252 void ServiceWorkerDispatcher::OnUnregistered( | 261 void ServiceWorkerDispatcher::OnUnregistered( |
253 int thread_id, | 262 int thread_id, |
254 int request_id) { | 263 int request_id) { |
255 WebServiceWorkerRegistrationCallbacks* callbacks = | 264 WebServiceWorkerRegistrationCallbacks* callbacks = |
256 pending_callbacks_.Lookup(request_id); | 265 pending_callbacks_.Lookup(request_id); |
257 DCHECK(callbacks); | 266 DCHECK(callbacks); |
258 if (!callbacks) | 267 if (!callbacks) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 registration_handle_id, | 318 registration_handle_id, |
310 attributes.waiting); | 319 attributes.waiting); |
311 } | 320 } |
312 if (mask.active_changed()) { | 321 if (mask.active_changed()) { |
313 SetActiveServiceWorker(provider_id, | 322 SetActiveServiceWorker(provider_id, |
314 registration_handle_id, | 323 registration_handle_id, |
315 attributes.active); | 324 attributes.active); |
316 } | 325 } |
317 } | 326 } |
318 | 327 |
| 328 void ServiceWorkerDispatcher::OnUpdateFound( |
| 329 int thread_id, |
| 330 const ServiceWorkerRegistrationObjectInfo& info) { |
| 331 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); |
| 332 if (found != registrations_.end()) |
| 333 found->second->OnUpdateFound(); |
| 334 } |
| 335 |
319 void ServiceWorkerDispatcher::SetInstallingServiceWorker( | 336 void ServiceWorkerDispatcher::SetInstallingServiceWorker( |
320 int provider_id, | 337 int provider_id, |
321 int registration_handle_id, | 338 int registration_handle_id, |
322 const ServiceWorkerObjectInfo& info) { | 339 const ServiceWorkerObjectInfo& info) { |
323 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 340 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
324 if (provider != provider_contexts_.end()) { | 341 if (provider != provider_contexts_.end()) { |
325 int existing_installing_id = provider->second->installing_handle_id(); | 342 int existing_installing_id = provider->second->installing_handle_id(); |
326 if (existing_installing_id != info.handle_id && | 343 if (existing_installing_id != info.handle_id && |
327 existing_installing_id != kInvalidServiceWorkerHandleId) { | 344 existing_installing_id != kInvalidServiceWorkerHandleId) { |
328 WorkerToProviderMap::iterator associated_provider = | 345 WorkerToProviderMap::iterator associated_provider = |
329 worker_to_provider_.find(existing_installing_id); | 346 worker_to_provider_.find(existing_installing_id); |
330 DCHECK(associated_provider != worker_to_provider_.end()); | 347 DCHECK(associated_provider != worker_to_provider_.end()); |
331 DCHECK(associated_provider->second->provider_id() == provider_id); | 348 DCHECK(associated_provider->second->provider_id() == provider_id); |
332 worker_to_provider_.erase(associated_provider); | 349 worker_to_provider_.erase(associated_provider); |
333 } | 350 } |
334 provider->second->OnSetInstallingServiceWorker(provider_id, info); | 351 provider->second->OnSetInstallingServiceWorker(provider_id, info); |
335 if (info.handle_id != kInvalidServiceWorkerHandleId) | 352 if (info.handle_id != kInvalidServiceWorkerHandleId) |
336 worker_to_provider_[info.handle_id] = provider->second; | 353 worker_to_provider_[info.handle_id] = provider->second; |
337 } | 354 } |
338 | 355 |
339 RegistrationObjectMap::iterator found = | 356 RegistrationObjectMap::iterator found = |
340 registrations_.find(registration_handle_id); | 357 registrations_.find(registration_handle_id); |
341 if (found != registrations_.end()) { | 358 if (found != registrations_.end()) { |
342 // Populate the .installing field with the new worker object. | 359 // Populate the .installing field with the new worker object. |
343 found->second->SetInstalling(GetServiceWorker(info, false)); | 360 found->second->SetInstalling(GetServiceWorker(info, false)); |
344 if (info.handle_id != kInvalidServiceWorkerHandleId) | |
345 found->second->OnUpdateFound(); | |
346 } | 361 } |
347 } | 362 } |
348 | 363 |
349 void ServiceWorkerDispatcher::SetWaitingServiceWorker( | 364 void ServiceWorkerDispatcher::SetWaitingServiceWorker( |
350 int provider_id, | 365 int provider_id, |
351 int registration_handle_id, | 366 int registration_handle_id, |
352 const ServiceWorkerObjectInfo& info) { | 367 const ServiceWorkerObjectInfo& info) { |
353 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 368 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
354 if (provider != provider_contexts_.end()) { | 369 if (provider != provider_contexts_.end()) { |
355 int existing_waiting_id = provider->second->waiting_handle_id(); | 370 int existing_waiting_id = provider->second->waiting_handle_id(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 registrations_[registration_handle_id] = registration; | 482 registrations_[registration_handle_id] = registration; |
468 } | 483 } |
469 | 484 |
470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 485 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
471 int registration_handle_id) { | 486 int registration_handle_id) { |
472 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 487 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
473 registrations_.erase(registration_handle_id); | 488 registrations_.erase(registration_handle_id); |
474 } | 489 } |
475 | 490 |
476 } // namespace content | 491 } // namespace content |
OLD | NEW |