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