Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(630)

Side by Side Diff: content/browser/service_worker/service_worker_registration.h

Issue 413063004: Service Worker: in Unregister, wait until after the active worker no longer controls a document (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 and script url are 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. The class roughly
27 // corresponds to navigator.serviceWorker.registgration. 27 // corresponds to navigator.serviceWorker.registgration.
28 class CONTENT_EXPORT ServiceWorkerRegistration 28 class CONTENT_EXPORT ServiceWorkerRegistration
29 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) { 29 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>),
30 public ServiceWorkerVersion::Listener {
30 public: 31 public:
31 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback; 32 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback;
32 33
33 class Listener { 34 class Listener {
34 public: 35 public:
35 virtual void OnVersionAttributesChanged( 36 virtual void OnVersionAttributesChanged(
36 ServiceWorkerRegistration* registration, 37 ServiceWorkerRegistration* registration,
37 ChangedVersionAttributesMask changed_mask, 38 ChangedVersionAttributesMask changed_mask,
38 const ServiceWorkerRegistrationInfo& info) = 0; 39 const ServiceWorkerRegistrationInfo& info) = 0;
39 }; 40 };
(...skipping 12 matching lines...) Expand all
52 } 53 }
53 54
54 ServiceWorkerVersion* waiting_version() const { 55 ServiceWorkerVersion* waiting_version() const {
55 return waiting_version_.get(); 56 return waiting_version_.get();
56 } 57 }
57 58
58 ServiceWorkerVersion* installing_version() const { 59 ServiceWorkerVersion* installing_version() const {
59 return installing_version_.get(); 60 return installing_version_.get();
60 } 61 }
61 62
63 bool is_uninstalling() const { return is_uninstalling_; }
michaeln 2014/07/25 00:02:04 i think the addition of this is very good since it
64
65 void set_uninstalling(bool is_uninstalling) {
66 is_uninstalling_ = is_uninstalling;
67 }
68
62 void AddListener(Listener* listener); 69 void AddListener(Listener* listener);
63 void RemoveListener(Listener* listener); 70 void RemoveListener(Listener* listener);
64 71
65 ServiceWorkerRegistrationInfo GetInfo(); 72 ServiceWorkerRegistrationInfo GetInfo();
66 73
67 // Sets the corresposding version attribute and resets the position 74 // Sets the corresposding version attribute and resets the position
68 // (if any) left vacant (ie. by a waiting version being promoted). 75 // (if any) left vacant (ie. by a waiting version being promoted).
69 // Also notifies listeners via OnVersionAttributesChanged. 76 // Also notifies listeners via OnVersionAttributesChanged.
70 void SetActiveVersion(ServiceWorkerVersion* version); 77 void SetActiveVersion(ServiceWorkerVersion* version);
71 void SetWaitingVersion(ServiceWorkerVersion* version); 78 void SetWaitingVersion(ServiceWorkerVersion* version);
72 void SetInstallingVersion(ServiceWorkerVersion* version); 79 void SetInstallingVersion(ServiceWorkerVersion* version);
73 80
74 // If version is the installing, waiting, active version of this 81 // If version is the installing, waiting, active version of this
75 // registation, the method will reset that field to NULL, and notify 82 // registation, the method will reset that field to NULL, and notify
76 // listeners via OnVersionAttributesChanged. 83 // listeners via OnVersionAttributesChanged.
77 void UnsetVersion(ServiceWorkerVersion* version); 84 void UnsetVersion(ServiceWorkerVersion* version);
78 85
86 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE;
87
79 // This method corresponds to the [[Activate]] algorithm described in 88 // This method corresponds to the [[Activate]] algorithm described in
80 // the service worker specification. It's only valid to call this method 89 // the service worker specification. It's only valid to call this method
81 // when the registration's active version has no controllees. 90 // when the registration's active version has no controllees.
82 void ActivateWaitingVersion(const StatusCallback& completion_callback); 91 void ActivateWaitingVersion(const StatusCallback& completion_callback);
83 92
93 void StartUninstall();
94 void Uninstall();
95
84 private: 96 private:
85 ~ServiceWorkerRegistration(); 97 virtual ~ServiceWorkerRegistration();
86 friend class base::RefCounted<ServiceWorkerRegistration>; 98 friend class base::RefCounted<ServiceWorkerRegistration>;
87 99
88 void SetVersionInternal( 100 void SetVersionInternal(
89 ServiceWorkerVersion* version, 101 ServiceWorkerVersion* version,
90 scoped_refptr<ServiceWorkerVersion>* data_member, 102 scoped_refptr<ServiceWorkerVersion>* data_member,
91 int change_flag); 103 int change_flag);
92 void UnsetVersionInternal( 104 void UnsetVersionInternal(
93 ServiceWorkerVersion* version, 105 ServiceWorkerVersion* version,
94 ChangedVersionAttributesMask* mask); 106 ChangedVersionAttributesMask* mask);
95 void OnActivateEventFinished( 107 void OnActivateEventFinished(
96 ServiceWorkerVersion* activating_version, 108 ServiceWorkerVersion* activating_version,
97 const StatusCallback& completion_callback, 109 const StatusCallback& completion_callback,
98 ServiceWorkerStatusCode status); 110 ServiceWorkerStatusCode status);
99 111
100 const GURL pattern_; 112 const GURL pattern_;
101 const GURL script_url_; 113 const GURL script_url_;
102 const int64 registration_id_; 114 const int64 registration_id_;
115 bool is_uninstalling_;
103 scoped_refptr<ServiceWorkerVersion> active_version_; 116 scoped_refptr<ServiceWorkerVersion> active_version_;
104 scoped_refptr<ServiceWorkerVersion> waiting_version_; 117 scoped_refptr<ServiceWorkerVersion> waiting_version_;
105 scoped_refptr<ServiceWorkerVersion> installing_version_; 118 scoped_refptr<ServiceWorkerVersion> installing_version_;
106 ObserverList<Listener> listeners_; 119 ObserverList<Listener> listeners_;
107 base::WeakPtr<ServiceWorkerContextCore> context_; 120 base::WeakPtr<ServiceWorkerContextCore> context_;
108 121
109 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); 122 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration);
110 }; 123 };
124
111 } // namespace content 125 } // namespace content
126
112 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ 127 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698