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

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

Issue 2658603003: ServiceWorker: Enable UseCounter for ServiceWorkerGlobalScope (Closed)
Patch Set: int32_t -> uint32_t Created 3 years, 10 months 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, 106 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged,
107 OnServiceWorkerStateChanged) 107 OnServiceWorkerStateChanged)
108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, 108 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes,
109 OnSetVersionAttributes) 109 OnSetVersionAttributes)
110 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound, 110 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_UpdateFound,
111 OnUpdateFound) 111 OnUpdateFound)
112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker, 112 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetControllerServiceWorker,
113 OnSetControllerServiceWorker) 113 OnSetControllerServiceWorker)
114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument, 114 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_MessageToDocument,
115 OnPostMessage) 115 OnPostMessage)
116 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_CountFeature, OnCountFeature)
116 IPC_MESSAGE_UNHANDLED(handled = false) 117 IPC_MESSAGE_UNHANDLED(handled = false)
117 IPC_END_MESSAGE_MAP() 118 IPC_END_MESSAGE_MAP()
118 DCHECK(handled) << "Unhandled message:" << msg.type(); 119 DCHECK(handled) << "Unhandled message:" << msg.type();
119 } 120 }
120 121
121 void ServiceWorkerDispatcher::RegisterServiceWorker( 122 void ServiceWorkerDispatcher::RegisterServiceWorker(
122 int provider_id, 123 int provider_id,
123 const GURL& pattern, 124 const GURL& pattern,
124 const GURL& script_url, 125 const GURL& script_url,
125 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { 126 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) {
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 RegistrationObjectMap::iterator found = 814 RegistrationObjectMap::iterator found =
814 registrations_.find(registration_handle_id); 815 registrations_.find(registration_handle_id);
815 if (found != registrations_.end()) 816 if (found != registrations_.end())
816 found->second->OnUpdateFound(); 817 found->second->OnUpdateFound();
817 } 818 }
818 819
819 void ServiceWorkerDispatcher::OnSetControllerServiceWorker( 820 void ServiceWorkerDispatcher::OnSetControllerServiceWorker(
820 int thread_id, 821 int thread_id,
821 int provider_id, 822 int provider_id,
822 const ServiceWorkerObjectInfo& info, 823 const ServiceWorkerObjectInfo& info,
823 bool should_notify_controllerchange) { 824 bool should_notify_controllerchange,
825 const std::set<uint32_t>& used_features) {
824 TRACE_EVENT2("ServiceWorker", 826 TRACE_EVENT2("ServiceWorker",
825 "ServiceWorkerDispatcher::OnSetControllerServiceWorker", 827 "ServiceWorkerDispatcher::OnSetControllerServiceWorker",
826 "Thread ID", thread_id, 828 "Thread ID", thread_id,
827 "Provider ID", provider_id); 829 "Provider ID", provider_id);
828 830
829 // Adopt the reference sent from the browser process and pass it to the 831 // Adopt the reference sent from the browser process and pass it to the
830 // provider context if it exists. 832 // provider context if it exists.
831 std::unique_ptr<ServiceWorkerHandleReference> handle_ref = Adopt(info); 833 std::unique_ptr<ServiceWorkerHandleReference> handle_ref = Adopt(info);
832 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id); 834 ProviderContextMap::iterator provider = provider_contexts_.find(provider_id);
833 if (provider != provider_contexts_.end()) 835 if (provider != provider_contexts_.end()) {
834 provider->second->OnSetControllerServiceWorker(std::move(handle_ref)); 836 provider->second->OnSetControllerServiceWorker(std::move(handle_ref),
837 used_features);
838 }
835 839
836 ProviderClientMap::iterator found = provider_clients_.find(provider_id); 840 ProviderClientMap::iterator found = provider_clients_.find(provider_id);
837 if (found != provider_clients_.end()) { 841 if (found != provider_clients_.end()) {
842 // Sync the controllee's use counter with the service worker's one.
843 for (uint32_t feature : used_features)
844 found->second->countFeature(feature);
845
838 // Get the existing worker object or create a new one with a new reference 846 // Get the existing worker object or create a new one with a new reference
839 // to populate the .controller field. 847 // to populate the .controller field.
840 scoped_refptr<WebServiceWorkerImpl> worker = GetOrCreateServiceWorker( 848 scoped_refptr<WebServiceWorkerImpl> worker = GetOrCreateServiceWorker(
841 ServiceWorkerHandleReference::Create(info, thread_safe_sender_.get())); 849 ServiceWorkerHandleReference::Create(info, thread_safe_sender_.get()));
842 found->second->setController(WebServiceWorkerImpl::CreateHandle(worker), 850 found->second->setController(WebServiceWorkerImpl::CreateHandle(worker),
843 should_notify_controllerchange); 851 should_notify_controllerchange);
852 // You must not access |found| after setController() because it may fire the
853 // controllerchange event that may remove the provider client, for example,
854 // by detaching an iframe.
844 } 855 }
845 } 856 }
846 857
847 void ServiceWorkerDispatcher::OnPostMessage( 858 void ServiceWorkerDispatcher::OnPostMessage(
848 const ServiceWorkerMsg_MessageToDocument_Params& params) { 859 const ServiceWorkerMsg_MessageToDocument_Params& params) {
849 // Make sure we're on the main document thread. (That must be the only 860 // Make sure we're on the main document thread. (That must be the only
850 // thread we get this message) 861 // thread we get this message)
851 DCHECK_EQ(kDocumentMainThreadId, params.thread_id); 862 DCHECK_EQ(kDocumentMainThreadId, params.thread_id);
852 TRACE_EVENT1("ServiceWorker", "ServiceWorkerDispatcher::OnPostMessage", 863 TRACE_EVENT1("ServiceWorker", "ServiceWorkerDispatcher::OnPostMessage",
853 "Thread ID", params.thread_id); 864 "Thread ID", params.thread_id);
(...skipping 14 matching lines...) Expand all
868 blink::WebMessagePortChannelArray ports = 879 blink::WebMessagePortChannelArray ports =
869 WebMessagePortChannelImpl::CreatePorts( 880 WebMessagePortChannelImpl::CreatePorts(
870 params.message_ports, params.new_routing_ids, 881 params.message_ports, params.new_routing_ids,
871 base::ThreadTaskRunnerHandle::Get()); 882 base::ThreadTaskRunnerHandle::Get());
872 883
873 found->second->dispatchMessageEvent( 884 found->second->dispatchMessageEvent(
874 WebServiceWorkerImpl::CreateHandle(worker), 885 WebServiceWorkerImpl::CreateHandle(worker),
875 blink::WebString::fromUTF16(params.message), ports); 886 blink::WebString::fromUTF16(params.message), ports);
876 } 887 }
877 888
889 void ServiceWorkerDispatcher::OnCountFeature(int thread_id,
890 int provider_id,
891 uint32_t feature) {
892 ProviderClientMap::iterator found = provider_clients_.find(provider_id);
893 if (found != provider_clients_.end())
894 found->second->countFeature(feature);
895 }
896
878 void ServiceWorkerDispatcher::AddServiceWorker( 897 void ServiceWorkerDispatcher::AddServiceWorker(
879 int handle_id, WebServiceWorkerImpl* worker) { 898 int handle_id, WebServiceWorkerImpl* worker) {
880 DCHECK(!base::ContainsKey(service_workers_, handle_id)); 899 DCHECK(!base::ContainsKey(service_workers_, handle_id));
881 service_workers_[handle_id] = worker; 900 service_workers_[handle_id] = worker;
882 } 901 }
883 902
884 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) { 903 void ServiceWorkerDispatcher::RemoveServiceWorker(int handle_id) {
885 DCHECK(base::ContainsKey(service_workers_, handle_id)); 904 DCHECK(base::ContainsKey(service_workers_, handle_id));
886 service_workers_.erase(handle_id); 905 service_workers_.erase(handle_id);
887 } 906 }
(...skipping 17 matching lines...) Expand all
905 return ServiceWorkerRegistrationHandleReference::Adopt( 924 return ServiceWorkerRegistrationHandleReference::Adopt(
906 info, thread_safe_sender_.get()); 925 info, thread_safe_sender_.get());
907 } 926 }
908 927
909 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( 928 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt(
910 const ServiceWorkerObjectInfo& info) { 929 const ServiceWorkerObjectInfo& info) {
911 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); 930 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get());
912 } 931 }
913 932
914 } // namespace content 933 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698