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

Unified Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 1017453006: ServiceWorker: Merge FindSWRegistration into FindOrCreateRegistration for cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refcount_test
Patch Set: Created 5 years, 9 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
« no previous file with comments | « content/child/service_worker/service_worker_dispatcher.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/service_worker/service_worker_dispatcher.cc
diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc
index ff0c79d72d34f97ab929d5c00dcfebb4a4a04d6d..e1372c450a45faef8d728b6ec50fd6e171c5296a 100644
--- a/content/child/service_worker/service_worker_dispatcher.cc
+++ b/content/child/service_worker/service_worker_dispatcher.cc
@@ -274,26 +274,10 @@ WebServiceWorkerImpl* ServiceWorkerDispatcher::GetServiceWorker(
}
WebServiceWorkerRegistrationImpl*
-ServiceWorkerDispatcher::FindServiceWorkerRegistration(
- const ServiceWorkerRegistrationObjectInfo& info,
- bool adopt_handle) {
- RegistrationObjectMap::iterator registration =
- registrations_.find(info.handle_id);
- if (registration == registrations_.end())
- return NULL;
- if (adopt_handle) {
- // We are instructed to adopt a handle but we already have one, so
- // adopt and destroy a handle ref.
- ServiceWorkerRegistrationHandleReference::Adopt(info, sender_.get());
- }
- return registration->second;
-}
-
-WebServiceWorkerRegistrationImpl*
ServiceWorkerDispatcher::CreateServiceWorkerRegistration(
const ServiceWorkerRegistrationObjectInfo& info,
bool adopt_handle) {
- DCHECK(!FindServiceWorkerRegistration(info, adopt_handle));
+ DCHECK(!ContainsKey(registrations_, info.handle_id));
if (info.handle_id == kInvalidServiceWorkerRegistrationHandleId)
return NULL;
@@ -683,20 +667,21 @@ WebServiceWorkerRegistrationImpl*
ServiceWorkerDispatcher::FindOrCreateRegistration(
const ServiceWorkerRegistrationObjectInfo& info,
const ServiceWorkerVersionAttributes& attrs) {
- WebServiceWorkerRegistrationImpl* registration =
- FindServiceWorkerRegistration(info, true);
- if (!registration) {
- registration = CreateServiceWorkerRegistration(info, true);
- registration->SetInstalling(GetServiceWorker(attrs.installing, true));
- registration->SetWaiting(GetServiceWorker(attrs.waiting, true));
- registration->SetActive(GetServiceWorker(attrs.active, true));
- } else {
- // |registration| must already have version attributes, so adopt and destroy
- // handle refs for them.
+ RegistrationObjectMap::iterator found = registrations_.find(info.handle_id);
+ if (found != registrations_.end()) {
+ ServiceWorkerRegistrationHandleReference::Adopt(info, sender_.get());
ServiceWorkerHandleReference::Adopt(attrs.installing, sender_.get());
ServiceWorkerHandleReference::Adopt(attrs.waiting, sender_.get());
ServiceWorkerHandleReference::Adopt(attrs.active, sender_.get());
+ return found->second;
}
+
+ bool adopt_handle = true;
+ WebServiceWorkerRegistrationImpl* registration =
+ CreateServiceWorkerRegistration(info, adopt_handle);
+ registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle));
+ registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle));
+ registration->SetActive(GetServiceWorker(attrs.active, adopt_handle));
return registration;
}
« no previous file with comments | « content/child/service_worker/service_worker_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698