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 (auto origin : origins) { |
michaeln
2014/10/08 01:22:27
whooohoooo, hooray for c++ 11
per the notes at ht
falken
2014/10/08 02:36:44
I see. Done.
| |
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 (std::vector<RegistrationData>::const_iterator itr = | |
715 registrations.begin(); itr != registrations.end(); ++itr) { | |
michaeln
2014/10/08 01:22:27
oh, care to for for range'ify this loop too?
falken
2014/10/08 02:36:44
Done.
| |
716 batch.Delete(CreateRegistrationKey(itr->registration_id, origin)); | |
717 status = DeleteResourceRecords( | |
718 itr->version_id, newly_purgeable_resources, &batch); | |
719 if (status != STATUS_OK) | |
720 return status; | |
721 } | |
720 } | 722 } |
721 | 723 |
722 return WriteBatch(&batch); | 724 return WriteBatch(&batch); |
723 } | 725 } |
724 | 726 |
725 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DestroyDatabase() { | 727 ServiceWorkerDatabase::Status ServiceWorkerDatabase::DestroyDatabase() { |
726 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); | 728 DCHECK(sequence_checker_.CalledOnValidSequencedThread()); |
727 Disable(FROM_HERE, STATUS_OK); | 729 Disable(FROM_HERE, STATUS_OK); |
728 return LevelDBStatusToStatus( | 730 return LevelDBStatusToStatus( |
729 leveldb::DestroyDB(path_.AsUTF8Unsafe(), leveldb::Options())); | 731 leveldb::DestroyDB(path_.AsUTF8Unsafe(), leveldb::Options())); |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1113 | 1115 |
1114 void ServiceWorkerDatabase::HandleWriteResult( | 1116 void ServiceWorkerDatabase::HandleWriteResult( |
1115 const tracked_objects::Location& from_here, | 1117 const tracked_objects::Location& from_here, |
1116 Status status) { | 1118 Status status) { |
1117 if (status != STATUS_OK) | 1119 if (status != STATUS_OK) |
1118 Disable(from_here, status); | 1120 Disable(from_here, status); |
1119 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1121 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1120 } | 1122 } |
1121 | 1123 |
1122 } // namespace content | 1124 } // namespace content |
OLD | NEW |