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

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

Issue 380093002: Update installed ServiceWorkers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 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 manages all persistence of service workers: 23 // This class represents a service worker registration. The
24 // - Registrations 24 // scope and script url are constant for the life of the persistent
25 // - Mapping of caches to registrations / versions 25 // registration. It's refcounted to facillitate multiple controllees
26 // 26 // being associated with the same registration. The class roughly
27 // This is the place where we manage simultaneous 27 // corresponds to navigator.serviceWorker.registgration.
28 // requests for the same registrations and caches, making sure that
29 // two pages that are registering the same pattern at the same time
30 // have their registrations coalesced rather than overwriting each
31 // other.
32 //
33 // This class also manages the state of the upgrade process, which
34 // includes managing which ServiceWorkerVersion is "active" vs "in
35 // waiting".
36 class CONTENT_EXPORT ServiceWorkerRegistration 28 class CONTENT_EXPORT ServiceWorkerRegistration
37 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) { 29 : NON_EXPORTED_BASE(public base::RefCounted<ServiceWorkerRegistration>) {
38 public: 30 public:
31 typedef base::Callback<void(ServiceWorkerStatusCode status)> StatusCallback;
32
39 class Listener { 33 class Listener {
40 public: 34 public:
41 virtual void OnVersionAttributesChanged( 35 virtual void OnVersionAttributesChanged(
42 ServiceWorkerRegistration* registration, 36 ServiceWorkerRegistration* registration,
43 ChangedVersionAttributesMask changed_mask, 37 ChangedVersionAttributesMask changed_mask,
44 const ServiceWorkerRegistrationInfo& info) = 0; 38 const ServiceWorkerRegistrationInfo& info) = 0;
45 }; 39 };
46 40
47 ServiceWorkerRegistration(const GURL& pattern, 41 ServiceWorkerRegistration(const GURL& pattern,
48 const GURL& script_url, 42 const GURL& script_url,
(...skipping 14 matching lines...) Expand all
63 57
64 ServiceWorkerVersion* installing_version() const { 58 ServiceWorkerVersion* installing_version() const {
65 return installing_version_.get(); 59 return installing_version_.get();
66 } 60 }
67 61
68 void AddListener(Listener* listener); 62 void AddListener(Listener* listener);
69 void RemoveListener(Listener* listener); 63 void RemoveListener(Listener* listener);
70 64
71 ServiceWorkerRegistrationInfo GetInfo(); 65 ServiceWorkerRegistrationInfo GetInfo();
72 66
73 // Sets the corresposding version attribute and resets the position (if any) 67 // Sets the corresposding version attribute and resets the position
74 // left vacant (ie. by a waiting version being promoted). 68 // (if any) left vacant (ie. by a waiting version being promoted).
75 // Also notifies listeners via OnVersionAttributesChanged. 69 // Also notifies listeners via OnVersionAttributesChanged.
76 void SetActiveVersion(ServiceWorkerVersion* version); 70 void SetActiveVersion(ServiceWorkerVersion* version);
77 void SetWaitingVersion(ServiceWorkerVersion* version); 71 void SetWaitingVersion(ServiceWorkerVersion* version);
78 void SetInstallingVersion(ServiceWorkerVersion* version); 72 void SetInstallingVersion(ServiceWorkerVersion* version);
79 73
80 // If version is the installing, waiting, active version of this 74 // If version is the installing, waiting, active version of this
81 // registation, the method will reset that field to NULL, and notify 75 // registation, the method will reset that field to NULL, and notify
82 // listeners via OnVersionAttributesChanged. 76 // listeners via OnVersionAttributesChanged.
83 void UnsetVersion(ServiceWorkerVersion* version); 77 void UnsetVersion(ServiceWorkerVersion* version);
84 78
79 // This method corresponds to the [[Activate]] algorithm described in
80 // the service worker specification. It's only valid to call this method
81 // when the registration's active version has no controllees.
82 void ActivateWaitingVersion(const StatusCallback& completion_callback);
83
85 private: 84 private:
86 ~ServiceWorkerRegistration(); 85 ~ServiceWorkerRegistration();
87 friend class base::RefCounted<ServiceWorkerRegistration>; 86 friend class base::RefCounted<ServiceWorkerRegistration>;
88 87
89 void SetVersionInternal( 88 void SetVersionInternal(
90 ServiceWorkerVersion* version, 89 ServiceWorkerVersion* version,
91 scoped_refptr<ServiceWorkerVersion>* data_member, 90 scoped_refptr<ServiceWorkerVersion>* data_member,
92 int change_flag); 91 int change_flag);
93 void UnsetVersionInternal( 92 void UnsetVersionInternal(
94 ServiceWorkerVersion* version, 93 ServiceWorkerVersion* version,
95 ChangedVersionAttributesMask* mask); 94 ChangedVersionAttributesMask* mask);
95 void OnActivateEventFinished(
96 ServiceWorkerVersion* activating_version,
97 const StatusCallback& completion_callback,
98 ServiceWorkerStatusCode status);
96 99
97 const GURL pattern_; 100 const GURL pattern_;
98 const GURL script_url_; 101 const GURL script_url_;
99 const int64 registration_id_; 102 const int64 registration_id_;
100 scoped_refptr<ServiceWorkerVersion> active_version_; 103 scoped_refptr<ServiceWorkerVersion> active_version_;
101 scoped_refptr<ServiceWorkerVersion> waiting_version_; 104 scoped_refptr<ServiceWorkerVersion> waiting_version_;
102 scoped_refptr<ServiceWorkerVersion> installing_version_; 105 scoped_refptr<ServiceWorkerVersion> installing_version_;
103 ObserverList<Listener> listeners_; 106 ObserverList<Listener> listeners_;
104 base::WeakPtr<ServiceWorkerContextCore> context_; 107 base::WeakPtr<ServiceWorkerContextCore> context_;
105 108
106 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration); 109 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRegistration);
107 }; 110 };
108 } // namespace content 111 } // namespace content
109 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_ 112 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REGISTRATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698