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

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

Issue 1106723002: ServiceWorker: Decompose SWRegistration::SetVersionInternal for readability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make the argument const-ref Created 5 years, 8 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 26d45285dec88a02aede08a2a5ff296807917566..e3d0552cf0078bad77568586383ad784ebf3dda6 100644
--- a/content/browser/service_worker/service_worker_registration.cc
+++ b/content/browser/service_worker/service_worker_registration.cc
@@ -84,23 +84,54 @@ ServiceWorkerRegistrationInfo ServiceWorkerRegistration::GetInfo() {
}
void ServiceWorkerRegistration::SetActiveVersion(
- ServiceWorkerVersion* version) {
+ const scoped_refptr<ServiceWorkerVersion>& version) {
should_activate_when_ready_ = false;
- SetVersionInternal(version, &active_version_,
- ChangedVersionAttributesMask::ACTIVE_VERSION);
+ if (active_version_ == version)
+ return;
+
+ ChangedVersionAttributesMask mask;
+ if (version)
+ UnsetVersionInternal(version.get(), &mask);
+ if (active_version_)
+ active_version_->RemoveListener(this);
+ active_version_ = version;
+ if (active_version_)
+ active_version_->AddListener(this);
+ mask.add(ChangedVersionAttributesMask::ACTIVE_VERSION);
+
+ FOR_EACH_OBSERVER(Listener, listeners_,
+ OnVersionAttributesChanged(this, mask, GetInfo()));
}
void ServiceWorkerRegistration::SetWaitingVersion(
- ServiceWorkerVersion* version) {
+ const scoped_refptr<ServiceWorkerVersion>& version) {
should_activate_when_ready_ = false;
- SetVersionInternal(version, &waiting_version_,
- ChangedVersionAttributesMask::WAITING_VERSION);
+ if (waiting_version_ == version)
+ return;
+
+ ChangedVersionAttributesMask mask;
+ if (version)
+ UnsetVersionInternal(version.get(), &mask);
+ waiting_version_ = version;
+ mask.add(ChangedVersionAttributesMask::WAITING_VERSION);
+
+ FOR_EACH_OBSERVER(Listener, listeners_,
+ OnVersionAttributesChanged(this, mask, GetInfo()));
}
void ServiceWorkerRegistration::SetInstallingVersion(
- ServiceWorkerVersion* version) {
- SetVersionInternal(version, &installing_version_,
- ChangedVersionAttributesMask::INSTALLING_VERSION);
+ const scoped_refptr<ServiceWorkerVersion>& version) {
+ if (installing_version_ == version)
+ return;
+
+ ChangedVersionAttributesMask mask;
+ if (version)
+ UnsetVersionInternal(version.get(), &mask);
+ installing_version_ = version;
+ mask.add(ChangedVersionAttributesMask::INSTALLING_VERSION);
+
+ FOR_EACH_OBSERVER(Listener, listeners_,
+ OnVersionAttributesChanged(this, mask, GetInfo()));
}
void ServiceWorkerRegistration::UnsetVersion(ServiceWorkerVersion* version) {
@@ -115,27 +146,6 @@ void ServiceWorkerRegistration::UnsetVersion(ServiceWorkerVersion* version) {
}
}
-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);
- if (*data_member && *data_member == active_version_)
- active_version_->RemoveListener(this);
- *data_member = version;
- if (active_version_.get() && active_version_.get() == version)
- active_version_->AddListener(this);
- mask.add(change_flag);
- ServiceWorkerRegistrationInfo info = GetInfo();
- FOR_EACH_OBSERVER(Listener, listeners_,
- OnVersionAttributesChanged(this, mask, info));
-}
-
void ServiceWorkerRegistration::UnsetVersionInternal(
ServiceWorkerVersion* version,
ChangedVersionAttributesMask* mask) {
@@ -278,7 +288,7 @@ void ServiceWorkerRegistration::ActivateWaitingVersion() {
// "6. Set serviceWorkerRegistration.activeWorker to activatingWorker."
// "7. Set serviceWorkerRegistration.waitingWorker to null."
- SetActiveVersion(activating_version.get());
+ SetActiveVersion(activating_version);
// "8. Run the [[UpdateState]] algorithm passing registration.activeWorker and
// "activating" as arguments."

Powered by Google App Engine
This is Rietveld 408576698