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

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

Issue 1693303002: ServiceWorker: Make ServiceWorkerStorage more self-defensive (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (!GetContentClient()->browser()->AllowServiceWorker( 576 if (!GetContentClient()->browser()->AllowServiceWorker(
577 provider_host->document_url(), provider_host->topmost_frame_url(), 577 provider_host->document_url(), provider_host->topmost_frame_url(),
578 resource_context_, render_process_id_, provider_host->frame_id())) { 578 resource_context_, render_process_id_, provider_host->frame_id())) {
579 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( 579 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
580 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, 580 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
581 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + 581 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) +
582 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); 582 base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
583 return; 583 return;
584 } 584 }
585 585
586 if (GetContext()->storage()->IsDisabled()) {
587 SendGetRegistrationError(thread_id, request_id, SERVICE_WORKER_ERROR_ABORT);
588 return;
589 }
590
591 TRACE_EVENT_ASYNC_BEGIN1( 586 TRACE_EVENT_ASYNC_BEGIN1(
592 "ServiceWorker", 587 "ServiceWorker",
593 "ServiceWorkerDispatcherHost::GetRegistration", 588 "ServiceWorkerDispatcherHost::GetRegistration",
594 request_id, 589 request_id,
595 "Document URL", document_url.spec()); 590 "Document URL", document_url.spec());
596 591
597 GetContext()->storage()->FindRegistrationForDocument( 592 GetContext()->storage()->FindRegistrationForDocument(
598 document_url, 593 document_url,
599 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, 594 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete,
600 this, 595 this,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 if (!GetContentClient()->browser()->AllowServiceWorker( 644 if (!GetContentClient()->browser()->AllowServiceWorker(
650 provider_host->document_url(), provider_host->topmost_frame_url(), 645 provider_host->document_url(), provider_host->topmost_frame_url(),
651 resource_context_, render_process_id_, provider_host->frame_id())) { 646 resource_context_, render_process_id_, provider_host->frame_id())) {
652 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( 647 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError(
653 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, 648 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
654 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) + 649 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) +
655 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); 650 base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
656 return; 651 return;
657 } 652 }
658 653
659 if (GetContext()->storage()->IsDisabled()) {
660 SendGetRegistrationsError(thread_id, request_id,
661 SERVICE_WORKER_ERROR_ABORT);
662 return;
663 }
664
665 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", 654 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker",
666 "ServiceWorkerDispatcherHost::GetRegistrations", 655 "ServiceWorkerDispatcherHost::GetRegistrations",
667 request_id); 656 request_id);
668 657
669 GetContext()->storage()->GetRegistrationsForOrigin( 658 GetContext()->storage()->GetRegistrationsForOrigin(
670 provider_host->document_url().GetOrigin(), 659 provider_host->document_url().GetOrigin(),
671 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationsComplete, this, 660 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationsComplete, this,
672 thread_id, provider_id, request_id)); 661 thread_id, provider_id, request_id));
673 } 662 }
674 663
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 } 1196 }
1208 1197
1209 Send(new ServiceWorkerMsg_DidGetRegistration( 1198 Send(new ServiceWorkerMsg_DidGetRegistration(
1210 thread_id, request_id, info, attrs)); 1199 thread_id, request_id, info, attrs));
1211 } 1200 }
1212 1201
1213 void ServiceWorkerDispatcherHost::GetRegistrationsComplete( 1202 void ServiceWorkerDispatcherHost::GetRegistrationsComplete(
1214 int thread_id, 1203 int thread_id,
1215 int provider_id, 1204 int provider_id,
1216 int request_id, 1205 int request_id,
1206 ServiceWorkerStatusCode status,
1217 const std::vector<scoped_refptr<ServiceWorkerRegistration>>& 1207 const std::vector<scoped_refptr<ServiceWorkerRegistration>>&
1218 registrations) { 1208 registrations) {
1219 TRACE_EVENT_ASYNC_END0("ServiceWorker", 1209 TRACE_EVENT_ASYNC_END0("ServiceWorker",
1220 "ServiceWorkerDispatcherHost::GetRegistrations", 1210 "ServiceWorkerDispatcherHost::GetRegistrations",
1221 request_id); 1211 request_id);
1222 if (!GetContext()) 1212 if (!GetContext())
1223 return; 1213 return;
1224 1214
1225 ServiceWorkerProviderHost* provider_host = 1215 ServiceWorkerProviderHost* provider_host =
1226 GetContext()->GetProviderHost(render_process_id_, provider_id); 1216 GetContext()->GetProviderHost(render_process_id_, provider_id);
1227 if (!provider_host) 1217 if (!provider_host)
1228 return; // The provider has already been destroyed. 1218 return; // The provider has already been destroyed.
1229 1219
1220 if (status != SERVICE_WORKER_OK) {
1221 SendGetRegistrationsError(thread_id, request_id, status);
1222 return;
1223 }
1224
1230 std::vector<ServiceWorkerRegistrationObjectInfo> object_infos; 1225 std::vector<ServiceWorkerRegistrationObjectInfo> object_infos;
1231 std::vector<ServiceWorkerVersionAttributes> version_attrs; 1226 std::vector<ServiceWorkerVersionAttributes> version_attrs;
1232 1227
1233 for (const auto& registration : registrations) { 1228 for (const auto& registration : registrations) {
1234 DCHECK(registration.get()); 1229 DCHECK(registration.get());
1235 if (!registration->is_uninstalling()) { 1230 if (!registration->is_uninstalling()) {
1236 ServiceWorkerRegistrationObjectInfo object_info; 1231 ServiceWorkerRegistrationObjectInfo object_info;
1237 ServiceWorkerVersionAttributes version_attr; 1232 ServiceWorkerVersionAttributes version_attr;
1238 GetRegistrationObjectInfoAndVersionAttributes( 1233 GetRegistrationObjectInfoAndVersionAttributes(
1239 provider_host->AsWeakPtr(), registration.get(), &object_info, 1234 provider_host->AsWeakPtr(), registration.get(), &object_info,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 if (!handle) { 1346 if (!handle) {
1352 bad_message::ReceivedBadMessage(this, 1347 bad_message::ReceivedBadMessage(this,
1353 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1348 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1354 return; 1349 return;
1355 } 1350 }
1356 handle->version()->StopWorker( 1351 handle->version()->StopWorker(
1357 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1352 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1358 } 1353 }
1359 1354
1360 } // namespace content 1355 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698