OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/settings/settings_api.h" | 5 #include "chrome/browser/extensions/api/storage/storage_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/storage/settings_frontend.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extensions_quota_service.h" | 15 #include "chrome/browser/extensions/extensions_quota_service.h" |
15 #include "chrome/browser/extensions/settings/settings_frontend.h" | |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/extensions/api/storage.h" | 17 #include "chrome/common/extensions/api/storage.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 | 19 |
20 namespace extensions { | 20 namespace extensions { |
21 | 21 |
22 using content::BrowserThread; | 22 using content::BrowserThread; |
23 | 23 |
24 namespace { | 24 namespace { |
25 const char kUnsupportedArgumentType[] = "Unsupported argument type"; | 25 const char kUnsupportedArgumentType[] = "Unsupported argument type"; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 heuristics->push_back( | 155 heuristics->push_back( |
156 new ExtensionsQuotaService::SustainedLimit( | 156 new ExtensionsQuotaService::SustainedLimit( |
157 base::TimeDelta::FromMinutes(10), | 157 base::TimeDelta::FromMinutes(10), |
158 shortLimitConfig, | 158 shortLimitConfig, |
159 new QuotaLimitHeuristic::SingletonBucketMapper(), | 159 new QuotaLimitHeuristic::SingletonBucketMapper(), |
160 "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE")); | 160 "MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE")); |
161 }; | 161 }; |
162 | 162 |
163 } // namespace | 163 } // namespace |
164 | 164 |
165 bool GetSettingsFunction::RunWithStorage(ValueStore* storage) { | 165 bool StorageGetFunction::RunWithStorage(ValueStore* storage) { |
166 Value* input = NULL; | 166 Value* input = NULL; |
167 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); | 167 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); |
168 | 168 |
169 switch (input->GetType()) { | 169 switch (input->GetType()) { |
170 case Value::TYPE_NULL: | 170 case Value::TYPE_NULL: |
171 return UseReadResult(storage->Get()); | 171 return UseReadResult(storage->Get()); |
172 | 172 |
173 case Value::TYPE_STRING: { | 173 case Value::TYPE_STRING: { |
174 std::string as_string; | 174 std::string as_string; |
175 input->GetAsString(&as_string); | 175 input->GetAsString(&as_string); |
(...skipping 18 matching lines...) Expand all Loading... |
194 return UseReadResult( | 194 return UseReadResult( |
195 ValueStore::MakeReadResult(with_default_values)); | 195 ValueStore::MakeReadResult(with_default_values)); |
196 } | 196 } |
197 | 197 |
198 default: | 198 default: |
199 return UseReadResult( | 199 return UseReadResult( |
200 ValueStore::MakeReadResult(kUnsupportedArgumentType)); | 200 ValueStore::MakeReadResult(kUnsupportedArgumentType)); |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 bool GetBytesInUseSettingsFunction::RunWithStorage(ValueStore* storage) { | 204 bool StorageGetBytesInUseFunction::RunWithStorage(ValueStore* storage) { |
205 Value* input = NULL; | 205 Value* input = NULL; |
206 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); | 206 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); |
207 | 207 |
208 size_t bytes_in_use = 0; | 208 size_t bytes_in_use = 0; |
209 | 209 |
210 switch (input->GetType()) { | 210 switch (input->GetType()) { |
211 case Value::TYPE_NULL: | 211 case Value::TYPE_NULL: |
212 bytes_in_use = storage->GetBytesInUse(); | 212 bytes_in_use = storage->GetBytesInUse(); |
213 break; | 213 break; |
214 | 214 |
(...skipping 13 matching lines...) Expand all Loading... |
228 | 228 |
229 default: | 229 default: |
230 error_ = kUnsupportedArgumentType; | 230 error_ = kUnsupportedArgumentType; |
231 return false; | 231 return false; |
232 } | 232 } |
233 | 233 |
234 SetResult(Value::CreateIntegerValue(bytes_in_use)); | 234 SetResult(Value::CreateIntegerValue(bytes_in_use)); |
235 return true; | 235 return true; |
236 } | 236 } |
237 | 237 |
238 bool SetSettingsFunction::RunWithStorage(ValueStore* storage) { | 238 bool StorageSetFunction::RunWithStorage(ValueStore* storage) { |
239 DictionaryValue* input = NULL; | 239 DictionaryValue* input = NULL; |
240 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &input)); | 240 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &input)); |
241 return UseWriteResult(storage->Set(ValueStore::DEFAULTS, *input)); | 241 return UseWriteResult(storage->Set(ValueStore::DEFAULTS, *input)); |
242 } | 242 } |
243 | 243 |
244 void SetSettingsFunction::GetQuotaLimitHeuristics( | 244 void StorageSetFunction::GetQuotaLimitHeuristics( |
245 QuotaLimitHeuristics* heuristics) const { | 245 QuotaLimitHeuristics* heuristics) const { |
246 GetModificationQuotaLimitHeuristics(heuristics); | 246 GetModificationQuotaLimitHeuristics(heuristics); |
247 } | 247 } |
248 | 248 |
249 bool RemoveSettingsFunction::RunWithStorage(ValueStore* storage) { | 249 bool StorageRemoveFunction::RunWithStorage(ValueStore* storage) { |
250 Value* input = NULL; | 250 Value* input = NULL; |
251 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); | 251 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); |
252 | 252 |
253 switch (input->GetType()) { | 253 switch (input->GetType()) { |
254 case Value::TYPE_STRING: { | 254 case Value::TYPE_STRING: { |
255 std::string as_string; | 255 std::string as_string; |
256 input->GetAsString(&as_string); | 256 input->GetAsString(&as_string); |
257 return UseWriteResult(storage->Remove(as_string)); | 257 return UseWriteResult(storage->Remove(as_string)); |
258 } | 258 } |
259 | 259 |
260 case Value::TYPE_LIST: { | 260 case Value::TYPE_LIST: { |
261 std::vector<std::string> as_string_list; | 261 std::vector<std::string> as_string_list; |
262 AddAllStringValues(*static_cast<ListValue*>(input), &as_string_list); | 262 AddAllStringValues(*static_cast<ListValue*>(input), &as_string_list); |
263 return UseWriteResult(storage->Remove(as_string_list)); | 263 return UseWriteResult(storage->Remove(as_string_list)); |
264 } | 264 } |
265 | 265 |
266 default: | 266 default: |
267 return UseWriteResult( | 267 return UseWriteResult( |
268 ValueStore::MakeWriteResult(kUnsupportedArgumentType)); | 268 ValueStore::MakeWriteResult(kUnsupportedArgumentType)); |
269 }; | 269 }; |
270 } | 270 } |
271 | 271 |
272 void RemoveSettingsFunction::GetQuotaLimitHeuristics( | 272 void StorageRemoveFunction::GetQuotaLimitHeuristics( |
273 QuotaLimitHeuristics* heuristics) const { | 273 QuotaLimitHeuristics* heuristics) const { |
274 GetModificationQuotaLimitHeuristics(heuristics); | 274 GetModificationQuotaLimitHeuristics(heuristics); |
275 } | 275 } |
276 | 276 |
277 bool ClearSettingsFunction::RunWithStorage(ValueStore* storage) { | 277 bool StorageClearFunction::RunWithStorage(ValueStore* storage) { |
278 return UseWriteResult(storage->Clear()); | 278 return UseWriteResult(storage->Clear()); |
279 } | 279 } |
280 | 280 |
281 void ClearSettingsFunction::GetQuotaLimitHeuristics( | 281 void StorageClearFunction::GetQuotaLimitHeuristics( |
282 QuotaLimitHeuristics* heuristics) const { | 282 QuotaLimitHeuristics* heuristics) const { |
283 GetModificationQuotaLimitHeuristics(heuristics); | 283 GetModificationQuotaLimitHeuristics(heuristics); |
284 } | 284 } |
285 | 285 |
286 } // namespace extensions | 286 } // namespace extensions |
OLD | NEW |