| 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 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 6 #define CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace IPC { | 25 namespace IPC { |
| 26 class Message; | 26 class Message; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 class ServiceWorkerMessageFilter; | 31 class ServiceWorkerMessageFilter; |
| 32 class ServiceWorkerProviderContext; | 32 class ServiceWorkerProviderContext; |
| 33 class ThreadSafeSender; | 33 class ThreadSafeSender; |
| 34 class WebServiceWorkerImpl; | 34 class WebServiceWorkerImpl; |
| 35 class WebServiceWorkerRegistrationImpl; |
| 35 struct ServiceWorkerObjectInfo; | 36 struct ServiceWorkerObjectInfo; |
| 36 struct ServiceWorkerVersionAttributes; | 37 struct ServiceWorkerVersionAttributes; |
| 37 | 38 |
| 38 // This class manages communication with the browser process about | 39 // This class manages communication with the browser process about |
| 39 // registration of the service worker, exposed to renderer and worker | 40 // registration of the service worker, exposed to renderer and worker |
| 40 // scripts through methods like navigator.registerServiceWorker(). | 41 // scripts through methods like navigator.registerServiceWorker(). |
| 41 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { | 42 class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { |
| 42 public: | 43 public: |
| 43 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks | 44 typedef blink::WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks |
| 44 WebServiceWorkerRegistrationCallbacks; | 45 WebServiceWorkerRegistrationCallbacks; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // |adopt_handle| is true, a ServiceWorkerHandleReference will be | 81 // |adopt_handle| is true, a ServiceWorkerHandleReference will be |
| 81 // adopted for the specified Service Worker. | 82 // adopted for the specified Service Worker. |
| 82 // | 83 // |
| 83 // TODO(dominicc): The lifetime of WebServiceWorkerImpl is too tricky; this | 84 // TODO(dominicc): The lifetime of WebServiceWorkerImpl is too tricky; this |
| 84 // method can return an existing WebServiceWorkerImpl, in which case | 85 // method can return an existing WebServiceWorkerImpl, in which case |
| 85 // it is owned by a WebCore::ServiceWorker and the lifetime is not | 86 // it is owned by a WebCore::ServiceWorker and the lifetime is not |
| 86 // being transferred to the owner; or it can create a | 87 // being transferred to the owner; or it can create a |
| 87 // WebServiceWorkerImpl, in which case ownership is transferred to | 88 // WebServiceWorkerImpl, in which case ownership is transferred to |
| 88 // the caller who must bounce it to a method that will associate it | 89 // the caller who must bounce it to a method that will associate it |
| 89 // with a WebCore::ServiceWorker. | 90 // with a WebCore::ServiceWorker. |
| 90 WebServiceWorkerImpl* GetServiceWorker(const ServiceWorkerObjectInfo&, | 91 WebServiceWorkerImpl* GetServiceWorker( |
| 91 bool adopt_handle); | 92 const ServiceWorkerObjectInfo& info, |
| 93 bool adopt_handle); |
| 94 |
| 95 // If an existing WebServiceWorkerRegistrationImpl exists for the |
| 96 // registration, it is returned; otherwise a WebServiceWorkerRegistrationImpl |
| 97 // is created and its ownership is transferred to the caller. If |
| 98 // |adopt_handle| is true, a ServiceWorkerRegistrationHandleReference will be |
| 99 // adopted for the specified registration. |
| 100 WebServiceWorkerRegistrationImpl* GetServiceWorkerRegistration( |
| 101 int registration_handle_id, |
| 102 const ServiceWorkerObjectInfo& info, |
| 103 bool adopt_handle); |
| 92 | 104 |
| 93 // |thread_safe_sender| needs to be passed in because if the call leads to | 105 // |thread_safe_sender| needs to be passed in because if the call leads to |
| 94 // construction it will be needed. | 106 // construction it will be needed. |
| 95 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( | 107 static ServiceWorkerDispatcher* GetOrCreateThreadSpecificInstance( |
| 96 ThreadSafeSender* thread_safe_sender); | 108 ThreadSafeSender* thread_safe_sender); |
| 97 | 109 |
| 98 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new | 110 // Unlike GetOrCreateThreadSpecificInstance() this doesn't create a new |
| 99 // instance if thread-local instance doesn't exist. | 111 // instance if thread-local instance doesn't exist. |
| 100 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); | 112 static ServiceWorkerDispatcher* GetThreadSpecificInstance(); |
| 101 | 113 |
| 102 private: | 114 private: |
| 103 typedef IDMap<WebServiceWorkerRegistrationCallbacks, | 115 typedef IDMap<WebServiceWorkerRegistrationCallbacks, |
| 104 IDMapOwnPointer> CallbackMap; | 116 IDMapOwnPointer> CallbackMap; |
| 105 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; | 117 typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; |
| 106 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; | 118 typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; |
| 107 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; | 119 typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; |
| 108 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; | 120 typedef std::map<int, ServiceWorkerProviderContext*> WorkerToProviderMap; |
| 121 typedef std::map<int, WebServiceWorkerRegistrationImpl*> |
| 122 RegistrationObjectMap; |
| 109 | 123 |
| 110 friend class WebServiceWorkerImpl; | 124 friend class WebServiceWorkerImpl; |
| 125 friend class WebServiceWorkerRegistrationImpl; |
| 111 | 126 |
| 112 // WorkerTaskRunner::Observer implementation. | 127 // WorkerTaskRunner::Observer implementation. |
| 113 virtual void OnWorkerRunLoopStopped() OVERRIDE; | 128 virtual void OnWorkerRunLoopStopped() OVERRIDE; |
| 114 | 129 |
| 115 void OnRegistered(int thread_id, | 130 void OnRegistered(int thread_id, |
| 116 int request_id, | 131 int request_id, |
| 132 int registration_handle_id, |
| 117 const ServiceWorkerObjectInfo& info); | 133 const ServiceWorkerObjectInfo& info); |
| 118 void OnUnregistered(int thread_id, | 134 void OnUnregistered(int thread_id, |
| 119 int request_id); | 135 int request_id); |
| 120 void OnRegistrationError(int thread_id, | 136 void OnRegistrationError(int thread_id, |
| 121 int request_id, | 137 int request_id, |
| 122 blink::WebServiceWorkerError::ErrorType error_type, | 138 blink::WebServiceWorkerError::ErrorType error_type, |
| 123 const base::string16& message); | 139 const base::string16& message); |
| 124 void OnServiceWorkerStateChanged(int thread_id, | 140 void OnServiceWorkerStateChanged(int thread_id, |
| 125 int handle_id, | 141 int handle_id, |
| 126 blink::WebServiceWorkerState state); | 142 blink::WebServiceWorkerState state); |
| 127 void OnSetVersionAttributes(int thread_id, | 143 void OnSetVersionAttributes(int thread_id, |
| 128 int provider_id, | 144 int provider_id, |
| 145 int registration_handle_id, |
| 129 int changed_mask, | 146 int changed_mask, |
| 130 const ServiceWorkerVersionAttributes& attributes); | 147 const ServiceWorkerVersionAttributes& attributes); |
| 131 void OnSetControllerServiceWorker(int thread_id, | 148 void OnSetControllerServiceWorker(int thread_id, |
| 132 int provider_id, | 149 int provider_id, |
| 133 const ServiceWorkerObjectInfo& info); | 150 const ServiceWorkerObjectInfo& info); |
| 134 void OnPostMessage(int thread_id, | 151 void OnPostMessage(int thread_id, |
| 135 int provider_id, | 152 int provider_id, |
| 136 const base::string16& message, | 153 const base::string16& message, |
| 137 const std::vector<int>& sent_message_port_ids, | 154 const std::vector<int>& sent_message_port_ids, |
| 138 const std::vector<int>& new_routing_ids); | 155 const std::vector<int>& new_routing_ids); |
| 139 | 156 |
| 140 void SetInstallingServiceWorker( | 157 void SetInstallingServiceWorker( |
| 141 int provider_id, | 158 int provider_id, |
| 159 int registration_handle_id, |
| 142 const ServiceWorkerObjectInfo& info); | 160 const ServiceWorkerObjectInfo& info); |
| 143 void SetWaitingServiceWorker( | 161 void SetWaitingServiceWorker( |
| 144 int provider_id, | 162 int provider_id, |
| 163 int registration_handle_id, |
| 145 const ServiceWorkerObjectInfo& info); | 164 const ServiceWorkerObjectInfo& info); |
| 146 void SetActiveServiceWorker( | 165 void SetActiveServiceWorker( |
| 147 int provider_id, | 166 int provider_id, |
| 167 int registration_handle_id, |
| 148 const ServiceWorkerObjectInfo& info); | 168 const ServiceWorkerObjectInfo& info); |
| 149 | 169 |
| 150 // Keeps map from handle_id to ServiceWorker object. | 170 // Keeps map from handle_id to ServiceWorker object. |
| 151 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); | 171 void AddServiceWorker(int handle_id, WebServiceWorkerImpl* worker); |
| 152 void RemoveServiceWorker(int handle_id); | 172 void RemoveServiceWorker(int handle_id); |
| 153 | 173 |
| 174 // Keeps map from registration_handle_id to ServiceWorkerRegistration object. |
| 175 void AddServiceWorkerRegistration( |
| 176 int registration_handle_id, |
| 177 WebServiceWorkerRegistrationImpl* registration); |
| 178 void RemoveServiceWorkerRegistration( |
| 179 int registration_handle_id); |
| 180 |
| 154 CallbackMap pending_callbacks_; | 181 CallbackMap pending_callbacks_; |
| 155 ScriptClientMap script_clients_; | 182 ScriptClientMap script_clients_; |
| 156 ProviderContextMap provider_contexts_; | 183 ProviderContextMap provider_contexts_; |
| 157 WorkerObjectMap service_workers_; | 184 WorkerObjectMap service_workers_; |
| 185 RegistrationObjectMap registrations_; |
| 158 | 186 |
| 159 // A map for ServiceWorkers that are associated to a particular document | 187 // A map for ServiceWorkers that are associated to a particular document |
| 160 // (e.g. as .current). | 188 // (e.g. as .current). |
| 161 WorkerToProviderMap worker_to_provider_; | 189 WorkerToProviderMap worker_to_provider_; |
| 162 | 190 |
| 163 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 191 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 164 | 192 |
| 165 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); | 193 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcher); |
| 166 }; | 194 }; |
| 167 | 195 |
| 168 } // namespace content | 196 } // namespace content |
| 169 | 197 |
| 170 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ | 198 #endif // CONTENT_CHILD_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_H_ |
| OLD | NEW |