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