OLD | NEW |
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_storage.h" | 5 #include "content/browser/service_worker/service_worker_storage.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 data.scope = registration->pattern(); | 532 data.scope = registration->pattern(); |
533 data.script = version->script_url(); | 533 data.script = version->script_url(); |
534 data.has_fetch_handler = true; | 534 data.has_fetch_handler = true; |
535 data.version_id = version->version_id(); | 535 data.version_id = version->version_id(); |
536 data.last_update_check = registration->last_update_check(); | 536 data.last_update_check = registration->last_update_check(); |
537 data.is_active = (version == registration->active_version()); | 537 data.is_active = (version == registration->active_version()); |
538 | 538 |
539 ResourceList resources; | 539 ResourceList resources; |
540 version->script_cache_map()->GetResources(&resources); | 540 version->script_cache_map()->GetResources(&resources); |
541 | 541 |
| 542 if (resources.empty()) { |
| 543 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); |
| 544 return; |
| 545 } |
| 546 |
542 uint64 resources_total_size_bytes = 0; | 547 uint64 resources_total_size_bytes = 0; |
543 for (const auto& resource : resources) { | 548 for (const auto& resource : resources) { |
544 resources_total_size_bytes += resource.size_bytes; | 549 resources_total_size_bytes += resource.size_bytes; |
545 } | 550 } |
546 data.resources_total_size_bytes = resources_total_size_bytes; | 551 data.resources_total_size_bytes = resources_total_size_bytes; |
547 | 552 |
548 if (!has_checked_for_stale_resources_) | 553 if (!has_checked_for_stale_resources_) |
549 DeleteStaleResources(); | 554 DeleteStaleResources(); |
550 | 555 |
551 database_task_manager_->GetTaskRunner()->PostTask( | 556 database_task_manager_->GetTaskRunner()->PostTask( |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 | 1092 |
1088 ScheduleDeleteAndStartOver(); | 1093 ScheduleDeleteAndStartOver(); |
1089 callback.Run(DatabaseStatusToStatusCode(status), | 1094 callback.Run(DatabaseStatusToStatusCode(status), |
1090 scoped_refptr<ServiceWorkerRegistration>()); | 1095 scoped_refptr<ServiceWorkerRegistration>()); |
1091 } | 1096 } |
1092 | 1097 |
1093 void ServiceWorkerStorage::ReturnFoundRegistration( | 1098 void ServiceWorkerStorage::ReturnFoundRegistration( |
1094 const FindRegistrationCallback& callback, | 1099 const FindRegistrationCallback& callback, |
1095 const ServiceWorkerDatabase::RegistrationData& data, | 1100 const ServiceWorkerDatabase::RegistrationData& data, |
1096 const ResourceList& resources) { | 1101 const ResourceList& resources) { |
| 1102 DCHECK(!resources.empty()); |
1097 scoped_refptr<ServiceWorkerRegistration> registration = | 1103 scoped_refptr<ServiceWorkerRegistration> registration = |
1098 GetOrCreateRegistration(data, resources); | 1104 GetOrCreateRegistration(data, resources); |
1099 CompleteFindNow(registration, SERVICE_WORKER_OK, callback); | 1105 CompleteFindNow(registration, SERVICE_WORKER_OK, callback); |
1100 } | 1106 } |
1101 | 1107 |
1102 void ServiceWorkerStorage::DidGetRegistrations( | 1108 void ServiceWorkerStorage::DidGetRegistrations( |
1103 const GetRegistrationsInfosCallback& callback, | 1109 const GetRegistrationsInfosCallback& callback, |
1104 RegistrationList* registrations, | 1110 RegistrationList* registrations, |
1105 const GURL& origin_filter, | 1111 const GURL& origin_filter, |
1106 ServiceWorkerDatabase::Status status) { | 1112 ServiceWorkerDatabase::Status status) { |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1813 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1808 return; | 1814 return; |
1809 } | 1815 } |
1810 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1816 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1811 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( | 1817 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( |
1812 ServiceWorkerMetrics::DELETE_OK); | 1818 ServiceWorkerMetrics::DELETE_OK); |
1813 callback.Run(SERVICE_WORKER_OK); | 1819 callback.Run(SERVICE_WORKER_OK); |
1814 } | 1820 } |
1815 | 1821 |
1816 } // namespace content | 1822 } // namespace content |
OLD | NEW |