summaryrefslogtreecommitdiffstats
path: root/extensions/browser
diff options
context:
space:
mode:
authorestade <estade@chromium.org>2015-05-15 18:02:34 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-16 01:02:46 +0000
commit8d04646294767ea1f3a7da596547b465d50cb4d1 (patch)
tree6bd6194b6fe2ac226114f9125570bd605e9b6d42 /extensions/browser
parentf39e5aff5aae8451a7ef190a2fc822bf80c4e30d (diff)
downloadchromium_src-8d04646294767ea1f3a7da596547b465d50cb4d1.zip
chromium_src-8d04646294767ea1f3a7da596547b465d50cb4d1.tar.gz
chromium_src-8d04646294767ea1f3a7da596547b465d50cb4d1.tar.bz2
Convert JsonWriter::Write to taking a const ref for the in-param
Clearer API; flushes out a lot of unnecessary heap allocations. depends on https://codereview.chromium.org/1129083003/ BUG=none Review URL: https://codereview.chromium.org/1131113004 Cr-Commit-Position: refs/heads/master@{#330255}
Diffstat (limited to 'extensions/browser')
-rw-r--r--extensions/browser/api/cast_channel/cast_channel_api.cc2
-rw-r--r--extensions/browser/api/cast_channel/keep_alive_delegate.cc2
-rw-r--r--extensions/browser/api/storage/settings_quota_unittest.cc333
-rw-r--r--extensions/browser/api/storage/settings_storage_quota_enforcer.cc2
-rw-r--r--extensions/browser/api/web_request/web_request_api.cc2
-rw-r--r--extensions/browser/computed_hashes.cc2
-rw-r--r--extensions/browser/value_store/leveldb_value_store.cc2
-rw-r--r--extensions/browser/value_store/value_store_change.cc2
-rw-r--r--extensions/browser/value_store/value_store_unittest.cc5
9 files changed, 175 insertions, 177 deletions
diff --git a/extensions/browser/api/cast_channel/cast_channel_api.cc b/extensions/browser/api/cast_channel/cast_channel_api.cc
index e00646e..4ad8624 100644
--- a/extensions/browser/api/cast_channel/cast_channel_api.cc
+++ b/extensions/browser/api/cast_channel/cast_channel_api.cc
@@ -59,7 +59,7 @@ template <class T>
std::string ParamToString(const T& info) {
scoped_ptr<base::DictionaryValue> dict = info.ToValue();
std::string out;
- base::JSONWriter::Write(dict.get(), &out);
+ base::JSONWriter::Write(*dict, &out);
return out;
}
diff --git a/extensions/browser/api/cast_channel/keep_alive_delegate.cc b/extensions/browser/api/cast_channel/keep_alive_delegate.cc
index 73c356f4..df23519 100644
--- a/extensions/browser/api/cast_channel/keep_alive_delegate.cc
+++ b/extensions/browser/api/cast_channel/keep_alive_delegate.cc
@@ -68,7 +68,7 @@ CastMessage KeepAliveDelegate::CreateKeepAliveMessage(
output.set_namespace_(kHeartbeatNamespace);
base::DictionaryValue type_dict;
type_dict.SetString(kTypeNodeId, message_type);
- if (!base::JSONWriter::Write(&type_dict, output.mutable_payload_utf8())) {
+ if (!base::JSONWriter::Write(type_dict, output.mutable_payload_utf8())) {
LOG(ERROR) << "Failed to serialize dictionary.";
return output;
}
diff --git a/extensions/browser/api/storage/settings_quota_unittest.cc b/extensions/browser/api/storage/settings_quota_unittest.cc
index 391043e..02e8735 100644
--- a/extensions/browser/api/storage/settings_quota_unittest.cc
+++ b/extensions/browser/api/storage/settings_quota_unittest.cc
@@ -24,23 +24,22 @@ const ValueStore::WriteOptions IGNORE_QUOTA =
class ExtensionSettingsQuotaTest : public testing::Test {
public:
ExtensionSettingsQuotaTest()
- : byte_value_1_(new base::FundamentalValue(1)),
- byte_value_16_(new base::StringValue("sixteen bytes.")),
- byte_value_256_(new base::ListValue()),
+ : byte_value_1_(1),
+ byte_value_16_("sixteen bytes."),
delegate_(new TestingValueStore()) {
for (int i = 1; i < 89; ++i) {
- byte_value_256_->Append(new base::FundamentalValue(i));
+ byte_value_256_.AppendInteger(i);
}
ValidateByteValues();
}
void ValidateByteValues() {
std::string validate_sizes;
- base::JSONWriter::Write(byte_value_1_.get(), &validate_sizes);
+ base::JSONWriter::Write(byte_value_1_, &validate_sizes);
ASSERT_EQ(1u, validate_sizes.size());
- base::JSONWriter::Write(byte_value_16_.get(), &validate_sizes);
+ base::JSONWriter::Write(byte_value_16_, &validate_sizes);
ASSERT_EQ(16u, validate_sizes.size());
- base::JSONWriter::Write(byte_value_256_.get(), &validate_sizes);
+ base::JSONWriter::Write(byte_value_256_, &validate_sizes);
ASSERT_EQ(256u, validate_sizes.size());
}
@@ -64,9 +63,9 @@ class ExtensionSettingsQuotaTest : public testing::Test {
}
// Values with different serialized sizes.
- scoped_ptr<base::Value> byte_value_1_;
- scoped_ptr<base::Value> byte_value_16_;
- scoped_ptr<base::ListValue> byte_value_256_;
+ base::FundamentalValue byte_value_1_;
+ base::StringValue byte_value_16_;
+ base::ListValue byte_value_256_;
// Quota enforcing storage area being tested.
scoped_ptr<SettingsStorageQuotaEnforcer> storage_;
@@ -79,7 +78,7 @@ TEST_F(ExtensionSettingsQuotaTest, ZeroQuotaBytes) {
base::DictionaryValue empty;
CreateStorage(0, UINT_MAX, UINT_MAX);
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_FALSE(storage_->Remove("a")->HasError());
EXPECT_FALSE(storage_->Remove("b")->HasError());
EXPECT_TRUE(SettingsEqual(empty));
@@ -89,7 +88,7 @@ TEST_F(ExtensionSettingsQuotaTest, KeySizeTakenIntoAccount) {
base::DictionaryValue empty;
CreateStorage(8u, UINT_MAX, UINT_MAX);
EXPECT_TRUE(
- storage_->Set(DEFAULTS, "Really long key", *byte_value_1_)->HasError());
+ storage_->Set(DEFAULTS, "Really long key", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(empty));
}
@@ -97,12 +96,12 @@ TEST_F(ExtensionSettingsQuotaTest, SmallByteQuota) {
base::DictionaryValue settings;
CreateStorage(8u, UINT_MAX, UINT_MAX);
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
- settings.Set("a", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_TRUE(storage_->Set(DEFAULTS, "b", *byte_value_16_)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "b", byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -111,20 +110,20 @@ TEST_F(ExtensionSettingsQuotaTest, MediumByteQuota) {
CreateStorage(40, UINT_MAX, UINT_MAX);
base::DictionaryValue to_set;
- to_set.Set("a", byte_value_1_->DeepCopy());
- to_set.Set("b", byte_value_16_->DeepCopy());
+ to_set.Set("a", byte_value_1_.CreateDeepCopy());
+ to_set.Set("b", byte_value_16_.CreateDeepCopy());
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- settings.Set("a", byte_value_1_->DeepCopy());
- settings.Set("b", byte_value_16_->DeepCopy());
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Should be able to set value to other under-quota value.
- to_set.Set("a", byte_value_16_->DeepCopy());
+ to_set.Set("a", byte_value_16_.CreateDeepCopy());
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- settings.Set("a", byte_value_16_->DeepCopy());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -132,7 +131,7 @@ TEST_F(ExtensionSettingsQuotaTest, ZeroMaxKeys) {
base::DictionaryValue empty;
CreateStorage(UINT_MAX, UINT_MAX, 0);
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_FALSE(storage_->Remove("a")->HasError());
EXPECT_FALSE(storage_->Remove("b")->HasError());
EXPECT_TRUE(SettingsEqual(empty));
@@ -142,17 +141,17 @@ TEST_F(ExtensionSettingsQuotaTest, SmallMaxKeys) {
base::DictionaryValue settings;
CreateStorage(UINT_MAX, UINT_MAX, 1);
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
- settings.Set("a", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Should be able to set existing key to other value without going over quota.
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_16_)->HasError());
- settings.Set("a", byte_value_16_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_16_)->HasError());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_TRUE(storage_->Set(DEFAULTS, "b", *byte_value_16_)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "b", byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -161,21 +160,21 @@ TEST_F(ExtensionSettingsQuotaTest, MediumMaxKeys) {
CreateStorage(UINT_MAX, UINT_MAX, 2);
base::DictionaryValue to_set;
- to_set.Set("a", byte_value_1_->DeepCopy());
- to_set.Set("b", byte_value_16_->DeepCopy());
+ to_set.Set("a", byte_value_1_.CreateDeepCopy());
+ to_set.Set("b", byte_value_16_.CreateDeepCopy());
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- settings.Set("a", byte_value_1_->DeepCopy());
- settings.Set("b", byte_value_16_->DeepCopy());
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Should be able to set existing keys to other values without going over
// quota.
- to_set.Set("a", byte_value_16_->DeepCopy());
+ to_set.Set("a", byte_value_16_.CreateDeepCopy());
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- settings.Set("a", byte_value_16_->DeepCopy());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -183,32 +182,32 @@ TEST_F(ExtensionSettingsQuotaTest, RemovingExistingSettings) {
base::DictionaryValue settings;
CreateStorage(266, UINT_MAX, 2);
- storage_->Set(DEFAULTS, "b", *byte_value_16_);
- settings.Set("b", byte_value_16_->DeepCopy());
+ storage_->Set(DEFAULTS, "b", byte_value_16_);
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
// Not enough quota.
- storage_->Set(DEFAULTS, "c", *byte_value_256_);
+ storage_->Set(DEFAULTS, "c", byte_value_256_);
EXPECT_TRUE(SettingsEqual(settings));
// Try again with "b" removed, enough quota.
EXPECT_FALSE(storage_->Remove("b")->HasError());
settings.Remove("b", NULL);
- EXPECT_FALSE(storage_->Set(DEFAULTS, "c", *byte_value_256_)->HasError());
- settings.Set("c", byte_value_256_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "c", byte_value_256_)->HasError());
+ settings.Set("c", byte_value_256_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Enough byte quota but max keys not high enough.
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
- settings.Set("a", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_TRUE(storage_->Set(DEFAULTS, "b", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "b", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
// Back under max keys.
EXPECT_FALSE(storage_->Remove("a")->HasError());
settings.Remove("a", NULL);
- EXPECT_FALSE(storage_->Set(DEFAULTS, "b", *byte_value_1_)->HasError());
- settings.Set("b", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "b", byte_value_1_)->HasError());
+ settings.Set("b", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -218,12 +217,12 @@ TEST_F(ExtensionSettingsQuotaTest, RemovingNonexistentSettings) {
// Max out bytes.
base::DictionaryValue to_set;
- to_set.Set("b1", byte_value_16_->DeepCopy());
- to_set.Set("b2", byte_value_16_->DeepCopy());
+ to_set.Set("b1", byte_value_16_.CreateDeepCopy());
+ to_set.Set("b2", byte_value_16_.CreateDeepCopy());
storage_->Set(DEFAULTS, to_set);
- settings.Set("b1", byte_value_16_->DeepCopy());
- settings.Set("b2", byte_value_16_->DeepCopy());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ settings.Set("b1", byte_value_16_.CreateDeepCopy());
+ settings.Set("b2", byte_value_16_.CreateDeepCopy());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
// Remove some settings that don't exist.
@@ -235,18 +234,18 @@ TEST_F(ExtensionSettingsQuotaTest, RemovingNonexistentSettings) {
EXPECT_TRUE(SettingsEqual(settings));
// Still no quota.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
// Max out key count.
to_set.Clear();
- to_set.Set("b1", byte_value_1_->DeepCopy());
- to_set.Set("b2", byte_value_1_->DeepCopy());
+ to_set.Set("b1", byte_value_1_.CreateDeepCopy());
+ to_set.Set("b2", byte_value_1_.CreateDeepCopy());
storage_->Set(DEFAULTS, to_set);
- settings.Set("b1", byte_value_1_->DeepCopy());
- settings.Set("b2", byte_value_1_->DeepCopy());
- storage_->Set(DEFAULTS, "b3", *byte_value_1_);
- settings.Set("b3", byte_value_1_->DeepCopy());
+ settings.Set("b1", byte_value_1_.CreateDeepCopy());
+ settings.Set("b2", byte_value_1_.CreateDeepCopy());
+ storage_->Set(DEFAULTS, "b3", byte_value_1_);
+ settings.Set("b3", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Remove some settings that don't exist.
@@ -258,7 +257,7 @@ TEST_F(ExtensionSettingsQuotaTest, RemovingNonexistentSettings) {
EXPECT_TRUE(SettingsEqual(settings));
// Still no quota.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -269,35 +268,35 @@ TEST_F(ExtensionSettingsQuotaTest, Clear) {
// Test running out of byte quota.
{
base::DictionaryValue to_set;
- to_set.Set("a", byte_value_16_->DeepCopy());
- to_set.Set("b", byte_value_16_->DeepCopy());
+ to_set.Set("a", byte_value_16_.CreateDeepCopy());
+ to_set.Set("b", byte_value_16_.CreateDeepCopy());
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_16_)->HasError());
EXPECT_FALSE(storage_->Clear()->HasError());
// (repeat)
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_16_)->HasError());
}
// Test reaching max keys.
storage_->Clear();
{
base::DictionaryValue to_set;
- to_set.Set("a", byte_value_1_->DeepCopy());
- to_set.Set("b", byte_value_1_->DeepCopy());
- to_set.Set("c", byte_value_1_->DeepCopy());
- to_set.Set("d", byte_value_1_->DeepCopy());
- to_set.Set("e", byte_value_1_->DeepCopy());
+ to_set.Set("a", byte_value_1_.CreateDeepCopy());
+ to_set.Set("b", byte_value_1_.CreateDeepCopy());
+ to_set.Set("c", byte_value_1_.CreateDeepCopy());
+ to_set.Set("d", byte_value_1_.CreateDeepCopy());
+ to_set.Set("e", byte_value_1_.CreateDeepCopy());
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "f", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "f", byte_value_1_)->HasError());
storage_->Clear();
// (repeat)
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "f", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "f", byte_value_1_)->HasError());
}
}
@@ -306,20 +305,20 @@ TEST_F(ExtensionSettingsQuotaTest, ChangingUsedBytesWithSet) {
CreateStorage(20, UINT_MAX, UINT_MAX);
// Change a setting to make it go over quota.
- storage_->Set(DEFAULTS, "a", *byte_value_16_);
- settings.Set("a", byte_value_16_->DeepCopy());
+ storage_->Set(DEFAULTS, "a", byte_value_16_);
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_256_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
// Change a setting to reduce usage and room for another setting.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "foobar", *byte_value_1_)->HasError());
- storage_->Set(DEFAULTS, "a", *byte_value_1_);
- settings.Set("a", byte_value_1_->DeepCopy());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "foobar", byte_value_1_)->HasError());
+ storage_->Set(DEFAULTS, "a", byte_value_1_);
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "foobar", *byte_value_1_)->HasError());
- settings.Set("foobar", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "foobar", byte_value_1_)->HasError());
+ settings.Set("foobar", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -327,22 +326,22 @@ TEST_F(ExtensionSettingsQuotaTest, SetsOnlyEntirelyCompletedWithByteQuota) {
base::DictionaryValue settings;
CreateStorage(40, UINT_MAX, UINT_MAX);
- storage_->Set(DEFAULTS, "a", *byte_value_16_);
- settings.Set("a", byte_value_16_->DeepCopy());
+ storage_->Set(DEFAULTS, "a", byte_value_16_);
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
// The entire change is over quota.
base::DictionaryValue to_set;
- to_set.Set("b", byte_value_16_->DeepCopy());
- to_set.Set("c", byte_value_16_->DeepCopy());
+ to_set.Set("b", byte_value_16_.CreateDeepCopy());
+ to_set.Set("c", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(storage_->Set(DEFAULTS, to_set)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
// The entire change is over quota, but quota reduced in existing key.
- to_set.Set("a", byte_value_1_->DeepCopy());
+ to_set.Set("a", byte_value_1_.CreateDeepCopy());
EXPECT_FALSE(storage_->Set(DEFAULTS, to_set)->HasError());
- settings.Set("a", byte_value_1_->DeepCopy());
- settings.Set("b", byte_value_16_->DeepCopy());
- settings.Set("c", byte_value_16_->DeepCopy());
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
+ settings.Set("c", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -350,44 +349,44 @@ TEST_F(ExtensionSettingsQuotaTest, SetsOnlyEntireCompletedWithMaxKeys) {
base::DictionaryValue settings;
CreateStorage(UINT_MAX, UINT_MAX, 2);
- storage_->Set(DEFAULTS, "a", *byte_value_1_);
- settings.Set("a", byte_value_1_->DeepCopy());
+ storage_->Set(DEFAULTS, "a", byte_value_1_);
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
base::DictionaryValue to_set;
- to_set.Set("b", byte_value_16_->DeepCopy());
- to_set.Set("c", byte_value_16_->DeepCopy());
+ to_set.Set("b", byte_value_16_.CreateDeepCopy());
+ to_set.Set("c", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(storage_->Set(DEFAULTS, to_set)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
TEST_F(ExtensionSettingsQuotaTest, WithInitialDataAndByteQuota) {
base::DictionaryValue settings;
- delegate_->Set(DEFAULTS, "a", *byte_value_256_);
- settings.Set("a", byte_value_256_->DeepCopy());
+ delegate_->Set(DEFAULTS, "a", byte_value_256_);
+ settings.Set("a", byte_value_256_.CreateDeepCopy());
CreateStorage(280, UINT_MAX, UINT_MAX);
EXPECT_TRUE(SettingsEqual(settings));
// Add some data.
- EXPECT_FALSE(storage_->Set(DEFAULTS, "b", *byte_value_16_)->HasError());
- settings.Set("b", byte_value_16_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "b", byte_value_16_)->HasError());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Not enough quota.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_16_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
// Reduce usage of original setting so that "c" can fit.
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_16_)->HasError());
- settings.Set("a", byte_value_16_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_16_)->HasError());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_FALSE(storage_->Set(DEFAULTS, "c", *byte_value_16_)->HasError());
- settings.Set("c", byte_value_16_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "c", byte_value_16_)->HasError());
+ settings.Set("c", byte_value_16_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Remove to free up some more data.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "d", *byte_value_256_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "d", byte_value_256_)->HasError());
std::vector<std::string> to_remove;
to_remove.push_back("a");
@@ -397,61 +396,61 @@ TEST_F(ExtensionSettingsQuotaTest, WithInitialDataAndByteQuota) {
settings.Remove("b", NULL);
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_FALSE(storage_->Set(DEFAULTS, "d", *byte_value_256_)->HasError());
- settings.Set("d", byte_value_256_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "d", byte_value_256_)->HasError());
+ settings.Set("d", byte_value_256_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
}
TEST_F(ExtensionSettingsQuotaTest, WithInitialDataAndMaxKeys) {
base::DictionaryValue settings;
- delegate_->Set(DEFAULTS, "a", *byte_value_1_);
- settings.Set("a", byte_value_1_->DeepCopy());
+ delegate_->Set(DEFAULTS, "a", byte_value_1_);
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
CreateStorage(UINT_MAX, UINT_MAX, 2);
- EXPECT_FALSE(storage_->Set(DEFAULTS, "b", *byte_value_1_)->HasError());
- settings.Set("b", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "b", byte_value_1_)->HasError());
+ settings.Set("b", byte_value_1_.CreateDeepCopy());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
TEST_F(ExtensionSettingsQuotaTest, InitiallyOverByteQuota) {
base::DictionaryValue settings;
- settings.Set("a", byte_value_16_->DeepCopy());
- settings.Set("b", byte_value_16_->DeepCopy());
- settings.Set("c", byte_value_16_->DeepCopy());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
+ settings.Set("c", byte_value_16_.CreateDeepCopy());
delegate_->Set(DEFAULTS, settings);
CreateStorage(40, UINT_MAX, UINT_MAX);
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_TRUE(storage_->Set(DEFAULTS, "d", *byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "d", byte_value_16_)->HasError());
// Take under quota by reducing size of an existing setting
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
- settings.Set("a", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
+ settings.Set("a", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Should be able set another small setting.
- EXPECT_FALSE(storage_->Set(DEFAULTS, "d", *byte_value_1_)->HasError());
- settings.Set("d", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "d", byte_value_1_)->HasError());
+ settings.Set("d", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
}
TEST_F(ExtensionSettingsQuotaTest, InitiallyOverMaxKeys) {
base::DictionaryValue settings;
- settings.Set("a", byte_value_16_->DeepCopy());
- settings.Set("b", byte_value_16_->DeepCopy());
- settings.Set("c", byte_value_16_->DeepCopy());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
+ settings.Set("c", byte_value_16_.CreateDeepCopy());
delegate_->Set(DEFAULTS, settings);
CreateStorage(UINT_MAX, UINT_MAX, 2);
EXPECT_TRUE(SettingsEqual(settings));
// Can't set either an existing or new setting.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "d", *byte_value_16_)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "d", byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
// Should be able after removing 2.
@@ -461,13 +460,13 @@ TEST_F(ExtensionSettingsQuotaTest, InitiallyOverMaxKeys) {
settings.Remove("b", NULL);
EXPECT_TRUE(SettingsEqual(settings));
- EXPECT_FALSE(storage_->Set(DEFAULTS, "e", *byte_value_1_)->HasError());
- settings.Set("e", byte_value_1_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "e", byte_value_1_)->HasError());
+ settings.Set("e", byte_value_1_.CreateDeepCopy());
EXPECT_TRUE(SettingsEqual(settings));
// Still can't set any.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "d", *byte_value_16_)->HasError());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "d", byte_value_16_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -475,7 +474,7 @@ TEST_F(ExtensionSettingsQuotaTest, ZeroQuotaBytesPerSetting) {
base::DictionaryValue empty;
CreateStorage(UINT_MAX, 0, UINT_MAX);
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
EXPECT_FALSE(storage_->Remove("a")->HasError());
EXPECT_FALSE(storage_->Remove("b")->HasError());
EXPECT_TRUE(SettingsEqual(empty));
@@ -486,15 +485,15 @@ TEST_F(ExtensionSettingsQuotaTest, QuotaBytesPerSetting) {
CreateStorage(UINT_MAX, 20, UINT_MAX);
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_16_)->HasError());
- settings.Set("a", byte_value_16_->DeepCopy());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_256_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_16_)->HasError());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_256_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "b", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "b", *byte_value_16_)->HasError());
- settings.Set("b", byte_value_16_->DeepCopy());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "b", *byte_value_256_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "b", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "b", byte_value_16_)->HasError());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "b", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -502,25 +501,25 @@ TEST_F(ExtensionSettingsQuotaTest, QuotaBytesPerSetting) {
TEST_F(ExtensionSettingsQuotaTest, QuotaBytesPerSettingWithInitialSettings) {
base::DictionaryValue settings;
- delegate_->Set(DEFAULTS, "a", *byte_value_1_);
- delegate_->Set(DEFAULTS, "b", *byte_value_16_);
- delegate_->Set(DEFAULTS, "c", *byte_value_256_);
+ delegate_->Set(DEFAULTS, "a", byte_value_1_);
+ delegate_->Set(DEFAULTS, "b", byte_value_16_);
+ delegate_->Set(DEFAULTS, "c", byte_value_256_);
CreateStorage(UINT_MAX, 20, UINT_MAX);
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "a", *byte_value_16_)->HasError());
- settings.Set("a", byte_value_16_->DeepCopy());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "a", *byte_value_256_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "a", byte_value_16_)->HasError());
+ settings.Set("a", byte_value_16_.CreateDeepCopy());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "a", byte_value_256_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "b", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "b", *byte_value_16_)->HasError());
- settings.Set("b", byte_value_16_->DeepCopy());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "b", *byte_value_256_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "b", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "b", byte_value_16_)->HasError());
+ settings.Set("b", byte_value_16_.CreateDeepCopy());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "b", byte_value_256_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "c", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(DEFAULTS, "c", *byte_value_16_)->HasError());
- settings.Set("c", byte_value_16_->DeepCopy());
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "c", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(DEFAULTS, "c", byte_value_16_)->HasError());
+ settings.Set("c", byte_value_16_.CreateDeepCopy());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -532,27 +531,27 @@ TEST_F(ExtensionSettingsQuotaTest,
// rejected...
base::DictionaryValue settings;
- delegate_->Set(DEFAULTS, "a", *byte_value_1_);
- delegate_->Set(DEFAULTS, "b", *byte_value_16_);
- delegate_->Set(DEFAULTS, "c", *byte_value_256_);
+ delegate_->Set(DEFAULTS, "a", byte_value_1_);
+ delegate_->Set(DEFAULTS, "b", byte_value_16_);
+ delegate_->Set(DEFAULTS, "c", byte_value_256_);
CreateStorage(UINT_MAX, 20, UINT_MAX);
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "a", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "a", *byte_value_16_)->HasError());
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "a", *byte_value_256_)->HasError());
- settings.Set("a", byte_value_256_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "a", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "a", byte_value_16_)->HasError());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "a", byte_value_256_)->HasError());
+ settings.Set("a", byte_value_256_.CreateDeepCopy());
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "b", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "b", *byte_value_16_)->HasError());
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "b", *byte_value_256_)->HasError());
- settings.Set("b", byte_value_256_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "b", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "b", byte_value_16_)->HasError());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "b", byte_value_256_)->HasError());
+ settings.Set("b", byte_value_256_.CreateDeepCopy());
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", *byte_value_1_)->HasError());
- EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", *byte_value_16_)->HasError());
- settings.Set("c", byte_value_16_->DeepCopy());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", byte_value_1_)->HasError());
+ EXPECT_FALSE(storage_->Set(IGNORE_QUOTA, "c", byte_value_16_)->HasError());
+ settings.Set("c", byte_value_16_.CreateDeepCopy());
// ... except the last. Make sure it can still fail.
- EXPECT_TRUE(storage_->Set(DEFAULTS, "c", *byte_value_256_)->HasError());
+ EXPECT_TRUE(storage_->Set(DEFAULTS, "c", byte_value_256_)->HasError());
EXPECT_TRUE(SettingsEqual(settings));
}
@@ -570,21 +569,21 @@ TEST_F(ExtensionSettingsQuotaTest, GetBytesInUse) {
EXPECT_EQ(0u, storage_->GetBytesInUse("b"));
EXPECT_EQ(0u, storage_->GetBytesInUse(ab));
- storage_->Set(DEFAULTS, "a", *byte_value_1_);
+ storage_->Set(DEFAULTS, "a", byte_value_1_);
EXPECT_EQ(2u, storage_->GetBytesInUse());
EXPECT_EQ(2u, storage_->GetBytesInUse("a"));
EXPECT_EQ(0u, storage_->GetBytesInUse("b"));
EXPECT_EQ(2u, storage_->GetBytesInUse(ab));
- storage_->Set(DEFAULTS, "b", *byte_value_1_);
+ storage_->Set(DEFAULTS, "b", byte_value_1_);
EXPECT_EQ(4u, storage_->GetBytesInUse());
EXPECT_EQ(2u, storage_->GetBytesInUse("a"));
EXPECT_EQ(2u, storage_->GetBytesInUse("b"));
EXPECT_EQ(4u, storage_->GetBytesInUse(ab));
- storage_->Set(DEFAULTS, "c", *byte_value_1_);
+ storage_->Set(DEFAULTS, "c", byte_value_1_);
EXPECT_EQ(6u, storage_->GetBytesInUse());
EXPECT_EQ(2u, storage_->GetBytesInUse("a"));
diff --git a/extensions/browser/api/storage/settings_storage_quota_enforcer.cc b/extensions/browser/api/storage/settings_storage_quota_enforcer.cc
index e448a5d..1fbcbbd 100644
--- a/extensions/browser/api/storage/settings_storage_quota_enforcer.cc
+++ b/extensions/browser/api/storage/settings_storage_quota_enforcer.cc
@@ -38,7 +38,7 @@ void Allocate(
// TODO(kalman): This is duplicating work that the leveldb delegate
// implementation is about to do, and it would be nice to avoid this.
std::string value_as_json;
- base::JSONWriter::Write(&value, &value_as_json);
+ base::JSONWriter::Write(value, &value_as_json);
size_t new_size = key.size() + value_as_json.size();
size_t existing_size = (*used_per_setting)[key];
diff --git a/extensions/browser/api/web_request/web_request_api.cc b/extensions/browser/api/web_request/web_request_api.cc
index 7de492e..f6c7527 100644
--- a/extensions/browser/api/web_request/web_request_api.cc
+++ b/extensions/browser/api/web_request/web_request_api.cc
@@ -2374,7 +2374,7 @@ bool WebRequestInternalEventHandledFunction::RunSync() {
headers_value->GetDictionary(i, &header_value));
if (!FromHeaderDictionary(header_value, &name, &value)) {
std::string serialized_header;
- base::JSONWriter::Write(header_value, &serialized_header);
+ base::JSONWriter::Write(*header_value, &serialized_header);
RespondWithError(event_name,
sub_event_name,
request_id,
diff --git a/extensions/browser/computed_hashes.cc b/extensions/browser/computed_hashes.cc
index 473ee3c..35ea525 100644
--- a/extensions/browser/computed_hashes.cc
+++ b/extensions/browser/computed_hashes.cc
@@ -156,7 +156,7 @@ bool ComputedHashes::Writer::WriteToFile(const base::FilePath& path) {
top_dictionary.SetInteger(kVersionKey, kVersion);
top_dictionary.Set(kFileHashesKey, file_list_.release());
- if (!base::JSONWriter::Write(&top_dictionary, &json))
+ if (!base::JSONWriter::Write(top_dictionary, &json))
return false;
int written = base::WriteFile(path, json.data(), json.size());
if (static_cast<unsigned>(written) != json.size()) {
diff --git a/extensions/browser/value_store/leveldb_value_store.cc b/extensions/browser/value_store/leveldb_value_store.cc
index ad8076d..4b7d274 100644
--- a/extensions/browser/value_store/leveldb_value_store.cc
+++ b/extensions/browser/value_store/leveldb_value_store.cc
@@ -389,7 +389,7 @@ scoped_ptr<ValueStore::Error> LeveldbValueStore::AddToBatch(
if (write_new_value) {
std::string value_as_json;
- if (!base::JSONWriter::Write(&value, &value_as_json))
+ if (!base::JSONWriter::Write(value, &value_as_json))
return Error::Create(OTHER_ERROR, kCannotSerialize, util::NewKey(key));
batch->Put(key, value_as_json);
}
diff --git a/extensions/browser/value_store/value_store_change.cc b/extensions/browser/value_store/value_store_change.cc
index 822c9b9..904ec82 100644
--- a/extensions/browser/value_store/value_store_change.cc
+++ b/extensions/browser/value_store/value_store_change.cc
@@ -23,7 +23,7 @@ std::string ValueStoreChange::ToJson(
changes_value.SetWithoutPathExpansion(it->key(), change_value);
}
std::string json;
- base::JSONWriter::Write(&changes_value, &json);
+ base::JSONWriter::Write(changes_value, &json);
return json;
}
diff --git a/extensions/browser/value_store/value_store_unittest.cc b/extensions/browser/value_store/value_store_unittest.cc
index 4293459..c2ecbab 100644
--- a/extensions/browser/value_store/value_store_unittest.cc
+++ b/extensions/browser/value_store/value_store_unittest.cc
@@ -18,9 +18,8 @@ const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS;
// Gets the pretty-printed JSON for a value.
std::string GetJSON(const base::Value& value) {
std::string json;
- base::JSONWriter::WriteWithOptions(&value,
- base::JSONWriter::OPTIONS_PRETTY_PRINT,
- &json);
+ base::JSONWriter::WriteWithOptions(
+ value, base::JSONWriter::OPTIONS_PRETTY_PRINT, &json);
return json;
}