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

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

Issue 552693002: ServiceWorker: Make GetOrCreateRegistrationHandle for refactoring (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 unified diff | Download patch
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/message_port_message_filter.h" 10 #include "content/browser/message_port_message_filter.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 if (channel_ready_) { 162 if (channel_ready_) {
163 BrowserMessageFilter::Send(message); 163 BrowserMessageFilter::Send(message);
164 // Don't bother passing through Send()'s result: it's not reliable. 164 // Don't bother passing through Send()'s result: it's not reliable.
165 return true; 165 return true;
166 } 166 }
167 167
168 pending_messages_.push_back(message); 168 pending_messages_.push_back(message);
169 return true; 169 return true;
170 } 170 }
171 171
172 ServiceWorkerRegistrationHandle*
173 ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle(
174 int provider_id,
175 ServiceWorkerRegistration* registration) {
176 ServiceWorkerRegistrationHandle* handle =
177 FindRegistrationHandle(provider_id, registration->id());
178 if (handle) {
179 handle->IncrementRefCount();
180 return handle;
181 }
182
183 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
184 new ServiceWorkerRegistrationHandle(
185 GetContext()->AsWeakPtr(), this, provider_id, registration));
186 handle = new_handle.get();
187 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
188 return handle;
189 }
190
172 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( 191 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle(
173 scoped_ptr<ServiceWorkerHandle> handle) { 192 scoped_ptr<ServiceWorkerHandle> handle) {
174 int handle_id = handle->handle_id(); 193 int handle_id = handle->handle_id();
175 handles_.AddWithID(handle.release(), handle_id); 194 handles_.AddWithID(handle.release(), handle_id);
176 } 195 }
177 196
178 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle( 197 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle(
179 scoped_ptr<ServiceWorkerRegistrationHandle> handle) { 198 scoped_ptr<ServiceWorkerRegistrationHandle> handle) {
180 int handle_id = handle->handle_id(); 199 int handle_id = handle->handle_id();
181 registration_handles_.AddWithID(handle.release(), handle_id); 200 registration_handles_.AddWithID(handle.release(), handle_id);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 if (status != SERVICE_WORKER_OK) { 403 if (status != SERVICE_WORKER_OK) {
385 SendRegistrationError(thread_id, request_id, status); 404 SendRegistrationError(thread_id, request_id, status);
386 return; 405 return;
387 } 406 }
388 407
389 ServiceWorkerRegistration* registration = 408 ServiceWorkerRegistration* registration =
390 GetContext()->GetLiveRegistration(registration_id); 409 GetContext()->GetLiveRegistration(registration_id);
391 DCHECK(registration); 410 DCHECK(registration);
392 411
393 ServiceWorkerRegistrationHandle* handle = 412 ServiceWorkerRegistrationHandle* handle =
394 FindRegistrationHandle(provider_id, registration_id); 413 GetOrCreateRegistrationHandle(provider_id, registration);
395 ServiceWorkerRegistrationObjectInfo info;
396 if (handle) {
397 handle->IncrementRefCount();
398 info = handle->GetObjectInfo();
399 } else {
400 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
401 new ServiceWorkerRegistrationHandle(
402 GetContext()->AsWeakPtr(), this, provider_id, registration));
403 info = new_handle->GetObjectInfo();
404 handle = new_handle.get();
405 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
406 }
407 414
408 ServiceWorkerVersionAttributes attrs; 415 ServiceWorkerVersionAttributes attrs;
409 attrs.installing = handle->CreateServiceWorkerHandleAndPass( 416 attrs.installing = handle->CreateServiceWorkerHandleAndPass(
410 registration->installing_version()); 417 registration->installing_version());
411 attrs.waiting = handle->CreateServiceWorkerHandleAndPass( 418 attrs.waiting = handle->CreateServiceWorkerHandleAndPass(
412 registration->waiting_version()); 419 registration->waiting_version());
413 attrs.active = handle->CreateServiceWorkerHandleAndPass( 420 attrs.active = handle->CreateServiceWorkerHandleAndPass(
414 registration->active_version()); 421 registration->active_version());
415 422
416 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( 423 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
417 thread_id, request_id, info, attrs)); 424 thread_id, request_id, handle->GetObjectInfo(), attrs));
418 TRACE_EVENT_ASYNC_END2("ServiceWorker", 425 TRACE_EVENT_ASYNC_END2("ServiceWorker",
419 "ServiceWorkerDispatcherHost::RegisterServiceWorker", 426 "ServiceWorkerDispatcherHost::RegisterServiceWorker",
420 request_id, 427 request_id,
421 "Registration ID", registration_id, 428 "Registration ID", registration_id,
422 "Version ID", version_id); 429 "Version ID", version_id);
423 } 430 }
424 431
425 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection( 432 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection(
426 int embedded_worker_id) { 433 int embedded_worker_id) {
427 TRACE_EVENT0("ServiceWorker", 434 TRACE_EVENT0("ServiceWorker",
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 status, &error_type, &error_message); 630 status, &error_type, &error_message);
624 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( 631 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
625 thread_id, request_id, error_type, error_message)); 632 thread_id, request_id, error_type, error_message));
626 } 633 }
627 634
628 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { 635 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
629 return context_wrapper_->context(); 636 return context_wrapper_->context();
630 } 637 }
631 638
632 } // namespace content 639 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_dispatcher_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698