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 "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 "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 class ServiceWorkerRegistrationInfo; | 20 class ServiceWorkerRegistrationInfo; |
| 20 class ServiceWorkerVersion; | 21 class ServiceWorkerVersion; |
| 21 | 22 |
| 22 // This class manages all persistence of service workers: | 23 // This class manages all persistence of service workers: |
| 23 // - Registrations | 24 // - Registrations |
| 24 // - Mapping of caches to registrations / versions | 25 // - Mapping of caches to registrations / versions |
| 25 // | 26 // |
| 26 // This is the place where we manage simultaneous | 27 // This is the place where we manage simultaneous |
| 27 // requests for the same registrations and caches, making sure that | 28 // requests for the same registrations and caches, making sure that |
| 28 // two pages that are registering the same pattern at the same time | 29 // two pages that are registering the same pattern at the same time |
| 29 // have their registrations coalesced rather than overwriting each | 30 // have their registrations coalesced rather than overwriting each |
| 30 // other. | 31 // other. |
| 31 // | 32 // |
| 32 // This class also manages the state of the upgrade process, which | 33 // This class also manages the state of the upgrade process, which |
| 33 // includes managing which ServiceWorkerVersion is "active" vs "in | 34 // includes managing which ServiceWorkerVersion is "active" vs "in |
| 34 // waiting". | 35 // waiting". |
| 35 class CONTENT_EXPORT ServiceWorkerRegistration | 36 class CONTENT_EXPORT ServiceWorkerRegistration |
| 36 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) { | 37 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) { |
| 37 public: | 38 public: |
| 39 | |
| 40 class Listener { | |
| 41 public: | |
| 42 virtual void OnVersionAttributesChanged( | |
| 43 ServiceWorkerRegistration* registration, | |
| 44 ChangedVersionAttributesMask changed_mask, | |
| 45 const ServiceWorkerRegistrationInfo& info) = 0; | |
| 46 }; | |
| 47 | |
| 38 ServiceWorkerRegistration(const GURL& pattern, | 48 ServiceWorkerRegistration(const GURL& pattern, |
| 39 const GURL& script_url, | 49 const GURL& script_url, |
| 40 int64 registration_id, | 50 int64 registration_id, |
| 41 base::WeakPtr<ServiceWorkerContextCore> context); | 51 base::WeakPtr<ServiceWorkerContextCore> context); |
| 42 | 52 |
| 43 int64 id() const { return registration_id_; } | 53 int64 id() const { return registration_id_; } |
| 44 const GURL& script_url() const { return script_url_; } | 54 const GURL& script_url() const { return script_url_; } |
| 45 const GURL& pattern() const { return pattern_; } | 55 const GURL& pattern() const { return pattern_; } |
| 46 | 56 |
| 47 ServiceWorkerVersion* active_version() const { | 57 ServiceWorkerVersion* active_version() const { |
| 48 DCHECK(!is_shutdown_); | |
| 49 return active_version_.get(); | 58 return active_version_.get(); |
| 50 } | 59 } |
| 51 | 60 |
| 52 ServiceWorkerVersion* waiting_version() const { | 61 ServiceWorkerVersion* waiting_version() const { |
| 53 DCHECK(!is_shutdown_); | |
| 54 return waiting_version_.get(); | 62 return waiting_version_.get(); |
| 55 } | 63 } |
| 56 | 64 |
| 57 void set_active_version(ServiceWorkerVersion* version) { | 65 ServiceWorkerVersion* installing_version() const { |
| 58 DCHECK(!is_shutdown_); | 66 return installing_version_.get(); |
| 59 active_version_ = version; | |
| 60 } | 67 } |
| 61 | 68 |
| 62 void set_waiting_version(ServiceWorkerVersion* version) { | 69 void AddListener(Listener* listener); |
| 63 DCHECK(!is_shutdown_); | 70 void RemoveListener(Listener* listener); |
| 64 waiting_version_ = version; | |
| 65 } | |
| 66 | 71 |
| 67 ServiceWorkerRegistrationInfo GetInfo(); | 72 ServiceWorkerRegistrationInfo GetInfo(); |
| 68 | 73 |
| 69 // Returns the active version, if it is not null; otherwise, returns the | 74 // Sets the corresposding version attribute and resets the position (if any) |
|
falken
2014/07/02 05:42:12
"corresponding"
| |
| 70 // waiting version. | 75 // left vacant (ie. by a waiting version being promoted). |
| 71 ServiceWorkerVersion* GetNewestVersion(); | 76 // Also notifies listeners via OnVersionAttributesChanged. |
| 77 void SetActiveVersion(ServiceWorkerVersion* version); | |
| 78 void SetWaitingVersion(ServiceWorkerVersion* version); | |
| 79 void SetInstallingVersion(ServiceWorkerVersion* version); | |
| 72 | 80 |
| 73 // The final synchronous switchover after all events have been | 81 // If version is the installing, waiting, active version of this |
| 74 // fired, and the old "active version" is being shut down. | 82 // registation, the method will reset that field to NULL, and notify |
|
falken
2014/07/02 05:42:12
"waiting, or active"
"registration"
| |
| 75 void ActivateWaitingVersion(); | 83 // listeners via OnVersionAttributesChanged. |
| 84 void UnsetVersion(ServiceWorkerVersion* version); | |
| 85 | |
| 76 | 86 |
| 77 private: | 87 private: |
| 78 ~ServiceWorkerRegistration(); | 88 ~ServiceWorkerRegistration(); |
| 79 friend class base::RefCounted<ServiceWorkerRegistration>; | 89 friend class base::RefCounted<ServiceWorkerRegistration>; |
| 80 | 90 |
| 91 void SetVersionInternal( | |
| 92 ServiceWorkerVersion* version, | |
| 93 scoped_refptr<ServiceWorkerVersion>* data_member, | |
| 94 int change_flag); | |
| 95 void UnsetVersionInternal( | |
| 96 ServiceWorkerVersion* version, | |
| 97 ChangedVersionAttributesMask* mask); | |
| 98 | |
| 81 const GURL pattern_; | 99 const GURL pattern_; |
| 82 const GURL script_url_; | 100 const GURL script_url_; |
| 83 const int64 registration_id_; | 101 const int64 registration_id_; |
| 84 | |
| 85 scoped_refptr<ServiceWorkerVersion> active_version_; | 102 scoped_refptr<ServiceWorkerVersion> active_version_; |
| 86 scoped_refptr<ServiceWorkerVersion> waiting_version_; | 103 scoped_refptr<ServiceWorkerVersion> waiting_version_; |
| 87 | 104 scoped_refptr<ServiceWorkerVersion> installing_version_; |
| 88 bool is_shutdown_; | 105 ObserverList<Listener> listeners_; |
| 89 base::WeakPtr<ServiceWorkerContextCore> context_; | 106 base::WeakPtr<ServiceWorkerContextCore> context_; |
| 90 | 107 |
| 91 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); | 108 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); |
| 92 }; | 109 }; |
| 93 } // namespace content | 110 } // namespace content |
| 94 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ | 111 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ |
| OLD | NEW |