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

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

Issue 1393783002: ServiceWorker: Schedule DeleteAndStartOver when failing to store resource ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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_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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return make_scoped_ptr( 529 return make_scoped_ptr(
530 new ServiceWorkerResponseWriter(response_id, disk_cache())); 530 new ServiceWorkerResponseWriter(response_id, disk_cache()));
531 } 531 }
532 532
533 scoped_ptr<ServiceWorkerResponseMetadataWriter> 533 scoped_ptr<ServiceWorkerResponseMetadataWriter>
534 ServiceWorkerStorage::CreateResponseMetadataWriter(int64 response_id) { 534 ServiceWorkerStorage::CreateResponseMetadataWriter(int64 response_id) {
535 return make_scoped_ptr( 535 return make_scoped_ptr(
536 new ServiceWorkerResponseMetadataWriter(response_id, disk_cache())); 536 new ServiceWorkerResponseMetadataWriter(response_id, disk_cache()));
537 } 537 }
538 538
539 void ServiceWorkerStorage::StoreUncommittedResponseId(int64 id) { 539 void ServiceWorkerStorage::StoreUncommittedResourceId(int64 resource_id) {
540 DCHECK_NE(kInvalidServiceWorkerResponseId, id); 540 DCHECK_NE(kInvalidServiceWorkerResponseId, resource_id);
541 DCHECK_EQ(INITIALIZED, state_); 541 DCHECK_EQ(INITIALIZED, state_);
542 542
543 if (!has_checked_for_stale_resources_) 543 if (!has_checked_for_stale_resources_)
544 DeleteStaleResources(); 544 DeleteStaleResources();
545 545
546 database_task_manager_->GetTaskRunner()->PostTask( 546 PostTaskAndReplyWithResult(
547 FROM_HERE, 547 database_task_manager_->GetTaskRunner(), FROM_HERE,
548 base::Bind(base::IgnoreResult( 548 base::Bind(&ServiceWorkerDatabase::WriteUncommittedResourceIds,
549 &ServiceWorkerDatabase::WriteUncommittedResourceIds), 549 base::Unretained(database_.get()),
550 base::Unretained(database_.get()), 550 std::set<int64>(&resource_id, &resource_id + 1)),
551 std::set<int64>(&id, &id + 1))); 551 base::Bind(&ServiceWorkerStorage::DidAccessDatabase,
552 weak_factory_.GetWeakPtr()));
552 } 553 }
553 554
554 void ServiceWorkerStorage::DoomUncommittedResponse(int64 id) { 555 void ServiceWorkerStorage::ClearUncommittedResourceId(int64 resource_id) {
555 DCHECK_NE(kInvalidServiceWorkerResponseId, id); 556 DCHECK_NE(kInvalidServiceWorkerResponseId, resource_id);
556 database_task_manager_->GetTaskRunner()->PostTask( 557 PostTaskAndReplyWithResult(
557 FROM_HERE, 558 database_task_manager_->GetTaskRunner(), FROM_HERE,
558 base::Bind(base::IgnoreResult( 559 base::Bind(&ServiceWorkerDatabase::ClearUncommittedResourceIds,
559 &ServiceWorkerDatabase::PurgeUncommittedResourceIds), 560 base::Unretained(database_.get()),
560 base::Unretained(database_.get()), 561 std::set<int64>(&resource_id, &resource_id + 1)),
561 std::set<int64>(&id, &id + 1))); 562 base::Bind(&ServiceWorkerStorage::DidAccessDatabase,
562 StartPurgingResources(std::vector<int64>(1, id)); 563 weak_factory_.GetWeakPtr()));
nhiroki 2015/10/07 06:10:27 |id| should not be stored in the diskcache yet, so
563 } 564 }
564 565
565 void ServiceWorkerStorage::StoreUserData( 566 void ServiceWorkerStorage::StoreUserData(
566 int64 registration_id, 567 int64 registration_id,
567 const GURL& origin, 568 const GURL& origin,
568 const std::string& key, 569 const std::string& key,
569 const std::string& data, 570 const std::string& data,
570 const StatusCallback& callback) { 571 const StatusCallback& callback) {
571 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; 572 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_;
572 if (IsDisabled()) { 573 if (IsDisabled()) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 ServiceWorkerStatusCode status) { 727 ServiceWorkerStatusCode status) {
727 installing_registrations_.erase(registration->id()); 728 installing_registrations_.erase(registration->id());
728 if (status != SERVICE_WORKER_OK && version) { 729 if (status != SERVICE_WORKER_OK && version) {
729 ResourceList resources; 730 ResourceList resources;
730 version->script_cache_map()->GetResources(&resources); 731 version->script_cache_map()->GetResources(&resources);
731 732
732 std::set<int64> ids; 733 std::set<int64> ids;
733 for (const auto& resource : resources) 734 for (const auto& resource : resources)
734 ids.insert(resource.resource_id); 735 ids.insert(resource.resource_id);
735 736
736 database_task_manager_->GetTaskRunner()->PostTask( 737 PostTaskAndReplyWithResult(
737 FROM_HERE, 738 database_task_manager_->GetTaskRunner(), FROM_HERE,
738 base::Bind(base::IgnoreResult( 739 base::Bind(
739 &ServiceWorkerDatabase::PurgeUncommittedResourceIds), 740 &ServiceWorkerDatabase::MoveResourceIdsFromUncommittedToPurgeable,
740 base::Unretained(database_.get()), 741 base::Unretained(database_.get()), ids),
741 ids)); 742 base::Bind(&ServiceWorkerStorage::DidAccessDatabase,
743 weak_factory_.GetWeakPtr()));
742 } 744 }
743 } 745 }
744 746
745 void ServiceWorkerStorage::NotifyUninstallingRegistration( 747 void ServiceWorkerStorage::NotifyUninstallingRegistration(
746 ServiceWorkerRegistration* registration) { 748 ServiceWorkerRegistration* registration) {
747 DCHECK(uninstalling_registrations_.find(registration->id()) == 749 DCHECK(uninstalling_registrations_.find(registration->id()) ==
748 uninstalling_registrations_.end()); 750 uninstalling_registrations_.end());
749 uninstalling_registrations_[registration->id()] = registration; 751 uninstalling_registrations_[registration->id()] = registration;
750 } 752 }
751 753
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 -deleted_version.resources_total_size_bytes); 1147 -deleted_version.resources_total_size_bytes);
1146 } 1148 }
1147 if (origin_is_deletable) 1149 if (origin_is_deletable)
1148 registered_origins_.erase(params.origin); 1150 registered_origins_.erase(params.origin);
1149 params.callback.Run(SERVICE_WORKER_OK); 1151 params.callback.Run(SERVICE_WORKER_OK);
1150 1152
1151 if (!context_->GetLiveVersion(deleted_version.version_id)) 1153 if (!context_->GetLiveVersion(deleted_version.version_id))
1152 StartPurgingResources(newly_purgeable_resources); 1154 StartPurgingResources(newly_purgeable_resources);
1153 } 1155 }
1154 1156
1157 void ServiceWorkerStorage::DidAccessDatabase(
1158 ServiceWorkerDatabase::Status status) {
1159 if (status != ServiceWorkerDatabase::STATUS_OK)
1160 ScheduleDeleteAndStartOver();
1161 }
1162
1155 void ServiceWorkerStorage::DidStoreUserData( 1163 void ServiceWorkerStorage::DidStoreUserData(
1156 const StatusCallback& callback, 1164 const StatusCallback& callback,
1157 ServiceWorkerDatabase::Status status) { 1165 ServiceWorkerDatabase::Status status) {
1158 // |status| can be NOT_FOUND when the associated registration did not exist in 1166 // |status| can be NOT_FOUND when the associated registration did not exist in
1159 // the database. In the case, we don't have to schedule the corruption 1167 // the database. In the case, we don't have to schedule the corruption
1160 // recovery. 1168 // recovery.
1161 if (status != ServiceWorkerDatabase::STATUS_OK && 1169 if (status != ServiceWorkerDatabase::STATUS_OK &&
1162 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 1170 status != ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
1163 ScheduleDeleteAndStartOver(); 1171 ScheduleDeleteAndStartOver();
1164 } 1172 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 ServiceWorkerDatabase::Status status = 1503 ServiceWorkerDatabase::Status status =
1496 database->GetUncommittedResourceIds(&ids); 1504 database->GetUncommittedResourceIds(&ids);
1497 if (status != ServiceWorkerDatabase::STATUS_OK) { 1505 if (status != ServiceWorkerDatabase::STATUS_OK) {
1498 original_task_runner->PostTask( 1506 original_task_runner->PostTask(
1499 FROM_HERE, 1507 FROM_HERE,
1500 base::Bind( 1508 base::Bind(
1501 callback, std::vector<int64>(ids.begin(), ids.end()), status)); 1509 callback, std::vector<int64>(ids.begin(), ids.end()), status));
1502 return; 1510 return;
1503 } 1511 }
1504 1512
1505 status = database->PurgeUncommittedResourceIds(ids); 1513 status = database->MoveResourceIdsFromUncommittedToPurgeable(ids);
1506 if (status != ServiceWorkerDatabase::STATUS_OK) { 1514 if (status != ServiceWorkerDatabase::STATUS_OK) {
1507 original_task_runner->PostTask( 1515 original_task_runner->PostTask(
1508 FROM_HERE, 1516 FROM_HERE,
1509 base::Bind( 1517 base::Bind(
1510 callback, std::vector<int64>(ids.begin(), ids.end()), status)); 1518 callback, std::vector<int64>(ids.begin(), ids.end()), status));
1511 return; 1519 return;
1512 } 1520 }
1513 1521
1514 ids.clear(); 1522 ids.clear();
1515 status = database->GetPurgeableResourceIds(&ids); 1523 status = database->GetPurgeableResourceIds(&ids);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1828 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1821 return; 1829 return;
1822 } 1830 }
1823 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1831 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1824 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( 1832 ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
1825 ServiceWorkerMetrics::DELETE_OK); 1833 ServiceWorkerMetrics::DELETE_OK);
1826 callback.Run(SERVICE_WORKER_OK); 1834 callback.Run(SERVICE_WORKER_OK);
1827 } 1835 }
1828 1836
1829 } // namespace content 1837 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698