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

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: delete/restore from storage Created 6 years, 4 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_; }
64
62 void AddListener(Listener* listener); 65 void AddListener(Listener* listener);
63 void RemoveListener(Listener* listener); 66 void RemoveListener(Listener* listener);
64 67
65 ServiceWorkerRegistrationInfo GetInfo(); 68 ServiceWorkerRegistrationInfo GetInfo();
66 69
67 // Sets the corresposding version attribute and resets the position 70 // Sets the corresposding version attribute and resets the position
68 // (if any) left vacant (ie. by a waiting version being promoted). 71 // (if any) left vacant (ie. by a waiting version being promoted).
69 // Also notifies listeners via OnVersionAttributesChanged. 72 // Also notifies listeners via OnVersionAttributesChanged.
70 void SetActiveVersion(ServiceWorkerVersion* version); 73 void SetActiveVersion(ServiceWorkerVersion* version);
71 void SetWaitingVersion(ServiceWorkerVersion* version); 74 void SetWaitingVersion(ServiceWorkerVersion* version);
72 void SetInstallingVersion(ServiceWorkerVersion* version); 75 void SetInstallingVersion(ServiceWorkerVersion* version);
73 76
74 // If version is the installing, waiting, active version of this 77 // If version is the installing, waiting, active version of this
75 // registation, the method will reset that field to NULL, and notify 78 // registation, the method will reset that field to NULL, and notify
76 // listeners via OnVersionAttributesChanged. 79 // listeners via OnVersionAttributesChanged.
77 void UnsetVersion(ServiceWorkerVersion* version); 80 void UnsetVersion(ServiceWorkerVersion* version);
78 81
82 virtual void OnNoControllees(ServiceWorkerVersion* version) OVERRIDE;
83
79 // This method corresponds to the [[Activate]] algorithm described in 84 // This method corresponds to the [[Activate]] algorithm described in
80 // the service worker specification. It's only valid to call this method 85 // the service worker specification. It's only valid to call this method
81 // when the registration's active version has no controllees. 86 // when the registration's active version has no controllees.
82 void ActivateWaitingVersion(const StatusCallback& completion_callback); 87 void ActivateWaitingVersion(const StatusCallback& completion_callback);
83 88
89 // Triggers the [[ClearRegistration]] algorithm when the currently
90 // active version has no controllees. Deletes this registration
91 // from storage immediately.
92 void ClearWhenReady();
93
94 // Restores this registration in storage and cancels the pending
95 // [[ClearRegistration]] algorithm. If the algorithm was already triggered,
96 // does nothing.
97 void AbortPendingClear();
98
84 private: 99 private:
85 ~ServiceWorkerRegistration(); 100 virtual ~ServiceWorkerRegistration();
101 void Clear();
86 friend class base::RefCounted<ServiceWorkerRegistration>; 102 friend class base::RefCounted<ServiceWorkerRegistration>;
87 103
88 void SetVersionInternal( 104 void SetVersionInternal(
89 ServiceWorkerVersion* version, 105 ServiceWorkerVersion* version,
90 scoped_refptr<ServiceWorkerVersion>* data_member, 106 scoped_refptr<ServiceWorkerVersion>* data_member,
91 int change_flag); 107 int change_flag);
92 void UnsetVersionInternal( 108 void UnsetVersionInternal(
93 ServiceWorkerVersion* version, 109 ServiceWorkerVersion* version,
94 ChangedVersionAttributesMask* mask); 110 ChangedVersionAttributesMask* mask);
95 void OnActivateEventFinished( 111 void OnActivateEventFinished(
96 ServiceWorkerVersion* activating_version, 112 ServiceWorkerVersion* activating_version,
97 const StatusCallback& completion_callback, 113 const StatusCallback& completion_callback,
98 ServiceWorkerStatusCode status); 114 ServiceWorkerStatusCode status);
99 115
100 const GURL pattern_; 116 const GURL pattern_;
101 const GURL script_url_; 117 const GURL script_url_;
102 const int64 registration_id_; 118 const int64 registration_id_;
119 bool is_uninstalling_;
103 scoped_refptr<ServiceWorkerVersion> active_version_; 120 scoped_refptr<ServiceWorkerVersion> active_version_;
104 scoped_refptr<ServiceWorkerVersion> waiting_version_; 121 scoped_refptr<ServiceWorkerVersion> waiting_version_;
105 scoped_refptr<ServiceWorkerVersion> installing_version_; 122 scoped_refptr<ServiceWorkerVersion> installing_version_;
106 ObserverList<Listener> listeners_; 123 ObserverList<Listener> listeners_;
107 base::WeakPtr<ServiceWorkerContextCore> context_; 124 base::WeakPtr<ServiceWorkerContextCore> context_;
108 125
109 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); 126 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration);
110 }; 127 };
128
111 } // namespace content 129 } // namespace content
130
112 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ 131 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698