Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 2564363002: ServiceWorker: Replace RegistrationCallback and GetRegistrationsCallback with CallbackPromiseAdapter (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/child/service_worker/web_service_worker_registration_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 TRACE_EVENT_ASYNC_END0("ServiceWorker", 516 TRACE_EVENT_ASYNC_END0("ServiceWorker",
517 "ServiceWorkerDispatcher::GetRegistrations", 517 "ServiceWorkerDispatcher::GetRegistrations",
518 request_id); 518 request_id);
519 519
520 WebServiceWorkerGetRegistrationsCallbacks* callbacks = 520 WebServiceWorkerGetRegistrationsCallbacks* callbacks =
521 pending_get_registrations_callbacks_.Lookup(request_id); 521 pending_get_registrations_callbacks_.Lookup(request_id);
522 DCHECK(callbacks); 522 DCHECK(callbacks);
523 if (!callbacks) 523 if (!callbacks)
524 return; 524 return;
525 525
526 typedef blink::WebVector<blink::WebServiceWorkerRegistration::Handle*> 526 using WebServiceWorkerRegistrationHandles =
527 WebServiceWorkerRegistrationArray; 527 WebServiceWorkerProvider::WebServiceWorkerRegistrationHandles;
528 std::unique_ptr<WebServiceWorkerRegistrationArray> registrations( 528 std::unique_ptr<WebServiceWorkerRegistrationHandles> registrations(
529 new WebServiceWorkerRegistrationArray(infos.size())); 529 new WebServiceWorkerRegistrationHandles(infos.size()));
shimazu 2016/12/12 11:04:53 nit: base::MakeUnique would be better than the bar
nhiroki 2016/12/13 03:16:27 Done.
530 for (size_t i = 0; i < infos.size(); ++i) { 530 for (size_t i = 0; i < infos.size(); ++i) {
531 if (infos[i].handle_id != kInvalidServiceWorkerHandleId) { 531 if (infos[i].handle_id == kInvalidServiceWorkerHandleId)
532 ServiceWorkerRegistrationObjectInfo info(infos[i]); 532 continue;
533 ServiceWorkerVersionAttributes attr(attrs[i]); 533 (*registrations)[i] = WebServiceWorkerRegistrationImpl::CreateHandle(
534 534 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 } 535 }
542 536
543 callbacks->onSuccess(std::move(registrations)); 537 callbacks->onSuccess(std::move(registrations));
544 pending_get_registrations_callbacks_.Remove(request_id); 538 pending_get_registrations_callbacks_.Remove(request_id);
545 } 539 }
546 540
547 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( 541 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady(
548 int thread_id, 542 int thread_id,
549 int request_id, 543 int request_id,
550 const ServiceWorkerRegistrationObjectInfo& info, 544 const ServiceWorkerRegistrationObjectInfo& info,
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 return ServiceWorkerRegistrationHandleReference::Adopt( 898 return ServiceWorkerRegistrationHandleReference::Adopt(
905 info, thread_safe_sender_.get()); 899 info, thread_safe_sender_.get());
906 } 900 }
907 901
908 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( 902 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt(
909 const ServiceWorkerObjectInfo& info) { 903 const ServiceWorkerObjectInfo& info) {
910 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); 904 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get());
911 } 905 }
912 906
913 } // namespace content 907 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/service_worker/web_service_worker_registration_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698