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

Side by Side Diff: extensions/browser/api/storage/storage_api.cc

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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 "extensions/browser/api/storage/storage_api.h" 5 #include "extensions/browser/api/storage/storage_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 } // namespace 143 } // namespace
144 144
145 ExtensionFunction::ResponseValue StorageStorageAreaGetFunction::RunWithStorage( 145 ExtensionFunction::ResponseValue StorageStorageAreaGetFunction::RunWithStorage(
146 ValueStore* storage) { 146 ValueStore* storage) {
147 base::Value* input = NULL; 147 base::Value* input = NULL;
148 if (!args_->Get(0, &input)) 148 if (!args_->Get(0, &input))
149 return BadMessage(); 149 return BadMessage();
150 150
151 switch (input->GetType()) { 151 switch (input->GetType()) {
152 case base::Value::TYPE_NULL: 152 case base::Value::Type::NONE:
153 return UseReadResult(storage->Get()); 153 return UseReadResult(storage->Get());
154 154
155 case base::Value::TYPE_STRING: { 155 case base::Value::Type::STRING: {
156 std::string as_string; 156 std::string as_string;
157 input->GetAsString(&as_string); 157 input->GetAsString(&as_string);
158 return UseReadResult(storage->Get(as_string)); 158 return UseReadResult(storage->Get(as_string));
159 } 159 }
160 160
161 case base::Value::TYPE_LIST: { 161 case base::Value::Type::LIST: {
162 std::vector<std::string> as_string_list; 162 std::vector<std::string> as_string_list;
163 AddAllStringValues(*static_cast<base::ListValue*>(input), 163 AddAllStringValues(*static_cast<base::ListValue*>(input),
164 &as_string_list); 164 &as_string_list);
165 return UseReadResult(storage->Get(as_string_list)); 165 return UseReadResult(storage->Get(as_string_list));
166 } 166 }
167 167
168 case base::Value::TYPE_DICTIONARY: { 168 case base::Value::Type::DICTIONARY: {
169 base::DictionaryValue* as_dict = 169 base::DictionaryValue* as_dict =
170 static_cast<base::DictionaryValue*>(input); 170 static_cast<base::DictionaryValue*>(input);
171 ValueStore::ReadResult result = storage->Get(GetKeys(*as_dict)); 171 ValueStore::ReadResult result = storage->Get(GetKeys(*as_dict));
172 if (!result->status().ok()) { 172 if (!result->status().ok()) {
173 return UseReadResult(std::move(result)); 173 return UseReadResult(std::move(result));
174 } 174 }
175 175
176 base::DictionaryValue* with_default_values = as_dict->DeepCopy(); 176 base::DictionaryValue* with_default_values = as_dict->DeepCopy();
177 with_default_values->MergeDictionary(&result->settings()); 177 with_default_values->MergeDictionary(&result->settings());
178 return UseReadResult(ValueStore::MakeReadResult( 178 return UseReadResult(ValueStore::MakeReadResult(
179 base::WrapUnique(with_default_values), result->status())); 179 base::WrapUnique(with_default_values), result->status()));
180 } 180 }
181 181
182 default: 182 default:
183 return BadMessage(); 183 return BadMessage();
184 } 184 }
185 } 185 }
186 186
187 ExtensionFunction::ResponseValue 187 ExtensionFunction::ResponseValue
188 StorageStorageAreaGetBytesInUseFunction::RunWithStorage(ValueStore* storage) { 188 StorageStorageAreaGetBytesInUseFunction::RunWithStorage(ValueStore* storage) {
189 base::Value* input = NULL; 189 base::Value* input = NULL;
190 if (!args_->Get(0, &input)) 190 if (!args_->Get(0, &input))
191 return BadMessage(); 191 return BadMessage();
192 192
193 size_t bytes_in_use = 0; 193 size_t bytes_in_use = 0;
194 194
195 switch (input->GetType()) { 195 switch (input->GetType()) {
196 case base::Value::TYPE_NULL: 196 case base::Value::Type::NONE:
197 bytes_in_use = storage->GetBytesInUse(); 197 bytes_in_use = storage->GetBytesInUse();
198 break; 198 break;
199 199
200 case base::Value::TYPE_STRING: { 200 case base::Value::Type::STRING: {
201 std::string as_string; 201 std::string as_string;
202 input->GetAsString(&as_string); 202 input->GetAsString(&as_string);
203 bytes_in_use = storage->GetBytesInUse(as_string); 203 bytes_in_use = storage->GetBytesInUse(as_string);
204 break; 204 break;
205 } 205 }
206 206
207 case base::Value::TYPE_LIST: { 207 case base::Value::Type::LIST: {
208 std::vector<std::string> as_string_list; 208 std::vector<std::string> as_string_list;
209 AddAllStringValues(*static_cast<base::ListValue*>(input), 209 AddAllStringValues(*static_cast<base::ListValue*>(input),
210 &as_string_list); 210 &as_string_list);
211 bytes_in_use = storage->GetBytesInUse(as_string_list); 211 bytes_in_use = storage->GetBytesInUse(as_string_list);
212 break; 212 break;
213 } 213 }
214 214
215 default: 215 default:
216 return BadMessage(); 216 return BadMessage();
217 } 217 }
(...skipping 15 matching lines...) Expand all
233 GetModificationQuotaLimitHeuristics(heuristics); 233 GetModificationQuotaLimitHeuristics(heuristics);
234 } 234 }
235 235
236 ExtensionFunction::ResponseValue 236 ExtensionFunction::ResponseValue
237 StorageStorageAreaRemoveFunction::RunWithStorage(ValueStore* storage) { 237 StorageStorageAreaRemoveFunction::RunWithStorage(ValueStore* storage) {
238 base::Value* input = NULL; 238 base::Value* input = NULL;
239 if (!args_->Get(0, &input)) 239 if (!args_->Get(0, &input))
240 return BadMessage(); 240 return BadMessage();
241 241
242 switch (input->GetType()) { 242 switch (input->GetType()) {
243 case base::Value::TYPE_STRING: { 243 case base::Value::Type::STRING: {
244 std::string as_string; 244 std::string as_string;
245 input->GetAsString(&as_string); 245 input->GetAsString(&as_string);
246 return UseWriteResult(storage->Remove(as_string)); 246 return UseWriteResult(storage->Remove(as_string));
247 } 247 }
248 248
249 case base::Value::TYPE_LIST: { 249 case base::Value::Type::LIST: {
250 std::vector<std::string> as_string_list; 250 std::vector<std::string> as_string_list;
251 AddAllStringValues(*static_cast<base::ListValue*>(input), 251 AddAllStringValues(*static_cast<base::ListValue*>(input),
252 &as_string_list); 252 &as_string_list);
253 return UseWriteResult(storage->Remove(as_string_list)); 253 return UseWriteResult(storage->Remove(as_string_list));
254 } 254 }
255 255
256 default: 256 default:
257 return BadMessage(); 257 return BadMessage();
258 } 258 }
259 } 259 }
260 260
261 void StorageStorageAreaRemoveFunction::GetQuotaLimitHeuristics( 261 void StorageStorageAreaRemoveFunction::GetQuotaLimitHeuristics(
262 QuotaLimitHeuristics* heuristics) const { 262 QuotaLimitHeuristics* heuristics) const {
263 GetModificationQuotaLimitHeuristics(heuristics); 263 GetModificationQuotaLimitHeuristics(heuristics);
264 } 264 }
265 265
266 ExtensionFunction::ResponseValue 266 ExtensionFunction::ResponseValue
267 StorageStorageAreaClearFunction::RunWithStorage(ValueStore* storage) { 267 StorageStorageAreaClearFunction::RunWithStorage(ValueStore* storage) {
268 return UseWriteResult(storage->Clear()); 268 return UseWriteResult(storage->Clear());
269 } 269 }
270 270
271 void StorageStorageAreaClearFunction::GetQuotaLimitHeuristics( 271 void StorageStorageAreaClearFunction::GetQuotaLimitHeuristics(
272 QuotaLimitHeuristics* heuristics) const { 272 QuotaLimitHeuristics* heuristics) const {
273 GetModificationQuotaLimitHeuristics(heuristics); 273 GetModificationQuotaLimitHeuristics(heuristics);
274 } 274 }
275 275
276 } // namespace extensions 276 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698