Chromium Code Reviews| 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 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 int thread_id, | 240 int thread_id, |
| 241 int request_id, | 241 int request_id, |
| 242 int registration_handle_id, | 242 int registration_handle_id, |
| 243 const ServiceWorkerObjectInfo& info) { | 243 const ServiceWorkerObjectInfo& info) { |
| 244 WebServiceWorkerRegistrationCallbacks* callbacks = | 244 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 245 pending_callbacks_.Lookup(request_id); | 245 pending_callbacks_.Lookup(request_id); |
| 246 DCHECK(callbacks); | 246 DCHECK(callbacks); |
| 247 if (!callbacks) | 247 if (!callbacks) |
| 248 return; | 248 return; |
| 249 | 249 |
| 250 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION | |
| 251 callbacks->onSuccess(GetServiceWorker(info, true)); | |
| 252 // We should adopt and destroy an unused handle ref. | |
| 253 ServiceWorkerRegistrationHandleReference::Adopt( | |
| 254 registration_handle_id, info, thread_safe_sender_); | |
| 255 #else | |
| 256 callbacks->onSuccess(GetServiceWorkerRegistration( | 250 callbacks->onSuccess(GetServiceWorkerRegistration( |
| 257 registration_handle_id, info, true)); | 251 registration_handle_id, info, true)); |
| 252 | |
| 258 // We should adopt and destroy an unused handle ref. | 253 // We should adopt and destroy an unused handle ref. |
|
falken
2014/08/18 06:41:39
not from this patch, but this comment says "should
nhiroki
2014/08/18 06:45:34
Done. Thanks!
| |
| 254 // TODO(nhiroki): ServiceWorkerDispatcherHost don't have to pass a handle ref. | |
| 259 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); | 255 ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_); |
| 260 #endif | 256 |
| 261 pending_callbacks_.Remove(request_id); | 257 pending_callbacks_.Remove(request_id); |
| 262 } | 258 } |
| 263 | 259 |
| 264 void ServiceWorkerDispatcher::OnUnregistered( | 260 void ServiceWorkerDispatcher::OnUnregistered( |
| 265 int thread_id, | 261 int thread_id, |
| 266 int request_id) { | 262 int request_id) { |
| 267 WebServiceWorkerRegistrationCallbacks* callbacks = | 263 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 268 pending_callbacks_.Lookup(request_id); | 264 pending_callbacks_.Lookup(request_id); |
| 269 DCHECK(callbacks); | 265 DCHECK(callbacks); |
| 270 if (!callbacks) | 266 if (!callbacks) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 worker_to_provider_.find(existing_installing_id); | 337 worker_to_provider_.find(existing_installing_id); |
| 342 DCHECK(associated_provider != worker_to_provider_.end()); | 338 DCHECK(associated_provider != worker_to_provider_.end()); |
| 343 DCHECK(associated_provider->second->provider_id() == provider_id); | 339 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 344 worker_to_provider_.erase(associated_provider); | 340 worker_to_provider_.erase(associated_provider); |
| 345 } | 341 } |
| 346 provider->second->OnSetInstallingServiceWorker(provider_id, info); | 342 provider->second->OnSetInstallingServiceWorker(provider_id, info); |
| 347 if (info.handle_id != kInvalidServiceWorkerHandleId) | 343 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 348 worker_to_provider_[info.handle_id] = provider->second; | 344 worker_to_provider_[info.handle_id] = provider->second; |
| 349 } | 345 } |
| 350 | 346 |
| 351 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION | |
| 352 ScriptClientMap::iterator found = script_clients_.find(provider_id); | |
| 353 if (found != script_clients_.end()) { | |
| 354 // Populate the .installing field with the new worker object. | |
| 355 found->second->setInstalling(GetServiceWorker(info, false)); | |
| 356 } | |
| 357 #else | |
| 358 RegistrationObjectMap::iterator found = | 347 RegistrationObjectMap::iterator found = |
| 359 registrations_.find(registration_handle_id); | 348 registrations_.find(registration_handle_id); |
| 360 if (found != registrations_.end()) { | 349 if (found != registrations_.end()) { |
| 350 // Populate the .installing field with the new worker object. | |
| 361 found->second->setInstalling(GetServiceWorker(info, false)); | 351 found->second->setInstalling(GetServiceWorker(info, false)); |
| 362 if (info.handle_id != kInvalidServiceWorkerHandleId) | 352 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 363 found->second->OnUpdateFound(); | 353 found->second->OnUpdateFound(); |
| 364 } | 354 } |
| 365 #endif | |
| 366 } | 355 } |
| 367 | 356 |
| 368 void ServiceWorkerDispatcher::SetWaitingServiceWorker( | 357 void ServiceWorkerDispatcher::SetWaitingServiceWorker( |
| 369 int provider_id, | 358 int provider_id, |
| 370 int registration_handle_id, | 359 int registration_handle_id, |
| 371 const ServiceWorkerObjectInfo& info) { | 360 const ServiceWorkerObjectInfo& info) { |
| 372 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 361 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 373 if (provider != provider_contexts_.end()) { | 362 if (provider != provider_contexts_.end()) { |
| 374 int existing_waiting_id = provider->second->waiting_handle_id(); | 363 int existing_waiting_id = provider->second->waiting_handle_id(); |
| 375 if (existing_waiting_id != info.handle_id && | 364 if (existing_waiting_id != info.handle_id && |
| 376 existing_waiting_id != kInvalidServiceWorkerHandleId) { | 365 existing_waiting_id != kInvalidServiceWorkerHandleId) { |
| 377 WorkerToProviderMap::iterator associated_provider = | 366 WorkerToProviderMap::iterator associated_provider = |
| 378 worker_to_provider_.find(existing_waiting_id); | 367 worker_to_provider_.find(existing_waiting_id); |
| 379 DCHECK(associated_provider != worker_to_provider_.end()); | 368 DCHECK(associated_provider != worker_to_provider_.end()); |
| 380 DCHECK(associated_provider->second->provider_id() == provider_id); | 369 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 381 worker_to_provider_.erase(associated_provider); | 370 worker_to_provider_.erase(associated_provider); |
| 382 } | 371 } |
| 383 provider->second->OnSetWaitingServiceWorker(provider_id, info); | 372 provider->second->OnSetWaitingServiceWorker(provider_id, info); |
| 384 if (info.handle_id != kInvalidServiceWorkerHandleId) | 373 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 385 worker_to_provider_[info.handle_id] = provider->second; | 374 worker_to_provider_[info.handle_id] = provider->second; |
| 386 } | 375 } |
| 387 | 376 |
| 388 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION | 377 RegistrationObjectMap::iterator found = |
| 389 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 378 registrations_.find(registration_handle_id); |
| 390 if (found != script_clients_.end()) { | 379 if (found != registrations_.end()) { |
| 391 // Populate the .waiting field with the new worker object. | 380 // Populate the .waiting field with the new worker object. |
| 392 found->second->setWaiting(GetServiceWorker(info, false)); | 381 found->second->setWaiting(GetServiceWorker(info, false)); |
| 393 } | 382 } |
| 394 #else | |
| 395 RegistrationObjectMap::iterator found = | |
| 396 registrations_.find(registration_handle_id); | |
| 397 if (found != registrations_.end()) | |
| 398 found->second->setWaiting(GetServiceWorker(info, false)); | |
| 399 #endif | |
| 400 } | 383 } |
| 401 | 384 |
| 402 void ServiceWorkerDispatcher::SetActiveServiceWorker( | 385 void ServiceWorkerDispatcher::SetActiveServiceWorker( |
| 403 int provider_id, | 386 int provider_id, |
| 404 int registration_handle_id, | 387 int registration_handle_id, |
| 405 const ServiceWorkerObjectInfo& info) { | 388 const ServiceWorkerObjectInfo& info) { |
| 406 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 389 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 407 if (provider != provider_contexts_.end()) { | 390 if (provider != provider_contexts_.end()) { |
| 408 int existing_active_id = provider->second->active_handle_id(); | 391 int existing_active_id = provider->second->active_handle_id(); |
| 409 if (existing_active_id != info.handle_id && | 392 if (existing_active_id != info.handle_id && |
| 410 existing_active_id != kInvalidServiceWorkerHandleId) { | 393 existing_active_id != kInvalidServiceWorkerHandleId) { |
| 411 WorkerToProviderMap::iterator associated_provider = | 394 WorkerToProviderMap::iterator associated_provider = |
| 412 worker_to_provider_.find(existing_active_id); | 395 worker_to_provider_.find(existing_active_id); |
| 413 DCHECK(associated_provider != worker_to_provider_.end()); | 396 DCHECK(associated_provider != worker_to_provider_.end()); |
| 414 DCHECK(associated_provider->second->provider_id() == provider_id); | 397 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 415 worker_to_provider_.erase(associated_provider); | 398 worker_to_provider_.erase(associated_provider); |
| 416 } | 399 } |
| 417 provider->second->OnSetActiveServiceWorker(provider_id, info); | 400 provider->second->OnSetActiveServiceWorker(provider_id, info); |
| 418 if (info.handle_id != kInvalidServiceWorkerHandleId) | 401 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 419 worker_to_provider_[info.handle_id] = provider->second; | 402 worker_to_provider_[info.handle_id] = provider->second; |
| 420 } | 403 } |
| 421 | 404 |
| 422 #ifdef DISABLE_SERVICE_WORKER_REGISTRATION | 405 RegistrationObjectMap::iterator found = |
| 423 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 406 registrations_.find(registration_handle_id); |
| 424 if (found != script_clients_.end()) { | 407 if (found != registrations_.end()) { |
| 425 // Populate the .active field with the new worker object. | 408 // Populate the .active field with the new worker object. |
| 426 found->second->setActive(GetServiceWorker(info, false)); | 409 found->second->setActive(GetServiceWorker(info, false)); |
| 427 } | 410 } |
| 428 #else | |
| 429 RegistrationObjectMap::iterator found = | |
| 430 registrations_.find(registration_handle_id); | |
| 431 if (found != registrations_.end()) | |
| 432 found->second->setActive(GetServiceWorker(info, false)); | |
| 433 #endif | |
| 434 } | 411 } |
| 435 | 412 |
| 436 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( | 413 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( |
| 437 int thread_id, | 414 int thread_id, |
| 438 int provider_id, | 415 int provider_id, |
| 439 const ServiceWorkerObjectInfo& info) { | 416 const ServiceWorkerObjectInfo& info) { |
| 440 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 417 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 441 if (provider != provider_contexts_.end()) { | 418 if (provider != provider_contexts_.end()) { |
| 442 provider->second->OnSetControllerServiceWorker(provider_id, info); | 419 provider->second->OnSetControllerServiceWorker(provider_id, info); |
| 443 worker_to_provider_[info.handle_id] = provider->second; | 420 worker_to_provider_[info.handle_id] = provider->second; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 registrations_[registration_handle_id] = registration; | 475 registrations_[registration_handle_id] = registration; |
| 499 } | 476 } |
| 500 | 477 |
| 501 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 478 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
| 502 int registration_handle_id) { | 479 int registration_handle_id) { |
| 503 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 480 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
| 504 registrations_.erase(registration_handle_id); | 481 registrations_.erase(registration_handle_id); |
| 505 } | 482 } |
| 506 | 483 |
| 507 } // namespace content | 484 } // namespace content |
| OLD | NEW |