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_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... | |
40 // document. | 40 // document. |
41 // | 41 // |
42 // Note this class can also host a running service worker, in which | 42 // Note this class can also host a running service worker, in which |
43 // case it will observe resource loads made directly by the service worker. | 43 // case it will observe resource loads made directly by the service worker. |
44 class CONTENT_EXPORT ServiceWorkerProviderHost | 44 class CONTENT_EXPORT ServiceWorkerProviderHost |
45 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), | 45 : public NON_EXPORTED_BASE(ServiceWorkerRegistration::Listener), |
46 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { | 46 public base::SupportsWeakPtr<ServiceWorkerProviderHost> { |
47 public: | 47 public: |
48 using GetClientInfoCallback = | 48 using GetClientInfoCallback = |
49 base::Callback<void(const ServiceWorkerClientInfo&)>; | 49 base::Callback<void(const ServiceWorkerClientInfo&)>; |
50 using GetRegistrationForReadyCallback = | |
51 base::Callback<void(ServiceWorkerRegistration* reigstration)>; | |
50 | 52 |
51 // If |render_frame_id| is MSG_ROUTING_NONE, this provider host works for the | 53 // If |render_frame_id| is MSG_ROUTING_NONE, this provider host works for the |
52 // worker context. | 54 // worker context. |
53 ServiceWorkerProviderHost(int render_process_id, | 55 ServiceWorkerProviderHost(int render_process_id, |
54 int render_frame_id, | 56 int render_frame_id, |
55 int provider_id, | 57 int provider_id, |
56 base::WeakPtr<ServiceWorkerContextCore> context, | 58 base::WeakPtr<ServiceWorkerContextCore> context, |
57 ServiceWorkerDispatcherHost* dispatcher_host); | 59 ServiceWorkerDispatcherHost* dispatcher_host); |
58 virtual ~ServiceWorkerProviderHost(); | 60 virtual ~ServiceWorkerProviderHost(); |
59 | 61 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 // Asks the renderer to send back the document information. | 150 // Asks the renderer to send back the document information. |
149 void GetClientInfo(const GetClientInfoCallback& callback) const; | 151 void GetClientInfo(const GetClientInfoCallback& callback) const; |
150 | 152 |
151 // Adds reference of this host's process to the |pattern|, the reference will | 153 // Adds reference of this host's process to the |pattern|, the reference will |
152 // be removed in destructor. | 154 // be removed in destructor. |
153 void AddScopedProcessReferenceToPattern(const GURL& pattern); | 155 void AddScopedProcessReferenceToPattern(const GURL& pattern); |
154 | 156 |
155 // |registration| claims the document to be controlled. | 157 // |registration| claims the document to be controlled. |
156 void ClaimedByRegistration(ServiceWorkerRegistration* registration); | 158 void ClaimedByRegistration(ServiceWorkerRegistration* registration); |
157 | 159 |
160 // Called by dispatcher host to get the registration for the "ready" property. | |
161 // http://www.w3.org/TR/service-workers/#navigator-service-worker-ready. | |
falken
2015/02/16 09:18:29
nit: We always link to the latest editor's draft:
xiang
2015/02/26 06:52:14
Done.
| |
162 void GetRegistrationForReady(const GetRegistrationForReadyCallback& callback); | |
163 | |
158 // Methods to support cross site navigations. | 164 // Methods to support cross site navigations. |
159 void PrepareForCrossSiteTransfer(); | 165 void PrepareForCrossSiteTransfer(); |
160 void CompleteCrossSiteTransfer( | 166 void CompleteCrossSiteTransfer( |
161 int new_process_id, | 167 int new_process_id, |
162 int new_frame_id, | 168 int new_frame_id, |
163 int new_provider_id, | 169 int new_provider_id, |
164 ServiceWorkerDispatcherHost* dispatcher_host); | 170 ServiceWorkerDispatcherHost* dispatcher_host); |
165 ServiceWorkerDispatcherHost* dispatcher_host() const { | 171 ServiceWorkerDispatcherHost* dispatcher_host() const { |
166 return dispatcher_host_; | 172 return dispatcher_host_; |
167 } | 173 } |
168 | 174 |
169 // Sends event messages to the renderer. Events for the worker are queued up | 175 // Sends event messages to the renderer. Events for the worker are queued up |
170 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). | 176 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). |
171 void SendUpdateFoundMessage( | 177 void SendUpdateFoundMessage( |
172 const ServiceWorkerRegistrationObjectInfo& object_info); | 178 const ServiceWorkerRegistrationObjectInfo& object_info); |
173 void SendSetVersionAttributesMessage( | 179 void SendSetVersionAttributesMessage( |
174 int registration_handle_id, | 180 int registration_handle_id, |
175 ChangedVersionAttributesMask changed_mask, | 181 ChangedVersionAttributesMask changed_mask, |
176 ServiceWorkerVersion* installing_version, | 182 ServiceWorkerVersion* installing_version, |
177 ServiceWorkerVersion* waiting_version, | 183 ServiceWorkerVersion* waiting_version, |
178 ServiceWorkerVersion* active_version); | 184 ServiceWorkerVersion* active_version); |
179 void SendServiceWorkerStateChangedMessage( | 185 void SendServiceWorkerStateChangedMessage( |
180 int worker_handle_id, | 186 int worker_handle_id, |
181 blink::WebServiceWorkerState state); | 187 blink::WebServiceWorkerState state); |
182 | 188 |
183 // Sets the worker thread id and flushes queued events. | 189 // Sets the worker thread id and flushes queued events. |
184 void SetReadyToSendMessagesToWorker(int render_thread_id); | 190 void SetReadyToSendMessagesToWorker(int render_thread_id); |
185 | 191 |
192 void AddMatchingRegistration(ServiceWorkerRegistration* registration); | |
193 void RemoveMatchingRegistration(ServiceWorkerRegistration* registration); | |
194 | |
195 // An optimized implementation of [[Match Service Worker Registration]] | |
196 // for current document. | |
197 ServiceWorkerRegistration* MatchRegistration() const; | |
198 | |
186 private: | 199 private: |
187 friend class ServiceWorkerProviderHostTest; | 200 friend class ServiceWorkerProviderHostTest; |
188 friend class ServiceWorkerWriteToCacheJobTest; | 201 friend class ServiceWorkerWriteToCacheJobTest; |
189 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 202 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
190 UpdateBefore24Hours); | 203 UpdateBefore24Hours); |
191 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 204 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
192 UpdateAfter24Hours); | 205 UpdateAfter24Hours); |
193 | 206 |
194 // ServiceWorkerRegistration::Listener overrides. | 207 // ServiceWorkerRegistration::Listener overrides. |
208 void OnVersionAttributesChanged( | |
209 ServiceWorkerRegistration* registration, | |
210 ChangedVersionAttributesMask changed_mask, | |
211 const ServiceWorkerRegistrationInfo& info) override; | |
195 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 212 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
213 void OnRegistrationFinishedUninstalling( | |
214 ServiceWorkerRegistration* registration) override; | |
196 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; | 215 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; |
197 | 216 |
198 // Sets the controller version field to |version| or if |version| is NULL, | 217 // Sets the controller version field to |version| or if |version| is NULL, |
199 // clears the field. | 218 // clears the field. |
200 void SetControllerVersionAttribute(ServiceWorkerVersion* version); | 219 void SetControllerVersionAttribute(ServiceWorkerVersion* version); |
201 | 220 |
202 void SendAssociateRegistrationMessage(); | 221 void SendAssociateRegistrationMessage(); |
203 | 222 |
204 // Increase/decrease this host's process reference for |pattern|. | 223 // Increase/decrease this host's process reference for |pattern|. |
205 void IncreaseProcessReference(const GURL& pattern); | 224 void IncreaseProcessReference(const GURL& pattern); |
206 void DecreaseProcessReference(const GURL& pattern); | 225 void DecreaseProcessReference(const GURL& pattern); |
207 | 226 |
227 void ReturnRegistrationForReadyIfNeeded(); | |
228 | |
208 bool IsReadyToSendMessages() const; | 229 bool IsReadyToSendMessages() const; |
209 void Send(IPC::Message* message) const; | 230 void Send(IPC::Message* message) const; |
210 | 231 |
211 int render_process_id_; | 232 int render_process_id_; |
212 int render_frame_id_; | 233 int render_frame_id_; |
213 int render_thread_id_; | 234 int render_thread_id_; |
214 int provider_id_; | 235 int provider_id_; |
215 GURL document_url_; | 236 GURL document_url_; |
216 GURL topmost_frame_url_; | 237 GURL topmost_frame_url_; |
217 | 238 |
218 std::vector<GURL> associated_patterns_; | 239 std::vector<GURL> associated_patterns_; |
219 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 240 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
220 | 241 |
242 // Keyed by registration scope URL length. | |
243 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> | |
244 ServiceWorkerRegistrationMap; | |
245 // Contains all living registrations which has pattern this document's | |
246 // URL starts with. | |
247 ServiceWorkerRegistrationMap matching_registrations_; | |
248 | |
249 GetRegistrationForReadyCallback get_ready_callback_; | |
221 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 250 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
222 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 251 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
223 base::WeakPtr<ServiceWorkerContextCore> context_; | 252 base::WeakPtr<ServiceWorkerContextCore> context_; |
224 ServiceWorkerDispatcherHost* dispatcher_host_; | 253 ServiceWorkerDispatcherHost* dispatcher_host_; |
225 bool allow_association_; | 254 bool allow_association_; |
226 bool is_claiming_; | 255 bool is_claiming_; |
227 | 256 |
228 std::vector<base::Closure> queued_events_; | 257 std::vector<base::Closure> queued_events_; |
229 | 258 |
230 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 259 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
231 }; | 260 }; |
232 | 261 |
233 } // namespace content | 262 } // namespace content |
234 | 263 |
235 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 264 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |