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

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

Issue 2873683002: PaymentHandler: Implement GetAllPaymentApps(). (Closed)
Patch Set: installed -> stored in public Created 3 years, 7 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 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 <utility> 7 #include <utility>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 break; 1022 break;
1023 } 1023 }
1024 user_data->push_back(std::make_pair(registration_id, value)); 1024 user_data->push_back(std::make_pair(registration_id, value));
1025 } 1025 }
1026 } 1026 }
1027 1027
1028 HandleReadResult(FROM_HERE, status); 1028 HandleReadResult(FROM_HERE, status);
1029 return status; 1029 return status;
1030 } 1030 }
1031 1031
1032 ServiceWorkerDatabase::Status
1033 ServiceWorkerDatabase::ReadUserDataForAllRegistrationsByKeyPrefix(
1034 const std::string& user_data_name_prefix,
1035 std::vector<std::pair<int64_t, std::string>>* user_data) {
1036 DCHECK(sequence_checker_.CalledOnValidSequence());
1037 DCHECK(user_data->empty());
1038
1039 Status status = LazyOpen(false);
1040 if (IsNewOrNonexistentDatabase(status))
1041 return STATUS_OK;
1042 if (status != STATUS_OK)
1043 return status;
1044
1045 std::string key_prefix = kRegHasUserDataKeyPrefix + user_data_name_prefix;
1046 {
1047 std::unique_ptr<leveldb::Iterator> itr(
1048 db_->NewIterator(leveldb::ReadOptions()));
1049 for (itr->Seek(key_prefix); itr->Valid(); itr->Next()) {
1050 status = LevelDBStatusToStatus(itr->status());
1051 if (status != STATUS_OK) {
1052 user_data->clear();
1053 break;
1054 }
1055
1056 if (!itr->key().starts_with(key_prefix))
1057 break;
1058
1059 std::string user_data_name_with_id;
1060 if (!RemovePrefix(itr->key().ToString(), kRegHasUserDataKeyPrefix,
1061 &user_data_name_with_id)) {
1062 break;
1063 }
1064
1065 std::vector<std::string> parts = base::SplitString(
1066 user_data_name_with_id, base::StringPrintf("%c", kKeySeparator),
1067 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
1068 if (parts.size() != 2) {
1069 status = STATUS_ERROR_CORRUPTED;
1070 user_data->clear();
1071 break;
1072 }
1073
1074 int64_t registration_id;
1075 status = ParseId(parts[1], &registration_id);
1076 if (status != STATUS_OK) {
1077 user_data->clear();
1078 break;
1079 }
1080
1081 std::string value;
1082 status = LevelDBStatusToStatus(
1083 db_->Get(leveldb::ReadOptions(),
1084 CreateUserDataKey(registration_id, parts[0]), &value));
1085 if (status != STATUS_OK) {
1086 user_data->clear();
1087 break;
1088 }
1089 user_data->push_back(std::make_pair(registration_id, value));
1090 }
1091 }
1092
1093 HandleReadResult(FROM_HERE, status);
1094 return status;
1095 }
1096
1032 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetUncommittedResourceIds( 1097 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetUncommittedResourceIds(
1033 std::set<int64_t>* ids) { 1098 std::set<int64_t>* ids) {
1034 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids); 1099 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids);
1035 } 1100 }
1036 1101
1037 ServiceWorkerDatabase::Status 1102 ServiceWorkerDatabase::Status
1038 ServiceWorkerDatabase::WriteUncommittedResourceIds( 1103 ServiceWorkerDatabase::WriteUncommittedResourceIds(
1039 const std::set<int64_t>& ids) { 1104 const std::set<int64_t>& ids) {
1040 leveldb::WriteBatch batch; 1105 leveldb::WriteBatch batch;
1041 Status status = 1106 Status status =
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1764 if (status != STATUS_OK) 1829 if (status != STATUS_OK)
1765 Disable(from_here, status); 1830 Disable(from_here, status);
1766 ServiceWorkerMetrics::CountWriteDatabaseResult(status); 1831 ServiceWorkerMetrics::CountWriteDatabaseResult(status);
1767 } 1832 }
1768 1833
1769 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { 1834 bool ServiceWorkerDatabase::IsDatabaseInMemory() const {
1770 return path_.empty(); 1835 return path_.empty();
1771 } 1836 }
1772 1837
1773 } // namespace content 1838 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698