Chromium Code Reviews| 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 <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" | |
| 18 #include "base/timer/timer.h" | |
| 16 #include "content/browser/service_worker/service_worker_version.h" | 19 #include "content/browser/service_worker/service_worker_version.h" |
| 17 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 18 #include "content/common/service_worker/service_worker_types.h" | 21 #include "content/common/service_worker/service_worker_types.h" |
| 22 #include "content/public/browser/browser_thread.h" | |
| 19 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 20 | 24 |
| 21 namespace content { | 25 namespace content { |
| 22 | 26 |
| 23 class ServiceWorkerVersion; | 27 class ServiceWorkerVersion; |
| 24 struct ServiceWorkerRegistrationInfo; | 28 struct ServiceWorkerRegistrationInfo; |
| 25 | 29 |
| 26 // Represents the core of a service worker registration object. Other | 30 // Represents the core of a service worker registration object. Other |
| 27 // registration derivatives (WebServiceWorkerRegistration etc) ultimately refer | 31 // registration derivatives (WebServiceWorkerRegistration etc) ultimately refer |
| 28 // to this class. This is refcounted via ServiceWorkerRegistrationHandle to | 32 // to this class. This is refcounted via ServiceWorkerRegistrationHandle to |
| 29 // facilitate multiple controllees being associated with the same registration. | 33 // facilitate multiple controllees being associated with the same registration. |
| 30 class CONTENT_EXPORT ServiceWorkerRegistration | 34 class CONTENT_EXPORT ServiceWorkerRegistration |
| 31 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), | 35 : public NON_EXPORTED_BASE( |
| 32 public ServiceWorkerVersion::Listener { | 36 base::RefCountedThreadSafe<ServiceWorkerRegistration, |
| 37 BrowserThread::DeleteOnIOThread>), | |
| 38 public NON_EXPORTED_BASE(ServiceWorkerVersion::Listener) { | |
| 33 public: | 39 public: |
| 34 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | 40 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
| 35 | 41 |
| 36 class Listener { | 42 class Listener { |
| 37 public: | 43 public: |
| 38 virtual void OnVersionAttributesChanged( | 44 virtual void OnVersionAttributesChanged( |
| 39 ServiceWorkerRegistration* registration, | 45 ServiceWorkerRegistration* registration, |
| 40 ChangedVersionAttributesMask changed_mask, | 46 ChangedVersionAttributesMask changed_mask, |
| 41 const ServiceWorkerRegistrationInfo& info) {} | 47 const ServiceWorkerRegistrationInfo& info) {} |
| 42 virtual void OnRegistrationFailed( | 48 virtual void OnRegistrationFailed( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 64 bool is_uninstalled() const { return is_uninstalled_; } | 70 bool is_uninstalled() const { return is_uninstalled_; } |
| 65 | 71 |
| 66 int64_t resources_total_size_bytes() const { | 72 int64_t resources_total_size_bytes() const { |
| 67 return resources_total_size_bytes_; | 73 return resources_total_size_bytes_; |
| 68 } | 74 } |
| 69 | 75 |
| 70 void set_resources_total_size_bytes(int64_t resources_total_size_bytes) { | 76 void set_resources_total_size_bytes(int64_t resources_total_size_bytes) { |
| 71 resources_total_size_bytes_ = resources_total_size_bytes; | 77 resources_total_size_bytes_ = resources_total_size_bytes; |
| 72 } | 78 } |
| 73 | 79 |
| 80 // Returns the active version. This version may be in ACTIVATING or ACTIVATED | |
| 81 // state. If you require an ACTIVATED version, use | |
| 82 // ServiceWorkerContextWrapper::FindReadyRegistration* to get a registration | |
| 83 // with such a version. Alternatively, use | |
| 84 // ServiceWorkerVersion::Listener::OnVersionStateChanged to wait for the | |
| 85 // ACTIVATING version to become ACTIVATED. | |
| 74 ServiceWorkerVersion* active_version() const { | 86 ServiceWorkerVersion* active_version() const { |
| 75 return active_version_.get(); | 87 return active_version_.get(); |
| 76 } | 88 } |
| 77 | 89 |
| 78 ServiceWorkerVersion* waiting_version() const { | 90 ServiceWorkerVersion* waiting_version() const { |
| 79 return waiting_version_.get(); | 91 return waiting_version_.get(); |
| 80 } | 92 } |
| 81 | 93 |
| 82 ServiceWorkerVersion* installing_version() const { | 94 ServiceWorkerVersion* installing_version() const { |
| 83 return installing_version_.get(); | 95 return installing_version_.get(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 base::Time last_update_check() const { return last_update_check_; } | 144 base::Time last_update_check() const { return last_update_check_; } |
| 133 void set_last_update_check(base::Time last) { last_update_check_ = last; } | 145 void set_last_update_check(base::Time last) { last_update_check_ = last; } |
| 134 | 146 |
| 135 // Unsets the version and deletes its resources. Also deletes this | 147 // Unsets the version and deletes its resources. Also deletes this |
| 136 // registration from storage if there is no longer a stored version. | 148 // registration from storage if there is no longer a stored version. |
| 137 void DeleteVersion(const scoped_refptr<ServiceWorkerVersion>& version); | 149 void DeleteVersion(const scoped_refptr<ServiceWorkerVersion>& version); |
| 138 | 150 |
| 139 void RegisterRegistrationFinishedCallback(const base::Closure& callback); | 151 void RegisterRegistrationFinishedCallback(const base::Closure& callback); |
| 140 void NotifyRegistrationFinished(); | 152 void NotifyRegistrationFinished(); |
| 141 | 153 |
| 154 void SetTimerTaskRunnerForTest( | |
| 155 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 156 | |
| 142 private: | 157 private: |
| 143 friend class base::RefCounted<ServiceWorkerRegistration>; | 158 friend class base::RefCountedThreadSafe< |
| 159 ServiceWorkerRegistration, | |
| 160 content::BrowserThread::DeleteOnIOThread>; | |
| 161 friend class base::DeleteHelper<ServiceWorkerRegistration>; | |
| 162 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; | |
| 144 | 163 |
| 145 ~ServiceWorkerRegistration() override; | 164 ~ServiceWorkerRegistration() override; |
| 146 | 165 |
| 147 void UnsetVersionInternal( | 166 void UnsetVersionInternal( |
| 148 ServiceWorkerVersion* version, | 167 ServiceWorkerVersion* version, |
| 149 ChangedVersionAttributesMask* mask); | 168 ChangedVersionAttributesMask* mask); |
| 150 | 169 |
| 151 // ServiceWorkerVersion::Listener override. | 170 // ServiceWorkerVersion::Listener override. |
| 152 void OnNoControllees(ServiceWorkerVersion* version) override; | 171 void OnNoControllees(ServiceWorkerVersion* version) override; |
| 153 | 172 |
| 154 // This method corresponds to the [[Activate]] algorithm. | 173 // Promotes the waiting version to active version. If |delay| is true, waits |
| 155 void ActivateWaitingVersion(); | 174 // a short time before attempting to start and dispatch the activate event |
| 175 // to the version. | |
| 176 void ActivateWaitingVersion(bool delay); | |
| 177 void ContinueActivation( | |
| 178 const scoped_refptr<ServiceWorkerVersion>& activating_version); | |
|
nhiroki
2016/06/01 05:51:48
[Optional] As you might already know, passing "con
falken
2016/06/01 09:20:05
I changed to use scoped_refptr and std::move when
nhiroki
2016/06/03 00:54:29
I use std::move if an object is not used anymore a
| |
| 156 void DispatchActivateEvent( | 179 void DispatchActivateEvent( |
| 157 const scoped_refptr<ServiceWorkerVersion>& activating_version); | 180 const scoped_refptr<ServiceWorkerVersion>& activating_version); |
| 158 void OnActivateEventFinished( | 181 void OnActivateEventFinished( |
| 159 const scoped_refptr<ServiceWorkerVersion>& activating_version, | 182 const scoped_refptr<ServiceWorkerVersion>& activating_version, |
| 160 ServiceWorkerStatusCode status); | 183 ServiceWorkerStatusCode status); |
| 184 // Actually sets |activating_version| to ACTIVATED and writes to | |
| 185 // storage that it's active. | |
| 186 void CompleteActivation( | |
| 187 const scoped_refptr<ServiceWorkerVersion>& activating_version, | |
| 188 ServiceWorkerStatusCode status, | |
| 189 bool is_shutdown); | |
| 190 | |
| 161 void OnDeleteFinished(ServiceWorkerStatusCode status); | 191 void OnDeleteFinished(ServiceWorkerStatusCode status); |
| 162 | 192 |
| 163 // This method corresponds to the [[ClearRegistration]] algorithm. | 193 // This method corresponds to the [[ClearRegistration]] algorithm. |
| 164 void Clear(); | 194 void Clear(); |
| 165 | 195 |
| 166 void OnRestoreFinished(const StatusCallback& callback, | 196 void OnRestoreFinished(const StatusCallback& callback, |
| 167 scoped_refptr<ServiceWorkerVersion> version, | 197 scoped_refptr<ServiceWorkerVersion> version, |
| 168 ServiceWorkerStatusCode status); | 198 ServiceWorkerStatusCode status); |
| 169 | 199 |
| 170 const GURL pattern_; | 200 const GURL pattern_; |
| 171 const int64_t registration_id_; | 201 const int64_t registration_id_; |
| 172 bool is_deleted_; | 202 bool is_deleted_; |
| 173 bool is_uninstalling_; | 203 bool is_uninstalling_; |
| 174 bool is_uninstalled_; | 204 bool is_uninstalled_; |
| 175 bool should_activate_when_ready_; | 205 bool should_activate_when_ready_; |
| 176 base::Time last_update_check_; | 206 base::Time last_update_check_; |
| 177 int64_t resources_total_size_bytes_; | 207 int64_t resources_total_size_bytes_; |
| 208 base::OneShotTimer timer_; | |
| 178 | 209 |
| 179 // This registration is the primary owner of these versions. | 210 // This registration is the primary owner of these versions. |
| 180 scoped_refptr<ServiceWorkerVersion> active_version_; | 211 scoped_refptr<ServiceWorkerVersion> active_version_; |
| 181 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 212 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
| 182 scoped_refptr<ServiceWorkerVersion> installing_version_; | 213 scoped_refptr<ServiceWorkerVersion> installing_version_; |
| 183 | 214 |
| 184 base::ObserverList<Listener> listeners_; | 215 base::ObserverList<Listener> listeners_; |
| 185 std::vector<base::Closure> registration_finished_callbacks_; | 216 std::vector<base::Closure> registration_finished_callbacks_; |
| 186 base::WeakPtr<ServiceWorkerContextCore> context_; | 217 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 187 | 218 |
| 188 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); | 219 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); |
| 189 }; | 220 }; |
| 190 | 221 |
| 191 } // namespace content | 222 } // namespace content |
| 192 | 223 |
| 193 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | 224 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
| OLD | NEW |