summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-21 16:50:56 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-21 16:50:56 +0000
commita0ce7e79684215666276bc123cc1db421ba3ff09 (patch)
tree47afc1d9ad46268e9d63468c0a80c4e0cf7e88b8 /base
parent28779ee003711fcb72270eb1549d727c51682419 (diff)
downloadchromium_src-a0ce7e79684215666276bc123cc1db421ba3ff09.zip
chromium_src-a0ce7e79684215666276bc123cc1db421ba3ff09.tar.gz
chromium_src-a0ce7e79684215666276bc123cc1db421ba3ff09.tar.bz2
Only compute pref hashes when about to serialize preferences to disk.
This is expected to help a perf regression reported in http://crbug.com/331273. Previously, a new hash would be computed and updated in memory every time a pref's value changes. Computing the hash is expensive as it requires serializing the pref's value to a string. This is particularly bad for the extensions dictionary which is big and can update often in a short time span. The hash is only really needed when writing the file to disk, this change makes sure to only compute the hash at that point. The hashes are still stored in local_state though, so for now this means we're going from a world in which a crash after updating pref1 in memory could result in either: 1) New pref1 in Preferences, new hash for pref1 in local_state 2) New pref1 in Preferences, old hash for pref1 in local_state 3) Old pref1 in Preferences, new hash for pref1 in local_state 4) Old pref1 in Preferences, old hash for pref1 in local_state Depending on which file was flushed to disk. We only want (1) and (4) to be possible; with this CL we remove (3). We still always get (1) on clean shutdowns as local_state is always last flushed after all profiles have been flushed/shutdown. We will later need to move the hashes to the same file as the prefs' values to get rid of (2) as well. BUG=331273 Review URL: https://codereview.chromium.org/143723002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/prefs/json_pref_store.cc10
-rw-r--r--base/prefs/pref_filter.h8
2 files changed, 11 insertions, 7 deletions
diff --git a/base/prefs/json_pref_store.cc b/base/prefs/json_pref_store.cc
index f417b8b..0703075 100644
--- a/base/prefs/json_pref_store.cc
+++ b/base/prefs/json_pref_store.cc
@@ -267,11 +267,8 @@ void JsonPrefStore::CommitPendingWrite() {
}
void JsonPrefStore::ReportValueChanged(const std::string& key) {
- if (pref_filter_) {
- const base::Value* tmp = NULL;
- prefs_->Get(key, &tmp);
- pref_filter_->FilterUpdate(key, tmp);
- }
+ if (pref_filter_)
+ pref_filter_->FilterUpdate(key);
FOR_EACH_OBSERVER(PrefStore::Observer, observers_, OnPrefValueChanged(key));
@@ -333,6 +330,9 @@ JsonPrefStore::~JsonPrefStore() {
}
bool JsonPrefStore::SerializeData(std::string* output) {
+ if (pref_filter_)
+ pref_filter_->FilterSerializeData(prefs_.get());
+
JSONStringValueSerializer serializer(output);
serializer.set_pretty_print(true);
return serializer.Serialize(*prefs_);
diff --git a/base/prefs/pref_filter.h b/base/prefs/pref_filter.h
index 3d136f7..0cf78a9 100644
--- a/base/prefs/pref_filter.h
+++ b/base/prefs/pref_filter.h
@@ -28,8 +28,12 @@ class BASE_PREFS_EXPORT PrefFilter {
// Receives notification when a pref store value is changed, before Observers
// are notified.
- virtual void FilterUpdate(const std::string& path,
- const base::Value* value) = 0;
+ virtual void FilterUpdate(const std::string& path) = 0;
+
+ // Receives notification when the pref store is about to serialize data
+ // contained in |pref_store_contents| to a string.
+ virtual void FilterSerializeData(
+ const base::DictionaryValue* pref_store_contents) = 0;
};
#endif // BASE_PREFS_PREF_FILTER_H_