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

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 1307133003: ServiceWorker: Make APIs that return ServiceWorkerRegistration coin a new JS object (2/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: split CreateRegistration() Created 5 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 unified diff | Download patch
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 #include "content/browser/service_worker/service_worker_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h" 8 #include "base/profiler/scoped_tracker.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 DCHECK(handle->version()); 252 DCHECK(handle->version());
253 if (handle->provider_id() == provider_id && 253 if (handle->provider_id() == provider_id &&
254 handle->version()->version_id() == version_id) { 254 handle->version()->version_id() == version_id) {
255 return handle; 255 return handle;
256 } 256 }
257 } 257 }
258 return NULL; 258 return NULL;
259 } 259 }
260 260
261 ServiceWorkerRegistrationHandle* 261 ServiceWorkerRegistrationHandle*
262 ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle( 262 ServiceWorkerDispatcherHost::CreateRegistrationHandle(
263 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 263 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
264 ServiceWorkerRegistration* registration) { 264 ServiceWorkerRegistration* registration) {
265 DCHECK(provider_host); 265 DCHECK(provider_host);
266 ServiceWorkerRegistrationHandle* handle = 266 scoped_ptr<ServiceWorkerRegistrationHandle> handle(
267 FindRegistrationHandle(provider_host->provider_id(), registration->id()); 267 new ServiceWorkerRegistrationHandle(GetContext()->AsWeakPtr(),
268 if (handle) { 268 provider_host, registration));
269 handle->IncrementRefCount(); 269 ServiceWorkerRegistrationHandle* handle_ptr = handle.get();
270 return handle; 270 RegisterServiceWorkerRegistrationHandle(handle.Pass());
271 } 271 return handle_ptr;
272
273 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
274 new ServiceWorkerRegistrationHandle(
275 GetContext()->AsWeakPtr(), provider_host, registration));
276 handle = new_handle.get();
277 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
278 return handle;
279 } 272 }
280 273
281 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( 274 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
282 int thread_id, 275 int thread_id,
283 int request_id, 276 int request_id,
284 int provider_id, 277 int provider_id,
285 const GURL& pattern, 278 const GURL& pattern,
286 const GURL& script_url) { 279 const GURL& script_url) {
287 TRACE_EVENT0("ServiceWorker", 280 TRACE_EVENT0("ServiceWorker",
288 "ServiceWorkerDispatcherHost::OnRegisterServiceWorker"); 281 "ServiceWorkerDispatcherHost::OnRegisterServiceWorker");
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 782
790 ServiceWorkerRegistrationObjectInfo info; 783 ServiceWorkerRegistrationObjectInfo info;
791 ServiceWorkerVersionAttributes attrs; 784 ServiceWorkerVersionAttributes attrs;
792 GetRegistrationObjectInfoAndVersionAttributes( 785 GetRegistrationObjectInfoAndVersionAttributes(
793 provider_host->AsWeakPtr(), registration, &info, &attrs); 786 provider_host->AsWeakPtr(), registration, &info, &attrs);
794 787
795 Send(new ServiceWorkerMsg_AssociateRegistrationWithServiceWorker( 788 Send(new ServiceWorkerMsg_AssociateRegistrationWithServiceWorker(
796 kDocumentMainThreadId, provider_id, info, attrs)); 789 kDocumentMainThreadId, provider_id, info, attrs));
797 } 790 }
798 791
799 ServiceWorkerRegistrationHandle*
800 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
801 int64 registration_id) {
802 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator
803 iter(&registration_handles_);
804 !iter.IsAtEnd();
805 iter.Advance()) {
806 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue();
807 DCHECK(handle);
808 DCHECK(handle->registration());
809 if (handle->provider_id() == provider_id &&
810 handle->registration()->id() == registration_id) {
811 return handle;
812 }
813 }
814 return NULL;
815 }
816
817 void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes( 792 void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes(
818 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 793 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
819 ServiceWorkerRegistration* registration, 794 ServiceWorkerRegistration* registration,
820 ServiceWorkerRegistrationObjectInfo* info, 795 ServiceWorkerRegistrationObjectInfo* info,
821 ServiceWorkerVersionAttributes* attrs) { 796 ServiceWorkerVersionAttributes* attrs) {
822 ServiceWorkerRegistrationHandle* handle = 797 ServiceWorkerRegistrationHandle* handle =
823 GetOrCreateRegistrationHandle(provider_host, registration); 798 CreateRegistrationHandle(provider_host, registration);
824 *info = handle->GetObjectInfo(); 799 *info = handle->GetObjectInfo();
825 800
826 attrs->installing = provider_host->GetOrCreateServiceWorkerHandle( 801 attrs->installing = provider_host->GetOrCreateServiceWorkerHandle(
827 registration->installing_version()); 802 registration->installing_version());
828 attrs->waiting = provider_host->GetOrCreateServiceWorkerHandle( 803 attrs->waiting = provider_host->GetOrCreateServiceWorkerHandle(
829 registration->waiting_version()); 804 registration->waiting_version());
830 attrs->active = provider_host->GetOrCreateServiceWorkerHandle( 805 attrs->active = provider_host->GetOrCreateServiceWorkerHandle(
831 registration->active_version()); 806 registration->active_version());
832 } 807 }
833 808
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 if (!handle) { 1261 if (!handle) {
1287 bad_message::ReceivedBadMessage(this, 1262 bad_message::ReceivedBadMessage(this,
1288 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1263 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1289 return; 1264 return;
1290 } 1265 }
1291 handle->version()->StopWorker( 1266 handle->version()->StopWorker(
1292 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1267 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1293 } 1268 }
1294 1269
1295 } // namespace content 1270 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698