| 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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 g_dispatcher_tls.Pointer()->Set(this); | 47 g_dispatcher_tls.Pointer()->Set(this); |
| 48 } | 48 } |
| 49 | 49 |
| 50 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { | 50 ServiceWorkerDispatcher::~ServiceWorkerDispatcher() { |
| 51 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); | 51 g_dispatcher_tls.Pointer()->Set(kHasBeenDeleted); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { | 54 void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 55 bool handled = true; | 55 bool handled = true; |
| 56 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) | 56 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcher, msg) |
| 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_AssociateRegistration, |
| 58 OnAssociateRegistration) |
| 59 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DisassociateRegistration, |
| 60 OnDisassociateRegistration) |
| 57 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) | 61 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) |
| 58 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, | 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, |
| 59 OnUnregistered) | 63 OnUnregistered) |
| 60 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, | 64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, |
| 61 OnRegistrationError) | 65 OnRegistrationError) |
| 62 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, | 66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, |
| 63 OnUnregistrationError) | 67 OnUnregistrationError) |
| 64 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, | 68 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, |
| 65 OnServiceWorkerStateChanged) | 69 OnServiceWorkerStateChanged) |
| 66 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, | 70 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 scoped_ptr<ServiceWorkerHandleReference> handle_ref = | 216 scoped_ptr<ServiceWorkerHandleReference> handle_ref = |
| 213 adopt_handle | 217 adopt_handle |
| 214 ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()) | 218 ? ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()) |
| 215 : ServiceWorkerHandleReference::Create(info, | 219 : ServiceWorkerHandleReference::Create(info, |
| 216 thread_safe_sender_.get()); | 220 thread_safe_sender_.get()); |
| 217 // WebServiceWorkerImpl constructor calls AddServiceWorker. | 221 // WebServiceWorkerImpl constructor calls AddServiceWorker. |
| 218 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_.get()); | 222 return new WebServiceWorkerImpl(handle_ref.Pass(), thread_safe_sender_.get()); |
| 219 } | 223 } |
| 220 | 224 |
| 221 WebServiceWorkerRegistrationImpl* | 225 WebServiceWorkerRegistrationImpl* |
| 222 ServiceWorkerDispatcher::GetServiceWorkerRegistration( | 226 ServiceWorkerDispatcher::FindServiceWorkerRegistration( |
| 223 const ServiceWorkerRegistrationObjectInfo& info, | 227 const ServiceWorkerRegistrationObjectInfo& info, |
| 224 bool adopt_handle) { | 228 bool adopt_handle) { |
| 229 RegistrationObjectMap::iterator registration = |
| 230 registrations_.find(info.handle_id); |
| 231 if (registration == registrations_.end()) |
| 232 return NULL; |
| 233 if (adopt_handle) { |
| 234 // We are instructed to adopt a handle but we already have one, so |
| 235 // adopt and destroy a handle ref. |
| 236 ServiceWorkerRegistrationHandleReference::Adopt( |
| 237 info, thread_safe_sender_.get()); |
| 238 } |
| 239 return registration->second; |
| 240 } |
| 241 |
| 242 WebServiceWorkerRegistrationImpl* |
| 243 ServiceWorkerDispatcher::CreateServiceWorkerRegistration( |
| 244 const ServiceWorkerRegistrationObjectInfo& info, |
| 245 bool adopt_handle) { |
| 246 DCHECK(!FindServiceWorkerRegistration(info, adopt_handle)); |
| 225 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) | 247 if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId) |
| 226 return NULL; | 248 return NULL; |
| 227 | 249 |
| 228 RegistrationObjectMap::iterator existing_registration = | |
| 229 registrations_.find(info.handle_id); | |
| 230 | |
| 231 if (existing_registration != registrations_.end()) { | |
| 232 if (adopt_handle) { | |
| 233 // We are instructed to adopt a handle but we already have one, so | |
| 234 // adopt and destroy a handle ref. | |
| 235 ServiceWorkerRegistrationHandleReference::Adopt( | |
| 236 info, thread_safe_sender_.get()); | |
| 237 } | |
| 238 return existing_registration->second; | |
| 239 } | |
| 240 | |
| 241 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = | 250 scoped_ptr<ServiceWorkerRegistrationHandleReference> handle_ref = |
| 242 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( | 251 adopt_handle ? ServiceWorkerRegistrationHandleReference::Adopt( |
| 243 info, thread_safe_sender_.get()) | 252 info, thread_safe_sender_.get()) |
| 244 : ServiceWorkerRegistrationHandleReference::Create( | 253 : ServiceWorkerRegistrationHandleReference::Create( |
| 245 info, thread_safe_sender_.get()); | 254 info, thread_safe_sender_.get()); |
| 246 | 255 |
| 247 // WebServiceWorkerRegistrationImpl constructor calls | 256 // WebServiceWorkerRegistrationImpl constructor calls |
| 248 // AddServiceWorkerRegistration. | 257 // AddServiceWorkerRegistration. |
| 249 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); | 258 return new WebServiceWorkerRegistrationImpl(handle_ref.Pass()); |
| 250 } | 259 } |
| 251 | 260 |
| 261 void ServiceWorkerDispatcher::OnAssociateRegistration( |
| 262 int thread_id, |
| 263 int provider_id, |
| 264 const ServiceWorkerRegistrationObjectInfo& info, |
| 265 const ServiceWorkerVersionAttributes& attrs) { |
| 266 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 267 if (provider == provider_contexts_.end()) |
| 268 return; |
| 269 provider->second->OnAssociateRegistration(info, attrs); |
| 270 if (attrs.installing.handle_id != kInvalidServiceWorkerHandleId) |
| 271 worker_to_provider_[attrs.installing.handle_id] = provider->second; |
| 272 if (attrs.waiting.handle_id != kInvalidServiceWorkerHandleId) |
| 273 worker_to_provider_[attrs.waiting.handle_id] = provider->second; |
| 274 if (attrs.active.handle_id != kInvalidServiceWorkerHandleId) |
| 275 worker_to_provider_[attrs.active.handle_id] = provider->second; |
| 276 } |
| 277 |
| 278 void ServiceWorkerDispatcher::OnDisassociateRegistration( |
| 279 int thread_id, |
| 280 int provider_id) { |
| 281 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 282 if (provider == provider_contexts_.end()) |
| 283 return; |
| 284 provider->second->OnDisassociateRegistration(); |
| 285 worker_to_provider_.erase(provider->second->installing_handle_id()); |
| 286 worker_to_provider_.erase(provider->second->waiting_handle_id()); |
| 287 worker_to_provider_.erase(provider->second->active_handle_id()); |
| 288 worker_to_provider_.erase(provider->second->controller_handle_id()); |
| 289 } |
| 290 |
| 252 void ServiceWorkerDispatcher::OnRegistered( | 291 void ServiceWorkerDispatcher::OnRegistered( |
| 253 int thread_id, | 292 int thread_id, |
| 254 int request_id, | 293 int request_id, |
| 255 const ServiceWorkerRegistrationObjectInfo& info, | 294 const ServiceWorkerRegistrationObjectInfo& info, |
| 256 const ServiceWorkerVersionAttributes& attrs) { | 295 const ServiceWorkerVersionAttributes& attrs) { |
| 257 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 296 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
| 258 "ServiceWorkerDispatcher::RegisterServiceWorker", | 297 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 259 request_id, | 298 request_id, |
| 260 "OnRegistered"); | 299 "OnRegistered"); |
| 261 WebServiceWorkerRegistrationCallbacks* callbacks = | 300 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 262 pending_registration_callbacks_.Lookup(request_id); | 301 pending_registration_callbacks_.Lookup(request_id); |
| 263 DCHECK(callbacks); | 302 DCHECK(callbacks); |
| 264 if (!callbacks) | 303 if (!callbacks) |
| 265 return; | 304 return; |
| 266 | 305 |
| 267 WebServiceWorkerRegistrationImpl* registration = | 306 WebServiceWorkerRegistrationImpl* registration = |
| 268 GetServiceWorkerRegistration(info, true); | 307 FindServiceWorkerRegistration(info, true); |
| 269 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); | 308 if (!registration) { |
| 270 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); | 309 registration = CreateServiceWorkerRegistration(info, true); |
| 271 registration->SetActive(GetServiceWorker(attrs.active, true)); | 310 registration->SetInstalling(GetServiceWorker(attrs.installing, true)); |
| 311 registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); |
| 312 registration->SetActive(GetServiceWorker(attrs.active, true)); |
| 313 } else { |
| 314 // |registration| must already have version attributes, so adopt and destroy |
| 315 // handle refs for them. |
| 316 ServiceWorkerHandleReference::Adopt( |
| 317 attrs.installing, thread_safe_sender_.get()); |
| 318 ServiceWorkerHandleReference::Adopt( |
| 319 attrs.waiting, thread_safe_sender_.get()); |
| 320 ServiceWorkerHandleReference::Adopt( |
| 321 attrs.active, thread_safe_sender_.get()); |
| 322 } |
| 272 | 323 |
| 273 callbacks->onSuccess(registration); | 324 callbacks->onSuccess(registration); |
| 274 pending_registration_callbacks_.Remove(request_id); | 325 pending_registration_callbacks_.Remove(request_id); |
| 275 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 326 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 276 "ServiceWorkerDispatcher::RegisterServiceWorker", | 327 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 277 request_id); | 328 request_id); |
| 278 } | 329 } |
| 279 | 330 |
| 280 void ServiceWorkerDispatcher::OnUnregistered( | 331 void ServiceWorkerDispatcher::OnUnregistered( |
| 281 int thread_id, | 332 int thread_id, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 432 } |
| 382 if (mask.waiting_changed()) { | 433 if (mask.waiting_changed()) { |
| 383 SetWaitingServiceWorker(provider_id, | 434 SetWaitingServiceWorker(provider_id, |
| 384 registration_handle_id, | 435 registration_handle_id, |
| 385 attributes.waiting); | 436 attributes.waiting); |
| 386 } | 437 } |
| 387 if (mask.active_changed()) { | 438 if (mask.active_changed()) { |
| 388 SetActiveServiceWorker(provider_id, | 439 SetActiveServiceWorker(provider_id, |
| 389 registration_handle_id, | 440 registration_handle_id, |
| 390 attributes.active); | 441 attributes.active); |
| 442 SetReadyRegistration(provider_id, registration_handle_id); |
| 391 } | 443 } |
| 392 } | 444 } |
| 393 | 445 |
| 394 void ServiceWorkerDispatcher::OnUpdateFound( | 446 void ServiceWorkerDispatcher::OnUpdateFound( |
| 395 int thread_id, | 447 int thread_id, |
| 396 const ServiceWorkerRegistrationObjectInfo& info) { | 448 const ServiceWorkerRegistrationObjectInfo& info) { |
| 397 TRACE_EVENT0("ServiceWorker", | 449 TRACE_EVENT0("ServiceWorker", |
| 398 "ServiceWorkerDispatcher::OnUpdateFound"); | 450 "ServiceWorkerDispatcher::OnUpdateFound"); |
| 399 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); | 451 RegistrationObjectMap::iterator found = registrations_.find(info.handle_id); |
| 400 if (found != registrations_.end()) | 452 if (found != registrations_.end()) |
| 401 found->second->OnUpdateFound(); | 453 found->second->OnUpdateFound(); |
| 402 } | 454 } |
| 403 | 455 |
| 404 void ServiceWorkerDispatcher::SetInstallingServiceWorker( | 456 void ServiceWorkerDispatcher::SetInstallingServiceWorker( |
| 405 int provider_id, | 457 int provider_id, |
| 406 int registration_handle_id, | 458 int registration_handle_id, |
| 407 const ServiceWorkerObjectInfo& info) { | 459 const ServiceWorkerObjectInfo& info) { |
| 408 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 460 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 409 if (provider != provider_contexts_.end()) { | 461 if (provider != provider_contexts_.end() && |
| 462 provider->second->registration_handle_id() == registration_handle_id) { |
| 410 int existing_installing_id = provider->second->installing_handle_id(); | 463 int existing_installing_id = provider->second->installing_handle_id(); |
| 411 if (existing_installing_id != info.handle_id && | 464 if (existing_installing_id != info.handle_id && |
| 412 existing_installing_id != kInvalidServiceWorkerHandleId) { | 465 existing_installing_id != kInvalidServiceWorkerHandleId) { |
| 413 WorkerToProviderMap::iterator associated_provider = | 466 WorkerToProviderMap::iterator associated_provider = |
| 414 worker_to_provider_.find(existing_installing_id); | 467 worker_to_provider_.find(existing_installing_id); |
| 415 DCHECK(associated_provider != worker_to_provider_.end()); | 468 DCHECK(associated_provider != worker_to_provider_.end()); |
| 416 DCHECK(associated_provider->second->provider_id() == provider_id); | 469 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 417 worker_to_provider_.erase(associated_provider); | 470 worker_to_provider_.erase(associated_provider); |
| 418 } | 471 } |
| 419 provider->second->OnSetInstallingServiceWorker(provider_id, info); | 472 provider->second->OnSetInstallingServiceWorker( |
| 473 registration_handle_id, info); |
| 420 if (info.handle_id != kInvalidServiceWorkerHandleId) | 474 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 421 worker_to_provider_[info.handle_id] = provider->second; | 475 worker_to_provider_[info.handle_id] = provider->second; |
| 422 } | 476 } |
| 423 | 477 |
| 424 RegistrationObjectMap::iterator found = | 478 RegistrationObjectMap::iterator found = |
| 425 registrations_.find(registration_handle_id); | 479 registrations_.find(registration_handle_id); |
| 426 if (found != registrations_.end()) { | 480 if (found != registrations_.end()) { |
| 427 // Populate the .installing field with the new worker object. | 481 // Populate the .installing field with the new worker object. |
| 428 found->second->SetInstalling(GetServiceWorker(info, false)); | 482 found->second->SetInstalling(GetServiceWorker(info, false)); |
| 429 } | 483 } |
| 430 } | 484 } |
| 431 | 485 |
| 432 void ServiceWorkerDispatcher::SetWaitingServiceWorker( | 486 void ServiceWorkerDispatcher::SetWaitingServiceWorker( |
| 433 int provider_id, | 487 int provider_id, |
| 434 int registration_handle_id, | 488 int registration_handle_id, |
| 435 const ServiceWorkerObjectInfo& info) { | 489 const ServiceWorkerObjectInfo& info) { |
| 436 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 490 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 437 if (provider != provider_contexts_.end()) { | 491 if (provider != provider_contexts_.end() && |
| 492 provider->second->registration_handle_id() == registration_handle_id) { |
| 438 int existing_waiting_id = provider->second->waiting_handle_id(); | 493 int existing_waiting_id = provider->second->waiting_handle_id(); |
| 439 if (existing_waiting_id != info.handle_id && | 494 if (existing_waiting_id != info.handle_id && |
| 440 existing_waiting_id != kInvalidServiceWorkerHandleId) { | 495 existing_waiting_id != kInvalidServiceWorkerHandleId) { |
| 441 WorkerToProviderMap::iterator associated_provider = | 496 WorkerToProviderMap::iterator associated_provider = |
| 442 worker_to_provider_.find(existing_waiting_id); | 497 worker_to_provider_.find(existing_waiting_id); |
| 443 DCHECK(associated_provider != worker_to_provider_.end()); | 498 DCHECK(associated_provider != worker_to_provider_.end()); |
| 444 DCHECK(associated_provider->second->provider_id() == provider_id); | 499 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 445 worker_to_provider_.erase(associated_provider); | 500 worker_to_provider_.erase(associated_provider); |
| 446 } | 501 } |
| 447 provider->second->OnSetWaitingServiceWorker(provider_id, info); | 502 provider->second->OnSetWaitingServiceWorker(registration_handle_id, info); |
| 448 if (info.handle_id != kInvalidServiceWorkerHandleId) | 503 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 449 worker_to_provider_[info.handle_id] = provider->second; | 504 worker_to_provider_[info.handle_id] = provider->second; |
| 450 } | 505 } |
| 451 | 506 |
| 452 RegistrationObjectMap::iterator found = | 507 RegistrationObjectMap::iterator found = |
| 453 registrations_.find(registration_handle_id); | 508 registrations_.find(registration_handle_id); |
| 454 if (found != registrations_.end()) { | 509 if (found != registrations_.end()) { |
| 455 // Populate the .waiting field with the new worker object. | 510 // Populate the .waiting field with the new worker object. |
| 456 found->second->SetWaiting(GetServiceWorker(info, false)); | 511 found->second->SetWaiting(GetServiceWorker(info, false)); |
| 457 } | 512 } |
| 458 } | 513 } |
| 459 | 514 |
| 460 void ServiceWorkerDispatcher::SetActiveServiceWorker( | 515 void ServiceWorkerDispatcher::SetActiveServiceWorker( |
| 461 int provider_id, | 516 int provider_id, |
| 462 int registration_handle_id, | 517 int registration_handle_id, |
| 463 const ServiceWorkerObjectInfo& info) { | 518 const ServiceWorkerObjectInfo& info) { |
| 464 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 519 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 465 if (provider != provider_contexts_.end()) { | 520 if (provider != provider_contexts_.end() && |
| 521 provider->second->registration_handle_id() == registration_handle_id) { |
| 466 int existing_active_id = provider->second->active_handle_id(); | 522 int existing_active_id = provider->second->active_handle_id(); |
| 467 if (existing_active_id != info.handle_id && | 523 if (existing_active_id != info.handle_id && |
| 468 existing_active_id != kInvalidServiceWorkerHandleId) { | 524 existing_active_id != kInvalidServiceWorkerHandleId) { |
| 469 WorkerToProviderMap::iterator associated_provider = | 525 WorkerToProviderMap::iterator associated_provider = |
| 470 worker_to_provider_.find(existing_active_id); | 526 worker_to_provider_.find(existing_active_id); |
| 471 DCHECK(associated_provider != worker_to_provider_.end()); | 527 DCHECK(associated_provider != worker_to_provider_.end()); |
| 472 DCHECK(associated_provider->second->provider_id() == provider_id); | 528 DCHECK(associated_provider->second->provider_id() == provider_id); |
| 473 worker_to_provider_.erase(associated_provider); | 529 worker_to_provider_.erase(associated_provider); |
| 474 } | 530 } |
| 475 provider->second->OnSetActiveServiceWorker(provider_id, info); | 531 provider->second->OnSetActiveServiceWorker(registration_handle_id, info); |
| 476 if (info.handle_id != kInvalidServiceWorkerHandleId) | 532 if (info.handle_id != kInvalidServiceWorkerHandleId) |
| 477 worker_to_provider_[info.handle_id] = provider->second; | 533 worker_to_provider_[info.handle_id] = provider->second; |
| 478 } | 534 } |
| 479 | 535 |
| 480 RegistrationObjectMap::iterator found = | 536 RegistrationObjectMap::iterator found = |
| 481 registrations_.find(registration_handle_id); | 537 registrations_.find(registration_handle_id); |
| 482 if (found != registrations_.end()) { | 538 if (found != registrations_.end()) { |
| 483 // Populate the .active field with the new worker object. | 539 // Populate the .active field with the new worker object. |
| 484 found->second->SetActive(GetServiceWorker(info, false)); | 540 found->second->SetActive(GetServiceWorker(info, false)); |
| 485 } | 541 } |
| 486 } | 542 } |
| 487 | 543 |
| 544 void ServiceWorkerDispatcher::SetReadyRegistration( |
| 545 int provider_id, |
| 546 int registration_handle_id) { |
| 547 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 548 if (provider == provider_contexts_.end() || |
| 549 provider->second->registration_handle_id() != registration_handle_id || |
| 550 provider->second->active_handle_id() == kInvalidServiceWorkerHandleId) { |
| 551 return; |
| 552 } |
| 553 |
| 554 ScriptClientMap::iterator client = script_clients_.find(provider_id); |
| 555 if (client == script_clients_.end()) |
| 556 return; |
| 557 |
| 558 ServiceWorkerRegistrationObjectInfo info = |
| 559 provider->second->registration()->info(); |
| 560 WebServiceWorkerRegistrationImpl* registration = |
| 561 FindServiceWorkerRegistration(info, false); |
| 562 if (!registration) { |
| 563 registration = CreateServiceWorkerRegistration(info, false); |
| 564 ServiceWorkerVersionAttributes attrs = |
| 565 provider->second->GetVersionAttributes(); |
| 566 registration->SetInstalling(GetServiceWorker(attrs.installing, false)); |
| 567 registration->SetWaiting(GetServiceWorker(attrs.waiting, false)); |
| 568 registration->SetActive(GetServiceWorker(attrs.active, false)); |
| 569 } |
| 570 |
| 571 // Resolve the .ready promise with the registration object. |
| 572 client->second->setReadyRegistration(registration); |
| 573 } |
| 574 |
| 488 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( | 575 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( |
| 489 int thread_id, | 576 int thread_id, |
| 490 int provider_id, | 577 int provider_id, |
| 491 const ServiceWorkerObjectInfo& info) { | 578 const ServiceWorkerObjectInfo& info) { |
| 492 TRACE_EVENT2("ServiceWorker", | 579 TRACE_EVENT2("ServiceWorker", |
| 493 "ServiceWorkerDispatcher::OnSetControllerServiceWorker", | 580 "ServiceWorkerDispatcher::OnSetControllerServiceWorker", |
| 494 "Thread ID", thread_id, | 581 "Thread ID", thread_id, |
| 495 "Provider ID", provider_id); | 582 "Provider ID", provider_id); |
| 496 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 583 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 497 if (provider != provider_contexts_.end()) { | 584 if (provider != provider_contexts_.end()) { |
| 498 provider->second->OnSetControllerServiceWorker(provider_id, info); | 585 provider->second->OnSetControllerServiceWorker( |
| 586 provider->second->registration_handle_id(), info); |
| 499 worker_to_provider_[info.handle_id] = provider->second; | 587 worker_to_provider_[info.handle_id] = provider->second; |
| 500 } | 588 } |
| 501 | 589 |
| 502 ScriptClientMap::iterator found = script_clients_.find(provider_id); | 590 ScriptClientMap::iterator found = script_clients_.find(provider_id); |
| 503 if (found != script_clients_.end()) { | 591 if (found != script_clients_.end()) { |
| 504 // Populate the .controller field with the new worker object. | 592 // Populate the .controller field with the new worker object. |
| 505 found->second->setController(GetServiceWorker(info, false)); | 593 found->second->setController(GetServiceWorker(info, false)); |
| 506 } | 594 } |
| 507 } | 595 } |
| 508 | 596 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 registrations_[registration_handle_id] = registration; | 645 registrations_[registration_handle_id] = registration; |
| 558 } | 646 } |
| 559 | 647 |
| 560 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( | 648 void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( |
| 561 int registration_handle_id) { | 649 int registration_handle_id) { |
| 562 DCHECK(ContainsKey(registrations_, registration_handle_id)); | 650 DCHECK(ContainsKey(registrations_, registration_handle_id)); |
| 563 registrations_.erase(registration_handle_id); | 651 registrations_.erase(registration_handle_id); |
| 564 } | 652 } |
| 565 | 653 |
| 566 } // namespace content | 654 } // namespace content |
| OLD | NEW |