Chromium Code Reviews| 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( | |
| 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 DCHECK(parts.size() == 2); | |
|
nhiroki
2017/05/11 07:12:40
Can you remove this check because we already check
zino
2017/05/11 14:21:04
Done.
| |
| 1074 | |
| 1075 int64_t registration_id; | |
| 1076 status = ParseId(parts[1], ®istration_id); | |
| 1077 if (status != STATUS_OK) { | |
| 1078 user_data->clear(); | |
| 1079 break; | |
| 1080 } | |
| 1081 | |
| 1082 std::string value; | |
| 1083 status = LevelDBStatusToStatus( | |
| 1084 db_->Get(leveldb::ReadOptions(), | |
| 1085 CreateUserDataKey(registration_id, parts[0]), &value)); | |
| 1086 if (status != STATUS_OK) { | |
| 1087 user_data->clear(); | |
| 1088 break; | |
| 1089 } | |
| 1090 user_data->push_back(std::make_pair(registration_id, value)); | |
| 1091 } | |
| 1092 } | |
| 1093 | |
| 1094 HandleReadResult(FROM_HERE, status); | |
| 1095 return status; | |
| 1096 } | |
| 1097 | |
| 1032 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetUncommittedResourceIds( | 1098 ServiceWorkerDatabase::Status ServiceWorkerDatabase::GetUncommittedResourceIds( |
| 1033 std::set<int64_t>* ids) { | 1099 std::set<int64_t>* ids) { |
| 1034 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids); | 1100 return ReadResourceIds(kUncommittedResIdKeyPrefix, ids); |
| 1035 } | 1101 } |
| 1036 | 1102 |
| 1037 ServiceWorkerDatabase::Status | 1103 ServiceWorkerDatabase::Status |
| 1038 ServiceWorkerDatabase::WriteUncommittedResourceIds( | 1104 ServiceWorkerDatabase::WriteUncommittedResourceIds( |
| 1039 const std::set<int64_t>& ids) { | 1105 const std::set<int64_t>& ids) { |
| 1040 leveldb::WriteBatch batch; | 1106 leveldb::WriteBatch batch; |
| 1041 Status status = | 1107 Status status = |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1764 if (status != STATUS_OK) | 1830 if (status != STATUS_OK) |
| 1765 Disable(from_here, status); | 1831 Disable(from_here, status); |
| 1766 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1832 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1767 } | 1833 } |
| 1768 | 1834 |
| 1769 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1835 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
| 1770 return path_.empty(); | 1836 return path_.empty(); |
| 1771 } | 1837 } |
| 1772 | 1838 |
| 1773 } // namespace content | 1839 } // namespace content |
| OLD | NEW |