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

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

Issue 477593007: ServiceWorker: Make '.ready' return a promise to be resolved with ServiceWorkerRegistration (2/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 3 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_dispatcher_host.cc
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc
index 44d5b796cc17791de8f48d6c013f442d26eb09ab..b2aa8c23ea51a9b1a019a06b9f0473bef6f038fe 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -329,6 +329,25 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId(
BadMessageReceived();
}
+ServiceWorkerRegistrationObjectInfo
+ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle(
+ int provider_id,
+ ServiceWorkerRegistration* registration) {
+ ServiceWorkerRegistrationHandle* handle =
+ FindRegistrationHandle(provider_id, registration->id());
+ if (handle) {
+ handle->IncrementRefCount();
+ return handle->GetObjectInfo();
+ }
+
+ scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
+ new ServiceWorkerRegistrationHandle(
+ GetContext()->AsWeakPtr(), this, provider_id, registration));
+ ServiceWorkerRegistrationObjectInfo info = new_handle->GetObjectInfo();
+ RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
+ return info;
+}
+
ServiceWorkerRegistrationHandle*
ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
int64 registration_id) {
@@ -365,20 +384,12 @@ void ServiceWorkerDispatcherHost::RegistrationComplete(
GetContext()->GetLiveRegistration(registration_id);
DCHECK(registration);
+ ServiceWorkerRegistrationObjectInfo info =
+ GetOrCreateRegistrationHandle(provider_id, registration);
michaeln 2014/09/04 00:27:23 seems like GetOrCreateRegistrationHandle() should
nhiroki 2014/09/08 15:55:51 Done in the separate CL (https://codereview.chromi
+
ServiceWorkerRegistrationHandle* handle =
FindRegistrationHandle(provider_id, registration_id);
- ServiceWorkerRegistrationObjectInfo info;
- if (handle) {
- handle->IncrementRefCount();
- info = handle->GetObjectInfo();
- } else {
- scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
- new ServiceWorkerRegistrationHandle(
- GetContext()->AsWeakPtr(), this, provider_id, registration));
- info = new_handle->GetObjectInfo();
- handle = new_handle.get();
- RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
- }
+ DCHECK(handle);
ServiceWorkerVersionAttributes attrs;
attrs.installing = handle->CreateServiceWorkerHandleAndPass(

Powered by Google App Engine
This is Rietveld 408576698