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, i.e. ServiceWorker or SharedWorker. | 54 // worker context, i.e. ServiceWorker or SharedWorker. |
53 // |provider_type| gives additional information whether the provider is | 55 // |provider_type| gives additional information whether the provider is |
54 // created for controller (ServiceWorker) or controllee (Document or | 56 // created for controller (ServiceWorker) or controllee (Document or |
55 // SharedWorker). | 57 // SharedWorker). |
56 ServiceWorkerProviderHost(int render_process_id, | 58 ServiceWorkerProviderHost(int render_process_id, |
57 int render_frame_id, | 59 int render_frame_id, |
58 int provider_id, | 60 int provider_id, |
59 ServiceWorkerProviderType provider_type, | 61 ServiceWorkerProviderType provider_type, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 static ServiceWorkerClientInfo GetClientInfoOnUI(int render_process_id, | 163 static ServiceWorkerClientInfo GetClientInfoOnUI(int render_process_id, |
162 int render_frame_id); | 164 int render_frame_id); |
163 | 165 |
164 // Adds reference of this host's process to the |pattern|, the reference will | 166 // Adds reference of this host's process to the |pattern|, the reference will |
165 // be removed in destructor. | 167 // be removed in destructor. |
166 void AddScopedProcessReferenceToPattern(const GURL& pattern); | 168 void AddScopedProcessReferenceToPattern(const GURL& pattern); |
167 | 169 |
168 // |registration| claims the document to be controlled. | 170 // |registration| claims the document to be controlled. |
169 void ClaimedByRegistration(ServiceWorkerRegistration* registration); | 171 void ClaimedByRegistration(ServiceWorkerRegistration* registration); |
170 | 172 |
| 173 // Called by dispatcher host to get the registration for the "ready" property. |
| 174 // Returns false if there's a completed or ongoing request for the document. |
| 175 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-
service-worker-ready |
| 176 bool GetRegistrationForReady(const GetRegistrationForReadyCallback& callback); |
| 177 |
171 // Methods to support cross site navigations. | 178 // Methods to support cross site navigations. |
172 void PrepareForCrossSiteTransfer(); | 179 void PrepareForCrossSiteTransfer(); |
173 void CompleteCrossSiteTransfer( | 180 void CompleteCrossSiteTransfer( |
174 int new_process_id, | 181 int new_process_id, |
175 int new_frame_id, | 182 int new_frame_id, |
176 int new_provider_id, | 183 int new_provider_id, |
177 ServiceWorkerProviderType new_provider_type, | 184 ServiceWorkerProviderType new_provider_type, |
178 ServiceWorkerDispatcherHost* dispatcher_host); | 185 ServiceWorkerDispatcherHost* dispatcher_host); |
179 ServiceWorkerDispatcherHost* dispatcher_host() const { | 186 ServiceWorkerDispatcherHost* dispatcher_host() const { |
180 return dispatcher_host_; | 187 return dispatcher_host_; |
181 } | 188 } |
182 | 189 |
183 // Sends event messages to the renderer. Events for the worker are queued up | 190 // Sends event messages to the renderer. Events for the worker are queued up |
184 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). | 191 // until the worker thread id is known via SetReadyToSendMessagesToWorker(). |
185 void SendUpdateFoundMessage( | 192 void SendUpdateFoundMessage( |
186 const ServiceWorkerRegistrationObjectInfo& object_info); | 193 const ServiceWorkerRegistrationObjectInfo& object_info); |
187 void SendSetVersionAttributesMessage( | 194 void SendSetVersionAttributesMessage( |
188 int registration_handle_id, | 195 int registration_handle_id, |
189 ChangedVersionAttributesMask changed_mask, | 196 ChangedVersionAttributesMask changed_mask, |
190 ServiceWorkerVersion* installing_version, | 197 ServiceWorkerVersion* installing_version, |
191 ServiceWorkerVersion* waiting_version, | 198 ServiceWorkerVersion* waiting_version, |
192 ServiceWorkerVersion* active_version); | 199 ServiceWorkerVersion* active_version); |
193 void SendServiceWorkerStateChangedMessage( | 200 void SendServiceWorkerStateChangedMessage( |
194 int worker_handle_id, | 201 int worker_handle_id, |
195 blink::WebServiceWorkerState state); | 202 blink::WebServiceWorkerState state); |
196 | 203 |
197 // Sets the worker thread id and flushes queued events. | 204 // Sets the worker thread id and flushes queued events. |
198 void SetReadyToSendMessagesToWorker(int render_thread_id); | 205 void SetReadyToSendMessagesToWorker(int render_thread_id); |
199 | 206 |
| 207 void AddMatchingRegistration(ServiceWorkerRegistration* registration); |
| 208 void RemoveMatchingRegistration(ServiceWorkerRegistration* registration); |
| 209 |
| 210 // An optimized implementation of [[Match Service Worker Registration]] |
| 211 // for current document. |
| 212 ServiceWorkerRegistration* MatchRegistration() const; |
| 213 |
200 private: | 214 private: |
201 friend class ServiceWorkerProviderHostTest; | 215 friend class ServiceWorkerProviderHostTest; |
202 friend class ServiceWorkerWriteToCacheJobTest; | 216 friend class ServiceWorkerWriteToCacheJobTest; |
203 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 217 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
204 UpdateBefore24Hours); | 218 UpdateBefore24Hours); |
205 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, | 219 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerContextRequestHandlerTest, |
206 UpdateAfter24Hours); | 220 UpdateAfter24Hours); |
207 | 221 |
| 222 struct OneShotGetReadyCallback { |
| 223 GetRegistrationForReadyCallback callback; |
| 224 bool called; |
| 225 |
| 226 explicit OneShotGetReadyCallback( |
| 227 const GetRegistrationForReadyCallback& callback); |
| 228 ~OneShotGetReadyCallback(); |
| 229 }; |
| 230 |
208 // ServiceWorkerRegistration::Listener overrides. | 231 // ServiceWorkerRegistration::Listener overrides. |
| 232 void OnVersionAttributesChanged( |
| 233 ServiceWorkerRegistration* registration, |
| 234 ChangedVersionAttributesMask changed_mask, |
| 235 const ServiceWorkerRegistrationInfo& info) override; |
209 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; | 236 void OnRegistrationFailed(ServiceWorkerRegistration* registration) override; |
| 237 void OnRegistrationFinishedUninstalling( |
| 238 ServiceWorkerRegistration* registration) override; |
210 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; | 239 void OnSkippedWaiting(ServiceWorkerRegistration* registration) override; |
211 | 240 |
212 // Sets the controller version field to |version| or if |version| is NULL, | 241 // Sets the controller version field to |version| or if |version| is NULL, |
213 // clears the field. | 242 // clears the field. |
214 void SetControllerVersionAttribute(ServiceWorkerVersion* version); | 243 void SetControllerVersionAttribute(ServiceWorkerVersion* version); |
215 | 244 |
216 void SendAssociateRegistrationMessage(); | 245 void SendAssociateRegistrationMessage(); |
217 | 246 |
218 // Increase/decrease this host's process reference for |pattern|. | 247 // Increase/decrease this host's process reference for |pattern|. |
219 void IncreaseProcessReference(const GURL& pattern); | 248 void IncreaseProcessReference(const GURL& pattern); |
220 void DecreaseProcessReference(const GURL& pattern); | 249 void DecreaseProcessReference(const GURL& pattern); |
221 | 250 |
| 251 void ReturnRegistrationForReadyIfNeeded(); |
| 252 |
222 bool IsReadyToSendMessages() const; | 253 bool IsReadyToSendMessages() const; |
223 void Send(IPC::Message* message) const; | 254 void Send(IPC::Message* message) const; |
224 | 255 |
225 int render_process_id_; | 256 int render_process_id_; |
226 int render_frame_id_; | 257 int render_frame_id_; |
227 int render_thread_id_; | 258 int render_thread_id_; |
228 int provider_id_; | 259 int provider_id_; |
229 ServiceWorkerProviderType provider_type_; | 260 ServiceWorkerProviderType provider_type_; |
230 GURL document_url_; | 261 GURL document_url_; |
231 GURL topmost_frame_url_; | 262 GURL topmost_frame_url_; |
232 | 263 |
233 std::vector<GURL> associated_patterns_; | 264 std::vector<GURL> associated_patterns_; |
234 scoped_refptr<ServiceWorkerRegistration> associated_registration_; | 265 scoped_refptr<ServiceWorkerRegistration> associated_registration_; |
235 | 266 |
| 267 // Keyed by registration scope URL length. |
| 268 typedef std::map<size_t, scoped_refptr<ServiceWorkerRegistration>> |
| 269 ServiceWorkerRegistrationMap; |
| 270 // Contains all living registrations which has pattern this document's |
| 271 // URL starts with. |
| 272 ServiceWorkerRegistrationMap matching_registrations_; |
| 273 |
| 274 scoped_ptr<OneShotGetReadyCallback> get_ready_callback_; |
236 scoped_refptr<ServiceWorkerVersion> controlling_version_; | 275 scoped_refptr<ServiceWorkerVersion> controlling_version_; |
237 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; | 276 scoped_refptr<ServiceWorkerVersion> running_hosted_version_; |
238 base::WeakPtr<ServiceWorkerContextCore> context_; | 277 base::WeakPtr<ServiceWorkerContextCore> context_; |
239 ServiceWorkerDispatcherHost* dispatcher_host_; | 278 ServiceWorkerDispatcherHost* dispatcher_host_; |
240 bool allow_association_; | 279 bool allow_association_; |
241 bool is_claiming_; | 280 bool is_claiming_; |
242 | 281 |
243 std::vector<base::Closure> queued_events_; | 282 std::vector<base::Closure> queued_events_; |
244 | 283 |
245 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); | 284 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerProviderHost); |
246 }; | 285 }; |
247 | 286 |
248 } // namespace content | 287 } // namespace content |
249 | 288 |
250 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ | 289 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_PROVIDER_HOST_H_ |
OLD | NEW |