| 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 represents a service worker registration. The | 23 // This class represents a Service Worker registration. The scope is constant |
| 24 // scope is constant for the life of the persistent | 24 // for the life of the persistent registration. It's refcounted to facilitate |
| 25 // registration. It's refcounted to facillitate multiple controllees | 25 // multiple controllees being associated with the same registration. |
| 26 // being associated with the same registration. | |
| 27 class CONTENT_EXPORT ServiceWorkerRegistration | 26 class CONTENT_EXPORT ServiceWorkerRegistration |
| 28 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), | 27 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), |
| 29 public ServiceWorkerVersion::Listener { | 28 public ServiceWorkerVersion::Listener { |
| 30 public: | 29 public: |
| 31 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | 30 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
| 32 | 31 |
| 33 class Listener { | 32 class Listener { |
| 34 public: | 33 public: |
| 35 virtual void OnVersionAttributesChanged( | 34 virtual void OnVersionAttributesChanged( |
| 36 ServiceWorkerRegistration* registration, | 35 ServiceWorkerRegistration* registration, |
| 37 ChangedVersionAttributesMask changed_mask, | 36 ChangedVersionAttributesMask changed_mask, |
| 38 const ServiceWorkerRegistrationInfo& info) = 0; | 37 const ServiceWorkerRegistrationInfo& info) {} |
| 39 virtual void OnRegistrationFailed( | 38 virtual void OnRegistrationFailed( |
| 40 ServiceWorkerRegistration* registration) = 0; | 39 ServiceWorkerRegistration* registration) {} |
| 40 virtual void OnRegistrationFinishedUninstalling( |
| 41 ServiceWorkerRegistration* registration) {} |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 ServiceWorkerRegistration(const GURL& pattern, | 44 ServiceWorkerRegistration(const GURL& pattern, |
| 44 int64 registration_id, | 45 int64 registration_id, |
| 45 base::WeakPtr<ServiceWorkerContextCore> context); | 46 base::WeakPtr<ServiceWorkerContextCore> context); |
| 46 | 47 |
| 47 int64 id() const { return registration_id_; } | 48 int64 id() const { return registration_id_; } |
| 48 const GURL& pattern() const { return pattern_; } | 49 const GURL& pattern() const { return pattern_; } |
| 49 | 50 |
| 50 bool is_deleted() const { return is_deleted_; } | 51 bool is_deleted() const { return is_deleted_; } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // has no controllees. If there are no controllees at the time the method | 89 // has no controllees. If there are no controllees at the time the method |
| 89 // is called, activation is initiated immediately. | 90 // is called, activation is initiated immediately. |
| 90 void ActivateWaitingVersionWhenReady(); | 91 void ActivateWaitingVersionWhenReady(); |
| 91 | 92 |
| 92 // Triggers the [[ClearRegistration]] algorithm when the currently | 93 // Triggers the [[ClearRegistration]] algorithm when the currently |
| 93 // active version has no controllees. Deletes this registration | 94 // active version has no controllees. Deletes this registration |
| 94 // from storage immediately. | 95 // from storage immediately. |
| 95 void ClearWhenReady(); | 96 void ClearWhenReady(); |
| 96 | 97 |
| 97 // Restores this registration in storage and cancels the pending | 98 // Restores this registration in storage and cancels the pending |
| 98 // [[ClearRegistration]] algorithm. If the algorithm was already triggered, | 99 // [[ClearRegistration]] algorithm. |
| 99 // does nothing. | 100 void AbortPendingClear(const StatusCallback& callback); |
| 100 void AbortPendingClear(); | |
| 101 | 101 |
| 102 // The time of the most recent update check. | 102 // The time of the most recent update check. |
| 103 base::Time last_update_check() const { return last_update_check_; } | 103 base::Time last_update_check() const { return last_update_check_; } |
| 104 void set_last_update_check(base::Time last) { last_update_check_ = last; } | 104 void set_last_update_check(base::Time last) { last_update_check_ = last; } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 friend class base::RefCounted<ServiceWorkerRegistration>; | 107 friend class base::RefCounted<ServiceWorkerRegistration>; |
| 108 | 108 |
| 109 virtual ~ServiceWorkerRegistration(); | 109 virtual ~ServiceWorkerRegistration(); |
| 110 | 110 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 121 | 121 |
| 122 // This method corresponds to the [[Activate]] algorithm. | 122 // This method corresponds to the [[Activate]] algorithm. |
| 123 void ActivateWaitingVersion(); | 123 void ActivateWaitingVersion(); |
| 124 void OnActivateEventFinished( | 124 void OnActivateEventFinished( |
| 125 ServiceWorkerVersion* activating_version, | 125 ServiceWorkerVersion* activating_version, |
| 126 ServiceWorkerStatusCode status); | 126 ServiceWorkerStatusCode status); |
| 127 void OnDeleteFinished(ServiceWorkerStatusCode status); | 127 void OnDeleteFinished(ServiceWorkerStatusCode status); |
| 128 | 128 |
| 129 // This method corresponds to the [[ClearRegistration]] algorithm. | 129 // This method corresponds to the [[ClearRegistration]] algorithm. |
| 130 void Clear(); | 130 void Clear(); |
| 131 void OnStoreFinished(scoped_refptr<ServiceWorkerVersion> version, | 131 |
| 132 ServiceWorkerStatusCode status); | 132 void OnRestoreFinished(const StatusCallback& callback, |
| 133 scoped_refptr<ServiceWorkerVersion> version, |
| 134 ServiceWorkerStatusCode status); |
| 133 | 135 |
| 134 const GURL pattern_; | 136 const GURL pattern_; |
| 135 const int64 registration_id_; | 137 const int64 registration_id_; |
| 136 bool is_deleted_; | 138 bool is_deleted_; |
| 137 bool is_uninstalling_; | 139 bool is_uninstalling_; |
| 138 bool should_activate_when_ready_; | 140 bool should_activate_when_ready_; |
| 139 base::Time last_update_check_; | 141 base::Time last_update_check_; |
| 140 scoped_refptr<ServiceWorkerVersion> active_version_; | 142 scoped_refptr<ServiceWorkerVersion> active_version_; |
| 141 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 143 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
| 142 scoped_refptr<ServiceWorkerVersion> installing_version_; | 144 scoped_refptr<ServiceWorkerVersion> installing_version_; |
| 143 ObserverList<Listener> listeners_; | 145 ObserverList<Listener> listeners_; |
| 144 base::WeakPtr<ServiceWorkerContextCore> context_; | 146 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 145 | 147 |
| 146 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); | 148 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); |
| 147 }; | 149 }; |
| 148 | 150 |
| 149 } // namespace content | 151 } // namespace content |
| 150 | 152 |
| 151 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | 153 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
| OLD | NEW |