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

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

Issue 2443103002: service worker: Implement NavigationPreloadManager.getState (Closed)
Patch Set: rm file added in bad merge 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"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/threading/thread_local.h" 13 #include "base/threading/thread_local.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/trace_event/trace_event.h" 15 #include "base/trace_event/trace_event.h"
16 #include "content/child/service_worker/service_worker_handle_reference.h" 16 #include "content/child/service_worker/service_worker_handle_reference.h"
17 #include "content/child/service_worker/service_worker_provider_context.h" 17 #include "content/child/service_worker/service_worker_provider_context.h"
18 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" 18 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h"
19 #include "content/child/service_worker/web_service_worker_impl.h" 19 #include "content/child/service_worker/web_service_worker_impl.h"
20 #include "content/child/service_worker/web_service_worker_registration_impl.h" 20 #include "content/child/service_worker/web_service_worker_registration_impl.h"
21 #include "content/child/thread_safe_sender.h" 21 #include "content/child/thread_safe_sender.h"
22 #include "content/child/webmessageportchannel_impl.h" 22 #include "content/child/webmessageportchannel_impl.h"
23 #include "content/common/service_worker/service_worker_messages.h" 23 #include "content/common/service_worker/service_worker_messages.h"
24 #include "content/common/service_worker/service_worker_types.h" 24 #include "content/common/service_worker/service_worker_types.h"
25 #include "content/public/common/content_constants.h" 25 #include "content/public/common/content_constants.h"
26 #include "third_party/WebKit/public/platform/WebString.h" 26 #include "third_party/WebKit/public/platform/WebString.h"
27 #include "third_party/WebKit/public/platform/modules/serviceworker/WebNavigation PreloadState.h"
27 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerProviderClient.h" 28 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerProviderClient.h"
28 #include "url/url_constants.h" 29 #include "url/url_constants.h"
29 30
30 using blink::WebServiceWorkerError; 31 using blink::WebServiceWorkerError;
31 using blink::WebServiceWorkerProvider; 32 using blink::WebServiceWorkerProvider;
32 using base::ThreadLocalPointer; 33 using base::ThreadLocalPointer;
33 34
34 namespace content { 35 namespace content {
35 36
36 namespace { 37 namespace {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, 75 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered,
75 OnUnregistered) 76 OnUnregistered)
76 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, 77 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration,
77 OnDidGetRegistration) 78 OnDidGetRegistration)
78 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations, 79 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrations,
79 OnDidGetRegistrations) 80 OnDidGetRegistrations)
80 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady, 81 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistrationForReady,
81 OnDidGetRegistrationForReady) 82 OnDidGetRegistrationForReady)
82 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidEnableNavigationPreload, 83 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidEnableNavigationPreload,
83 OnDidEnableNavigationPreload) 84 OnDidEnableNavigationPreload)
85 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetNavigationPreloadState,
86 OnDidGetNavigationPreloadState)
84 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, 87 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError,
85 OnRegistrationError) 88 OnRegistrationError)
86 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdateError, 89 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUpdateError,
87 OnUpdateError) 90 OnUpdateError)
88 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, 91 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError,
89 OnUnregistrationError) 92 OnUnregistrationError)
90 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, 93 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError,
91 OnGetRegistrationError) 94 OnGetRegistrationError)
92 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError, 95 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationsError,
93 OnGetRegistrationsError) 96 OnGetRegistrationsError)
94 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_EnableNavigationPreloadError, 97 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_EnableNavigationPreloadError,
95 OnEnableNavigationPreloadError) 98 OnEnableNavigationPreloadError)
99 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GetNavigationPreloadStateError,
100 OnGetNavigationPreloadStateError)
96 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 101 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
97 OnServiceWorkerStateChanged) 102 OnServiceWorkerStateChanged)
98 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 103 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
99 OnSetVersionAttributes) 104 OnSetVersionAttributes)
100 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 105 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
101 OnUpdateFound) 106 OnUpdateFound)
102 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 107 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
103 OnSetControllerServiceWorker) 108 OnSetControllerServiceWorker)
104 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 109 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
105 OnPostMessage) 110 OnPostMessage)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 int64_t registration_id, 220 int64_t registration_id,
216 bool enable, 221 bool enable,
217 std::unique_ptr<WebEnableNavigationPreloadCallbacks> callbacks) { 222 std::unique_ptr<WebEnableNavigationPreloadCallbacks> callbacks) {
218 DCHECK(callbacks); 223 DCHECK(callbacks);
219 int request_id = 224 int request_id =
220 enable_navigation_preload_callbacks_.Add(callbacks.release()); 225 enable_navigation_preload_callbacks_.Add(callbacks.release());
221 thread_safe_sender_->Send(new ServiceWorkerHostMsg_EnableNavigationPreload( 226 thread_safe_sender_->Send(new ServiceWorkerHostMsg_EnableNavigationPreload(
222 CurrentWorkerId(), request_id, provider_id, registration_id, enable)); 227 CurrentWorkerId(), request_id, provider_id, registration_id, enable));
223 } 228 }
224 229
230 void ServiceWorkerDispatcher::GetNavigationPreloadState(
231 int provider_id,
232 int64_t registration_id,
233 std::unique_ptr<WebGetNavigationPreloadStateCallbacks> callbacks) {
234 DCHECK(callbacks);
235 int request_id =
236 get_navigation_preload_state_callbacks_.Add(callbacks.release());
237 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetNavigationPreloadState(
238 CurrentWorkerId(), request_id, provider_id, registration_id));
239 }
240
225 void ServiceWorkerDispatcher::AddProviderContext( 241 void ServiceWorkerDispatcher::AddProviderContext(
226 ServiceWorkerProviderContext* provider_context) { 242 ServiceWorkerProviderContext* provider_context) {
227 DCHECK(provider_context); 243 DCHECK(provider_context);
228 int provider_id = provider_context->provider_id(); 244 int provider_id = provider_context->provider_id();
229 DCHECK(!base::ContainsKey(provider_contexts_, provider_id)); 245 DCHECK(!base::ContainsKey(provider_contexts_, provider_id));
230 provider_contexts_[provider_id] = provider_context; 246 provider_contexts_[provider_id] = provider_context;
231 } 247 }
232 248
233 void ServiceWorkerDispatcher::RemoveProviderContext( 249 void ServiceWorkerDispatcher::RemoveProviderContext(
234 ServiceWorkerProviderContext* provider_context) { 250 ServiceWorkerProviderContext* provider_context) {
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 int request_id) { 556 int request_id) {
541 WebEnableNavigationPreloadCallbacks* callbacks = 557 WebEnableNavigationPreloadCallbacks* callbacks =
542 enable_navigation_preload_callbacks_.Lookup(request_id); 558 enable_navigation_preload_callbacks_.Lookup(request_id);
543 DCHECK(callbacks); 559 DCHECK(callbacks);
544 if (!callbacks) 560 if (!callbacks)
545 return; 561 return;
546 callbacks->onSuccess(); 562 callbacks->onSuccess();
547 enable_navigation_preload_callbacks_.Remove(request_id); 563 enable_navigation_preload_callbacks_.Remove(request_id);
548 } 564 }
549 565
566 void ServiceWorkerDispatcher::OnDidGetNavigationPreloadState(int thread_id,
567 int request_id,
568 bool enabled) {
569 WebGetNavigationPreloadStateCallbacks* callbacks =
570 get_navigation_preload_state_callbacks_.Lookup(request_id);
571 DCHECK(callbacks);
572 if (!callbacks)
573 return;
574 // TODO(falken): Implement populating headerValue.
575 callbacks->onSuccess(
576 blink::WebNavigationPreloadState(enabled, blink::WebString()));
577 get_navigation_preload_state_callbacks_.Remove(request_id);
578 }
579
550 void ServiceWorkerDispatcher::OnRegistrationError( 580 void ServiceWorkerDispatcher::OnRegistrationError(
551 int thread_id, 581 int thread_id,
552 int request_id, 582 int request_id,
553 WebServiceWorkerError::ErrorType error_type, 583 WebServiceWorkerError::ErrorType error_type,
554 const base::string16& message) { 584 const base::string16& message) {
555 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", 585 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker",
556 "ServiceWorkerDispatcher::RegisterServiceWorker", 586 "ServiceWorkerDispatcher::RegisterServiceWorker",
557 request_id, 587 request_id,
558 "OnRegistrationError"); 588 "OnRegistrationError");
559 TRACE_EVENT_ASYNC_END0("ServiceWorker", 589 TRACE_EVENT_ASYNC_END0("ServiceWorker",
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 WebEnableNavigationPreloadCallbacks* callbacks = 697 WebEnableNavigationPreloadCallbacks* callbacks =
668 enable_navigation_preload_callbacks_.Lookup(request_id); 698 enable_navigation_preload_callbacks_.Lookup(request_id);
669 DCHECK(callbacks); 699 DCHECK(callbacks);
670 if (!callbacks) 700 if (!callbacks)
671 return; 701 return;
672 callbacks->onError( 702 callbacks->onError(
673 WebServiceWorkerError(error_type, blink::WebString::fromUTF8(message))); 703 WebServiceWorkerError(error_type, blink::WebString::fromUTF8(message)));
674 enable_navigation_preload_callbacks_.Remove(request_id); 704 enable_navigation_preload_callbacks_.Remove(request_id);
675 } 705 }
676 706
707 void ServiceWorkerDispatcher::OnGetNavigationPreloadStateError(
708 int thread_id,
709 int request_id,
710 WebServiceWorkerError::ErrorType error_type,
711 const std::string& message) {
712 WebGetNavigationPreloadStateCallbacks* callbacks =
713 get_navigation_preload_state_callbacks_.Lookup(request_id);
714 DCHECK(callbacks);
715 if (!callbacks)
716 return;
717 callbacks->onError(
718 WebServiceWorkerError(error_type, blink::WebString::fromUTF8(message)));
719 get_navigation_preload_state_callbacks_.Remove(request_id);
720 }
721
677 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( 722 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
678 int thread_id, 723 int thread_id,
679 int handle_id, 724 int handle_id,
680 blink::WebServiceWorkerState state) { 725 blink::WebServiceWorkerState state) {
681 TRACE_EVENT2("ServiceWorker", 726 TRACE_EVENT2("ServiceWorker",
682 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", 727 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged",
683 "Thread ID", thread_id, 728 "Thread ID", thread_id,
684 "State", state); 729 "State", state);
685 WorkerObjectMap::iterator worker = service_workers_.find(handle_id); 730 WorkerObjectMap::iterator worker = service_workers_.find(handle_id);
686 if (worker != service_workers_.end()) 731 if (worker != service_workers_.end())
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 return ServiceWorkerRegistrationHandleReference::Adopt( 862 return ServiceWorkerRegistrationHandleReference::Adopt(
818 info, thread_safe_sender_.get()); 863 info, thread_safe_sender_.get());
819 } 864 }
820 865
821 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( 866 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt(
822 const ServiceWorkerObjectInfo& info) { 867 const ServiceWorkerObjectInfo& info) {
823 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); 868 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get());
824 } 869 }
825 870
826 } // namespace content 871 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698