| 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 |
| 24 // scope and script url are constant for the life of the persistent | 24 // scope is constant for the life of the persistent |
| 25 // registration. It's refcounted to facillitate multiple controllees | 25 // registration. It's refcounted to facillitate multiple controllees |
| 26 // being associated with the same registration. The class roughly | 26 // being associated with the same registration. |
| 27 // corresponds to navigator.serviceWorker.registgration. | |
| 28 class CONTENT_EXPORT ServiceWorkerRegistration | 27 class CONTENT_EXPORT ServiceWorkerRegistration |
| 29 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), | 28 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>), |
| 30 public ServiceWorkerVersion::Listener { | 29 public ServiceWorkerVersion::Listener { |
| 31 public: | 30 public: |
| 32 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; | 31 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; |
| 33 | 32 |
| 34 class Listener { | 33 class Listener { |
| 35 public: | 34 public: |
| 36 virtual void OnVersionAttributesChanged( | 35 virtual void OnVersionAttributesChanged( |
| 37 ServiceWorkerRegistration* registration, | 36 ServiceWorkerRegistration* registration, |
| 38 ChangedVersionAttributesMask changed_mask, | 37 ChangedVersionAttributesMask changed_mask, |
| 39 const ServiceWorkerRegistrationInfo& info) = 0; | 38 const ServiceWorkerRegistrationInfo& info) = 0; |
| 40 virtual void OnRegistrationFailed( | 39 virtual void OnRegistrationFailed( |
| 41 ServiceWorkerRegistration* registration) = 0; | 40 ServiceWorkerRegistration* registration) = 0; |
| 42 }; | 41 }; |
| 43 | 42 |
| 44 ServiceWorkerRegistration(const GURL& pattern, | 43 ServiceWorkerRegistration(const GURL& pattern, |
| 45 const GURL& script_url, | |
| 46 int64 registration_id, | 44 int64 registration_id, |
| 47 base::WeakPtr<ServiceWorkerContextCore> context); | 45 base::WeakPtr<ServiceWorkerContextCore> context); |
| 48 | 46 |
| 49 int64 id() const { return registration_id_; } | 47 int64 id() const { return registration_id_; } |
| 50 const GURL& script_url() const { return script_url_; } | |
| 51 const GURL& pattern() const { return pattern_; } | 48 const GURL& pattern() const { return pattern_; } |
| 52 | 49 |
| 53 bool is_deleted() const { return is_deleted_; } | 50 bool is_deleted() const { return is_deleted_; } |
| 54 void set_is_deleted(bool deleted) { is_deleted_ = deleted; } | 51 void set_is_deleted(bool deleted) { is_deleted_ = deleted; } |
| 55 | 52 |
| 56 bool is_uninstalling() const { return is_uninstalling_; } | 53 bool is_uninstalling() const { return is_uninstalling_; } |
| 57 | 54 |
| 58 ServiceWorkerVersion* active_version() const { | 55 ServiceWorkerVersion* active_version() const { |
| 59 return active_version_.get(); | 56 return active_version_.get(); |
| 60 } | 57 } |
| 61 | 58 |
| 62 ServiceWorkerVersion* waiting_version() const { | 59 ServiceWorkerVersion* waiting_version() const { |
| 63 return waiting_version_.get(); | 60 return waiting_version_.get(); |
| 64 } | 61 } |
| 65 | 62 |
| 66 ServiceWorkerVersion* installing_version() const { | 63 ServiceWorkerVersion* installing_version() const { |
| 67 return installing_version_.get(); | 64 return installing_version_.get(); |
| 68 } | 65 } |
| 69 | 66 |
| 67 ServiceWorkerVersion* GetNewestVersion() const; |
| 68 |
| 70 void AddListener(Listener* listener); | 69 void AddListener(Listener* listener); |
| 71 void RemoveListener(Listener* listener); | 70 void RemoveListener(Listener* listener); |
| 72 void NotifyRegistrationFailed(); | 71 void NotifyRegistrationFailed(); |
| 73 | 72 |
| 74 ServiceWorkerRegistrationInfo GetInfo(); | 73 ServiceWorkerRegistrationInfo GetInfo(); |
| 75 | 74 |
| 76 // Sets the corresposding version attribute and resets the position | 75 // Sets the corresposding version attribute and resets the position |
| 77 // (if any) left vacant (ie. by a waiting version being promoted). | 76 // (if any) left vacant (ie. by a waiting version being promoted). |
| 78 // Also notifies listeners via OnVersionAttributesChanged. | 77 // Also notifies listeners via OnVersionAttributesChanged. |
| 79 void SetActiveVersion(ServiceWorkerVersion* version); | 78 void SetActiveVersion(ServiceWorkerVersion* version); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ServiceWorkerVersion* activating_version, | 125 ServiceWorkerVersion* activating_version, |
| 127 ServiceWorkerStatusCode status); | 126 ServiceWorkerStatusCode status); |
| 128 void OnDeleteFinished(ServiceWorkerStatusCode status); | 127 void OnDeleteFinished(ServiceWorkerStatusCode status); |
| 129 | 128 |
| 130 // This method corresponds to the [[ClearRegistration]] algorithm. | 129 // This method corresponds to the [[ClearRegistration]] algorithm. |
| 131 void Clear(); | 130 void Clear(); |
| 132 void OnStoreFinished(scoped_refptr<ServiceWorkerVersion> version, | 131 void OnStoreFinished(scoped_refptr<ServiceWorkerVersion> version, |
| 133 ServiceWorkerStatusCode status); | 132 ServiceWorkerStatusCode status); |
| 134 | 133 |
| 135 const GURL pattern_; | 134 const GURL pattern_; |
| 136 const GURL script_url_; | |
| 137 const int64 registration_id_; | 135 const int64 registration_id_; |
| 138 bool is_deleted_; | 136 bool is_deleted_; |
| 139 bool is_uninstalling_; | 137 bool is_uninstalling_; |
| 140 bool should_activate_when_ready_; | 138 bool should_activate_when_ready_; |
| 141 base::Time last_update_check_; | 139 base::Time last_update_check_; |
| 142 scoped_refptr<ServiceWorkerVersion> active_version_; | 140 scoped_refptr<ServiceWorkerVersion> active_version_; |
| 143 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 141 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
| 144 scoped_refptr<ServiceWorkerVersion> installing_version_; | 142 scoped_refptr<ServiceWorkerVersion> installing_version_; |
| 145 ObserverList<Listener> listeners_; | 143 ObserverList<Listener> listeners_; |
| 146 base::WeakPtr<ServiceWorkerContextCore> context_; | 144 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 147 | 145 |
| 148 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); | 146 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); |
| 149 }; | 147 }; |
| 150 | 148 |
| 151 } // namespace content | 149 } // namespace content |
| 152 | 150 |
| 153 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | 151 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
| OLD | NEW |