Chromium Code Reviews| Index: content/browser/service_worker/service_worker_database.cc |
| diff --git a/content/browser/service_worker/service_worker_database.cc b/content/browser/service_worker/service_worker_database.cc |
| index 535b6a402700aefe223ee0b4d021fdfb54e32c03..f93413de05bdd3b4b67825790cc53475e5a1e195 100644 |
| --- a/content/browser/service_worker/service_worker_database.cc |
| +++ b/content/browser/service_worker/service_worker_database.cc |
| @@ -1029,6 +1029,67 @@ ServiceWorkerDatabase::ReadUserDataForAllRegistrations( |
| return status; |
| } |
| +ServiceWorkerDatabase::Status |
| +ServiceWorkerDatabase::ReadUserDataForAllRegistrationsByKeyPrefix( |
|
nhiroki
2017/05/09 23:49:15
Can you add unittests for this API?
zino
2017/05/10 15:57:42
Done.
|
| + 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
|
| + std::vector<std::pair<int64_t, std::string>>* user_data) { |
| + DCHECK(sequence_checker_.CalledOnValidSequence()); |
| + DCHECK(user_data->empty()); |
| + |
| + Status status = LazyOpen(false); |
| + if (IsNewOrNonexistentDatabase(status)) |
| + return STATUS_OK; |
| + if (status != STATUS_OK) |
| + return status; |
| + |
| + std::string key_prefix = kRegHasUserDataKeyPrefix + user_data_name_prefix; |
| + { |
| + std::unique_ptr<leveldb::Iterator> itr( |
| + db_->NewIterator(leveldb::ReadOptions())); |
| + for (itr->Seek(key_prefix); itr->Valid(); itr->Next()) { |
| + status = LevelDBStatusToStatus(itr->status()); |
| + if (status != STATUS_OK) { |
| + user_data->clear(); |
| + break; |
| + } |
| + |
| + if (!itr->key().starts_with(key_prefix)) |
| + break; |
| + |
| + std::string user_data_name_with_id; |
| + if (!RemovePrefix(itr->key().ToString(), kRegHasUserDataKeyPrefix, |
| + &user_data_name_with_id)) { |
| + break; |
| + } |
| + |
| + 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.
|
| + user_data_name_with_id, base::StringPrintf("%c", kKeySeparator), |
| + base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| + 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.
|
| + |
| + int64_t registration_id; |
| + status = ParseId(splited_data[1], ®istration_id); |
| + if (status != STATUS_OK) { |
| + user_data->clear(); |
| + break; |
| + } |
| + |
| + std::string value; |
| + status = LevelDBStatusToStatus(db_->Get( |
| + leveldb::ReadOptions(), |
| + CreateUserDataKey(registration_id, splited_data[0]), &value)); |
| + if (status != STATUS_OK) { |
| + user_data->clear(); |
| + break; |
| + } |
| + user_data->push_back(std::make_pair(registration_id, value)); |
| + } |
| + } |
| + |
| + HandleReadResult(FROM_HERE, status); |
| + return status; |
| +} |
| + |
| ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetUncommittedResourceIds( |
| std::set<int64_t>* ids) { |
| return ReadResourceIds(kUncommittedResIdKeyPrefix, ids); |