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

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

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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
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/settings_storage_quota_enforcer.h" 5 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 20 matching lines...) Expand all
31 void Allocate( 31 void Allocate(
32 const std::string& key, 32 const std::string& key,
33 const base::Value& value, 33 const base::Value& value,
34 size_t* used_total, 34 size_t* used_total,
35 std::map<std::string, size_t>* used_per_setting) { 35 std::map<std::string, size_t>* used_per_setting) {
36 // Calculate the setting size based on its JSON serialization size. 36 // Calculate the setting size based on its JSON serialization size.
37 // TODO(kalman): Does this work with different encodings? 37 // TODO(kalman): Does this work with different encodings?
38 // TODO(kalman): This is duplicating work that the leveldb delegate 38 // TODO(kalman): This is duplicating work that the leveldb delegate
39 // implementation is about to do, and it would be nice to avoid this. 39 // implementation is about to do, and it would be nice to avoid this.
40 std::string value_as_json; 40 std::string value_as_json;
41 base::JSONWriter::Write(&value, &value_as_json); 41 base::JSONWriter::Write(value, &value_as_json);
42 size_t new_size = key.size() + value_as_json.size(); 42 size_t new_size = key.size() + value_as_json.size();
43 size_t existing_size = (*used_per_setting)[key]; 43 size_t existing_size = (*used_per_setting)[key];
44 44
45 *used_total += (new_size - existing_size); 45 *used_total += (new_size - existing_size);
46 (*used_per_setting)[key] = new_size; 46 (*used_per_setting)[key] = new_size;
47 } 47 }
48 48
49 // Frees the allocation of a setting in a record of total and per-setting usage. 49 // Frees the allocation of a setting in a record of total and per-setting usage.
50 void Free( 50 void Free(
51 size_t* used_total, 51 size_t* used_total,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 264 }
265 265
266 for (base::DictionaryValue::Iterator it(maybe_settings->settings()); 266 for (base::DictionaryValue::Iterator it(maybe_settings->settings());
267 !it.IsAtEnd(); 267 !it.IsAtEnd();
268 it.Advance()) { 268 it.Advance()) {
269 Allocate(it.key(), it.value(), &used_total_, &used_per_setting_); 269 Allocate(it.key(), it.value(), &used_total_, &used_per_setting_);
270 } 270 }
271 } 271 }
272 272
273 } // namespace extensions 273 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/storage/settings_quota_unittest.cc ('k') | extensions/browser/api/web_request/web_request_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698