Commit c7a310d0 authored by kalman@chromium.org's avatar kalman@chromium.org

Extension settings API: force through changes that come from sync (ignoring

local quota) by adding a WriteOptions flag to Set and using FORCE when
writing from sync.

Otherwise sync will effectively be permanently disabled when the settings are
over quota.


BUG=103514
TEST=*ExtensionSetting* (unit_tests, browser_tests)


Review URL: http://codereview.chromium.org/8587025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110852 0039d316-1c4b-4281-b951-d872f2087c98
parent d43899e8
......@@ -35,12 +35,12 @@ SettingsStorage::ReadResult FailingSettingsStorage::Get() {
}
SettingsStorage::WriteResult FailingSettingsStorage::Set(
const std::string& key, const Value& value) {
WriteOptions options, const std::string& key, const Value& value) {
return WriteResultError();
}
SettingsStorage::WriteResult FailingSettingsStorage::Set(
const DictionaryValue& settings) {
WriteOptions options, const DictionaryValue& settings) {
return WriteResultError();
}
......
......@@ -20,8 +20,12 @@ class FailingSettingsStorage : public SettingsStorage {
virtual ReadResult Get(const std::string& key) OVERRIDE;
virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
virtual ReadResult Get() OVERRIDE;
virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE;
virtual WriteResult Set(const DictionaryValue& values) OVERRIDE;
virtual WriteResult Set(
WriteOptions options,
const std::string& key,
const Value& value) OVERRIDE;
virtual WriteResult Set(
WriteOptions options, const DictionaryValue& values) OVERRIDE;
virtual WriteResult Remove(const std::string& key) OVERRIDE;
virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
virtual WriteResult Clear() OVERRIDE;
......
......@@ -148,7 +148,8 @@ bool SetSettingsFunction::RunWithStorage(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DictionaryValue *input;
EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &input));
return UseWriteResult(observers, storage->Set(*input));
return UseWriteResult(
observers, storage->Set(SettingsStorage::DEFAULTS, *input));
}
bool RemoveSettingsFunction::RunWithStorage(
......
......@@ -23,6 +23,9 @@ using namespace settings_test_util;
namespace {
// To save typing SettingsStorage::DEFAULTS everywhere.
const SettingsStorage::WriteOptions DEFAULTS = SettingsStorage::DEFAULTS;
// A SettingsStorageFactory which always returns NULL.
class NullSettingsStorageFactory : public SettingsStorageFactory {
public:
......@@ -89,7 +92,7 @@ TEST_F(ExtensionSettingsFrontendTest, SettingsPreservedAcrossReconstruction) {
// be too rigorous.
{
StringValue bar("bar");
SettingsStorage::WriteResult result = storage->Set("foo", bar);
SettingsStorage::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
ASSERT_FALSE(result.HasError());
}
......@@ -118,7 +121,7 @@ TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) {
{
StringValue bar("bar");
SettingsStorage::WriteResult result = storage->Set("foo", bar);
SettingsStorage::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
ASSERT_FALSE(result.HasError());
}
......@@ -144,7 +147,7 @@ TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) {
{
StringValue bar("bar");
SettingsStorage::WriteResult result = storage->Set("foo", bar);
SettingsStorage::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
ASSERT_FALSE(result.HasError());
EXPECT_TRUE(file_util::PathExists(temp_dir_.path()));
}
......@@ -179,7 +182,7 @@ TEST_F(ExtensionSettingsFrontendTest,
EXPECT_TRUE(storage->Get().HasError());
EXPECT_TRUE(storage->Clear().HasError());
EXPECT_TRUE(storage->Set("foo", bar).HasError());
EXPECT_TRUE(storage->Set(DEFAULTS, "foo", bar).HasError());
EXPECT_TRUE(storage->Remove("foo").HasError());
// For simplicity: just always fail those requests, even if the leveldb
......@@ -191,7 +194,7 @@ TEST_F(ExtensionSettingsFrontendTest,
EXPECT_TRUE(storage->Get().HasError());
EXPECT_TRUE(storage->Clear().HasError());
EXPECT_TRUE(storage->Set("foo", bar).HasError());
EXPECT_TRUE(storage->Set(DEFAULTS, "foo", bar).HasError());
EXPECT_TRUE(storage->Remove("foo").HasError());
}
......
......@@ -164,21 +164,20 @@ SettingsStorage::ReadResult SettingsLeveldbStorage::Get() {
}
SettingsStorage::WriteResult SettingsLeveldbStorage::Set(
const std::string& key, const Value& value) {
WriteOptions options, const std::string& key, const Value& value) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DictionaryValue settings;
settings.SetWithoutPathExpansion(key, value.DeepCopy());
return Set(settings);
return Set(options, settings);
}
SettingsStorage::WriteResult SettingsLeveldbStorage::Set(
const DictionaryValue& settings) {
WriteOptions options, const DictionaryValue& settings) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
std::string value_as_json;
leveldb::WriteBatch batch;
scoped_ptr<SettingChangeList> changes(
new SettingChangeList());
scoped_ptr<SettingChangeList> changes(new SettingChangeList());
for (DictionaryValue::Iterator it(settings); it.HasNext(); it.Advance()) {
scoped_ptr<Value> old_value;
......@@ -246,16 +245,15 @@ SettingsStorage::WriteResult SettingsLeveldbStorage::Remove(
SettingsStorage::WriteResult SettingsLeveldbStorage::Clear() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
leveldb::ReadOptions options;
leveldb::ReadOptions read_options;
// All interaction with the db is done on the same thread, so snapshotting
// isn't strictly necessary. This is just defensive.
leveldb::WriteBatch batch;
scoped_ptr<SettingChangeList> changes(
new SettingChangeList());
scoped_ptr<SettingChangeList> changes(new SettingChangeList());
ScopedSnapshot snapshot(db_.get());
options.snapshot = snapshot.get();
scoped_ptr<leveldb::Iterator> it(db_->NewIterator(options));
read_options.snapshot = snapshot.get();
scoped_ptr<leveldb::Iterator> it(db_->NewIterator(read_options));
for (it->SeekToFirst(); it->Valid(); it->Next()) {
const std::string key = it->key().ToString();
const std::string old_value_json = it->value().ToString();
......
......@@ -47,8 +47,12 @@ class SettingsLeveldbStorage : public SettingsStorage {
virtual ReadResult Get(const std::string& key) OVERRIDE;
virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
virtual ReadResult Get() OVERRIDE;
virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE;
virtual WriteResult Set(const DictionaryValue& settings) OVERRIDE;
virtual WriteResult Set(
WriteOptions options,
const std::string& key,
const Value& value) OVERRIDE;
virtual WriteResult Set(
WriteOptions options, const DictionaryValue& values) OVERRIDE;
virtual WriteResult Remove(const std::string& key) OVERRIDE;
virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
virtual WriteResult Clear() OVERRIDE;
......
......@@ -89,6 +89,17 @@ class SettingsStorage {
scoped_refptr<Inner> inner_;
};
// Options for write operations.
enum WriteOptions {
// Callers should usually use this.
DEFAULTS,
// Ignore restrictions, such as quota. It is still possible for the
// operation to fail, such as on hard drive failure or if the storage area
// is configured to fail.
FORCE
};
virtual ~SettingsStorage() {}
// Gets a single value from storage.
......@@ -101,10 +112,12 @@ class SettingsStorage {
virtual ReadResult Get() = 0;
// Sets a single key to a new value.
virtual WriteResult Set(const std::string& key, const Value& value) = 0;
virtual WriteResult Set(
WriteOptions options, const std::string& key, const Value& value) = 0;
// Sets multiple keys to new values.
virtual WriteResult Set(const DictionaryValue& values) = 0;
virtual WriteResult Set(
WriteOptions options, const DictionaryValue& values) = 0;
// Removes a key from the storage.
virtual WriteResult Remove(const std::string& key) = 0;
......
......@@ -67,8 +67,8 @@ SettingsStorage::ReadResult SettingsStorageCache::Get() {
}
SettingsStorage::WriteResult SettingsStorageCache::Set(
const std::string& key, const Value& value) {
WriteResult result = delegate_->Set(key, value);
WriteOptions options, const std::string& key, const Value& value) {
WriteResult result = delegate_->Set(options, key, value);
if (!result.HasError()) {
cache_.SetWithoutPathExpansion(key, value.DeepCopy());
}
......@@ -76,8 +76,8 @@ SettingsStorage::WriteResult SettingsStorageCache::Set(
}
SettingsStorage::WriteResult SettingsStorageCache::Set(
const DictionaryValue& settings) {
WriteResult result = delegate_->Set(settings);
WriteOptions options, const DictionaryValue& settings) {
WriteResult result = delegate_->Set(options, settings);
if (result.HasError()) {
return result;
}
......
......@@ -30,8 +30,12 @@ class SettingsStorageCache : public SettingsStorage {
virtual ReadResult Get(const std::string& key) OVERRIDE;
virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
virtual ReadResult Get() OVERRIDE;
virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE;
virtual WriteResult Set(const DictionaryValue& settings) OVERRIDE;
virtual WriteResult Set(
WriteOptions options,
const std::string& key,
const Value& value) OVERRIDE;
virtual WriteResult Set(
WriteOptions options, const DictionaryValue& values) OVERRIDE;
virtual WriteResult Remove(const std::string& key) OVERRIDE;
virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
virtual WriteResult Clear() OVERRIDE;
......
......@@ -98,8 +98,7 @@ SettingsStorageQuotaEnforcer::SettingsStorageQuotaEnforcer(
}
}
SettingsStorageQuotaEnforcer::~SettingsStorageQuotaEnforcer(
) {}
SettingsStorageQuotaEnforcer::~SettingsStorageQuotaEnforcer() {}
SettingsStorage::ReadResult SettingsStorageQuotaEnforcer::Get(
const std::string& key) {
......@@ -111,29 +110,29 @@ SettingsStorage::ReadResult SettingsStorageQuotaEnforcer::Get(
return delegate_->Get(keys);
}
SettingsStorage::ReadResult
SettingsStorageQuotaEnforcer::Get() {
SettingsStorage::ReadResult SettingsStorageQuotaEnforcer::Get() {
return delegate_->Get();
}
SettingsStorage::WriteResult
SettingsStorageQuotaEnforcer::Set(
const std::string& key, const Value& value) {
SettingsStorage::WriteResult SettingsStorageQuotaEnforcer::Set(
WriteOptions options, const std::string& key, const Value& value) {
size_t new_used_total = used_total_;
std::map<std::string, size_t> new_used_per_setting = used_per_setting_;
Allocate(key, value, &new_used_total, &new_used_per_setting);
if (new_used_total > quota_bytes_) {
return QuotaExceededFor(TOTAL_BYTES);
}
if (new_used_per_setting[key] > quota_bytes_per_setting_) {
return QuotaExceededFor(BYTES_PER_SETTING);
}
if (new_used_per_setting.size() > max_keys_) {
return QuotaExceededFor(KEY_COUNT);
if (options != FORCE) {
if (new_used_total > quota_bytes_) {
return QuotaExceededFor(TOTAL_BYTES);
}
if (new_used_per_setting[key] > quota_bytes_per_setting_) {
return QuotaExceededFor(BYTES_PER_SETTING);
}
if (new_used_per_setting.size() > max_keys_) {
return QuotaExceededFor(KEY_COUNT);
}
}
WriteResult result = delegate_->Set(key, value);
WriteResult result = delegate_->Set(options, key, value);
if (result.HasError()) {
return result;
}
......@@ -143,26 +142,29 @@ SettingsStorageQuotaEnforcer::Set(
return result;
}
SettingsStorage::WriteResult
SettingsStorageQuotaEnforcer::Set(
const DictionaryValue& values) {
SettingsStorage::WriteResult SettingsStorageQuotaEnforcer::Set(
WriteOptions options, const DictionaryValue& values) {
size_t new_used_total = used_total_;
std::map<std::string, size_t> new_used_per_setting = used_per_setting_;
for (DictionaryValue::Iterator it(values); it.HasNext(); it.Advance()) {
Allocate(it.key(), it.value(), &new_used_total, &new_used_per_setting);
if (new_used_per_setting[it.key()] > quota_bytes_per_setting_) {
if (options != FORCE &&
new_used_per_setting[it.key()] > quota_bytes_per_setting_) {
return QuotaExceededFor(BYTES_PER_SETTING);
}
}
if (new_used_total > quota_bytes_) {
return QuotaExceededFor(TOTAL_BYTES);
}
if (new_used_per_setting.size() > max_keys_) {
return QuotaExceededFor(KEY_COUNT);
if (options != FORCE) {
if (new_used_total > quota_bytes_) {
return QuotaExceededFor(TOTAL_BYTES);
}
if (new_used_per_setting.size() > max_keys_) {
return QuotaExceededFor(KEY_COUNT);
}
}
WriteResult result = delegate_->Set(values);
WriteResult result = delegate_->Set(options, values);
if (result.HasError()) {
return result;
}
......@@ -172,8 +174,7 @@ SettingsStorageQuotaEnforcer::Set(
return result;
}
SettingsStorage::WriteResult
SettingsStorageQuotaEnforcer::Remove(
SettingsStorage::WriteResult SettingsStorageQuotaEnforcer::Remove(
const std::string& key) {
WriteResult result = delegate_->Remove(key);
if (result.HasError()) {
......@@ -183,8 +184,7 @@ SettingsStorageQuotaEnforcer::Remove(
return result;
}
SettingsStorage::WriteResult
SettingsStorageQuotaEnforcer::Remove(
SettingsStorage::WriteResult SettingsStorageQuotaEnforcer::Remove(
const std::vector<std::string>& keys) {
WriteResult result = delegate_->Remove(keys);
if (result.HasError()) {
......@@ -198,9 +198,7 @@ SettingsStorageQuotaEnforcer::Remove(
return result;
}
SettingsStorage::WriteResult
SettingsStorageQuotaEnforcer::Clear(
) {
SettingsStorage::WriteResult SettingsStorageQuotaEnforcer::Clear() {
WriteResult result = delegate_->Clear();
if (result.HasError()) {
return result;
......
......@@ -29,8 +29,12 @@ class SettingsStorageQuotaEnforcer : public SettingsStorage {
virtual ReadResult Get(const std::string& key) OVERRIDE;
virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
virtual ReadResult Get() OVERRIDE;
virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE;
virtual WriteResult Set(const DictionaryValue& settings) OVERRIDE;
virtual WriteResult Set(
WriteOptions options,
const std::string& key,
const Value& value) OVERRIDE;
virtual WriteResult Set(
WriteOptions options, const DictionaryValue& values) OVERRIDE;
virtual WriteResult Remove(const std::string& key) OVERRIDE;
virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
virtual WriteResult Clear() OVERRIDE;
......
......@@ -14,6 +14,9 @@ using content::BrowserThread;
namespace {
// To save typing SettingsStorage::DEFAULTS everywhere.
const SettingsStorage::WriteOptions DEFAULTS = SettingsStorage::DEFAULTS;
// Gets the pretty-printed JSON for a value.
std::string GetJSON(const Value& value) {
std::string json;
......@@ -199,7 +202,8 @@ TEST_P(ExtensionSettingsStorageTest, GetWithSingleValue) {
{
SettingChangeList changes;
changes.push_back(SettingChange(key1_, NULL, val1_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(key1_, *val1_));
EXPECT_PRED_FORMAT2(ChangesEq,
changes, storage_->Set(DEFAULTS, key1_, *val1_));
}
EXPECT_PRED_FORMAT2(SettingsEq, *dict1_, storage_->Get(key1_));
......@@ -215,7 +219,7 @@ TEST_P(ExtensionSettingsStorageTest, GetWithMultipleValues) {
SettingChangeList changes;
changes.push_back(SettingChange(key1_, NULL, val1_->DeepCopy()));
changes.push_back(SettingChange(key2_, NULL, val2_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(*dict12_));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(DEFAULTS, *dict12_));
}
EXPECT_PRED_FORMAT2(SettingsEq, *dict1_, storage_->Get(key1_));
......@@ -226,8 +230,7 @@ TEST_P(ExtensionSettingsStorageTest, GetWithMultipleValues) {
}
TEST_P(ExtensionSettingsStorageTest, RemoveWhenEmpty) {
EXPECT_PRED_FORMAT2(ChangesEq,
SettingChangeList(), storage_->Remove(key1_));
EXPECT_PRED_FORMAT2(ChangesEq, SettingChangeList(), storage_->Remove(key1_));
EXPECT_PRED_FORMAT2(SettingsEq, *empty_dict_, storage_->Get(key1_));
EXPECT_PRED_FORMAT2(SettingsEq, *empty_dict_, storage_->Get(list1_));
......@@ -235,7 +238,7 @@ TEST_P(ExtensionSettingsStorageTest, RemoveWhenEmpty) {
}
TEST_P(ExtensionSettingsStorageTest, RemoveWithSingleValue) {
storage_->Set(*dict1_);
storage_->Set(DEFAULTS, *dict1_);
{
SettingChangeList changes;
changes.push_back(SettingChange(key1_, val1_->DeepCopy(), NULL));
......@@ -250,7 +253,7 @@ TEST_P(ExtensionSettingsStorageTest, RemoveWithSingleValue) {
}
TEST_P(ExtensionSettingsStorageTest, RemoveWithMultipleValues) {
storage_->Set(*dict123_);
storage_->Set(DEFAULTS, *dict123_);
{
SettingChangeList changes;
changes.push_back(SettingChange(key3_, val3_->DeepCopy(), NULL));
......@@ -284,13 +287,13 @@ TEST_P(ExtensionSettingsStorageTest, RemoveWithMultipleValues) {
}
TEST_P(ExtensionSettingsStorageTest, SetWhenOverwriting) {
storage_->Set(key1_, *val2_);
storage_->Set(DEFAULTS, key1_, *val2_);
{
SettingChangeList changes;
changes.push_back(
SettingChange(key1_, val2_->DeepCopy(), val1_->DeepCopy()));
changes.push_back(SettingChange(key2_, NULL, val2_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(*dict12_));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(DEFAULTS, *dict12_));
}
EXPECT_PRED_FORMAT2(SettingsEq, *dict1_, storage_->Get(key1_));
......@@ -304,8 +307,7 @@ TEST_P(ExtensionSettingsStorageTest, SetWhenOverwriting) {
}
TEST_P(ExtensionSettingsStorageTest, ClearWhenEmpty) {
EXPECT_PRED_FORMAT2(ChangesEq,
SettingChangeList(), storage_->Clear());
EXPECT_PRED_FORMAT2(ChangesEq, SettingChangeList(), storage_->Clear());
EXPECT_PRED_FORMAT2(SettingsEq, *empty_dict_, storage_->Get(key1_));
EXPECT_PRED_FORMAT2(SettingsEq, *empty_dict_, storage_->Get(empty_list_));
......@@ -314,7 +316,7 @@ TEST_P(ExtensionSettingsStorageTest, ClearWhenEmpty) {
}
TEST_P(ExtensionSettingsStorageTest, ClearWhenNotEmpty) {
storage_->Set(*dict12_);
storage_->Set(DEFAULTS, *dict12_);
{
SettingChangeList changes;
changes.push_back(SettingChange(key1_, val1_->DeepCopy(), NULL));
......@@ -344,10 +346,11 @@ TEST_P(ExtensionSettingsStorageTest, DotsInKeyNames) {
SettingChangeList changes;
changes.push_back(
SettingChange(dot_key, NULL, dot_value.DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(dot_key, dot_value));
EXPECT_PRED_FORMAT2(ChangesEq,
changes, storage_->Set(DEFAULTS, dot_key, dot_value));
}
EXPECT_PRED_FORMAT2(ChangesEq,
SettingChangeList(), storage_->Set(dot_key, dot_value));
SettingChangeList(), storage_->Set(DEFAULTS, dot_key, dot_value));
EXPECT_PRED_FORMAT2(SettingsEq, dot_dict, storage_->Get(dot_key));
......@@ -363,7 +366,7 @@ TEST_P(ExtensionSettingsStorageTest, DotsInKeyNames) {
SettingChangeList changes;
changes.push_back(
SettingChange(dot_key, NULL, dot_value.DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(dot_dict));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(DEFAULTS, dot_dict));
}
EXPECT_PRED_FORMAT2(SettingsEq, dot_dict, storage_->Get(dot_list));
......@@ -390,7 +393,8 @@ TEST_P(ExtensionSettingsStorageTest, DotsInKeyNamesWithDicts) {
SettingChangeList changes;
changes.push_back(
SettingChange("foo", NULL, inner_dict->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(outer_dict));
EXPECT_PRED_FORMAT2(ChangesEq,
changes, storage_->Set(DEFAULTS, outer_dict));
}
EXPECT_PRED_FORMAT2(SettingsEq, outer_dict, storage_->Get("foo"));
......@@ -405,14 +409,15 @@ TEST_P(ExtensionSettingsStorageTest, ComplexChangedKeysScenarios) {
std::vector<std::string> complex_list;
DictionaryValue complex_changed_dict;
storage_->Set(key1_, *val1_);
storage_->Set(DEFAULTS, key1_, *val1_);
EXPECT_PRED_FORMAT2(ChangesEq,
SettingChangeList(), storage_->Set(key1_, *val1_));
SettingChangeList(), storage_->Set(DEFAULTS, key1_, *val1_));
{
SettingChangeList changes;
changes.push_back(SettingChange(
key1_, val1_->DeepCopy(), val2_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(key1_, *val2_));
EXPECT_PRED_FORMAT2(ChangesEq,
changes, storage_->Set(DEFAULTS, key1_, *val2_));
}
{
SettingChangeList changes;
......@@ -424,28 +429,28 @@ TEST_P(ExtensionSettingsStorageTest, ComplexChangedKeysScenarios) {
{
SettingChangeList changes;
changes.push_back(SettingChange(key1_, NULL, val1_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(key1_, *val1_));
EXPECT_PRED_FORMAT2(ChangesEq,
changes, storage_->Set(DEFAULTS, key1_, *val1_));
}
{
SettingChangeList changes;
changes.push_back(SettingChange(key1_, val1_->DeepCopy(), NULL));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Clear());
EXPECT_PRED_FORMAT2(ChangesEq,
SettingChangeList(), storage_->Clear());
EXPECT_PRED_FORMAT2(ChangesEq, SettingChangeList(), storage_->Clear());
}
{
SettingChangeList changes;
changes.push_back(SettingChange(key1_, NULL, val1_->DeepCopy()));
changes.push_back(SettingChange(key2_, NULL, val2_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(*dict12_));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(DEFAULTS, *dict12_));
EXPECT_PRED_FORMAT2(ChangesEq,
SettingChangeList(), storage_->Set(*dict12_));
SettingChangeList(), storage_->Set(DEFAULTS, *dict12_));
}
{
SettingChangeList changes;
changes.push_back(SettingChange(key3_, NULL, val3_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(*dict123_));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(DEFAULTS, *dict123_));
}
{
DictionaryValue to_set;
......@@ -460,7 +465,7 @@ TEST_P(ExtensionSettingsStorageTest, ComplexChangedKeysScenarios) {
changes.push_back(SettingChange("asdf", NULL, val1_->DeepCopy()));
changes.push_back(
SettingChange("qwerty", NULL, val3_->DeepCopy()));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(to_set));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Set(DEFAULTS, to_set));
}
{
SettingChangeList changes;
......@@ -483,8 +488,7 @@ TEST_P(ExtensionSettingsStorageTest, ComplexChangedKeysScenarios) {
changes.push_back(
SettingChange("qwerty", val3_->DeepCopy(), NULL));
EXPECT_PRED_FORMAT2(ChangesEq, changes, storage_->Clear());
EXPECT_PRED_FORMAT2(ChangesEq,
SettingChangeList(), storage_->Clear());
EXPECT_PRED_FORMAT2(ChangesEq, SettingChangeList(), storage_->Clear());
}
}
......
......@@ -49,9 +49,9 @@ SettingsStorage::ReadResult SyncableSettingsStorage::Get() {
}
SettingsStorage::WriteResult SyncableSettingsStorage::Set(
const std::string& key, const Value& value) {
WriteOptions options, const std::string& key, const Value& value) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
WriteResult result = delegate_->Set(key, value);
WriteResult result = delegate_->Set(options, key, value);
if (result.HasError()) {
return result;
}
......@@ -62,9 +62,9 @@ SettingsStorage::WriteResult SyncableSettingsStorage::Set(
}
SettingsStorage::WriteResult SyncableSettingsStorage::Set(
const DictionaryValue& values) {
WriteOptions options, const DictionaryValue& values) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
WriteResult result = delegate_->Set(values);
WriteResult result = delegate_->Set(options, values);
if (result.HasError()) {
return result;
}
......@@ -100,8 +100,7 @@ SettingsStorage::WriteResult SyncableSettingsStorage::Remove(
return result;
}
SettingsStorage::WriteResult
SyncableSettingsStorage::Clear() {
SettingsStorage::WriteResult SyncableSettingsStorage::Clear() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
WriteResult result = delegate_->Clear();
if (result.HasError()) {
......@@ -396,7 +395,7 @@ SyncError SyncableSettingsStorage::OnSyncAdd(
SettingChangeList* changes) {
DCHECK(new_value);
synced_keys_.insert(key);
WriteResult result = delegate_->Set(key, *new_value);
WriteResult result = delegate_->Set(FORCE, key, *new_value);
if (result.HasError()) {
return SyncError(
FROM_HERE,
......@@ -415,7 +414,7 @@ SyncError SyncableSettingsStorage::OnSyncUpdate(
SettingChangeList* changes) {
DCHECK(old_value);
DCHECK(new_value);
WriteResult result = delegate_->Set(key, *new_value);
WriteResult result = delegate_->Set(FORCE, key, *new_value);
if (result.HasError()) {
return SyncError(
FROM_HERE,
......
......@@ -34,8 +34,12 @@ class SyncableSettingsStorage : public SettingsStorage {
virtual ReadResult Get(const std::string& key) OVERRIDE;
virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
virtual ReadResult Get() OVERRIDE;
virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE;
virtual WriteResult Set(const DictionaryValue& settings) OVERRIDE;
virtual WriteResult Set(
WriteOptions options,
const std::string& key,
const Value& value) OVERRIDE;
virtual WriteResult Set(
WriteOptions options, const DictionaryValue& values) OVERRIDE;
virtual WriteResult Remove(const std::string& key) OVERRIDE;
virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
virtual WriteResult Clear() OVERRIDE;
......
......@@ -67,14 +67,14 @@ SettingsStorage::ReadResult TestingSettingsStorage::Get() {
}
SettingsStorage::WriteResult TestingSettingsStorage::Set(
const std::string& key, const Value& value) {
WriteOptions options, const std::string& key, const Value& value) {
DictionaryValue settings;
settings.SetWithoutPathExpansion(key, value.DeepCopy());
return Set(settings);
return Set(options, settings);
}
SettingsStorage::WriteResult TestingSettingsStorage::Set(
const DictionaryValue& settings) {
WriteOptions options, const DictionaryValue& settings) {
if (fail_all_requests_) {
return WriteResultError();
}
......
......@@ -25,8 +25,12 @@ class TestingSettingsStorage : public SettingsStorage {
virtual ReadResult Get(const std::string& key) OVERRIDE;
virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE;
virtual ReadResult Get() OVERRIDE;
virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE;
virtual WriteResult Set(const DictionaryValue& values) OVERRIDE;
virtual WriteResult Set(
WriteOptions options,
const std::string& key,
const Value& value) OVERRIDE;
virtual WriteResult Set(
WriteOptions options, const DictionaryValue& values) OVERRIDE;
virtual WriteResult Remove(const std::string& key) OVERRIDE;
virtual WriteResult Remove(const std::vector<std::string>& keys) OVERRIDE;
virtual WriteResult Clear() OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment