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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 333 } |
334 provider->second->OnSetInstallingServiceWorker(provider_id, info); | 334 provider->second->OnSetInstallingServiceWorker(provider_id, info); |
335 if (info.handle_id != kInvalidServiceWorkerHandleId) | 335 if (info.handle_id != kInvalidServiceWorkerHandleId) |
336 worker_to_provider_[info.handle_id] = provider->second; | 336 worker_to_provider_[info.handle_id] = provider->second; |
337 } | 337 } |
338 | 338 |
339 RegistrationObjectMap::iterator found = | 339 RegistrationObjectMap::iterator found = |
340 registrations_.find(registration_handle_id); | 340 registrations_.find(registration_handle_id); |
341 if (found != registrations_.end()) { | 341 if (found != registrations_.end()) { |
342 // Populate the .installing field with the new worker object. | 342 // Populate the .installing field with the new worker object. |
343 found->second->setInstalling(GetServiceWorker(info, false)); | 343 found->second->SetInstalling(GetServiceWorker(info, false)); |
344 if (info.handle_id != kInvalidServiceWorkerHandleId) | 344 if (info.handle_id != kInvalidServiceWorkerHandleId) |
345 found->second->OnUpdateFound(); | 345 found->second->OnUpdateFound(); |
346 } | 346 } |
347 } | 347 } |
348 | 348 |
349 void ServiceWorkerDispatcher::SetWaitingServiceWorker( | 349 void ServiceWorkerDispatcher::SetWaitingServiceWorker( |
350 int provider_id, | 350 int provider_id, |
351 int registration_handle_id, | 351 int registration_handle_id, |
352 const ServiceWorkerObjectInfo& info) { | 352 const ServiceWorkerObjectInfo& info) { |
353 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 353 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
354 if (provider != provider_contexts_.end()) { | 354 if (provider != provider_contexts_.end()) { |
355 int existing_waiting_id = provider->second->waiting_handle_id(); | 355 int existing_waiting_id = provider->second->waiting_handle_id(); |
356 if (existing_waiting_id != info.handle_id && | 356 if (existing_waiting_id != info.handle_id && |
357 existing_waiting_id != kInvalidServiceWorkerHandleId) { | 357 existing_waiting_id != kInvalidServiceWorkerHandleId) { |
358 WorkerToProviderMap::iterator associated_provider = | 358 WorkerToProviderMap::iterator associated_provider = |
359 worker_to_provider_.find(existing_waiting_id); | 359 worker_to_provider_.find(existing_waiting_id); |
360 DCHECK(associated_provider != worker_to_provider_.end()); | 360 DCHECK(associated_provider != worker_to_provider_.end()); |
361 DCHECK(associated_provider->second->provider_id() == provider_id); | 361 DCHECK(associated_provider->second->provider_id() == provider_id); |
362 worker_to_provider_.erase(associated_provider); | 362 worker_to_provider_.erase(associated_provider); |
363 } | 363 } |
364 provider->second->OnSetWaitingServiceWorker(provider_id, info); | 364 provider->second->OnSetWaitingServiceWorker(provider_id, info); |
365 if (info.handle_id != kInvalidServiceWorkerHandleId) | 365 if (info.handle_id != kInvalidServiceWorkerHandleId) |
366 worker_to_provider_[info.handle_id] = provider->second; | 366 worker_to_provider_[info.handle_id] = provider->second; |
367 } | 367 } |
368 | 368 |
369 RegistrationObjectMap::iterator found = | 369 RegistrationObjectMap::iterator found = |
370 registrations_.find(registration_handle_id); | 370 registrations_.find(registration_handle_id); |
371 if (found != registrations_.end()) { | 371 if (found != registrations_.end()) { |
372 // Populate the .waiting field with the new worker object. | 372 // Populate the .waiting field with the new worker object. |
373 found->second->setWaiting(GetServiceWorker(info, false)); | 373 found->second->SetWaiting(GetServiceWorker(info, false)); |
374 } | 374 } |
375 } | 375 } |
376 | 376 |
377 void ServiceWorkerDispatcher::SetActiveServiceWorker( | 377 void ServiceWorkerDispatcher::SetActiveServiceWorker( |
378 int provider_id, | 378 int provider_id, |
379 int registration_handle_id, | 379 int registration_handle_id, |
380 const ServiceWorkerObjectInfo& info) { | 380 const ServiceWorkerObjectInfo& info) { |
381 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 381 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
382 if (provider != provider_contexts_.end()) { | 382 if (provider != provider_contexts_.end()) { |
383 int existing_active_id = provider->second->active_handle_id(); | 383 int existing_active_id = provider->second->active_handle_id(); |
384 if (existing_active_id != info.handle_id && | 384 if (existing_active_id != info.handle_id && |
385 existing_active_id != kInvalidServiceWorkerHandleId) { | 385 existing_active_id != kInvalidServiceWorkerHandleId) { |
386 WorkerToProviderMap::iterator associated_provider = | 386 WorkerToProviderMap::iterator associated_provider = |
387 worker_to_provider_.find(existing_active_id); | 387 worker_to_provider_.find(existing_active_id); |
388 DCHECK(associated_provider != worker_to_provider_.end()); | 388 DCHECK(associated_provider != worker_to_provider_.end()); |
389 DCHECK(associated_provider->second->provider_id() == provider_id); | 389 DCHECK(associated_provider->second->provider_id() == provider_id); |
390 worker_to_provider_.erase(associated_provider); | 390 worker_to_provider_.erase(associated_provider); |
391 } | 391 } |
392 provider->second->OnSetActiveServiceWorker(provider_id, info); | 392 provider->second->OnSetActiveServiceWorker(provider_id, info); |
393 if (info.handle_id != kInvalidServiceWorkerHandleId) | 393 if (info.handle_id != kInvalidServiceWorkerHandleId) |
394 worker_to_provider_[info.handle_id] = provider->second; | 394 worker_to_provider_[info.handle_id] = provider->second; |
395 } | 395 } |
396 | 396 |
397 RegistrationObjectMap::iterator found = | 397 RegistrationObjectMap::iterator found = |
398 registrations_.find(registration_handle_id); | 398 registrations_.find(registration_handle_id); |
399 if (found != registrations_.end()) { | 399 if (found != registrations_.end()) { |
400 // Populate the .active field with the new worker object. | 400 // Populate the .active field with the new worker object. |
401 found->second->setActive(GetServiceWorker(info, false)); | 401 found->second->SetActive(GetServiceWorker(info, false)); |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( | 405 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( |
406 int thread_id, | 406 int thread_id, |
407 int provider_id, | 407 int provider_id, |
408 const ServiceWorkerObjectInfo& info) { | 408 const ServiceWorkerObjectInfo& info) { |
409 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 409 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
410 if (provider != provider_contexts_.end()) { | 410 if (provider != provider_contexts_.end()) { |
411 provider->second->OnSetControllerServiceWorker(provider_id, info); | 411 provider->second->OnSetControllerServiceWorker(provider_id, info); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 registrations_[registration_handle_id] = registration; | 467 registrations_[registration_handle_id] = registration; |
468 } | 468 } |
469 | 469 |
470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 470 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
471 int registration_handle_id) { | 471 int registration_handle_id) { |
472 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 472 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
473 registrations_.erase(registration_handle_id); | 473 registrations_.erase(registration_handle_id); |
474 } | 474 } |
475 | 475 |
476 } // namespace content | 476 } // namespace content |
OLD | NEW |