Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Side by Side Diff: content/browser/service_worker/service_worker_registration.h

Issue 2027583002: service worker: Avoid starting up for activation during shutdown (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add unittest Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector>
12 13
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/single_thread_task_runner.h"
16 #include "content/browser/service_worker/service_worker_version.h" 18 #include "content/browser/service_worker/service_worker_version.h"
17 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
18 #include "content/common/service_worker/service_worker_types.h" 20 #include "content/common/service_worker/service_worker_types.h"
19 #include "url/gurl.h" 21 #include "url/gurl.h"
20 22
21 namespace content { 23 namespace content {
22 24
23 class ServiceWorkerVersion; 25 class ServiceWorkerVersion;
24 struct ServiceWorkerRegistrationInfo; 26 struct ServiceWorkerRegistrationInfo;
25 27
26 // Represents the core of a service worker registration object. Other 28 // Represents the core of a service worker registration object. Other
27 // registration derivatives (WebServiceWorkerRegistration etc) ultimately refer 29 // registration derivatives (WebServiceWorkerRegistration etc) ultimately refer
28 // to this class. This is refcounted via ServiceWorkerRegistrationHandle to 30 // to this class. This is refcounted via ServiceWorkerRegistrationHandle to
29 // facilitate multiple controllees being associated with the same registration. 31 // facilitate multiple controllees being associated with the same registration.
30 class CONTENT_EXPORT ServiceWorkerRegistration 32 class CONTENT_EXPORT ServiceWorkerRegistration
31 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), 33 : public NON_EXPORTED_BASE(base::RefCounted<ServiceWorkerRegistration>),
32 public ServiceWorkerVersion::Listener { 34 public NON_EXPORTED_BASE(ServiceWorkerVersion::Listener) {
33 public: 35 public:
34 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; 36 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback;
35 37
36 class Listener { 38 class Listener {
37 public: 39 public:
38 virtual void OnVersionAttributesChanged( 40 virtual void OnVersionAttributesChanged(
39 ServiceWorkerRegistration* registration, 41 ServiceWorkerRegistration* registration,
40 ChangedVersionAttributesMask changed_mask, 42 ChangedVersionAttributesMask changed_mask,
41 const ServiceWorkerRegistrationInfo& info) {} 43 const ServiceWorkerRegistrationInfo& info) {}
42 virtual void OnRegistrationFailed( 44 virtual void OnRegistrationFailed(
(...skipping 21 matching lines...) Expand all
64 bool is_uninstalled() const { return is_uninstalled_; } 66 bool is_uninstalled() const { return is_uninstalled_; }
65 67
66 int64_t resources_total_size_bytes() const { 68 int64_t resources_total_size_bytes() const {
67 return resources_total_size_bytes_; 69 return resources_total_size_bytes_;
68 } 70 }
69 71
70 void set_resources_total_size_bytes(int64_t resources_total_size_bytes) { 72 void set_resources_total_size_bytes(int64_t resources_total_size_bytes) {
71 resources_total_size_bytes_ = resources_total_size_bytes; 73 resources_total_size_bytes_ = resources_total_size_bytes;
72 } 74 }
73 75
76 // Returns the active version. This version may be in ACTIVATING or ACTIVATED
77 // state. If you require an ACTIVATED version, use
78 // ServiceWorkerContextWrapper::FindReadyRegistration* to get a registration
79 // with such a version. Alternatively, use
80 // ServiceWorkerVersion::Listener::OnVersionStateChanged to wait for the
81 // ACTIVATING version to become ACTIVATED.
74 ServiceWorkerVersion* active_version() const { 82 ServiceWorkerVersion* active_version() const {
75 return active_version_.get(); 83 return active_version_.get();
76 } 84 }
77 85
78 ServiceWorkerVersion* waiting_version() const { 86 ServiceWorkerVersion* waiting_version() const {
79 return waiting_version_.get(); 87 return waiting_version_.get();
80 } 88 }
81 89
82 ServiceWorkerVersion* installing_version() const { 90 ServiceWorkerVersion* installing_version() const {
83 return installing_version_.get(); 91 return installing_version_.get();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 base::Time last_update_check() const { return last_update_check_; } 140 base::Time last_update_check() const { return last_update_check_; }
133 void set_last_update_check(base::Time last) { last_update_check_ = last; } 141 void set_last_update_check(base::Time last) { last_update_check_ = last; }
134 142
135 // Unsets the version and deletes its resources. Also deletes this 143 // Unsets the version and deletes its resources. Also deletes this
136 // registration from storage if there is no longer a stored version. 144 // registration from storage if there is no longer a stored version.
137 void DeleteVersion(const scoped_refptr<ServiceWorkerVersion>& version); 145 void DeleteVersion(const scoped_refptr<ServiceWorkerVersion>& version);
138 146
139 void RegisterRegistrationFinishedCallback(const base::Closure& callback); 147 void RegisterRegistrationFinishedCallback(const base::Closure& callback);
140 void NotifyRegistrationFinished(); 148 void NotifyRegistrationFinished();
141 149
150 void SetTaskRunnerForTest(
151 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
152
142 private: 153 private:
143 friend class base::RefCounted<ServiceWorkerRegistration>; 154 friend class base::RefCounted<ServiceWorkerRegistration>;
144 155
145 ~ServiceWorkerRegistration() override; 156 ~ServiceWorkerRegistration() override;
146 157
147 void UnsetVersionInternal( 158 void UnsetVersionInternal(
148 ServiceWorkerVersion* version, 159 ServiceWorkerVersion* version,
149 ChangedVersionAttributesMask* mask); 160 ChangedVersionAttributesMask* mask);
150 161
151 // ServiceWorkerVersion::Listener override. 162 // ServiceWorkerVersion::Listener override.
152 void OnNoControllees(ServiceWorkerVersion* version) override; 163 void OnNoControllees(ServiceWorkerVersion* version) override;
153 164
154 // This method corresponds to the [[Activate]] algorithm. 165 // Promotes the waiting version to active version. If |delay| is true, waits
155 void ActivateWaitingVersion(); 166 // a short time before attempting to start and dispatch the activate event
167 // to the version.
168 void ActivateWaitingVersion(bool delay);
169 void ContinueActivation(
170 scoped_refptr<ServiceWorkerVersion> activating_version);
156 void DispatchActivateEvent( 171 void DispatchActivateEvent(
157 const scoped_refptr<ServiceWorkerVersion>& activating_version); 172 scoped_refptr<ServiceWorkerVersion> activating_version);
158 void OnActivateEventFinished( 173 void OnActivateEventFinished(
159 const scoped_refptr<ServiceWorkerVersion>& activating_version, 174 scoped_refptr<ServiceWorkerVersion> activating_version,
160 ServiceWorkerStatusCode status); 175 ServiceWorkerStatusCode status);
176
161 void OnDeleteFinished(ServiceWorkerStatusCode status); 177 void OnDeleteFinished(ServiceWorkerStatusCode status);
162 178
163 // This method corresponds to the [[ClearRegistration]] algorithm. 179 // This method corresponds to the [[ClearRegistration]] algorithm.
164 void Clear(); 180 void Clear();
165 181
166 void OnRestoreFinished(const StatusCallback& callback, 182 void OnRestoreFinished(const StatusCallback& callback,
167 scoped_refptr<ServiceWorkerVersion> version, 183 scoped_refptr<ServiceWorkerVersion> version,
168 ServiceWorkerStatusCode status); 184 ServiceWorkerStatusCode status);
169 185
170 const GURL pattern_; 186 const GURL pattern_;
171 const int64_t registration_id_; 187 const int64_t registration_id_;
172 bool is_deleted_; 188 bool is_deleted_;
173 bool is_uninstalling_; 189 bool is_uninstalling_;
174 bool is_uninstalled_; 190 bool is_uninstalled_;
175 bool should_activate_when_ready_; 191 bool should_activate_when_ready_;
176 base::Time last_update_check_; 192 base::Time last_update_check_;
177 int64_t resources_total_size_bytes_; 193 int64_t resources_total_size_bytes_;
178 194
179 // This registration is the primary owner of these versions. 195 // This registration is the primary owner of these versions.
180 scoped_refptr<ServiceWorkerVersion> active_version_; 196 scoped_refptr<ServiceWorkerVersion> active_version_;
181 scoped_refptr<ServiceWorkerVersion> waiting_version_; 197 scoped_refptr<ServiceWorkerVersion> waiting_version_;
182 scoped_refptr<ServiceWorkerVersion> installing_version_; 198 scoped_refptr<ServiceWorkerVersion> installing_version_;
183 199
184 base::ObserverList<Listener> listeners_; 200 base::ObserverList<Listener> listeners_;
185 std::vector<base::Closure> registration_finished_callbacks_; 201 std::vector<base::Closure> registration_finished_callbacks_;
186 base::WeakPtr<ServiceWorkerContextCore> context_; 202 base::WeakPtr<ServiceWorkerContextCore> context_;
203 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
187 204
188 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); 205 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration);
189 }; 206 };
190 207
191 } // namespace content 208 } // namespace content
192 209
193 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ 210 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698