Commit beefaef1 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Make DefaultPrefStore::ReplaceDefaultValue() more efficient.

Fix some other nits in prefs code too.

Change-Id: If08a48575024d8e338cc5ef009ba8535627584dd
Reviewed-on: https://chromium-review.googlesource.com/721805Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509487}
parent 9585805f
...@@ -35,16 +35,14 @@ bool DefaultPrefStore::HasObservers() const { ...@@ -35,16 +35,14 @@ bool DefaultPrefStore::HasObservers() const {
void DefaultPrefStore::SetDefaultValue(const std::string& key, void DefaultPrefStore::SetDefaultValue(const std::string& key,
std::unique_ptr<Value> value) { std::unique_ptr<Value> value) {
DCHECK(!GetValue(key, NULL)); DCHECK(!GetValue(key, nullptr));
prefs_.SetValue(key, std::move(value)); prefs_.SetValue(key, std::move(value));
} }
void DefaultPrefStore::ReplaceDefaultValue(const std::string& key, void DefaultPrefStore::ReplaceDefaultValue(const std::string& key,
std::unique_ptr<Value> value) { std::unique_ptr<Value> value) {
const Value* old_value = NULL; DCHECK(GetValue(key, nullptr));
GetValue(key, &old_value); bool notify = prefs_.SetValue(key, std::move(value));
bool notify = !old_value->Equals(value.get());
prefs_.SetValue(key, std::move(value));
if (notify) { if (notify) {
for (Observer& observer : observers_) for (Observer& observer : observers_)
observer.OnPrefValueChanged(key); observer.OnPrefValueChanged(key);
......
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
#include "components/prefs/pref_store.h" #include "components/prefs/pref_store.h"
PrefRegistry::PrefRegistry() PrefRegistry::PrefRegistry()
: defaults_(new DefaultPrefStore()) { : defaults_(base::MakeRefCounted<DefaultPrefStore>()) {}
}
PrefRegistry::~PrefRegistry() { PrefRegistry::~PrefRegistry() {
} }
...@@ -23,9 +22,7 @@ PrefRegistry::~PrefRegistry() { ...@@ -23,9 +22,7 @@ PrefRegistry::~PrefRegistry() {
uint32_t PrefRegistry::GetRegistrationFlags( uint32_t PrefRegistry::GetRegistrationFlags(
const std::string& pref_name) const { const std::string& pref_name) const {
const auto& it = registration_flags_.find(pref_name); const auto& it = registration_flags_.find(pref_name);
if (it == registration_flags_.end()) return it != registration_flags_.end() ? it->second : NO_REGISTRATION_FLAGS;
return NO_REGISTRATION_FLAGS;
return it->second;
} }
scoped_refptr<PrefStore> PrefRegistry::defaults() { scoped_refptr<PrefStore> PrefRegistry::defaults() {
......
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