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

Side by Side Diff: content/child/service_worker/service_worker_dispatcher.cc

Issue 1275903003: Service Worker: Stop using a scoped_ptr for an object to be released immediately. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | 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/child/service_worker/service_worker_dispatcher.h" 5 #include "content/child/service_worker/service_worker_dispatcher.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const GURL& script_url, 112 const GURL& script_url,
113 WebServiceWorkerRegistrationCallbacks* callbacks) { 113 WebServiceWorkerRegistrationCallbacks* callbacks) {
114 DCHECK(callbacks); 114 DCHECK(callbacks);
115 115
116 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() || 116 if (pattern.possibly_invalid_spec().size() > GetMaxURLChars() ||
117 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) { 117 script_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
118 scoped_ptr<WebServiceWorkerRegistrationCallbacks> 118 scoped_ptr<WebServiceWorkerRegistrationCallbacks>
119 owned_callbacks(callbacks); 119 owned_callbacks(callbacks);
120 std::string error_message(kServiceWorkerRegisterErrorPrefix); 120 std::string error_message(kServiceWorkerRegisterErrorPrefix);
121 error_message += "The provided scriptURL or scope is too long."; 121 error_message += "The provided scriptURL or scope is too long.";
122 scoped_ptr<WebServiceWorkerError> error( 122 callbacks->onError(
123 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, 123 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity,
124 blink::WebString::fromUTF8(error_message))); 124 blink::WebString::fromUTF8(error_message)));
125 callbacks->onError(error.release());
126 return; 125 return;
127 } 126 }
128 127
129 int request_id = pending_registration_callbacks_.Add(callbacks); 128 int request_id = pending_registration_callbacks_.Add(callbacks);
130 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", 129 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker",
131 "ServiceWorkerDispatcher::RegisterServiceWorker", 130 "ServiceWorkerDispatcher::RegisterServiceWorker",
132 request_id, 131 request_id,
133 "Scope", pattern.spec(), 132 "Scope", pattern.spec(),
134 "Script URL", script_url.spec()); 133 "Script URL", script_url.spec());
135 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( 134 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker(
(...skipping 27 matching lines...) Expand all
163 int provider_id, 162 int provider_id,
164 const GURL& document_url, 163 const GURL& document_url,
165 WebServiceWorkerRegistrationCallbacks* callbacks) { 164 WebServiceWorkerRegistrationCallbacks* callbacks) {
166 DCHECK(callbacks); 165 DCHECK(callbacks);
167 166
168 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { 167 if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) {
169 scoped_ptr<WebServiceWorkerRegistrationCallbacks> 168 scoped_ptr<WebServiceWorkerRegistrationCallbacks>
170 owned_callbacks(callbacks); 169 owned_callbacks(callbacks);
171 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); 170 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix);
172 error_message += "The provided documentURL is too long."; 171 error_message += "The provided documentURL is too long.";
173 scoped_ptr<WebServiceWorkerError> error( 172 callbacks->onError(
174 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, 173 new WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity,
175 blink::WebString::fromUTF8(error_message))); 174 blink::WebString::fromUTF8(error_message)));
176 callbacks->onError(error.release());
177 return; 175 return;
178 } 176 }
179 177
180 int request_id = pending_get_registration_callbacks_.Add(callbacks); 178 int request_id = pending_get_registration_callbacks_.Add(callbacks);
181 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", 179 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
182 "ServiceWorkerDispatcher::GetRegistration", 180 "ServiceWorkerDispatcher::GetRegistration",
183 request_id, 181 request_id,
184 "Document URL", document_url.spec()); 182 "Document URL", document_url.spec());
185 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( 183 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration(
186 CurrentWorkerId(), request_id, provider_id, document_url)); 184 CurrentWorkerId(), request_id, provider_id, document_url));
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 request_id); 467 request_id);
470 468
471 WebServiceWorkerGetRegistrationsCallbacks* callbacks = 469 WebServiceWorkerGetRegistrationsCallbacks* callbacks =
472 pending_get_registrations_callbacks_.Lookup(request_id); 470 pending_get_registrations_callbacks_.Lookup(request_id);
473 DCHECK(callbacks); 471 DCHECK(callbacks);
474 if (!callbacks) 472 if (!callbacks)
475 return; 473 return;
476 474
477 typedef blink::WebVector<blink::WebServiceWorkerRegistration*> 475 typedef blink::WebVector<blink::WebServiceWorkerRegistration*>
478 WebServiceWorkerRegistrationArray; 476 WebServiceWorkerRegistrationArray;
479 scoped_ptr<WebServiceWorkerRegistrationArray> 477 WebServiceWorkerRegistrationArray* registrations =
480 registrations(new WebServiceWorkerRegistrationArray(infos.size())); 478 new WebServiceWorkerRegistrationArray(infos.size());
481 for (size_t i = 0; i < infos.size(); ++i) { 479 for (size_t i = 0; i < infos.size(); ++i) {
482 if (infos[i].handle_id != kInvalidServiceWorkerHandleId) { 480 if (infos[i].handle_id != kInvalidServiceWorkerHandleId) {
483 ServiceWorkerRegistrationObjectInfo info(infos[i]); 481 ServiceWorkerRegistrationObjectInfo info(infos[i]);
484 ServiceWorkerVersionAttributes attr(attrs[i]); 482 ServiceWorkerVersionAttributes attr(attrs[i]);
485 (*registrations)[i] = FindOrCreateRegistration(info, attr); 483 (*registrations)[i] = FindOrCreateRegistration(info, attr);
486 } 484 }
487 } 485 }
488 486
489 callbacks->onSuccess(registrations.release()); 487 callbacks->onSuccess(registrations);
490 pending_get_registrations_callbacks_.Remove(request_id); 488 pending_get_registrations_callbacks_.Remove(request_id);
491 } 489 }
492 490
493 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady( 491 void ServiceWorkerDispatcher::OnDidGetRegistrationForReady(
494 int thread_id, 492 int thread_id,
495 int request_id, 493 int request_id,
496 const ServiceWorkerRegistrationObjectInfo& info, 494 const ServiceWorkerRegistrationObjectInfo& info,
497 const ServiceWorkerVersionAttributes& attrs) { 495 const ServiceWorkerVersionAttributes& attrs) {
498 TRACE_EVENT_ASYNC_STEP_INTO0( 496 TRACE_EVENT_ASYNC_STEP_INTO0(
499 "ServiceWorker", 497 "ServiceWorker",
(...skipping 27 matching lines...) Expand all
527 "OnRegistrationError"); 525 "OnRegistrationError");
528 TRACE_EVENT_ASYNC_END0("ServiceWorker", 526 TRACE_EVENT_ASYNC_END0("ServiceWorker",
529 "ServiceWorkerDispatcher::RegisterServiceWorker", 527 "ServiceWorkerDispatcher::RegisterServiceWorker",
530 request_id); 528 request_id);
531 WebServiceWorkerRegistrationCallbacks* callbacks = 529 WebServiceWorkerRegistrationCallbacks* callbacks =
532 pending_registration_callbacks_.Lookup(request_id); 530 pending_registration_callbacks_.Lookup(request_id);
533 DCHECK(callbacks); 531 DCHECK(callbacks);
534 if (!callbacks) 532 if (!callbacks)
535 return; 533 return;
536 534
537 scoped_ptr<WebServiceWorkerError> error( 535 callbacks->onError(new WebServiceWorkerError(error_type, message));
538 new WebServiceWorkerError(error_type, message));
539 callbacks->onError(error.release());
540 pending_registration_callbacks_.Remove(request_id); 536 pending_registration_callbacks_.Remove(request_id);
541 } 537 }
542 538
543 void ServiceWorkerDispatcher::OnUpdateError( 539 void ServiceWorkerDispatcher::OnUpdateError(
544 int thread_id, 540 int thread_id,
545 int request_id, 541 int request_id,
546 WebServiceWorkerError::ErrorType error_type, 542 WebServiceWorkerError::ErrorType error_type,
547 const base::string16& message) { 543 const base::string16& message) {
548 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker", 544 TRACE_EVENT_ASYNC_STEP_INTO0("ServiceWorker",
549 "ServiceWorkerDispatcher::UpdateServiceWorker", 545 "ServiceWorkerDispatcher::UpdateServiceWorker",
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 "OnGetRegistrationError"); 592 "OnGetRegistrationError");
597 TRACE_EVENT_ASYNC_END0("ServiceWorker", 593 TRACE_EVENT_ASYNC_END0("ServiceWorker",
598 "ServiceWorkerDispatcher::GetRegistration", 594 "ServiceWorkerDispatcher::GetRegistration",
599 request_id); 595 request_id);
600 WebServiceWorkerGetRegistrationCallbacks* callbacks = 596 WebServiceWorkerGetRegistrationCallbacks* callbacks =
601 pending_get_registration_callbacks_.Lookup(request_id); 597 pending_get_registration_callbacks_.Lookup(request_id);
602 DCHECK(callbacks); 598 DCHECK(callbacks);
603 if (!callbacks) 599 if (!callbacks)
604 return; 600 return;
605 601
606 scoped_ptr<WebServiceWorkerError> error( 602 callbacks->onError(new WebServiceWorkerError(error_type, message));
607 new WebServiceWorkerError(error_type, message));
608 callbacks->onError(error.release());
609 pending_get_registration_callbacks_.Remove(request_id); 603 pending_get_registration_callbacks_.Remove(request_id);
610 } 604 }
611 605
612 void ServiceWorkerDispatcher::OnGetRegistrationsError( 606 void ServiceWorkerDispatcher::OnGetRegistrationsError(
613 int thread_id, 607 int thread_id,
614 int request_id, 608 int request_id,
615 WebServiceWorkerError::ErrorType error_type, 609 WebServiceWorkerError::ErrorType error_type,
616 const base::string16& message) { 610 const base::string16& message) {
617 TRACE_EVENT_ASYNC_STEP_INTO0( 611 TRACE_EVENT_ASYNC_STEP_INTO0(
618 "ServiceWorker", 612 "ServiceWorker",
619 "ServiceWorkerDispatcher::GetRegistrations", 613 "ServiceWorkerDispatcher::GetRegistrations",
620 request_id, 614 request_id,
621 "OnGetRegistrationsError"); 615 "OnGetRegistrationsError");
622 TRACE_EVENT_ASYNC_END0("ServiceWorker", 616 TRACE_EVENT_ASYNC_END0("ServiceWorker",
623 "ServiceWorkerDispatcher::GetRegistrations", 617 "ServiceWorkerDispatcher::GetRegistrations",
624 request_id); 618 request_id);
625 WebServiceWorkerGetRegistrationsCallbacks* callbacks = 619 WebServiceWorkerGetRegistrationsCallbacks* callbacks =
626 pending_get_registrations_callbacks_.Lookup(request_id); 620 pending_get_registrations_callbacks_.Lookup(request_id);
627 DCHECK(callbacks); 621 DCHECK(callbacks);
628 if (!callbacks) 622 if (!callbacks)
629 return; 623 return;
630 624
631 scoped_ptr<WebServiceWorkerError> error( 625 callbacks->onError(new WebServiceWorkerError(error_type, message));
632 new WebServiceWorkerError(error_type, message));
633 callbacks->onError(error.release());
634 pending_get_registrations_callbacks_.Remove(request_id); 626 pending_get_registrations_callbacks_.Remove(request_id);
635 } 627 }
636 628
637 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( 629 void ServiceWorkerDispatcher::OnServiceWorkerStateChanged(
638 int thread_id, 630 int thread_id,
639 int handle_id, 631 int handle_id,
640 blink::WebServiceWorkerState state) { 632 blink::WebServiceWorkerState state) {
641 TRACE_EVENT2("ServiceWorker", 633 TRACE_EVENT2("ServiceWorker",
642 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged", 634 "ServiceWorkerDispatcher::OnServiceWorkerStateChanged",
643 "Thread ID", thread_id, 635 "Thread ID", thread_id,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 bool adopt_handle = true; 795 bool adopt_handle = true;
804 WebServiceWorkerRegistrationImpl* registration = 796 WebServiceWorkerRegistrationImpl* registration =
805 CreateServiceWorkerRegistration(info, adopt_handle); 797 CreateServiceWorkerRegistration(info, adopt_handle);
806 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle)); 798 registration->SetInstalling(GetServiceWorker(attrs.installing, adopt_handle));
807 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle)); 799 registration->SetWaiting(GetServiceWorker(attrs.waiting, adopt_handle));
808 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle)); 800 registration->SetActive(GetServiceWorker(attrs.active, adopt_handle));
809 return registration; 801 return registration;
810 } 802 }
811 803
812 } // namespace content 804 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698