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

Side by Side Diff: chrome/browser/extensions/settings/settings_api.cc

Issue 9284013: Extension Storage API: expose storage quota information to extensions, via: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: with use-after-free fixed Created 8 years, 10 months 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 | Annotate | Revision Log
OLDNEW
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 new ExtensionsQuotaService::SustainedLimit( 136 new ExtensionsQuotaService::SustainedLimit(
137 base::TimeDelta::FromMinutes(10), 137 base::TimeDelta::FromMinutes(10),
138 shortLimitConfig, 138 shortLimitConfig,
139 new QuotaLimitHeuristic::SingletonBucketMapper())); 139 new QuotaLimitHeuristic::SingletonBucketMapper()));
140 }; 140 };
141 141
142 } // namespace 142 } // namespace
143 143
144 bool GetSettingsFunction::RunWithStorage(SettingsStorage* storage) { 144 bool GetSettingsFunction::RunWithStorage(SettingsStorage* storage) {
145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
146 Value *input; 146 Value* input = NULL;
147 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); 147 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input));
148 148
149 switch (input->GetType()) { 149 switch (input->GetType()) {
150 case Value::TYPE_NULL: 150 case Value::TYPE_NULL:
151 return UseReadResult(storage->Get()); 151 return UseReadResult(storage->Get());
152 152
153 case Value::TYPE_STRING: { 153 case Value::TYPE_STRING: {
154 std::string as_string; 154 std::string as_string;
155 input->GetAsString(&as_string); 155 input->GetAsString(&as_string);
156 return UseReadResult(storage->Get(as_string)); 156 return UseReadResult(storage->Get(as_string));
(...skipping 18 matching lines...) Expand all
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 = NULL;
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 = NULL;
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);
195 } 230 }
196 231
197 bool RemoveSettingsFunction::RunWithStorage(SettingsStorage* storage) { 232 bool RemoveSettingsFunction::RunWithStorage(SettingsStorage* storage) {
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
199 Value *input; 234 Value* input = NULL;
200 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input)); 235 EXTENSION_FUNCTION_VALIDATE(args_->Get(0, &input));
201 236
202 switch (input->GetType()) { 237 switch (input->GetType()) {
203 case Value::TYPE_STRING: { 238 case Value::TYPE_STRING: {
204 std::string as_string; 239 std::string as_string;
205 input->GetAsString(&as_string); 240 input->GetAsString(&as_string);
206 return UseWriteResult(storage->Remove(as_string)); 241 return UseWriteResult(storage->Remove(as_string));
207 } 242 }
208 243
209 case Value::TYPE_LIST: { 244 case Value::TYPE_LIST: {
(...skipping 17 matching lines...) Expand all
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
OLDNEW
« no previous file with comments | « chrome/browser/extensions/settings/settings_api.h ('k') | chrome/browser/extensions/settings/settings_frontend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698