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_VERSION_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <set> |
9 #include <string> | 10 #include <string> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
13 #include "base/callback.h" | 14 #include "base/callback.h" |
14 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
15 #include "base/id_map.h" | 16 #include "base/id_map.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
(...skipping 14 matching lines...) Expand all Loading... |
33 } | 34 } |
34 | 35 |
35 namespace content { | 36 namespace content { |
36 | 37 |
37 struct CrossOriginServiceWorkerClient; | 38 struct CrossOriginServiceWorkerClient; |
38 class EmbeddedWorkerRegistry; | 39 class EmbeddedWorkerRegistry; |
39 struct PlatformNotificationData; | 40 struct PlatformNotificationData; |
40 class ServiceWorkerContextCore; | 41 class ServiceWorkerContextCore; |
41 class ServiceWorkerProviderHost; | 42 class ServiceWorkerProviderHost; |
42 class ServiceWorkerRegistration; | 43 class ServiceWorkerRegistration; |
| 44 class ServiceWorkerURLRequestJob; |
43 class ServiceWorkerVersionInfo; | 45 class ServiceWorkerVersionInfo; |
44 | 46 |
45 // This class corresponds to a specific version of a ServiceWorker | 47 // This class corresponds to a specific version of a ServiceWorker |
46 // script for a given pattern. When a script is upgraded, there may be | 48 // script for a given pattern. When a script is upgraded, there may be |
47 // more than one ServiceWorkerVersion "running" at a time, but only | 49 // more than one ServiceWorkerVersion "running" at a time, but only |
48 // one of them is activated. This class connects the actual script with a | 50 // one of them is activated. This class connects the actual script with a |
49 // running worker. | 51 // running worker. |
50 class CONTENT_EXPORT ServiceWorkerVersion | 52 class CONTENT_EXPORT ServiceWorkerVersion |
51 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), | 53 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerVersion>), |
52 public EmbeddedWorkerInstance::Listener { | 54 public EmbeddedWorkerInstance::Listener { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 261 |
260 // Adds and removes |provider_host| as a controllee of this ServiceWorker. | 262 // Adds and removes |provider_host| as a controllee of this ServiceWorker. |
261 // A potential controllee is a host having the version as its .installing | 263 // A potential controllee is a host having the version as its .installing |
262 // or .waiting version. | 264 // or .waiting version. |
263 void AddControllee(ServiceWorkerProviderHost* provider_host); | 265 void AddControllee(ServiceWorkerProviderHost* provider_host); |
264 void RemoveControllee(ServiceWorkerProviderHost* provider_host); | 266 void RemoveControllee(ServiceWorkerProviderHost* provider_host); |
265 | 267 |
266 // Returns if it has controllee. | 268 // Returns if it has controllee. |
267 bool HasControllee() const { return !controllee_map_.empty(); } | 269 bool HasControllee() const { return !controllee_map_.empty(); } |
268 | 270 |
| 271 // Adds and removes |request_job| as a dependent job not to stop the |
| 272 // ServiceWorker while |request_job| is reading the stream of the fetch event |
| 273 // response from the ServiceWorker. |
| 274 void AddStreamingURLRequestJob(const ServiceWorkerURLRequestJob* request_job); |
| 275 void RemoveStreamingURLRequestJob( |
| 276 const ServiceWorkerURLRequestJob* request_job); |
| 277 |
269 // Adds and removes Listeners. | 278 // Adds and removes Listeners. |
270 void AddListener(Listener* listener); | 279 void AddListener(Listener* listener); |
271 void RemoveListener(Listener* listener); | 280 void RemoveListener(Listener* listener); |
272 | 281 |
273 ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; } | 282 ServiceWorkerScriptCacheMap* script_cache_map() { return &script_cache_map_; } |
274 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } | 283 EmbeddedWorkerInstance* embedded_worker() { return embedded_worker_.get(); } |
275 | 284 |
276 // Dooms this version to have REDUNDANT status and its resources deleted. If | 285 // Dooms this version to have REDUNDANT status and its resources deleted. If |
277 // the version is controlling a page, these changes will happen when the | 286 // the version is controlling a page, these changes will happen when the |
278 // version no longer controls any pages. | 287 // version no longer controls any pages. |
279 void Doom(); | 288 void Doom(); |
280 bool is_doomed() const { return is_doomed_; } | 289 bool is_doomed() const { return is_doomed_; } |
281 | 290 |
282 bool skip_waiting() const { return skip_waiting_; } | 291 bool skip_waiting() const { return skip_waiting_; } |
283 | 292 |
284 void SetDevToolsAttached(bool attached); | 293 void SetDevToolsAttached(bool attached); |
285 | 294 |
286 private: | 295 private: |
287 class GetClientDocumentsCallback; | 296 class GetClientDocumentsCallback; |
288 | 297 |
289 friend class base::RefCounted<ServiceWorkerVersion>; | 298 friend class base::RefCounted<ServiceWorkerVersion>; |
| 299 friend class ServiceWorkerURLRequestJobTest; |
290 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, | 300 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest, |
291 ActivateWaitingVersion); | 301 ActivateWaitingVersion); |
292 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker); | 302 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ScheduleStopWorker); |
293 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive); | 303 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, KeepAlive); |
294 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability); | 304 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerVersionTest, ListenerAvailability); |
295 typedef ServiceWorkerVersion self; | 305 typedef ServiceWorkerVersion self; |
296 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; | 306 typedef std::map<ServiceWorkerProviderHost*, int> ControlleeMap; |
297 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; | 307 typedef IDMap<ServiceWorkerProviderHost> ControlleeByIDMap; |
298 | 308 |
299 ~ServiceWorkerVersion() override; | 309 ~ServiceWorkerVersion() override; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; | 387 IDMap<StatusCallback, IDMapOwnPointer> install_callbacks_; |
378 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; | 388 IDMap<FetchCallback, IDMapOwnPointer> fetch_callbacks_; |
379 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; | 389 IDMap<StatusCallback, IDMapOwnPointer> sync_callbacks_; |
380 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_; | 390 IDMap<StatusCallback, IDMapOwnPointer> notification_click_callbacks_; |
381 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; | 391 IDMap<StatusCallback, IDMapOwnPointer> push_callbacks_; |
382 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_; | 392 IDMap<StatusCallback, IDMapOwnPointer> geofencing_callbacks_; |
383 IDMap<GetClientInfoCallback, IDMapOwnPointer> get_client_info_callbacks_; | 393 IDMap<GetClientInfoCallback, IDMapOwnPointer> get_client_info_callbacks_; |
384 IDMap<CrossOriginConnectCallback, IDMapOwnPointer> | 394 IDMap<CrossOriginConnectCallback, IDMapOwnPointer> |
385 cross_origin_connect_callbacks_; | 395 cross_origin_connect_callbacks_; |
386 | 396 |
| 397 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; |
| 398 |
387 ControlleeMap controllee_map_; | 399 ControlleeMap controllee_map_; |
388 ControlleeByIDMap controllee_by_id_; | 400 ControlleeByIDMap controllee_by_id_; |
389 base::WeakPtr<ServiceWorkerContextCore> context_; | 401 base::WeakPtr<ServiceWorkerContextCore> context_; |
390 ObserverList<Listener> listeners_; | 402 ObserverList<Listener> listeners_; |
391 ServiceWorkerScriptCacheMap script_cache_map_; | 403 ServiceWorkerScriptCacheMap script_cache_map_; |
392 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; | 404 base::OneShotTimer<ServiceWorkerVersion> stop_worker_timer_; |
393 base::OneShotTimer<ServiceWorkerVersion> update_timer_; | 405 base::OneShotTimer<ServiceWorkerVersion> update_timer_; |
394 bool is_doomed_; | 406 bool is_doomed_; |
395 std::vector<int> pending_skip_waiting_requests_; | 407 std::vector<int> pending_skip_waiting_requests_; |
396 bool skip_waiting_; | 408 bool skip_waiting_; |
397 | 409 |
398 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; | 410 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; |
399 | 411 |
400 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); | 412 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); |
401 }; | 413 }; |
402 | 414 |
403 } // namespace content | 415 } // namespace content |
404 | 416 |
405 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ | 417 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ |
OLD | NEW |