| 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 and script url are 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. The class roughly | |
| 27 // corresponds to navigator.serviceWorker.registgration. | |
| 28 class CONTENT_EXPORT ServiceWorkerRegistration | 26 class CONTENT_EXPORT ServiceWorkerRegistration |
| 29 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), | 27 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), |
| 30 public ServiceWorkerVersion::Listener { | 28 public ServiceWorkerVersion::Listener { |
| 31 public: | 29 public: |
| 32 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | 30 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
| 33 | 31 |
| 34 class Listener { | 32 class Listener { |
| 35 public: | 33 public: |
| 36 virtual void OnVersionAttributesChanged( | 34 virtual void OnVersionAttributesChanged( |
| 37 ServiceWorkerRegistration* registration, | 35 ServiceWorkerRegistration* registration, |
| 38 ChangedVersionAttributesMask changed_mask, | 36 ChangedVersionAttributesMask changed_mask, |
| 39 const ServiceWorkerRegistrationInfo& info) = 0; | 37 const ServiceWorkerRegistrationInfo& info) {} |
| 40 virtual void OnRegistrationFailed( | 38 virtual void OnRegistrationFailed( |
| 41 ServiceWorkerRegistration* registration) = 0; | 39 ServiceWorkerRegistration* registration) {} |
| 40 virtual void OnRegistrationFinishedUninstalling( |
| 41 ServiceWorkerRegistration* registration) {} |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 ServiceWorkerRegistration(const GURL& pattern, | 44 ServiceWorkerRegistration(const GURL& pattern, |
| 45 const GURL& script_url, | 45 const GURL& script_url, |
| 46 int64 registration_id, | 46 int64 registration_id, |
| 47 base::WeakPtr<ServiceWorkerContextCore> context); | 47 base::WeakPtr<ServiceWorkerContextCore> context); |
| 48 | 48 |
| 49 const GURL& pattern() const { return pattern_; } |
| 50 |
| 51 // Corresponds to the spec's [[ScriptURL]]: the URL passed to the |
| 52 // serviceWorker.navigator.register() call that created or last updated this |
| 53 // registration. |
| 54 const GURL& script_url() const { return script_url_; } |
| 55 void set_script_url(const GURL& url) { script_url_ = url; } |
| 56 |
| 49 int64 id() const { return registration_id_; } | 57 int64 id() const { return registration_id_; } |
| 50 const GURL& script_url() const { return script_url_; } | |
| 51 const GURL& pattern() const { return pattern_; } | |
| 52 | 58 |
| 53 bool is_deleted() const { return is_deleted_; } | 59 bool is_deleted() const { return is_deleted_; } |
| 54 void set_is_deleted(bool deleted) { is_deleted_ = deleted; } | 60 void set_is_deleted(bool deleted) { is_deleted_ = deleted; } |
| 55 | 61 |
| 56 bool is_uninstalling() const { return is_uninstalling_; } | 62 bool is_uninstalling() const { return is_uninstalling_; } |
| 57 | 63 |
| 58 ServiceWorkerVersion* active_version() const { | 64 ServiceWorkerVersion* active_version() const { |
| 59 return active_version_.get(); | 65 return active_version_.get(); |
| 60 } | 66 } |
| 61 | 67 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 89 // has no controllees. If there are no controllees at the time the method | 95 // has no controllees. If there are no controllees at the time the method |
| 90 // is called, activation is initiated immediately. | 96 // is called, activation is initiated immediately. |
| 91 void ActivateWaitingVersionWhenReady(); | 97 void ActivateWaitingVersionWhenReady(); |
| 92 | 98 |
| 93 // Triggers the [[ClearRegistration]] algorithm when the currently | 99 // Triggers the [[ClearRegistration]] algorithm when the currently |
| 94 // active version has no controllees. Deletes this registration | 100 // active version has no controllees. Deletes this registration |
| 95 // from storage immediately. | 101 // from storage immediately. |
| 96 void ClearWhenReady(); | 102 void ClearWhenReady(); |
| 97 | 103 |
| 98 // Restores this registration in storage and cancels the pending | 104 // Restores this registration in storage and cancels the pending |
| 99 // [[ClearRegistration]] algorithm. If the algorithm was already triggered, | 105 // [[ClearRegistration]] algorithm. |
| 100 // does nothing. | 106 void AbortPendingClear(const StatusCallback& callback); |
| 101 void AbortPendingClear(); | |
| 102 | 107 |
| 103 // The time of the most recent update check. | 108 // The time of the most recent update check. |
| 104 base::Time last_update_check() const { return last_update_check_; } | 109 base::Time last_update_check() const { return last_update_check_; } |
| 105 void set_last_update_check(base::Time last) { last_update_check_ = last; } | 110 void set_last_update_check(base::Time last) { last_update_check_ = last; } |
| 106 | 111 |
| 107 private: | 112 private: |
| 108 friend class base::RefCounted<ServiceWorkerRegistration>; | 113 friend class base::RefCounted<ServiceWorkerRegistration>; |
| 109 | 114 |
| 110 virtual ~ServiceWorkerRegistration(); | 115 virtual ~ServiceWorkerRegistration(); |
| 111 | 116 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 122 | 127 |
| 123 // This method corresponds to the [[Activate]] algorithm. | 128 // This method corresponds to the [[Activate]] algorithm. |
| 124 void ActivateWaitingVersion(); | 129 void ActivateWaitingVersion(); |
| 125 void OnActivateEventFinished( | 130 void OnActivateEventFinished( |
| 126 ServiceWorkerVersion* activating_version, | 131 ServiceWorkerVersion* activating_version, |
| 127 ServiceWorkerStatusCode status); | 132 ServiceWorkerStatusCode status); |
| 128 void OnDeleteFinished(ServiceWorkerStatusCode status); | 133 void OnDeleteFinished(ServiceWorkerStatusCode status); |
| 129 | 134 |
| 130 // This method corresponds to the [[ClearRegistration]] algorithm. | 135 // This method corresponds to the [[ClearRegistration]] algorithm. |
| 131 void Clear(); | 136 void Clear(); |
| 132 void OnStoreFinished(scoped_refptr<ServiceWorkerVersion> version, | 137 |
| 133 ServiceWorkerStatusCode status); | 138 void OnRestoreFinished(const StatusCallback& callback, |
| 139 scoped_refptr<ServiceWorkerVersion> version, |
| 140 ServiceWorkerStatusCode status); |
| 134 | 141 |
| 135 const GURL pattern_; | 142 const GURL pattern_; |
| 136 const GURL script_url_; | 143 GURL script_url_; |
| 137 const int64 registration_id_; | 144 const int64 registration_id_; |
| 138 bool is_deleted_; | 145 bool is_deleted_; |
| 139 bool is_uninstalling_; | 146 bool is_uninstalling_; |
| 140 bool should_activate_when_ready_; | 147 bool should_activate_when_ready_; |
| 141 base::Time last_update_check_; | 148 base::Time last_update_check_; |
| 142 scoped_refptr<ServiceWorkerVersion> active_version_; | 149 scoped_refptr<ServiceWorkerVersion> active_version_; |
| 143 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 150 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
| 144 scoped_refptr<ServiceWorkerVersion> installing_version_; | 151 scoped_refptr<ServiceWorkerVersion> installing_version_; |
| 145 ObserverList<Listener> listeners_; | 152 ObserverList<Listener> listeners_; |
| 146 base::WeakPtr<ServiceWorkerContextCore> context_; | 153 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 147 | 154 |
| 148 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); | 155 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); |
| 149 }; | 156 }; |
| 150 | 157 |
| 151 } // namespace content | 158 } // namespace content |
| 152 | 159 |
| 153 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | 160 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
| OLD | NEW |