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