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

Unified Diff: content/browser/service_worker/service_worker_registration.cc

Issue 360123002: ServiceWorker: some more groundwork in support of the update process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_registration.cc
diff --git a/content/browser/service_worker/service_worker_registration.cc b/content/browser/service_worker/service_worker_registration.cc
index 7ea5029b10cdd734cdbf03d6ddd4442283eeb690..9c5f572d909f32730bf5ef3226e9db906e38ada2 100644
--- a/content/browser/service_worker/service_worker_registration.cc
+++ b/content/browser/service_worker/service_worker_registration.cc
@@ -10,6 +10,16 @@
namespace content {
+namespace {
+
+ServiceWorkerVersionInfo GetVersionInfo(ServiceWorkerVersion* version) {
+ if (!version)
+ return ServiceWorkerVersionInfo();
+ return version->GetInfo();
+}
+
+} // namespace
+
ServiceWorkerRegistration::ServiceWorkerRegistration(
const GURL& pattern,
const GURL& script_url,
@@ -18,7 +28,6 @@ ServiceWorkerRegistration::ServiceWorkerRegistration(
: pattern_(pattern),
script_url_(script_url),
registration_id_(registration_id),
- is_shutdown_(false),
context_(context) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(context_);
@@ -31,29 +40,87 @@ ServiceWorkerRegistration::~ServiceWorkerRegistration() {
context_->RemoveLiveRegistration(registration_id_);
}
+void ServiceWorkerRegistration::AddListener(Listener* listener) {
+ listeners_.AddObserver(listener);
+}
+
+void ServiceWorkerRegistration::RemoveListener(Listener* listener) {
+ listeners_.RemoveObserver(listener);
+}
+
ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
return ServiceWorkerRegistrationInfo(
script_url(),
pattern(),
registration_id_,
- active_version_ ? active_version_->GetInfo() : ServiceWorkerVersionInfo(),
- waiting_version_ ? waiting_version_->GetInfo()
- : ServiceWorkerVersionInfo());
+ GetVersionInfo(active_version_),
+ GetVersionInfo(waiting_version_),
+ GetVersionInfo(installing_version_));
}
-ServiceWorkerVersion* ServiceWorkerRegistration::GetNewestVersion() {
- if (active_version())
- return active_version();
- return waiting_version();
+void ServiceWorkerRegistration::SetActiveVersion(
+ ServiceWorkerVersion* version) {
+ SetVersionInternal(version, &active_version_,
+ ChangedVersionAttributesMask::ACTIVE_VERSION);
}
-void ServiceWorkerRegistration::ActivateWaitingVersion() {
- active_version_->SetStatus(ServiceWorkerVersion::REDUNDANT);
- active_version_ = waiting_version_;
- // TODO(kinuko): This should be set to ACTIVATING until activation finishes.
- active_version_->SetStatus(ServiceWorkerVersion::ACTIVE);
- waiting_version_ = NULL;
+void ServiceWorkerRegistration::SetWaitingVersion(
+ ServiceWorkerVersion* version) {
+ SetVersionInternal(version, &waiting_version_,
+ ChangedVersionAttributesMask::WAITING_VERSION);
}
+void ServiceWorkerRegistration::SetInstallingVersion(
+ ServiceWorkerVersion* version) {
+ SetVersionInternal(version, &installing_version_,
+ ChangedVersionAttributesMask::INSTALLING_VERSION);
+}
+
+void ServiceWorkerRegistration::UnsetVersion(ServiceWorkerVersion* version) {
+ if (!version)
+ return;
+ ChangedVersionAttributesMask mask;
+ UnsetVersionInternal(version, &mask);
+ if (mask.changed()) {
+ ServiceWorkerRegistrationInfo info = GetInfo();
+ FOR_EACH_OBSERVER(Listener, listeners_,
+ OnVersionAttributesChanged(this, mask, info));
+ }
+}
+
+void ServiceWorkerRegistration::SetVersionInternal(
+ ServiceWorkerVersion* version,
+ scoped_refptr<ServiceWorkerVersion>* data_member,
+ int change_flag) {
+ if (version == data_member->get())
+ return;
+ scoped_refptr<ServiceWorkerVersion> protect(version);
+ ChangedVersionAttributesMask mask;
+ if (version)
+ UnsetVersionInternal(version, &mask);
+ *data_member = version;
+ mask.add(change_flag);
+ ServiceWorkerRegistrationInfo info = GetInfo();
+ FOR_EACH_OBSERVER(Listener, listeners_,
+ OnVersionAttributesChanged(this, mask, info));
+}
+
+ void ServiceWorkerRegistration::UnsetVersionInternal(
+ ServiceWorkerVersion* version,
+ ChangedVersionAttributesMask* mask) {
+ DCHECK(version);
+ if (installing_version_ == version) {
+ installing_version_ = NULL;
+ mask->add(ChangedVersionAttributesMask::INSTALLING_VERSION);
+ } else if (waiting_version_ == version) {
+ waiting_version_ = NULL;
+ mask->add(ChangedVersionAttributesMask::WAITING_VERSION);
+ } else if (active_version_ == version) {
+ active_version_ = NULL;
+ mask->add(ChangedVersionAttributesMask::ACTIVE_VERSION);
+ }
+}
+
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698