| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); | 414 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); |
| 415 if (provider == provider_contexts_.end()) | 415 if (provider == provider_contexts_.end()) |
| 416 return; | 416 return; |
| 417 provider->second->OnDisassociateRegistration(); | 417 provider->second->OnDisassociateRegistration(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 void ServiceWorkerDispatcher::OnRegistered( | 420 void ServiceWorkerDispatcher::OnRegistered( |
| 421 int thread_id, | 421 int thread_id, |
| 422 int request_id, | 422 int request_id, |
| 423 const ServiceWorkerRegistrationObjectInfo& info, | 423 const ServiceWorkerRegistrationObjectInfo& info, |
| 424 const ServiceWorkerVersionAttributes& attrs) { | 424 const ServiceWorkerVersionAttributes& attrs, |
| 425 const mojo::MessagePipeHandle& url_loader_factory) { |
| 425 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 426 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
| 426 "ServiceWorkerDispatcher::RegisterServiceWorker", | 427 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 427 request_id, | 428 request_id, |
| 428 "OnRegistered"); | 429 "OnRegistered"); |
| 429 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 430 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 430 "ServiceWorkerDispatcher::RegisterServiceWorker", | 431 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 431 request_id); | 432 request_id); |
| 432 WebServiceWorkerRegistrationCallbacks* callbacks = | 433 WebServiceWorkerRegistrationCallbacks* callbacks = |
| 433 pending_registration_callbacks_.Lookup(request_id); | 434 pending_registration_callbacks_.Lookup(request_id); |
| 434 DCHECK(callbacks); | 435 DCHECK(callbacks); |
| 435 if (!callbacks) | 436 if (!callbacks) |
| 436 return; | 437 return; |
| 437 | 438 |
| 439 if (url_loader_factory.is_valid()) { |
| 440 // Chrome doesn't use interface versioning. |
| 441 url_loader_factory_.Bind(mojom::URLLoaderFactoryPtrInfo( |
| 442 mojo::ScopedMessagePipeHandle(url_loader_factory), 0u)); |
| 443 } |
| 444 |
| 438 callbacks->OnSuccess(WebServiceWorkerRegistrationImpl::CreateHandle( | 445 callbacks->OnSuccess(WebServiceWorkerRegistrationImpl::CreateHandle( |
| 439 GetOrAdoptRegistration(info, attrs))); | 446 GetOrAdoptRegistration(info, attrs))); |
| 440 pending_registration_callbacks_.Remove(request_id); | 447 pending_registration_callbacks_.Remove(request_id); |
| 441 } | 448 } |
| 442 | 449 |
| 443 void ServiceWorkerDispatcher::OnUpdated(int thread_id, int request_id) { | 450 void ServiceWorkerDispatcher::OnUpdated(int thread_id, int request_id) { |
| 444 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", | 451 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", |
| 445 "ServiceWorkerDispatcher::UpdateServiceWorker", | 452 "ServiceWorkerDispatcher::UpdateServiceWorker", |
| 446 request_id, "OnUpdated"); | 453 request_id, "OnUpdated"); |
| 447 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 454 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| (...skipping 26 matching lines...) Expand all Loading... |
| 474 if (!callbacks) | 481 if (!callbacks) |
| 475 return; | 482 return; |
| 476 callbacks->OnSuccess(is_success); | 483 callbacks->OnSuccess(is_success); |
| 477 pending_unregistration_callbacks_.Remove(request_id); | 484 pending_unregistration_callbacks_.Remove(request_id); |
| 478 } | 485 } |
| 479 | 486 |
| 480 void ServiceWorkerDispatcher::OnDidGetRegistration( | 487 void ServiceWorkerDispatcher::OnDidGetRegistration( |
| 481 int thread_id, | 488 int thread_id, |
| 482 int request_id, | 489 int request_id, |
| 483 const ServiceWorkerRegistrationObjectInfo& info, | 490 const ServiceWorkerRegistrationObjectInfo& info, |
| 484 const ServiceWorkerVersionAttributes& attrs) { | 491 const ServiceWorkerVersionAttributes& attrs, |
| 492 const mojo::MessagePipeHandle& url_loader_factory) { |
| 485 TRACE_EVENT_ASYNC_STEP_INTO0( | 493 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 486 "ServiceWorker", | 494 "ServiceWorker", |
| 487 "ServiceWorkerDispatcher::GetRegistration", | 495 "ServiceWorkerDispatcher::GetRegistration", |
| 488 request_id, | 496 request_id, |
| 489 "OnDidGetRegistration"); | 497 "OnDidGetRegistration"); |
| 490 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 498 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 491 "ServiceWorkerDispatcher::GetRegistration", | 499 "ServiceWorkerDispatcher::GetRegistration", |
| 492 request_id); | 500 request_id); |
| 493 WebServiceWorkerGetRegistrationCallbacks* callbacks = | 501 WebServiceWorkerGetRegistrationCallbacks* callbacks = |
| 494 pending_get_registration_callbacks_.Lookup(request_id); | 502 pending_get_registration_callbacks_.Lookup(request_id); |
| 495 DCHECK(callbacks); | 503 DCHECK(callbacks); |
| 496 if (!callbacks) | 504 if (!callbacks) |
| 497 return; | 505 return; |
| 498 | 506 |
| 499 scoped_refptr<WebServiceWorkerRegistrationImpl> registration; | 507 scoped_refptr<WebServiceWorkerRegistrationImpl> registration; |
| 500 if (info.handle_id != kInvalidServiceWorkerRegistrationHandleId) | 508 if (info.handle_id != kInvalidServiceWorkerRegistrationHandleId) |
| 501 registration = GetOrAdoptRegistration(info, attrs); | 509 registration = GetOrAdoptRegistration(info, attrs); |
| 502 | 510 |
| 511 // TODO(scottmg) factory |
| 512 |
| 503 callbacks->OnSuccess( | 513 callbacks->OnSuccess( |
| 504 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); | 514 WebServiceWorkerRegistrationImpl::CreateHandle(registration)); |
| 505 pending_get_registration_callbacks_.Remove(request_id); | 515 pending_get_registration_callbacks_.Remove(request_id); |
| 506 } | 516 } |
| 507 | 517 |
| 508 void ServiceWorkerDispatcher::OnDidGetRegistrations( | 518 void ServiceWorkerDispatcher::OnDidGetRegistrations( |
| 509 int thread_id, | 519 int thread_id, |
| 510 int request_id, | 520 int request_id, |
| 511 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, | 521 const std::vector<ServiceWorkerRegistrationObjectInfo>& infos, |
| 512 const std::vector<ServiceWorkerVersionAttributes>& attrs) { | 522 const std::vector<ServiceWorkerVersionAttributes>& attrs, |
| 523 const std::vector<mojo::MessagePipeHandle>& url_loader_factories) { |
| 513 TRACE_EVENT_ASYNC_STEP_INTO0( | 524 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 514 "ServiceWorker", | 525 "ServiceWorker", |
| 515 "ServiceWorkerDispatcher::GetRegistrations", | 526 "ServiceWorkerDispatcher::GetRegistrations", |
| 516 request_id, | 527 request_id, |
| 517 "OnDidGetRegistrations"); | 528 "OnDidGetRegistrations"); |
| 518 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 529 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 519 "ServiceWorkerDispatcher::GetRegistrations", | 530 "ServiceWorkerDispatcher::GetRegistrations", |
| 520 request_id); | 531 request_id); |
| 521 | 532 |
| 522 WebServiceWorkerGetRegistrationsCallbacks* callbacks = | 533 WebServiceWorkerGetRegistrationsCallbacks* callbacks = |
| 523 pending_get_registrations_callbacks_.Lookup(request_id); | 534 pending_get_registrations_callbacks_.Lookup(request_id); |
| 524 DCHECK(callbacks); | 535 DCHECK(callbacks); |
| 525 if (!callbacks) | 536 if (!callbacks) |
| 526 return; | 537 return; |
| 527 | 538 |
| 539 // TODO(scottmg) factory |
| 540 |
| 528 using WebServiceWorkerRegistrationHandles = | 541 using WebServiceWorkerRegistrationHandles = |
| 529 WebServiceWorkerProvider::WebServiceWorkerRegistrationHandles; | 542 WebServiceWorkerProvider::WebServiceWorkerRegistrationHandles; |
| 530 std::unique_ptr<WebServiceWorkerRegistrationHandles> registrations = | 543 std::unique_ptr<WebServiceWorkerRegistrationHandles> registrations = |
| 531 base::MakeUnique<WebServiceWorkerRegistrationHandles>(infos.size()); | 544 base::MakeUnique<WebServiceWorkerRegistrationHandles>(infos.size()); |
| 532 for (size_t i = 0; i < infos.size(); ++i) { | 545 for (size_t i = 0; i < infos.size(); ++i) { |
| 533 if (infos[i].handle_id == kInvalidServiceWorkerHandleId) | 546 if (infos[i].handle_id == kInvalidServiceWorkerHandleId) |
| 534 continue; | 547 continue; |
| 535 (*registrations)[i] = WebServiceWorkerRegistrationImpl::CreateHandle( | 548 (*registrations)[i] = WebServiceWorkerRegistrationImpl::CreateHandle( |
| 536 GetOrAdoptRegistration(infos[i], attrs[i])); | 549 GetOrAdoptRegistration(infos[i], attrs[i])); |
| 537 } | 550 } |
| 538 | 551 |
| 539 callbacks->OnSuccess(std::move(registrations)); | 552 callbacks->OnSuccess(std::move(registrations)); |
| 540 pending_get_registrations_callbacks_.Remove(request_id); | 553 pending_get_registrations_callbacks_.Remove(request_id); |
| 541 } | 554 } |
| 542 | 555 |
| 543 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( | 556 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( |
| 544 int thread_id, | 557 int thread_id, |
| 545 int request_id, | 558 int request_id, |
| 546 const ServiceWorkerRegistrationObjectInfo& info, | 559 const ServiceWorkerRegistrationObjectInfo& info, |
| 547 const ServiceWorkerVersionAttributes& attrs) { | 560 const ServiceWorkerVersionAttributes& attrs, |
| 561 const mojo::MessagePipeHandle& url_loader_factory) { |
| 548 TRACE_EVENT_ASYNC_STEP_INTO0( | 562 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 549 "ServiceWorker", | 563 "ServiceWorker", |
| 550 "ServiceWorkerDispatcher::GetRegistrationForReady", | 564 "ServiceWorkerDispatcher::GetRegistrationForReady", |
| 551 request_id, | 565 request_id, |
| 552 "OnDidGetRegistrationForReady"); | 566 "OnDidGetRegistrationForReady"); |
| 553 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 567 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 554 "ServiceWorkerDispatcher::GetRegistrationForReady", | 568 "ServiceWorkerDispatcher::GetRegistrationForReady", |
| 555 request_id); | 569 request_id); |
| 556 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks = | 570 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks = |
| 557 get_for_ready_callbacks_.Lookup(request_id); | 571 get_for_ready_callbacks_.Lookup(request_id); |
| 558 DCHECK(callbacks); | 572 DCHECK(callbacks); |
| 559 if (!callbacks) | 573 if (!callbacks) |
| 560 return; | 574 return; |
| 561 | 575 |
| 576 // TODO(scottmg): factory |
| 577 |
| 562 callbacks->OnSuccess(WebServiceWorkerRegistrationImpl::CreateHandle( | 578 callbacks->OnSuccess(WebServiceWorkerRegistrationImpl::CreateHandle( |
| 563 GetOrAdoptRegistration(info, attrs))); | 579 GetOrAdoptRegistration(info, attrs))); |
| 564 get_for_ready_callbacks_.Remove(request_id); | 580 get_for_ready_callbacks_.Remove(request_id); |
| 565 } | 581 } |
| 566 | 582 |
| 567 void ServiceWorkerDispatcher::OnDidEnableNavigationPreload(int thread_id, | 583 void ServiceWorkerDispatcher::OnDidEnableNavigationPreload(int thread_id, |
| 568 int request_id) { | 584 int request_id) { |
| 569 WebEnableNavigationPreloadCallbacks* callbacks = | 585 WebEnableNavigationPreloadCallbacks* callbacks = |
| 570 enable_navigation_preload_callbacks_.Lookup(request_id); | 586 enable_navigation_preload_callbacks_.Lookup(request_id); |
| 571 DCHECK(callbacks); | 587 DCHECK(callbacks); |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 return ServiceWorkerRegistrationHandleReference::Adopt( | 938 return ServiceWorkerRegistrationHandleReference::Adopt( |
| 923 info, thread_safe_sender_.get()); | 939 info, thread_safe_sender_.get()); |
| 924 } | 940 } |
| 925 | 941 |
| 926 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 942 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
| 927 const ServiceWorkerObjectInfo& info) { | 943 const ServiceWorkerObjectInfo& info) { |
| 928 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 944 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
| 929 } | 945 } |
| 930 | 946 |
| 931 } // namespace content | 947 } // namespace content |
| OLD | NEW |