| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_database.h" | 5 #include "content/browser/service_worker/service_worker_database.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 Status status = DeleteResourceIdsInBatch( | 680 Status status = DeleteResourceIdsInBatch( |
| 681 kUncommittedResIdKeyPrefix, ids, &batch); | 681 kUncommittedResIdKeyPrefix, ids, &batch); |
| 682 if (status != STATUS_OK) | 682 if (status != STATUS_OK) |
| 683 return status; | 683 return status; |
| 684 status = WriteResourceIdsInBatch(kPurgeableResIdKeyPrefix, ids, &batch); | 684 status = WriteResourceIdsInBatch(kPurgeableResIdKeyPrefix, ids, &batch); |
| 685 if (status != STATUS_OK) | 685 if (status != STATUS_OK) |
| 686 return status; | 686 return status; |
| 687 return WriteBatch(&batch); | 687 return WriteBatch(&batch); |
| 688 } | 688 } |
| 689 | 689 |
| 690 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteAllDataForOrigin( | 690 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DeleteAllDataForOrigins( |
| 691 const GURL& origin, | 691 const std::set<GURL>& origins, |
| 692 std::vector<int64>* newly_purgeable_resources) { | 692 std::vector<int64>* newly_purgeable_resources) { |
| 693 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 693 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 694 Status status = LazyOpen(false); | 694 Status status = LazyOpen(false); |
| 695 if (IsNewOrNonexistentDatabase(status)) | 695 if (IsNewOrNonexistentDatabase(status)) |
| 696 return STATUS_OK; | 696 return STATUS_OK; |
| 697 if (status != STATUS_OK) | 697 if (status != STATUS_OK) |
| 698 return status; | 698 return status; |
| 699 if (!origin.is_valid()) | |
| 700 return STATUS_ERROR_FAILED; | |
| 701 | |
| 702 leveldb::WriteBatch batch; | 699 leveldb::WriteBatch batch; |
| 703 | 700 |
| 704 // Delete from the unique origin list. | 701 for (const GURL& origin : origins) { |
| 705 batch.Delete(CreateUniqueOriginKey(origin)); | 702 if (!origin.is_valid()) |
| 703 return STATUS_ERROR_FAILED; |
| 706 | 704 |
| 707 std::vector<RegistrationData> registrations; | 705 // Delete from the unique origin list. |
| 708 status = GetRegistrationsForOrigin(origin, ®istrations); | 706 batch.Delete(CreateUniqueOriginKey(origin)); |
| 709 if (status != STATUS_OK) | |
| 710 return status; | |
| 711 | 707 |
| 712 // Delete registrations and resource records. | 708 std::vector<RegistrationData> registrations; |
| 713 for (std::vector<RegistrationData>::const_iterator itr = | 709 status = GetRegistrationsForOrigin(origin, ®istrations); |
| 714 registrations.begin(); itr != registrations.end(); ++itr) { | |
| 715 batch.Delete(CreateRegistrationKey(itr->registration_id, origin)); | |
| 716 status = DeleteResourceRecords( | |
| 717 itr->version_id, newly_purgeable_resources, &batch); | |
| 718 if (status != STATUS_OK) | 710 if (status != STATUS_OK) |
| 719 return status; | 711 return status; |
| 712 |
| 713 // Delete registrations and resource records. |
| 714 for (const RegistrationData& data : registrations) { |
| 715 batch.Delete(CreateRegistrationKey(data.registration_id, origin)); |
| 716 status = DeleteResourceRecords( |
| 717 data.version_id, newly_purgeable_resources, &batch); |
| 718 if (status != STATUS_OK) |
| 719 return status; |
| 720 } |
| 720 } | 721 } |
| 721 | 722 |
| 722 return WriteBatch(&batch); | 723 return WriteBatch(&batch); |
| 723 } | 724 } |
| 724 | 725 |
| 725 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DestroyDatabase() { | 726 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DestroyDatabase() { |
| 726 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 727 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
| 727 Disable(FROM_HERE, STATUS_OK); | 728 Disable(FROM_HERE, STATUS_OK); |
| 728 return LevelDBStatusToStatus( | 729 return LevelDBStatusToStatus( |
| 729 leveldb::DestroyDB(path_.AsUTF8Unsafe(), leveldb::Options())); | 730 leveldb::DestroyDB(path_.AsUTF8Unsafe(), leveldb::Options())); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 | 1114 |
| 1114 void ServiceWorkerDatabase::HandleWriteResult( | 1115 void ServiceWorkerDatabase::HandleWriteResult( |
| 1115 const tracked_objects::Location& from_here, | 1116 const tracked_objects::Location& from_here, |
| 1116 Status status) { | 1117 Status status) { |
| 1117 if (status != STATUS_OK) | 1118 if (status != STATUS_OK) |
| 1118 Disable(from_here, status); | 1119 Disable(from_here, status); |
| 1119 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1120 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1120 } | 1121 } |
| 1121 | 1122 |
| 1122 } // namespace content | 1123 } // namespace content |
| OLD | NEW |