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

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

Issue 2451373003: service worker: Implement NavigationPreloadManager.setHeaderValue (Closed)
Patch Set: rebase Created 4 years, 1 month 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
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, 77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration,
78 OnDidGetRegistration) 78 OnDidGetRegistration)
79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations, 79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations,
80 OnDidGetRegistrations) 80 OnDidGetRegistrations)
81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady, 81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady,
82 OnDidGetRegistrationForReady) 82 OnDidGetRegistrationForReady)
83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidEnableNavigationPreload, 83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidEnableNavigationPreload,
84 OnDidEnableNavigationPreload) 84 OnDidEnableNavigationPreload)
85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetNavigationPreloadState, 85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetNavigationPreloadState,
86 OnDidGetNavigationPreloadState) 86 OnDidGetNavigationPreloadState)
87 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSetNavigationPreloadHeader,
88 OnDidSetNavigationPreloadHeader)
87 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, 89 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
88 OnRegistrationError) 90 OnRegistrationError)
89 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdateError, 91 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdateError,
90 OnUpdateError) 92 OnUpdateError)
91 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, 93 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError,
92 OnUnregistrationError) 94 OnUnregistrationError)
93 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, 95 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError,
94 OnGetRegistrationError) 96 OnGetRegistrationError)
95 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError, 97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError,
96 OnGetRegistrationsError) 98 OnGetRegistrationsError)
97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_EnableNavigationPreloadError, 99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_EnableNavigationPreloadError,
98 OnEnableNavigationPreloadError) 100 OnEnableNavigationPreloadError)
99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GetNavigationPreloadStateError, 101 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GetNavigationPreloadStateError,
100 OnGetNavigationPreloadStateError) 102 OnGetNavigationPreloadStateError)
103 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetNavigationPreloadHeaderError,
104 OnSetNavigationPreloadHeaderError)
101 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 105 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
102 OnServiceWorkerStateChanged) 106 OnServiceWorkerStateChanged)
103 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 107 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
104 OnSetVersionAttributes) 108 OnSetVersionAttributes)
105 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 109 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
106 OnUpdateFound) 110 OnUpdateFound)
107 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 111 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
108 OnSetControllerServiceWorker) 112 OnSetControllerServiceWorker)
109 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 113 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
110 OnPostMessage) 114 OnPostMessage)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 int provider_id, 235 int provider_id,
232 int64_t registration_id, 236 int64_t registration_id,
233 std::unique_ptr<WebGetNavigationPreloadStateCallbacks> callbacks) { 237 std::unique_ptr<WebGetNavigationPreloadStateCallbacks> callbacks) {
234 DCHECK(callbacks); 238 DCHECK(callbacks);
235 int request_id = 239 int request_id =
236 get_navigation_preload_state_callbacks_.Add(callbacks.release()); 240 get_navigation_preload_state_callbacks_.Add(callbacks.release());
237 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetNavigationPreloadState( 241 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetNavigationPreloadState(
238 CurrentWorkerId(), request_id, provider_id, registration_id)); 242 CurrentWorkerId(), request_id, provider_id, registration_id));
239 } 243 }
240 244
245 void ServiceWorkerDispatcher::SetNavigationPreloadHeader(
246 int provider_id,
247 int64_t registration_id,
248 const std::string& value,
249 std::unique_ptr<WebSetNavigationPreloadHeaderCallbacks> callbacks) {
250 DCHECK(callbacks);
251 int request_id =
252 set_navigation_preload_header_callbacks_.Add(callbacks.release());
253 thread_safe_sender_->Send(new ServiceWorkerHostMsg_SetNavigationPreloadHeader(
254 CurrentWorkerId(), request_id, provider_id, registration_id, value));
255 }
256
241 void ServiceWorkerDispatcher::AddProviderContext( 257 void ServiceWorkerDispatcher::AddProviderContext(
242 ServiceWorkerProviderContext* provider_context) { 258 ServiceWorkerProviderContext* provider_context) {
243 DCHECK(provider_context); 259 DCHECK(provider_context);
244 int provider_id = provider_context->provider_id(); 260 int provider_id = provider_context->provider_id();
245 DCHECK(!base::ContainsKey(provider_contexts_, provider_id)); 261 DCHECK(!base::ContainsKey(provider_contexts_, provider_id));
246 provider_contexts_[provider_id] = provider_context; 262 provider_contexts_[provider_id] = provider_context;
247 } 263 }
248 264
249 void ServiceWorkerDispatcher::RemoveProviderContext( 265 void ServiceWorkerDispatcher::RemoveProviderContext(
250 ServiceWorkerProviderContext* provider_context) { 266 ServiceWorkerProviderContext* provider_context) {
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 int request_id) { 572 int request_id) {
557 WebEnableNavigationPreloadCallbacks* callbacks = 573 WebEnableNavigationPreloadCallbacks* callbacks =
558 enable_navigation_preload_callbacks_.Lookup(request_id); 574 enable_navigation_preload_callbacks_.Lookup(request_id);
559 DCHECK(callbacks); 575 DCHECK(callbacks);
560 if (!callbacks) 576 if (!callbacks)
561 return; 577 return;
562 callbacks->onSuccess(); 578 callbacks->onSuccess();
563 enable_navigation_preload_callbacks_.Remove(request_id); 579 enable_navigation_preload_callbacks_.Remove(request_id);
564 } 580 }
565 581
566 void ServiceWorkerDispatcher::OnDidGetNavigationPreloadState(int thread_id, 582 void ServiceWorkerDispatcher::OnDidGetNavigationPreloadState(
567 int request_id, 583 int thread_id,
568 bool enabled) { 584 int request_id,
585 const NavigationPreloadState& state) {
569 WebGetNavigationPreloadStateCallbacks* callbacks = 586 WebGetNavigationPreloadStateCallbacks* callbacks =
570 get_navigation_preload_state_callbacks_.Lookup(request_id); 587 get_navigation_preload_state_callbacks_.Lookup(request_id);
571 DCHECK(callbacks); 588 DCHECK(callbacks);
572 if (!callbacks) 589 if (!callbacks)
573 return; 590 return;
574 // TODO(falken): Implement populating headerValue. 591 callbacks->onSuccess(blink::WebNavigationPreloadState(
575 callbacks->onSuccess( 592 state.enabled, blink::WebString::fromUTF8(state.header)));
576 blink::WebNavigationPreloadState(enabled, blink::WebString()));
577 get_navigation_preload_state_callbacks_.Remove(request_id); 593 get_navigation_preload_state_callbacks_.Remove(request_id);
578 } 594 }
579 595
596 void ServiceWorkerDispatcher::OnDidSetNavigationPreloadHeader(int thread_id,
597 int request_id) {
598 WebSetNavigationPreloadHeaderCallbacks* callbacks =
599 set_navigation_preload_header_callbacks_.Lookup(request_id);
600 DCHECK(callbacks);
601 if (!callbacks)
602 return;
603 callbacks->onSuccess();
604 set_navigation_preload_header_callbacks_.Remove(request_id);
605 }
606
580 void ServiceWorkerDispatcher::OnRegistrationError( 607 void ServiceWorkerDispatcher::OnRegistrationError(
581 int thread_id, 608 int thread_id,
582 int request_id, 609 int request_id,
583 WebServiceWorkerError::ErrorType error_type, 610 WebServiceWorkerError::ErrorType error_type,
584 const base::string16& message) { 611 const base::string16& message) {
585 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", 612 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker",
586 "ServiceWorkerDispatcher::RegisterServiceWorker", 613 "ServiceWorkerDispatcher::RegisterServiceWorker",
587 request_id, 614 request_id,
588 "OnRegistrationError"); 615 "OnRegistrationError");
589 TRACE_EVENT_ASYNC_END0("ServiceWorker", 616 TRACE_EVENT_ASYNC_END0("ServiceWorker",
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 WebGetNavigationPreloadStateCallbacks* callbacks = 739 WebGetNavigationPreloadStateCallbacks* callbacks =
713 get_navigation_preload_state_callbacks_.Lookup(request_id); 740 get_navigation_preload_state_callbacks_.Lookup(request_id);
714 DCHECK(callbacks); 741 DCHECK(callbacks);
715 if (!callbacks) 742 if (!callbacks)
716 return; 743 return;
717 callbacks->onError( 744 callbacks->onError(
718 WebServiceWorkerError(error_type, blink::WebString::fromUTF8(message))); 745 WebServiceWorkerError(error_type, blink::WebString::fromUTF8(message)));
719 get_navigation_preload_state_callbacks_.Remove(request_id); 746 get_navigation_preload_state_callbacks_.Remove(request_id);
720 } 747 }
721 748
749 void ServiceWorkerDispatcher::OnSetNavigationPreloadHeaderError(
750 int thread_id,
751 int request_id,
752 WebServiceWorkerError::ErrorType error_type,
753 const std::string& message) {
754 WebSetNavigationPreloadHeaderCallbacks* callbacks =
755 set_navigation_preload_header_callbacks_.Lookup(request_id);
756 DCHECK(callbacks);
757 if (!callbacks)
758 return;
759 callbacks->onError(
760 WebServiceWorkerError(error_type, blink::WebString::fromUTF8(message)));
761 set_navigation_preload_header_callbacks_.Remove(request_id);
762 }
763
722 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( 764 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
723 int thread_id, 765 int thread_id,
724 int handle_id, 766 int handle_id,
725 blink::WebServiceWorkerState state) { 767 blink::WebServiceWorkerState state) {
726 TRACE_EVENT2("ServiceWorker", 768 TRACE_EVENT2("ServiceWorker",
727 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", 769 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged",
728 "Thread ID", thread_id, 770 "Thread ID", thread_id,
729 "State", state); 771 "State", state);
730 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); 772 WorkerObjectMap::iterator worker = service_workers_.find(handle_id);
731 if (worker != service_workers_.end()) 773 if (worker != service_workers_.end())
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 return ServiceWorkerRegistrationHandleReference::Adopt( 904 return ServiceWorkerRegistrationHandleReference::Adopt(
863 info, thread_safe_sender_.get()); 905 info, thread_safe_sender_.get());
864 } 906 }
865 907
866 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( 908 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt(
867 const ServiceWorkerObjectInfo& info) { 909 const ServiceWorkerObjectInfo& info) {
868 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); 910 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get());
869 } 911 }
870 912
871 } // namespace content 913 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698