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 <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 Loading... | |
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( | |
nhiroki
2017/05/09 23:49:15
Can you add unittests for this API?
zino
2017/05/10 15:57:42
Done.
| |
1034 const std::string& user_data_name_prefix, | |
nhiroki
2017/05/09 23:49:15
Can you explain key/value format that we're about
zino
2017/05/10 15:57:43
Unfortunately, there is no latest version of desig
please use gerrit instead
2017/05/10 18:14:35
Please put this information in the design doc. Lin
zino
2017/05/10 18:36:32
I don't disagree but I didn't find any past case i
| |
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> splited_data = base::SplitString( | |
please use gerrit instead
2017/05/09 18:01:47
s/splited_data/parts/
zino
2017/05/10 15:57:42
Done.
| |
1066 user_data_name_with_id, base::StringPrintf("%c", kKeySeparator), | |
1067 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | |
1068 DCHECK(splited_data.size() == 2); | |
please use gerrit instead
2017/05/09 18:01:47
Database can be corrupted on disk, so don't make a
nhiroki
2017/05/09 23:49:15
+1 to erase the corrupt data. Maybe it's like this
zino
2017/05/10 15:57:43
Done.
| |
1069 | |
1070 int64_t registration_id; | |
1071 status = ParseId(splited_data[1], ®istration_id); | |
1072 if (status != STATUS_OK) { | |
1073 user_data->clear(); | |
1074 break; | |
1075 } | |
1076 | |
1077 std::string value; | |
1078 status = LevelDBStatusToStatus(db_->Get( | |
1079 leveldb::ReadOptions(), | |
1080 CreateUserDataKey(registration_id, splited_data[0]), &value)); | |
1081 if (status != STATUS_OK) { | |
1082 user_data->clear(); | |
1083 break; | |
1084 } | |
1085 user_data->push_back(std::make_pair(registration_id, value)); | |
1086 } | |
1087 } | |
1088 | |
1089 HandleReadResult(FROM_HERE, status); | |
1090 return status; | |
1091 } | |
1092 | |
1032 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetUncommittedResourceIds( | 1093 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetUncommittedResourceIds( |
1033 std::set<int64_t>* ids) { | 1094 std::set<int64_t>* ids) { |
1034 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids); | 1095 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids); |
1035 } | 1096 } |
1036 | 1097 |
1037 ServiceWorkerDatabase::Status | 1098 ServiceWorkerDatabase::Status |
1038 ServiceWorkerDatabase::WriteUncommittedResourceIds( | 1099 ServiceWorkerDatabase::WriteUncommittedResourceIds( |
1039 const std::set<int64_t>& ids) { | 1100 const std::set<int64_t>& ids) { |
1040 leveldb::WriteBatch batch; | 1101 leveldb::WriteBatch batch; |
1041 Status status = | 1102 Status status = |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1764 if (status != STATUS_OK) | 1825 if (status != STATUS_OK) |
1765 Disable(from_here, status); | 1826 Disable(from_here, status); |
1766 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1827 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
1767 } | 1828 } |
1768 | 1829 |
1769 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1830 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
1770 return path_.empty(); | 1831 return path_.empty(); |
1771 } | 1832 } |
1772 | 1833 |
1773 } // namespace content | 1834 } // namespace content |
OLD | NEW |