OLD | NEW |
---|---|
1 // Copyright (c) 2011 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/settings/settings_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extensions_quota_service.h" | 10 #include "chrome/browser/extensions/extensions_quota_service.h" |
11 #include "chrome/browser/extensions/settings/settings_api.h" | 11 #include "chrome/browser/extensions/settings/settings_api.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 return UseReadResult( | 175 return UseReadResult( |
176 SettingsStorage::ReadResult(with_default_values)); | 176 SettingsStorage::ReadResult(with_default_values)); |
177 } | 177 } |
178 | 178 |
179 default: | 179 default: |
180 return UseReadResult( | 180 return UseReadResult( |
181 SettingsStorage::ReadResult(kUnsupportedArgumentType)); | 181 SettingsStorage::ReadResult(kUnsupportedArgumentType)); |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 bool GetBytesInUseSettingsFunction::RunWithStorage(SettingsStorage* storage) { | |
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
187 Value *input; | |
Aaron Boodman
2012/01/24 23:40:53
*twitch* - initialize primitives.
not at google - send to devlin
2012/01/25 00:00:14
Done.
oops, fixed up the other cases of this (thi
| |
188 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); | |
189 | |
190 size_t bytes_in_use = 0; | |
191 | |
192 switch (input->GetType()) { | |
193 case Value::TYPE_NULL: | |
194 bytes_in_use = storage->GetBytesInUse(); | |
195 break; | |
196 | |
197 case Value::TYPE_STRING: { | |
198 std::string as_string; | |
199 input->GetAsString(&as_string); | |
200 bytes_in_use = storage->GetBytesInUse(as_string); | |
201 break; | |
202 } | |
203 | |
204 case Value::TYPE_LIST: { | |
205 std::vector<std::string> as_string_list; | |
206 AddAllStringValues(*static_cast<ListValue*>(input), &as_string_list); | |
207 bytes_in_use = storage->GetBytesInUse(as_string_list); | |
208 break; | |
209 } | |
210 | |
211 default: | |
212 error_ = kUnsupportedArgumentType; | |
213 return false; | |
214 } | |
215 | |
216 result_.reset(Value::CreateIntegerValue(bytes_in_use)); | |
217 return true; | |
218 } | |
219 | |
185 bool SetSettingsFunction::RunWithStorage(SettingsStorage* storage) { | 220 bool SetSettingsFunction::RunWithStorage(SettingsStorage* storage) { |
186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
187 DictionaryValue* input; | 222 DictionaryValue* input; |
188 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &input)); | 223 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &input)); |
189 return UseWriteResult(storage->Set(SettingsStorage::DEFAULTS, *input)); | 224 return UseWriteResult(storage->Set(SettingsStorage::DEFAULTS, *input)); |
190 } | 225 } |
191 | 226 |
192 void SetSettingsFunction::GetQuotaLimitHeuristics( | 227 void SetSettingsFunction::GetQuotaLimitHeuristics( |
193 QuotaLimitHeuristics* heuristics) const { | 228 QuotaLimitHeuristics* heuristics) const { |
194 GetModificationQuotaLimitHeuristics(heuristics); | 229 GetModificationQuotaLimitHeuristics(heuristics); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 262 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
228 return UseWriteResult(storage->Clear()); | 263 return UseWriteResult(storage->Clear()); |
229 } | 264 } |
230 | 265 |
231 void ClearSettingsFunction::GetQuotaLimitHeuristics( | 266 void ClearSettingsFunction::GetQuotaLimitHeuristics( |
232 QuotaLimitHeuristics* heuristics) const { | 267 QuotaLimitHeuristics* heuristics) const { |
233 GetModificationQuotaLimitHeuristics(heuristics); | 268 GetModificationQuotaLimitHeuristics(heuristics); |
234 } | 269 } |
235 | 270 |
236 } // namespace extensions | 271 } // namespace extensions |
OLD | NEW |