| 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" |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 13 #include "base/threading/thread_local.h" | 14 #include "base/threading/thread_local.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 16 #include "content/child/service_worker/service_worker_handle_reference.h" | 17 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 17 #include "content/child/service_worker/service_worker_provider_context.h" | 18 #include "content/child/service_worker/service_worker_provider_context.h" |
| 18 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 19 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
| 19 #include "content/child/service_worker/web_service_worker_impl.h" | 20 #include "content/child/service_worker/web_service_worker_impl.h" |
| 20 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 21 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 517 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
| 517 "ServiceWorkerDispatcher::GetRegistrations", | 518 "ServiceWorkerDispatcher::GetRegistrations", |
| 518 request_id); | 519 request_id); |
| 519 | 520 |
| 520 WebServiceWorkerGetRegistrationsCallbacks* callbacks = | 521 WebServiceWorkerGetRegistrationsCallbacks* callbacks = |
| 521 pending_get_registrations_callbacks_.Lookup(request_id); | 522 pending_get_registrations_callbacks_.Lookup(request_id); |
| 522 DCHECK(callbacks); | 523 DCHECK(callbacks); |
| 523 if (!callbacks) | 524 if (!callbacks) |
| 524 return; | 525 return; |
| 525 | 526 |
| 526 typedef blink::WebVector<blink::WebServiceWorkerRegistration::Handle*> | 527 using WebServiceWorkerRegistrationHandles = |
| 527 WebServiceWorkerRegistrationArray; | 528 WebServiceWorkerProvider::WebServiceWorkerRegistrationHandles; |
| 528 std::unique_ptr<WebServiceWorkerRegistrationArray> registrations( | 529 std::unique_ptr<WebServiceWorkerRegistrationHandles> registrations = |
| 529 new WebServiceWorkerRegistrationArray(infos.size())); | 530 base::MakeUnique<WebServiceWorkerRegistrationHandles>(infos.size()); |
| 530 for (size_t i = 0; i < infos.size(); ++i) { | 531 for (size_t i = 0; i < infos.size(); ++i) { |
| 531 if (infos[i].handle_id != kInvalidServiceWorkerHandleId) { | 532 if (infos[i].handle_id == kInvalidServiceWorkerHandleId) |
| 532 ServiceWorkerRegistrationObjectInfo info(infos[i]); | 533 continue; |
| 533 ServiceWorkerVersionAttributes attr(attrs[i]); | 534 (*registrations)[i] = WebServiceWorkerRegistrationImpl::CreateHandle( |
| 534 | 535 GetOrAdoptRegistration(infos[i], attrs[i])); |
| 535 // WebServiceWorkerGetRegistrationsCallbacks cannot receive an array of | |
| 536 // std::unique_ptr<WebServiceWorkerRegistration::Handle>, so create leaky | |
| 537 // handles instead. | |
| 538 (*registrations)[i] = WebServiceWorkerRegistrationImpl::CreateLeakyHandle( | |
| 539 GetOrAdoptRegistration(info, attr)); | |
| 540 } | |
| 541 } | 536 } |
| 542 | 537 |
| 543 callbacks->onSuccess(std::move(registrations)); | 538 callbacks->onSuccess(std::move(registrations)); |
| 544 pending_get_registrations_callbacks_.Remove(request_id); | 539 pending_get_registrations_callbacks_.Remove(request_id); |
| 545 } | 540 } |
| 546 | 541 |
| 547 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( | 542 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( |
| 548 int thread_id, | 543 int thread_id, |
| 549 int request_id, | 544 int request_id, |
| 550 const ServiceWorkerRegistrationObjectInfo& info, | 545 const ServiceWorkerRegistrationObjectInfo& info, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 return ServiceWorkerRegistrationHandleReference::Adopt( | 899 return ServiceWorkerRegistrationHandleReference::Adopt( |
| 905 info, thread_safe_sender_.get()); | 900 info, thread_safe_sender_.get()); |
| 906 } | 901 } |
| 907 | 902 |
| 908 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 903 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
| 909 const ServiceWorkerObjectInfo& info) { | 904 const ServiceWorkerObjectInfo& info) { |
| 910 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 905 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
| 911 } | 906 } |
| 912 | 907 |
| 913 } // namespace content | 908 } // namespace content |
| OLD | NEW |