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_REGISTRATION_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "content/browser/service_worker/service_worker_version.h" | 13 #include "content/browser/service_worker/service_worker_version.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 class ServiceWorkerRegistrationInfo; | 20 class ServiceWorkerRegistrationInfo; |
21 class ServiceWorkerVersion; | 21 class ServiceWorkerVersion; |
22 | 22 |
23 // This class manages all persistence of service workers: | 23 // This class represents a service worker regiratration. The |
falken
2014/07/17 06:33:42
nit: registration
| |
24 // - Registrations | 24 // scope and script url are constant for the life of the persistent |
25 // - Mapping of caches to registrations / versions | 25 // registration. It's refcounted to facillitate multiple controllees |
falken
2014/07/17 06:33:41
nit: facilitate
| |
26 // | 26 // being associated with the same registration. The class roughly |
27 // This is the place where we manage simultaneous | 27 // corresponds to navigator.serviceWorker.registgration. |
falken
2014/07/17 06:33:41
nit: registration
| |
28 // requests for the same registrations and caches, making sure that | |
29 // two pages that are registering the same pattern at the same time | |
30 // have their registrations coalesced rather than overwriting each | |
31 // other. | |
32 // | |
33 // This class also manages the state of the upgrade process, which | |
34 // includes managing which ServiceWorkerVersion is "active" vs "in | |
35 // waiting". | |
36 class CONTENT_EXPORT ServiceWorkerRegistration | 28 class CONTENT_EXPORT ServiceWorkerRegistration |
37 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) { | 29 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) { |
38 public: | 30 public: |
31 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | |
39 | 32 |
40 class Listener { | 33 class Listener { |
41 public: | 34 public: |
42 virtual void OnVersionAttributesChanged( | 35 virtual void OnVersionAttributesChanged( |
43 ServiceWorkerRegistration* registration, | 36 ServiceWorkerRegistration* registration, |
44 ChangedVersionAttributesMask changed_mask, | 37 ChangedVersionAttributesMask changed_mask, |
45 const ServiceWorkerRegistrationInfo& info) = 0; | 38 const ServiceWorkerRegistrationInfo& info) = 0; |
46 }; | 39 }; |
47 | 40 |
48 ServiceWorkerRegistration(const GURL& pattern, | 41 ServiceWorkerRegistration(const GURL& pattern, |
(...skipping 15 matching lines...) Expand all Loading... | |
64 | 57 |
65 ServiceWorkerVersion* installing_version() const { | 58 ServiceWorkerVersion* installing_version() const { |
66 return installing_version_.get(); | 59 return installing_version_.get(); |
67 } | 60 } |
68 | 61 |
69 void AddListener(Listener* listener); | 62 void AddListener(Listener* listener); |
70 void RemoveListener(Listener* listener); | 63 void RemoveListener(Listener* listener); |
71 | 64 |
72 ServiceWorkerRegistrationInfo GetInfo(); | 65 ServiceWorkerRegistrationInfo GetInfo(); |
73 | 66 |
74 // Sets the corresposding version attribute and resets the position (if any) | 67 // Sets the corresposding version attribute and resets the position |
falken
2014/07/17 06:33:41
nit: corresponding
| |
75 // left vacant (ie. by a waiting version being promoted). | 68 // (if any) left vacant (ie. by a waiting version being promoted). |
76 // Also notifies listeners via OnVersionAttributesChanged. | 69 // Also notifies listeners via OnVersionAttributesChanged. |
77 void SetActiveVersion(ServiceWorkerVersion* version); | 70 void SetActiveVersion(ServiceWorkerVersion* version); |
78 void SetWaitingVersion(ServiceWorkerVersion* version); | 71 void SetWaitingVersion(ServiceWorkerVersion* version); |
79 void SetInstallingVersion(ServiceWorkerVersion* version); | 72 void SetInstallingVersion(ServiceWorkerVersion* version); |
80 | 73 |
81 // If version is the installing, waiting, active version of this | 74 // If version is the installing, waiting, active version of this |
82 // registation, the method will reset that field to NULL, and notify | 75 // registation, the method will reset that field to NULL, and notify |
83 // listeners via OnVersionAttributesChanged. | 76 // listeners via OnVersionAttributesChanged. |
84 void UnsetVersion(ServiceWorkerVersion* version); | 77 void UnsetVersion(ServiceWorkerVersion* version); |
85 | 78 |
79 // This method corresponds to the [[Activate]] algorithm described in | |
80 // the service worker specification. It's only valid to call this method | |
81 // when the registration's active version has no controllees. | |
82 void ActivateWaitingVersion(const StatusCallback& completion_callback); | |
83 | |
86 private: | 84 private: |
87 ~ServiceWorkerRegistration(); | 85 ~ServiceWorkerRegistration(); |
88 friend class base::RefCounted<ServiceWorkerRegistration>; | 86 friend class base::RefCounted<ServiceWorkerRegistration>; |
89 | 87 |
90 void SetVersionInternal( | 88 void SetVersionInternal( |
91 ServiceWorkerVersion* version, | 89 ServiceWorkerVersion* version, |
92 scoped_refptr<ServiceWorkerVersion>* data_member, | 90 scoped_refptr<ServiceWorkerVersion>* data_member, |
93 int change_flag); | 91 int change_flag); |
94 void UnsetVersionInternal( | 92 void UnsetVersionInternal( |
95 ServiceWorkerVersion* version, | 93 ServiceWorkerVersion* version, |
96 ChangedVersionAttributesMask* mask); | 94 ChangedVersionAttributesMask* mask); |
95 void OnActivateEventFinished( | |
96 ServiceWorkerVersion* activating_version, | |
97 const StatusCallback& completion_callback, | |
98 ServiceWorkerStatusCode status); | |
97 | 99 |
98 const GURL pattern_; | 100 const GURL pattern_; |
99 const GURL script_url_; | 101 const GURL script_url_; |
100 const int64 registration_id_; | 102 const int64 registration_id_; |
101 scoped_refptr<ServiceWorkerVersion> active_version_; | 103 scoped_refptr<ServiceWorkerVersion> active_version_; |
102 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 104 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
103 scoped_refptr<ServiceWorkerVersion> installing_version_; | 105 scoped_refptr<ServiceWorkerVersion> installing_version_; |
104 ObserverList<Listener> listeners_; | 106 ObserverList<Listener> listeners_; |
105 base::WeakPtr<ServiceWorkerContextCore> context_; | 107 base::WeakPtr<ServiceWorkerContextCore> context_; |
106 | 108 |
107 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); | 109 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); |
108 }; | 110 }; |
109 } // namespace content | 111 } // namespace content |
110 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | 112 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
OLD | NEW |