summaryrefslogtreecommitdiffstats
path: root/chrome/common/json_pref_store.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 21:17:59 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-24 21:17:59 +0000
commit9b5f56b43a17fbee9f595a42f4733b4ccb1b7095 (patch)
treed3e5067ecf4173cc49909bdd16e0eab354f2c918 /chrome/common/json_pref_store.cc
parentdb3fecb2745b58baaa1fec2f170453e75746fc20 (diff)
downloadchromium_src-9b5f56b43a17fbee9f595a42f4733b4ccb1b7095.zip
chromium_src-9b5f56b43a17fbee9f595a42f4733b4ccb1b7095.tar.gz
chromium_src-9b5f56b43a17fbee9f595a42f4733b4ccb1b7095.tar.bz2
Reverts debugging code added in hopes of tracking crash. This also
reverts 97997 as it was only needed with this debugging code. I'm TBRing this as it's just a revert (well, two reverts). BUG=91396 TEST=none R=brettw@chromium.org,mnissler@chromium.org,ben@chromium.org TBR=brettw@chromium.org,mnissler@chromium.org,ben@chromium.org Review URL: http://codereview.chromium.org/7714038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/json_pref_store.cc')
-rw-r--r--chrome/common/json_pref_store.cc81
1 files changed, 16 insertions, 65 deletions
diff --git a/chrome/common/json_pref_store.cc b/chrome/common/json_pref_store.cc
index 8767fc5..f3bd776 100644
--- a/chrome/common/json_pref_store.cc
+++ b/chrome/common/json_pref_store.cc
@@ -148,7 +148,6 @@ JsonPrefStore::JsonPrefStore(const FilePath& filename,
}
JsonPrefStore::~JsonPrefStore() {
- ResetCheckIfValueDestroyed(prefs_.get());
CommitPendingWrite();
}
@@ -181,20 +180,29 @@ PrefStore::ReadResult JsonPrefStore::GetMutableValue(const std::string& key,
}
void JsonPrefStore::SetValue(const std::string& key, Value* value) {
- SetValueImpl(key, value, SET_VALUE_NOTIFY);
+ DCHECK(value);
+ scoped_ptr<Value> new_value(value);
+ Value* old_value = NULL;
+ prefs_->Get(key, &old_value);
+ if (!old_value || !value->Equals(old_value)) {
+ prefs_->Set(key, new_value.release());
+ FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+ }
}
void JsonPrefStore::SetValueSilently(const std::string& key, Value* value) {
- SetValueImpl(key, value, SET_VALUE_DONT_NOTIFY);
+ DCHECK(value);
+ scoped_ptr<Value> new_value(value);
+ Value* old_value = NULL;
+ prefs_->Get(key, &old_value);
+ if (!old_value || !value->Equals(old_value))
+ prefs_->Set(key, new_value.release());
}
void JsonPrefStore::RemoveValue(const std::string& key) {
- Value* value = NULL;
- bool path_existed = prefs_->Remove(key, &value);
- scoped_ptr<Value> owned_value(value);
- ResetCheckIfValueDestroyed(value);
- if (path_existed)
+ if (prefs_->Remove(key, NULL)) {
FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
+ }
}
bool JsonPrefStore::ReadOnly() const {
@@ -224,7 +232,6 @@ void JsonPrefStore::OnFileRead(Value* value_owned,
break;
case PREF_READ_ERROR_NONE:
DCHECK(value.get());
- ResetCheckIfValueDestroyed(prefs_.get());
prefs_.reset(static_cast<DictionaryValue*>(value.release()));
break;
case PREF_READ_ERROR_NO_FILE:
@@ -303,13 +310,6 @@ void JsonPrefStore::ReportValueChanged(const std::string& key) {
FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
}
-void JsonPrefStore::CheckIfValueDestroyed(const std::string& key) {
- Value* value = NULL;
- CHECK_EQ(READ_OK, GetMutableValue(key, &value));
- CHECK(value);
- value->set_check_on_delete(true);
-}
-
bool JsonPrefStore::SerializeData(std::string* output) {
// TODO(tc): Do we want to prune webkit preferences that match the default
// value?
@@ -318,52 +318,3 @@ bool JsonPrefStore::SerializeData(std::string* output) {
scoped_ptr<DictionaryValue> copy(prefs_->DeepCopyWithoutEmptyChildren());
return serializer.Serialize(*(copy.get()));
}
-
-void JsonPrefStore::SetValueImpl(const std::string& key,
- Value* value,
- SetValueType type) {
- DCHECK(value);
- scoped_ptr<Value> new_value(value);
- Value* old_value = NULL;
- prefs_->Get(key, &old_value);
- ResetCheckIfValueDestroyed(old_value);
- if (!old_value || !value->Equals(old_value)) {
- prefs_->Set(key, new_value.release());
- if (type == SET_VALUE_NOTIFY)
- ReportValueChanged(key);
- }
-}
-
-// static
-void JsonPrefStore::ResetCheckIfValueDestroyed(Value* value) {
- if (!value)
- return;
-
- value->set_check_on_delete(false);
-
- switch (value->GetType()) {
- case Value::TYPE_DICTIONARY: {
- DictionaryValue* dictionary = static_cast<DictionaryValue*>(value);
- for (DictionaryValue::key_iterator i = dictionary->begin_keys();
- i != dictionary->end_keys(); ++i) {
- Value* child_value = NULL;
- dictionary->GetWithoutPathExpansion(*i, &child_value);
- ResetCheckIfValueDestroyed(child_value);
- }
- break;
- }
-
- case Value::TYPE_LIST: {
- ListValue* list = static_cast<ListValue*>(value);
- for (size_t i = 0; i < list->GetSize(); ++i) {
- Value* child_value = NULL;
- list->Get(i, &child_value);
- ResetCheckIfValueDestroyed(child_value);
- }
- break;
- }
-
- default:
- break;
- }
-}