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