summaryrefslogtreecommitdiffstats
path: root/base/prefs
diff options
context:
space:
mode:
authorgeorgesak <georgesak@chromium.org>2014-12-02 17:10:29 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-03 01:10:44 +0000
commit7da6e9da88541615b6e709baa4ed6b05c40fcdcf (patch)
tree5d8cb270470640b6ea521547d1d14240bbb73842 /base/prefs
parent3d4df94e080daaccf0c58ceb52e231883bcf2e55 (diff)
downloadchromium_src-7da6e9da88541615b6e709baa4ed6b05c40fcdcf.zip
chromium_src-7da6e9da88541615b6e709baa4ed6b05c40fcdcf.tar.gz
chromium_src-7da6e9da88541615b6e709baa4ed6b05c40fcdcf.tar.bz2
Change preference APIs to take std::string instead of const char*.
The string can't be NULL, and most callers have std::strings already, so this makes the intent clearer and avoid unnecessary switch between std::string and const char*. Right now, the prefs are stored in char*, then converted to strings, then passed again as char*, only to be converted again, which creates the unnecessary temporary strings. For example, PrefValueStore::OnPrefValueChanged passes |key|, which is a string, as a const char* to PrefValueStore::NotifyPrefChanged, which then passes it to PrefNotifierImpl::OnPreferenceChanged as a string again. Our tests show that this change reduces on average by ~9% the number of total allocations in the browser process. Notes: - The underlying pref map in the PrefRegistry is based on string keys and thus any call to it, e.g. find(), needs to convert to string anyways at the bottom of the implementation so might as well force the string to be passed into the API originally. - A strict char* API, i.e. all the way into the pref map with a custom comparator/etc., would make memory harder to manage since we can't strictly force the caller to pass only pointers to constants in .rodata and would thus require explicit memory management. - Ideally, we would need a hybrid string class that manages the memory on demand. That way, it can point to hard coded strings with the memory management disabled or allocate a buffer that it will manage, to get the best of both worlds. BUG=438215 Review URL: https://codereview.chromium.org/753603002 Cr-Commit-Position: refs/heads/master@{#306514}
Diffstat (limited to 'base/prefs')
-rw-r--r--base/prefs/mock_pref_change_callback.h3
-rw-r--r--base/prefs/pref_change_registrar.cc11
-rw-r--r--base/prefs/pref_change_registrar.h6
-rw-r--r--base/prefs/pref_change_registrar_unittest.cc6
-rw-r--r--base/prefs/pref_member.cc26
-rw-r--r--base/prefs/pref_member.h13
-rw-r--r--base/prefs/pref_member_unittest.cc2
-rw-r--r--base/prefs/pref_notifier_impl.cc6
-rw-r--r--base/prefs/pref_notifier_impl.h4
-rw-r--r--base/prefs/pref_notifier_impl_unittest.cc2
-rw-r--r--base/prefs/pref_registry.cc4
-rw-r--r--base/prefs/pref_registry.h4
-rw-r--r--base/prefs/pref_registry_simple.cc20
-rw-r--r--base/prefs/pref_registry_simple.h23
-rw-r--r--base/prefs/pref_service.cc95
-rw-r--r--base/prefs/pref_service.h61
-rw-r--r--base/prefs/pref_value_store.cc42
-rw-r--r--base/prefs/pref_value_store.h30
-rw-r--r--base/prefs/pref_value_store_unittest.cc2
-rw-r--r--base/prefs/scoped_user_pref_update.cc8
-rw-r--r--base/prefs/scoped_user_pref_update.h4
-rw-r--r--base/prefs/testing_pref_service.h114
22 files changed, 240 insertions, 246 deletions
diff --git a/base/prefs/mock_pref_change_callback.h b/base/prefs/mock_pref_change_callback.h
index 422754a..3030fab 100644
--- a/base/prefs/mock_pref_change_callback.h
+++ b/base/prefs/mock_pref_change_callback.h
@@ -19,8 +19,7 @@ using testing::Truly;
// |pref_name| in |prefs| matches |value|. If |value| is NULL, the matcher
// checks that the value is not set.
MATCHER_P3(PrefValueMatches, prefs, pref_name, value, "") {
- const PrefService::Preference* pref =
- prefs->FindPreference(pref_name.c_str());
+ const PrefService::Preference* pref = prefs->FindPreference(pref_name);
if (!pref)
return false;
diff --git a/base/prefs/pref_change_registrar.cc b/base/prefs/pref_change_registrar.cc
index 28ac374..13193484 100644
--- a/base/prefs/pref_change_registrar.cc
+++ b/base/prefs/pref_change_registrar.cc
@@ -23,12 +23,12 @@ void PrefChangeRegistrar::Init(PrefService* service) {
service_ = service;
}
-void PrefChangeRegistrar::Add(const char* path,
+void PrefChangeRegistrar::Add(const std::string& path,
const base::Closure& obs) {
Add(path, base::Bind(&PrefChangeRegistrar::InvokeUnnamedCallback, obs));
}
-void PrefChangeRegistrar::Add(const char* path,
+void PrefChangeRegistrar::Add(const std::string& path,
const NamedChangeCallback& obs) {
if (!service_) {
NOTREACHED();
@@ -40,7 +40,7 @@ void PrefChangeRegistrar::Add(const char* path,
observers_[path] = obs;
}
-void PrefChangeRegistrar::Remove(const char* path) {
+void PrefChangeRegistrar::Remove(const std::string& path) {
DCHECK(IsObserved(path));
observers_.erase(path);
@@ -50,7 +50,7 @@ void PrefChangeRegistrar::Remove(const char* path) {
void PrefChangeRegistrar::RemoveAll() {
for (ObserverMap::const_iterator it = observers_.begin();
it != observers_.end(); ++it) {
- service_->RemovePrefObserver(it->first.c_str(), this);
+ service_->RemovePrefObserver(it->first, this);
}
observers_.clear();
@@ -67,8 +67,7 @@ bool PrefChangeRegistrar::IsObserved(const std::string& pref) {
bool PrefChangeRegistrar::IsManaged() {
for (ObserverMap::const_iterator it = observers_.begin();
it != observers_.end(); ++it) {
- const PrefService::Preference* pref =
- service_->FindPreference(it->first.c_str());
+ const PrefService::Preference* pref = service_->FindPreference(it->first);
if (pref && pref->IsManaged())
return true;
}
diff --git a/base/prefs/pref_change_registrar.h b/base/prefs/pref_change_registrar.h
index 70c22fe..acf0a68 100644
--- a/base/prefs/pref_change_registrar.h
+++ b/base/prefs/pref_change_registrar.h
@@ -40,11 +40,11 @@ class BASE_PREFS_EXPORT PrefChangeRegistrar : public PrefObserver {
// the preference that is changing as its parameter.
//
// Only one observer may be registered per path.
- void Add(const char* path, const base::Closure& obs);
- void Add(const char* path, const NamedChangeCallback& obs);
+ void Add(const std::string& path, const base::Closure& obs);
+ void Add(const std::string& path, const NamedChangeCallback& obs);
// Removes the pref observer registered for |path|.
- void Remove(const char* path);
+ void Remove(const std::string& path);
// Removes all observers that have been previously added with a call to Add.
void RemoveAll();
diff --git a/base/prefs/pref_change_registrar_unittest.cc b/base/prefs/pref_change_registrar_unittest.cc
index e9255a0..e449084 100644
--- a/base/prefs/pref_change_registrar_unittest.cc
+++ b/base/prefs/pref_change_registrar_unittest.cc
@@ -27,10 +27,8 @@ class MockPrefService : public TestingPrefServiceSimple {
MockPrefService() {}
virtual ~MockPrefService() {}
- MOCK_METHOD2(AddPrefObserver,
- void(const char*, PrefObserver*));
- MOCK_METHOD2(RemovePrefObserver,
- void(const char*, PrefObserver*));
+ MOCK_METHOD2(AddPrefObserver, void(const std::string&, PrefObserver*));
+ MOCK_METHOD2(RemovePrefObserver, void(const std::string&, PrefObserver*));
};
} // namespace
diff --git a/base/prefs/pref_member.cc b/base/prefs/pref_member.cc
index 4fa616f..8d80dd0 100644
--- a/base/prefs/pref_member.cc
+++ b/base/prefs/pref_member.cc
@@ -25,23 +25,20 @@ PrefMemberBase::~PrefMemberBase() {
Destroy();
}
-void PrefMemberBase::Init(const char* pref_name,
+void PrefMemberBase::Init(const std::string& pref_name,
PrefService* prefs,
const NamedChangeCallback& observer) {
observer_ = observer;
Init(pref_name, prefs);
}
-void PrefMemberBase::Init(const char* pref_name,
- PrefService* prefs) {
- DCHECK(pref_name);
+void PrefMemberBase::Init(const std::string& pref_name, PrefService* prefs) {
DCHECK(prefs);
DCHECK(pref_name_.empty()); // Check that Init is only called once.
prefs_ = prefs;
pref_name_ = pref_name;
// Check that the preference is registered.
- DCHECK(prefs_->FindPreference(pref_name_.c_str()))
- << pref_name << " not registered.";
+ DCHECK(prefs_->FindPreference(pref_name_)) << pref_name << " not registered.";
// Add ourselves as a pref observer so we can keep our local value in sync.
prefs_->AddPrefObserver(pref_name, this);
@@ -49,7 +46,7 @@ void PrefMemberBase::Init(const char* pref_name,
void PrefMemberBase::Destroy() {
if (prefs_ && !pref_name_.empty()) {
- prefs_->RemovePrefObserver(pref_name_.c_str(), this);
+ prefs_->RemovePrefObserver(pref_name_, this);
prefs_ = NULL;
}
}
@@ -72,8 +69,7 @@ void PrefMemberBase::OnPreferenceChanged(PrefService* service,
void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const {
VerifyValuePrefName();
- const PrefService::Preference* pref =
- prefs_->FindPreference(pref_name_.c_str());
+ const PrefService::Preference* pref = prefs_->FindPreference(pref_name_);
DCHECK(pref);
if (!internal())
CreateInternal();
@@ -158,7 +154,7 @@ bool PrefMemberVectorStringUpdate(const base::Value& value,
template <>
void PrefMember<bool>::UpdatePref(const bool& value) {
- prefs()->SetBoolean(pref_name().c_str(), value);
+ prefs()->SetBoolean(pref_name(), value);
}
template <>
@@ -169,7 +165,7 @@ bool PrefMember<bool>::Internal::UpdateValueInternal(
template <>
void PrefMember<int>::UpdatePref(const int& value) {
- prefs()->SetInteger(pref_name().c_str(), value);
+ prefs()->SetInteger(pref_name(), value);
}
template <>
@@ -180,7 +176,7 @@ bool PrefMember<int>::Internal::UpdateValueInternal(
template <>
void PrefMember<double>::UpdatePref(const double& value) {
- prefs()->SetDouble(pref_name().c_str(), value);
+ prefs()->SetDouble(pref_name(), value);
}
template <>
@@ -191,7 +187,7 @@ bool PrefMember<double>::Internal::UpdateValueInternal(const base::Value& value)
template <>
void PrefMember<std::string>::UpdatePref(const std::string& value) {
- prefs()->SetString(pref_name().c_str(), value);
+ prefs()->SetString(pref_name(), value);
}
template <>
@@ -203,7 +199,7 @@ bool PrefMember<std::string>::Internal::UpdateValueInternal(
template <>
void PrefMember<base::FilePath>::UpdatePref(const base::FilePath& value) {
- prefs()->SetFilePath(pref_name().c_str(), value);
+ prefs()->SetFilePath(pref_name(), value);
}
template <>
@@ -218,7 +214,7 @@ void PrefMember<std::vector<std::string> >::UpdatePref(
const std::vector<std::string>& value) {
base::ListValue list_value;
list_value.AppendStrings(value);
- prefs()->Set(pref_name().c_str(), list_value);
+ prefs()->Set(pref_name(), list_value);
}
template <>
diff --git a/base/prefs/pref_member.h b/base/prefs/pref_member.h
index a05d60e..b47cae2 100644
--- a/base/prefs/pref_member.h
+++ b/base/prefs/pref_member.h
@@ -103,9 +103,10 @@ class BASE_PREFS_EXPORT PrefMemberBase : public PrefObserver {
virtual ~PrefMemberBase();
// See PrefMember<> for description.
- void Init(const char* pref_name, PrefService* prefs,
+ void Init(const std::string& pref_name,
+ PrefService* prefs,
const NamedChangeCallback& observer);
- void Init(const char* pref_name, PrefService* prefs);
+ void Init(const std::string& pref_name, PrefService* prefs);
virtual void CreateInternal() const = 0;
@@ -169,17 +170,19 @@ class PrefMember : public subtle::PrefMemberBase {
// Do the actual initialization of the class. Use the two-parameter
// version if you don't want any notifications of changes. This
// method should only be called on the UI thread.
- void Init(const char* pref_name, PrefService* prefs,
+ void Init(const std::string& pref_name,
+ PrefService* prefs,
const NamedChangeCallback& observer) {
subtle::PrefMemberBase::Init(pref_name, prefs, observer);
}
- void Init(const char* pref_name, PrefService* prefs,
+ void Init(const std::string& pref_name,
+ PrefService* prefs,
const base::Closure& observer) {
subtle::PrefMemberBase::Init(
pref_name, prefs,
base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer));
}
- void Init(const char* pref_name, PrefService* prefs) {
+ void Init(const std::string& pref_name, PrefService* prefs) {
subtle::PrefMemberBase::Init(pref_name, prefs);
}
diff --git a/base/prefs/pref_member_unittest.cc b/base/prefs/pref_member_unittest.cc
index d4d7e02..435122b 100644
--- a/base/prefs/pref_member_unittest.cc
+++ b/base/prefs/pref_member_unittest.cc
@@ -35,7 +35,7 @@ class GetPrefValueHelper
pref_thread_.Start();
}
- void Init(const char* pref_name, PrefService* prefs) {
+ void Init(const std::string& pref_name, PrefService* prefs) {
pref_.Init(pref_name, prefs);
pref_.MoveToThread(pref_thread_.message_loop_proxy());
}
diff --git a/base/prefs/pref_notifier_impl.cc b/base/prefs/pref_notifier_impl.cc
index c02a7b3..6bf9603 100644
--- a/base/prefs/pref_notifier_impl.cc
+++ b/base/prefs/pref_notifier_impl.cc
@@ -38,7 +38,7 @@ PrefNotifierImpl::~PrefNotifierImpl() {
init_observers_.clear();
}
-void PrefNotifierImpl::AddPrefObserver(const char* path,
+void PrefNotifierImpl::AddPrefObserver(const std::string& path,
PrefObserver* obs) {
// Get the pref observer list associated with the path.
PrefObserverList* observer_list = NULL;
@@ -56,7 +56,7 @@ void PrefNotifierImpl::AddPrefObserver(const char* path,
observer_list->AddObserver(obs);
}
-void PrefNotifierImpl::RemovePrefObserver(const char* path,
+void PrefNotifierImpl::RemovePrefObserver(const std::string& path,
PrefObserver* obs) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -98,7 +98,7 @@ void PrefNotifierImpl::FireObservers(const std::string& path) {
DCHECK(thread_checker_.CalledOnValidThread());
// Only send notifications for registered preferences.
- if (!pref_service_->FindPreference(path.c_str()))
+ if (!pref_service_->FindPreference(path))
return;
const PrefObserverMap::iterator observer_iterator =
diff --git a/base/prefs/pref_notifier_impl.h b/base/prefs/pref_notifier_impl.h
index 3f4c254..cfd46ff 100644
--- a/base/prefs/pref_notifier_impl.h
+++ b/base/prefs/pref_notifier_impl.h
@@ -29,8 +29,8 @@ class BASE_PREFS_EXPORT PrefNotifierImpl
// If the pref at the given path changes, we call the observer's
// OnPreferenceChanged method.
- void AddPrefObserver(const char* path, PrefObserver* observer);
- void RemovePrefObserver(const char* path, PrefObserver* observer);
+ void AddPrefObserver(const std::string& path, PrefObserver* observer);
+ void RemovePrefObserver(const std::string& path, PrefObserver* observer);
// We run the callback once, when initialization completes. The bool
// parameter will be set to true for successful initialization,
diff --git a/base/prefs/pref_notifier_impl_unittest.cc b/base/prefs/pref_notifier_impl_unittest.cc
index 8482c02..04564c8 100644
--- a/base/prefs/pref_notifier_impl_unittest.cc
+++ b/base/prefs/pref_notifier_impl_unittest.cc
@@ -51,7 +51,7 @@ class MockPrefNotifier : public PrefNotifierImpl {
MOCK_METHOD1(FireObservers, void(const std::string& path));
- size_t CountObserver(const char* path, PrefObserver* obs) {
+ size_t CountObserver(const std::string& path, PrefObserver* obs) {
PrefObserverMap::const_iterator observer_iterator =
pref_observers()->find(path);
if (observer_iterator == pref_observers()->end())
diff --git a/base/prefs/pref_registry.cc b/base/prefs/pref_registry.cc
index 1349961..69f0494 100644
--- a/base/prefs/pref_registry.cc
+++ b/base/prefs/pref_registry.cc
@@ -28,7 +28,7 @@ PrefRegistry::const_iterator PrefRegistry::end() const {
return defaults_->end();
}
-void PrefRegistry::SetDefaultPrefValue(const char* pref_name,
+void PrefRegistry::SetDefaultPrefValue(const std::string& pref_name,
base::Value* value) {
DCHECK(value);
const base::Value* current_value = NULL;
@@ -40,7 +40,7 @@ void PrefRegistry::SetDefaultPrefValue(const char* pref_name,
defaults_->ReplaceDefaultValue(pref_name, make_scoped_ptr(value));
}
-void PrefRegistry::RegisterPreference(const char* path,
+void PrefRegistry::RegisterPreference(const std::string& path,
base::Value* default_value) {
base::Value::Type orig_type = default_value->GetType();
DCHECK(orig_type != base::Value::TYPE_NULL &&
diff --git a/base/prefs/pref_registry.h b/base/prefs/pref_registry.h
index 896db3f..a500b6e 100644
--- a/base/prefs/pref_registry.h
+++ b/base/prefs/pref_registry.h
@@ -41,14 +41,14 @@ class BASE_PREFS_EXPORT PrefRegistry : public base::RefCounted<PrefRegistry> {
// Changes the default value for a preference. Takes ownership of |value|.
//
// |pref_name| must be a previously registered preference.
- void SetDefaultPrefValue(const char* pref_name, base::Value* value);
+ void SetDefaultPrefValue(const std::string& pref_name, base::Value* value);
protected:
friend class base::RefCounted<PrefRegistry>;
virtual ~PrefRegistry();
// Used by subclasses to register a default value for a preference.
- void RegisterPreference(const char* path, base::Value* default_value);
+ void RegisterPreference(const std::string& path, base::Value* default_value);
scoped_refptr<DefaultPrefStore> defaults_;
diff --git a/base/prefs/pref_registry_simple.cc b/base/prefs/pref_registry_simple.cc
index 7453016..fa679dc 100644
--- a/base/prefs/pref_registry_simple.cc
+++ b/base/prefs/pref_registry_simple.cc
@@ -14,52 +14,52 @@ PrefRegistrySimple::PrefRegistrySimple() {
PrefRegistrySimple::~PrefRegistrySimple() {
}
-void PrefRegistrySimple::RegisterBooleanPref(const char* path,
+void PrefRegistrySimple::RegisterBooleanPref(const std::string& path,
bool default_value) {
RegisterPreference(path, new base::FundamentalValue(default_value));
}
-void PrefRegistrySimple::RegisterIntegerPref(const char* path,
+void PrefRegistrySimple::RegisterIntegerPref(const std::string& path,
int default_value) {
RegisterPreference(path, new base::FundamentalValue(default_value));
}
-void PrefRegistrySimple::RegisterDoublePref(const char* path,
+void PrefRegistrySimple::RegisterDoublePref(const std::string& path,
double default_value) {
RegisterPreference(path, new base::FundamentalValue(default_value));
}
-void PrefRegistrySimple::RegisterStringPref(const char* path,
+void PrefRegistrySimple::RegisterStringPref(const std::string& path,
const std::string& default_value) {
RegisterPreference(path, new base::StringValue(default_value));
}
void PrefRegistrySimple::RegisterFilePathPref(
- const char* path,
+ const std::string& path,
const base::FilePath& default_value) {
RegisterPreference(path, new base::StringValue(default_value.value()));
}
-void PrefRegistrySimple::RegisterListPref(const char* path) {
+void PrefRegistrySimple::RegisterListPref(const std::string& path) {
RegisterPreference(path, new base::ListValue());
}
-void PrefRegistrySimple::RegisterListPref(const char* path,
+void PrefRegistrySimple::RegisterListPref(const std::string& path,
base::ListValue* default_value) {
RegisterPreference(path, default_value);
}
-void PrefRegistrySimple::RegisterDictionaryPref(const char* path) {
+void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path) {
RegisterPreference(path, new base::DictionaryValue());
}
void PrefRegistrySimple::RegisterDictionaryPref(
- const char* path,
+ const std::string& path,
base::DictionaryValue* default_value) {
RegisterPreference(path, default_value);
}
-void PrefRegistrySimple::RegisterInt64Pref(const char* path,
+void PrefRegistrySimple::RegisterInt64Pref(const std::string& path,
int64 default_value) {
RegisterPreference(
path, new base::StringValue(base::Int64ToString(default_value)));
diff --git a/base/prefs/pref_registry_simple.h b/base/prefs/pref_registry_simple.h
index 41fe590..73ae216 100644
--- a/base/prefs/pref_registry_simple.h
+++ b/base/prefs/pref_registry_simple.h
@@ -21,19 +21,20 @@ class BASE_PREFS_EXPORT PrefRegistrySimple : public PrefRegistry {
public:
PrefRegistrySimple();
- void RegisterBooleanPref(const char* path, bool default_value);
- void RegisterIntegerPref(const char* path, int default_value);
- void RegisterDoublePref(const char* path, double default_value);
- void RegisterStringPref(const char* path, const std::string& default_value);
- void RegisterFilePathPref(const char* path,
+ void RegisterBooleanPref(const std::string& path, bool default_value);
+ void RegisterIntegerPref(const std::string& path, int default_value);
+ void RegisterDoublePref(const std::string& path, double default_value);
+ void RegisterStringPref(const std::string& path,
+ const std::string& default_value);
+ void RegisterFilePathPref(const std::string& path,
const base::FilePath& default_value);
- void RegisterListPref(const char* path);
- void RegisterDictionaryPref(const char* path);
- void RegisterListPref(const char* path, base::ListValue* default_value);
- void RegisterDictionaryPref(const char* path,
+ void RegisterListPref(const std::string& path);
+ void RegisterDictionaryPref(const std::string& path);
+ void RegisterListPref(const std::string& path,
+ base::ListValue* default_value);
+ void RegisterDictionaryPref(const std::string& path,
base::DictionaryValue* default_value);
- void RegisterInt64Pref(const char* path,
- int64 default_value);
+ void RegisterInt64Pref(const std::string& path, int64 default_value);
private:
~PrefRegistrySimple() override;
diff --git a/base/prefs/pref_service.cc b/base/prefs/pref_service.cc
index 88fe938..66323a1 100644
--- a/base/prefs/pref_service.cc
+++ b/base/prefs/pref_service.cc
@@ -86,7 +86,7 @@ void PrefService::CommitPendingWrite() {
user_pref_store_->CommitPendingWrite();
}
-bool PrefService::GetBoolean(const char* path) const {
+bool PrefService::GetBoolean(const std::string& path) const {
DCHECK(CalledOnValidThread());
bool result = false;
@@ -101,7 +101,7 @@ bool PrefService::GetBoolean(const char* path) const {
return result;
}
-int PrefService::GetInteger(const char* path) const {
+int PrefService::GetInteger(const std::string& path) const {
DCHECK(CalledOnValidThread());
int result = 0;
@@ -116,7 +116,7 @@ int PrefService::GetInteger(const char* path) const {
return result;
}
-double PrefService::GetDouble(const char* path) const {
+double PrefService::GetDouble(const std::string& path) const {
DCHECK(CalledOnValidThread());
double result = 0.0;
@@ -131,7 +131,7 @@ double PrefService::GetDouble(const char* path) const {
return result;
}
-std::string PrefService::GetString(const char* path) const {
+std::string PrefService::GetString(const std::string& path) const {
DCHECK(CalledOnValidThread());
std::string result;
@@ -146,7 +146,7 @@ std::string PrefService::GetString(const char* path) const {
return result;
}
-base::FilePath PrefService::GetFilePath(const char* path) const {
+base::FilePath PrefService::GetFilePath(const std::string& path) const {
DCHECK(CalledOnValidThread());
base::FilePath result;
@@ -161,7 +161,7 @@ base::FilePath PrefService::GetFilePath(const char* path) const {
return result;
}
-bool PrefService::HasPrefPath(const char* path) const {
+bool PrefService::HasPrefPath(const std::string& path) const {
const Preference* pref = FindPreference(path);
return pref && !pref->IsDefaultValue();
}
@@ -181,7 +181,7 @@ scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValuesOmitDefaults()
DCHECK(CalledOnValidThread());
scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
for (const auto& it : *pref_registry_) {
- const Preference* pref = FindPreference(it.first.c_str());
+ const Preference* pref = FindPreference(it.first);
if (pref->IsDefaultValue())
continue;
out->Set(it.first, pref->GetValue()->DeepCopy());
@@ -202,7 +202,7 @@ PrefService::GetPreferenceValuesWithoutPathExpansion() const {
}
const PrefService::Preference* PrefService::FindPreference(
- const char* pref_name) const {
+ const std::string& pref_name) const {
DCHECK(CalledOnValidThread());
PreferenceMap::iterator it = prefs_map_.find(pref_name);
if (it != prefs_map_.end())
@@ -235,18 +235,19 @@ PrefService::PrefInitializationStatus PrefService::GetInitializationStatus()
}
}
-bool PrefService::IsManagedPreference(const char* pref_name) const {
+bool PrefService::IsManagedPreference(const std::string& pref_name) const {
const Preference* pref = FindPreference(pref_name);
return pref && pref->IsManaged();
}
-bool PrefService::IsUserModifiablePreference(const char* pref_name) const {
+bool PrefService::IsUserModifiablePreference(
+ const std::string& pref_name) const {
const Preference* pref = FindPreference(pref_name);
return pref && pref->IsUserModifiable();
}
const base::DictionaryValue* PrefService::GetDictionary(
- const char* path) const {
+ const std::string& path) const {
DCHECK(CalledOnValidThread());
const base::Value* value = GetPreferenceValue(path);
@@ -261,7 +262,8 @@ const base::DictionaryValue* PrefService::GetDictionary(
return static_cast<const base::DictionaryValue*>(value);
}
-const base::Value* PrefService::GetUserPrefValue(const char* path) const {
+const base::Value* PrefService::GetUserPrefValue(
+ const std::string& path) const {
DCHECK(CalledOnValidThread());
const Preference* pref = FindPreference(path);
@@ -284,13 +286,14 @@ const base::Value* PrefService::GetUserPrefValue(const char* path) const {
return value;
}
-void PrefService::SetDefaultPrefValue(const char* path,
+void PrefService::SetDefaultPrefValue(const std::string& path,
base::Value* value) {
DCHECK(CalledOnValidThread());
pref_registry_->SetDefaultPrefValue(path, value);
}
-const base::Value* PrefService::GetDefaultPrefValue(const char* path) const {
+const base::Value* PrefService::GetDefaultPrefValue(
+ const std::string& path) const {
DCHECK(CalledOnValidThread());
// Lookup the preference in the default store.
const base::Value* value = NULL;
@@ -301,7 +304,7 @@ const base::Value* PrefService::GetDefaultPrefValue(const char* path) const {
return value;
}
-const base::ListValue* PrefService::GetList(const char* path) const {
+const base::ListValue* PrefService::GetList(const std::string& path) const {
DCHECK(CalledOnValidThread());
const base::Value* value = GetPreferenceValue(path);
@@ -316,11 +319,12 @@ const base::ListValue* PrefService::GetList(const char* path) const {
return static_cast<const base::ListValue*>(value);
}
-void PrefService::AddPrefObserver(const char* path, PrefObserver* obs) {
+void PrefService::AddPrefObserver(const std::string& path, PrefObserver* obs) {
pref_notifier_->AddPrefObserver(path, obs);
}
-void PrefService::RemovePrefObserver(const char* path, PrefObserver* obs) {
+void PrefService::RemovePrefObserver(const std::string& path,
+ PrefObserver* obs) {
pref_notifier_->RemovePrefObserver(path, obs);
}
@@ -332,7 +336,7 @@ PrefRegistry* PrefService::DeprecatedGetPrefRegistry() {
return pref_registry_.get();
}
-void PrefService::ClearPref(const char* path) {
+void PrefService::ClearPref(const std::string& path) {
DCHECK(CalledOnValidThread());
const Preference* pref = FindPreference(path);
@@ -343,35 +347,36 @@ void PrefService::ClearPref(const char* path) {
user_pref_store_->RemoveValue(path);
}
-void PrefService::Set(const char* path, const base::Value& value) {
+void PrefService::Set(const std::string& path, const base::Value& value) {
SetUserPrefValue(path, value.DeepCopy());
}
-void PrefService::SetBoolean(const char* path, bool value) {
+void PrefService::SetBoolean(const std::string& path, bool value) {
SetUserPrefValue(path, new base::FundamentalValue(value));
}
-void PrefService::SetInteger(const char* path, int value) {
+void PrefService::SetInteger(const std::string& path, int value) {
SetUserPrefValue(path, new base::FundamentalValue(value));
}
-void PrefService::SetDouble(const char* path, double value) {
+void PrefService::SetDouble(const std::string& path, double value) {
SetUserPrefValue(path, new base::FundamentalValue(value));
}
-void PrefService::SetString(const char* path, const std::string& value) {
+void PrefService::SetString(const std::string& path, const std::string& value) {
SetUserPrefValue(path, new base::StringValue(value));
}
-void PrefService::SetFilePath(const char* path, const base::FilePath& value) {
+void PrefService::SetFilePath(const std::string& path,
+ const base::FilePath& value) {
SetUserPrefValue(path, base::CreateFilePathValue(value));
}
-void PrefService::SetInt64(const char* path, int64 value) {
+void PrefService::SetInt64(const std::string& path, int64 value) {
SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value)));
}
-int64 PrefService::GetInt64(const char* path) const {
+int64 PrefService::GetInt64(const std::string& path) const {
DCHECK(CalledOnValidThread());
const base::Value* value = GetPreferenceValue(path);
@@ -388,11 +393,11 @@ int64 PrefService::GetInt64(const char* path) const {
return val;
}
-void PrefService::SetUint64(const char* path, uint64 value) {
+void PrefService::SetUint64(const std::string& path, uint64 value) {
SetUserPrefValue(path, new base::StringValue(base::Uint64ToString(value)));
}
-uint64 PrefService::GetUint64(const char* path) const {
+uint64 PrefService::GetUint64(const std::string& path) const {
DCHECK(CalledOnValidThread());
const base::Value* value = GetPreferenceValue(path);
@@ -409,7 +414,7 @@ uint64 PrefService::GetUint64(const char* path) const {
return val;
}
-base::Value* PrefService::GetMutableUserPref(const char* path,
+base::Value* PrefService::GetMutableUserPref(const std::string& path,
base::Value::Type type) {
CHECK(type == base::Value::TYPE_DICTIONARY || type == base::Value::TYPE_LIST);
DCHECK(CalledOnValidThread());
@@ -446,7 +451,8 @@ void PrefService::ReportUserPrefChanged(const std::string& key) {
user_pref_store_->ReportValueChanged(key);
}
-void PrefService::SetUserPrefValue(const char* path, base::Value* new_value) {
+void PrefService::SetUserPrefValue(const std::string& path,
+ base::Value* new_value) {
scoped_ptr<base::Value> owned_value(new_value);
DCHECK(CalledOnValidThread());
@@ -473,12 +479,9 @@ void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) {
// PrefService::Preference
PrefService::Preference::Preference(const PrefService* service,
- const char* name,
+ const std::string& name,
base::Value::Type type)
- : name_(name),
- type_(type),
- pref_service_(service) {
- DCHECK(name);
+ : name_(name), type_(type), pref_service_(service) {
DCHECK(service);
}
@@ -497,8 +500,8 @@ const base::Value* PrefService::Preference::GetValue() const {
}
const base::Value* PrefService::Preference::GetRecommendedValue() const {
- DCHECK(pref_service_->FindPreference(name_.c_str())) <<
- "Must register pref before getting its value";
+ DCHECK(pref_service_->FindPreference(name_))
+ << "Must register pref before getting its value";
const base::Value* found_value = NULL;
if (pref_value_store()->GetRecommendedValue(name_, type_, &found_value)) {
@@ -511,39 +514,39 @@ const base::Value* PrefService::Preference::GetRecommendedValue() const {
}
bool PrefService::Preference::IsManaged() const {
- return pref_value_store()->PrefValueInManagedStore(name_.c_str());
+ return pref_value_store()->PrefValueInManagedStore(name_);
}
bool PrefService::Preference::IsRecommended() const {
- return pref_value_store()->PrefValueFromRecommendedStore(name_.c_str());
+ return pref_value_store()->PrefValueFromRecommendedStore(name_);
}
bool PrefService::Preference::HasExtensionSetting() const {
- return pref_value_store()->PrefValueInExtensionStore(name_.c_str());
+ return pref_value_store()->PrefValueInExtensionStore(name_);
}
bool PrefService::Preference::HasUserSetting() const {
- return pref_value_store()->PrefValueInUserStore(name_.c_str());
+ return pref_value_store()->PrefValueInUserStore(name_);
}
bool PrefService::Preference::IsExtensionControlled() const {
- return pref_value_store()->PrefValueFromExtensionStore(name_.c_str());
+ return pref_value_store()->PrefValueFromExtensionStore(name_);
}
bool PrefService::Preference::IsUserControlled() const {
- return pref_value_store()->PrefValueFromUserStore(name_.c_str());
+ return pref_value_store()->PrefValueFromUserStore(name_);
}
bool PrefService::Preference::IsDefaultValue() const {
- return pref_value_store()->PrefValueFromDefaultStore(name_.c_str());
+ return pref_value_store()->PrefValueFromDefaultStore(name_);
}
bool PrefService::Preference::IsUserModifiable() const {
- return pref_value_store()->PrefValueUserModifiable(name_.c_str());
+ return pref_value_store()->PrefValueUserModifiable(name_);
}
bool PrefService::Preference::IsExtensionModifiable() const {
- return pref_value_store()->PrefValueExtensionModifiable(name_.c_str());
+ return pref_value_store()->PrefValueExtensionModifiable(name_);
}
const base::Value* PrefService::GetPreferenceValue(
diff --git a/base/prefs/pref_service.h b/base/prefs/pref_service.h
index fec6906..734cc2b 100644
--- a/base/prefs/pref_service.h
+++ b/base/prefs/pref_service.h
@@ -65,7 +65,7 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// dictionary (a branch), or list. You shouldn't need to construct this on
// your own; use the PrefService::Register*Pref methods instead.
Preference(const PrefService* service,
- const char* name,
+ const std::string& name,
base::Value::Type type);
~Preference() {}
@@ -156,76 +156,75 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// Returns true if the preference for the given preference name is available
// and is managed.
- bool IsManagedPreference(const char* pref_name) const;
+ bool IsManagedPreference(const std::string& pref_name) const;
// Returns |true| if a preference with the given name is available and its
// value can be changed by the user.
- bool IsUserModifiablePreference(const char* pref_name) const;
+ bool IsUserModifiablePreference(const std::string& pref_name) const;
// Look up a preference. Returns NULL if the preference is not
// registered.
- const PrefService::Preference* FindPreference(const char* path) const;
+ const PrefService::Preference* FindPreference(const std::string& path) const;
// If the path is valid and the value at the end of the path matches the type
// specified, it will return the specified value. Otherwise, the default
// value (set when the pref was registered) will be returned.
- bool GetBoolean(const char* path) const;
- int GetInteger(const char* path) const;
- double GetDouble(const char* path) const;
- std::string GetString(const char* path) const;
- base::FilePath GetFilePath(const char* path) const;
+ bool GetBoolean(const std::string& path) const;
+ int GetInteger(const std::string& path) const;
+ double GetDouble(const std::string& path) const;
+ std::string GetString(const std::string& path) const;
+ base::FilePath GetFilePath(const std::string& path) const;
// Returns the branch if it exists, or the registered default value otherwise.
// Note that |path| must point to a registered preference. In that case, these
// functions will never return NULL.
- const base::DictionaryValue* GetDictionary(
- const char* path) const;
- const base::ListValue* GetList(const char* path) const;
+ const base::DictionaryValue* GetDictionary(const std::string& path) const;
+ const base::ListValue* GetList(const std::string& path) const;
// Removes a user pref and restores the pref to its default value.
- void ClearPref(const char* path);
+ void ClearPref(const std::string& path);
// If the path is valid (i.e., registered), update the pref value in the user
// prefs.
// To set the value of dictionary or list values in the pref tree use
// Set(), but to modify the value of a dictionary or list use either
// ListPrefUpdate or DictionaryPrefUpdate from scoped_user_pref_update.h.
- void Set(const char* path, const base::Value& value);
- void SetBoolean(const char* path, bool value);
- void SetInteger(const char* path, int value);
- void SetDouble(const char* path, double value);
- void SetString(const char* path, const std::string& value);
- void SetFilePath(const char* path, const base::FilePath& value);
+ void Set(const std::string& path, const base::Value& value);
+ void SetBoolean(const std::string& path, bool value);
+ void SetInteger(const std::string& path, int value);
+ void SetDouble(const std::string& path, double value);
+ void SetString(const std::string& path, const std::string& value);
+ void SetFilePath(const std::string& path, const base::FilePath& value);
// Int64 helper methods that actually store the given value as a string.
// Note that if obtaining the named value via GetDictionary or GetList, the
// Value type will be TYPE_STRING.
- void SetInt64(const char* path, int64 value);
- int64 GetInt64(const char* path) const;
+ void SetInt64(const std::string& path, int64 value);
+ int64 GetInt64(const std::string& path) const;
// As above, but for unsigned values.
- void SetUint64(const char* path, uint64 value);
- uint64 GetUint64(const char* path) const;
+ void SetUint64(const std::string& path, uint64 value);
+ uint64 GetUint64(const std::string& path) const;
// Returns the value of the given preference, from the user pref store. If
// the preference is not set in the user pref store, returns NULL.
- const base::Value* GetUserPrefValue(const char* path) const;
+ const base::Value* GetUserPrefValue(const std::string& path) const;
// Changes the default value for a preference. Takes ownership of |value|.
//
// Will cause a pref change notification to be fired if this causes
// the effective value to change.
- void SetDefaultPrefValue(const char* path, base::Value* value);
+ void SetDefaultPrefValue(const std::string& path, base::Value* value);
// Returns the default value of the given preference. |path| must point to a
// registered preference. In that case, will never return NULL.
- const base::Value* GetDefaultPrefValue(const char* path) const;
+ const base::Value* GetDefaultPrefValue(const std::string& path) const;
// Returns true if a value has been set for the specified path.
// NOTE: this is NOT the same as FindPreference. In particular
// FindPreference returns whether RegisterXXX has been invoked, where as
// this checks if a value exists for the path.
- bool HasPrefPath(const char* path) const;
+ bool HasPrefPath(const std::string& path) const;
// Returns a dictionary with effective preference values.
scoped_ptr<base::DictionaryValue> GetPreferenceValues() const;
@@ -318,8 +317,8 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// make sure the observer gets cleaned up properly.
//
// Virtual for testing.
- virtual void AddPrefObserver(const char* path, PrefObserver* obs);
- virtual void RemovePrefObserver(const char* path, PrefObserver* obs);
+ virtual void AddPrefObserver(const std::string& path, PrefObserver* obs);
+ virtual void RemovePrefObserver(const std::string& path, PrefObserver* obs);
// Sends notification of a changed preference. This needs to be called by
// a ScopedUserPrefUpdate if a DictionaryValue or ListValue is changed.
@@ -327,7 +326,7 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// Sets the value for this pref path in the user pref store and informs the
// PrefNotifier of the change.
- void SetUserPrefValue(const char* path, base::Value* new_value);
+ void SetUserPrefValue(const std::string& path, base::Value* new_value);
// Load preferences from storage, attempting to diagnose and handle errors.
// This should only be called from the constructor.
@@ -340,7 +339,7 @@ class BASE_PREFS_EXPORT PrefService : public base::NonThreadSafe {
// |type| may only be Values::TYPE_DICTIONARY or Values::TYPE_LIST and
// |path| must point to a registered preference of type |type|.
// Ownership of the returned value remains at the user pref store.
- base::Value* GetMutableUserPref(const char* path,
+ base::Value* GetMutableUserPref(const std::string& path,
base::Value::Type type);
// GetPreferenceValue is the equivalent of FindPreference(path)->GetValue(),
diff --git a/base/prefs/pref_value_store.cc b/base/prefs/pref_value_store.cc
index 2c22f17..4b7aab9 100644
--- a/base/prefs/pref_value_store.cc
+++ b/base/prefs/pref_value_store.cc
@@ -109,8 +109,8 @@ bool PrefValueStore::GetValue(const std::string& name,
// Check the |PrefStore|s in order of their priority from highest to lowest,
// looking for the first preference value with the given |name| and |type|.
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
- if (GetValueFromStoreWithType(name.c_str(), type,
- static_cast<PrefStoreType>(i), out_value))
+ if (GetValueFromStoreWithType(name, type, static_cast<PrefStoreType>(i),
+ out_value))
return true;
}
return false;
@@ -119,12 +119,11 @@ bool PrefValueStore::GetValue(const std::string& name,
bool PrefValueStore::GetRecommendedValue(const std::string& name,
base::Value::Type type,
const base::Value** out_value) const {
- return GetValueFromStoreWithType(name.c_str(), type, RECOMMENDED_STORE,
- out_value);
+ return GetValueFromStoreWithType(name, type, RECOMMENDED_STORE, out_value);
}
void PrefValueStore::NotifyPrefChanged(
- const char* path,
+ const std::string& path,
PrefValueStore::PrefStoreType new_store) {
DCHECK(new_store != INVALID_STORE);
// A notification is sent when the pref value in any store changes. If this
@@ -135,41 +134,44 @@ void PrefValueStore::NotifyPrefChanged(
pref_changed_callback_.Run(path);
}
-bool PrefValueStore::PrefValueInManagedStore(const char* name) const {
+bool PrefValueStore::PrefValueInManagedStore(const std::string& name) const {
return PrefValueInStore(name, MANAGED_STORE);
}
-bool PrefValueStore::PrefValueInExtensionStore(const char* name) const {
+bool PrefValueStore::PrefValueInExtensionStore(const std::string& name) const {
return PrefValueInStore(name, EXTENSION_STORE);
}
-bool PrefValueStore::PrefValueInUserStore(const char* name) const {
+bool PrefValueStore::PrefValueInUserStore(const std::string& name) const {
return PrefValueInStore(name, USER_STORE);
}
-bool PrefValueStore::PrefValueFromExtensionStore(const char* name) const {
+bool PrefValueStore::PrefValueFromExtensionStore(
+ const std::string& name) const {
return ControllingPrefStoreForPref(name) == EXTENSION_STORE;
}
-bool PrefValueStore::PrefValueFromUserStore(const char* name) const {
+bool PrefValueStore::PrefValueFromUserStore(const std::string& name) const {
return ControllingPrefStoreForPref(name) == USER_STORE;
}
-bool PrefValueStore::PrefValueFromRecommendedStore(const char* name) const {
+bool PrefValueStore::PrefValueFromRecommendedStore(
+ const std::string& name) const {
return ControllingPrefStoreForPref(name) == RECOMMENDED_STORE;
}
-bool PrefValueStore::PrefValueFromDefaultStore(const char* name) const {
+bool PrefValueStore::PrefValueFromDefaultStore(const std::string& name) const {
return ControllingPrefStoreForPref(name) == DEFAULT_STORE;
}
-bool PrefValueStore::PrefValueUserModifiable(const char* name) const {
+bool PrefValueStore::PrefValueUserModifiable(const std::string& name) const {
PrefStoreType effective_store = ControllingPrefStoreForPref(name);
return effective_store >= USER_STORE ||
effective_store == INVALID_STORE;
}
-bool PrefValueStore::PrefValueExtensionModifiable(const char* name) const {
+bool PrefValueStore::PrefValueExtensionModifiable(
+ const std::string& name) const {
PrefStoreType effective_store = ControllingPrefStoreForPref(name);
return effective_store >= EXTENSION_STORE ||
effective_store == INVALID_STORE;
@@ -180,7 +182,7 @@ void PrefValueStore::UpdateCommandLinePrefStore(PrefStore* command_line_prefs) {
}
bool PrefValueStore::PrefValueInStore(
- const char* name,
+ const std::string& name,
PrefValueStore::PrefStoreType store) const {
// Declare a temp Value* and call GetValueFromStore,
// ignoring the output value.
@@ -189,7 +191,7 @@ bool PrefValueStore::PrefValueInStore(
}
bool PrefValueStore::PrefValueInStoreRange(
- const char* name,
+ const std::string& name,
PrefValueStore::PrefStoreType first_checked_store,
PrefValueStore::PrefStoreType last_checked_store) const {
if (first_checked_store > last_checked_store) {
@@ -206,7 +208,7 @@ bool PrefValueStore::PrefValueInStoreRange(
}
PrefValueStore::PrefStoreType PrefValueStore::ControllingPrefStoreForPref(
- const char* name) const {
+ const std::string& name) const {
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
if (PrefValueInStore(name, static_cast<PrefStoreType>(i)))
return static_cast<PrefStoreType>(i);
@@ -214,7 +216,7 @@ PrefValueStore::PrefStoreType PrefValueStore::ControllingPrefStoreForPref(
return INVALID_STORE;
}
-bool PrefValueStore::GetValueFromStore(const char* name,
+bool PrefValueStore::GetValueFromStore(const std::string& name,
PrefValueStore::PrefStoreType store_type,
const base::Value** out_value) const {
// Only return true if we find a value and it is the correct type, so stale
@@ -230,7 +232,7 @@ bool PrefValueStore::GetValueFromStore(const char* name,
}
bool PrefValueStore::GetValueFromStoreWithType(
- const char* name,
+ const std::string& name,
base::Value::Type type,
PrefStoreType store,
const base::Value** out_value) const {
@@ -249,7 +251,7 @@ bool PrefValueStore::GetValueFromStoreWithType(
void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type,
const std::string& key) {
- NotifyPrefChanged(key.c_str(), type);
+ NotifyPrefChanged(key, type);
}
void PrefValueStore::OnInitializationCompleted(
diff --git a/base/prefs/pref_value_store.h b/base/prefs/pref_value_store.h
index db82a82..33203bd 100644
--- a/base/prefs/pref_value_store.h
+++ b/base/prefs/pref_value_store.h
@@ -94,25 +94,25 @@ class BASE_PREFS_EXPORT PrefValueStore {
// These methods return true if a preference with the given name is in the
// indicated pref store, even if that value is currently being overridden by
// a higher-priority source.
- bool PrefValueInManagedStore(const char* name) const;
- bool PrefValueInExtensionStore(const char* name) const;
- bool PrefValueInUserStore(const char* name) const;
+ bool PrefValueInManagedStore(const std::string& name) const;
+ bool PrefValueInExtensionStore(const std::string& name) const;
+ bool PrefValueInUserStore(const std::string& name) const;
// These methods return true if a preference with the given name is actually
// being controlled by the indicated pref store and not being overridden by
// a higher-priority source.
- bool PrefValueFromExtensionStore(const char* name) const;
- bool PrefValueFromUserStore(const char* name) const;
- bool PrefValueFromRecommendedStore(const char* name) const;
- bool PrefValueFromDefaultStore(const char* name) const;
+ bool PrefValueFromExtensionStore(const std::string& name) const;
+ bool PrefValueFromUserStore(const std::string& name) const;
+ bool PrefValueFromRecommendedStore(const std::string& name) const;
+ bool PrefValueFromDefaultStore(const std::string& name) const;
// Check whether a Preference value is modifiable by the user, i.e. whether
// there is no higher-priority source controlling it.
- bool PrefValueUserModifiable(const char* name) const;
+ bool PrefValueUserModifiable(const std::string& name) const;
// Check whether a Preference value is modifiable by an extension, i.e.
// whether there is no higher-priority source controlling it.
- bool PrefValueExtensionModifiable(const char* name) const;
+ bool PrefValueExtensionModifiable(const std::string& name) const;
// Update the command line PrefStore with |command_line_prefs|.
void UpdateCommandLinePrefStore(PrefStore* command_line_prefs);
@@ -188,13 +188,13 @@ class BASE_PREFS_EXPORT PrefValueStore {
// Returns true if the preference with the given name has a value in the
// given PrefStoreType, of the same value type as the preference was
// registered with.
- bool PrefValueInStore(const char* name, PrefStoreType store) const;
+ bool PrefValueInStore(const std::string& name, PrefStoreType store) const;
// Returns true if a preference has an explicit value in any of the
// stores in the range specified by |first_checked_store| and
// |last_checked_store|, even if that value is currently being
// overridden by a higher-priority store.
- bool PrefValueInStoreRange(const char* name,
+ bool PrefValueInStoreRange(const std::string& name,
PrefStoreType first_checked_store,
PrefStoreType last_checked_store) const;
@@ -203,15 +203,15 @@ class BASE_PREFS_EXPORT PrefValueStore {
// INVALID_STORE is returned. In practice, the default PrefStore
// should always have a value for any registered preferencem, so INVALID_STORE
// indicates an error.
- PrefStoreType ControllingPrefStoreForPref(const char* name) const;
+ PrefStoreType ControllingPrefStoreForPref(const std::string& name) const;
// Get a value from the specified |store|.
- bool GetValueFromStore(const char* name,
+ bool GetValueFromStore(const std::string& name,
PrefStoreType store,
const base::Value** out_value) const;
// Get a value from the specified |store| if its |type| matches.
- bool GetValueFromStoreWithType(const char* name,
+ bool GetValueFromStoreWithType(const std::string& name,
base::Value::Type type,
PrefStoreType store,
const base::Value** out_value) const;
@@ -220,7 +220,7 @@ class BASE_PREFS_EXPORT PrefValueStore {
// the user-visible pref value has changed. Triggers the change notification
// if the effective value of the preference has changed, or if the store
// controlling the pref has changed.
- void NotifyPrefChanged(const char* path, PrefStoreType new_store);
+ void NotifyPrefChanged(const std::string& path, PrefStoreType new_store);
// Called from the PrefStoreKeeper implementation when a pref value for |key|
// changed in the pref store for |type|.
diff --git a/base/prefs/pref_value_store_unittest.cc b/base/prefs/pref_value_store_unittest.cc
index 3afe9dc..9194b22 100644
--- a/base/prefs/pref_value_store_unittest.cc
+++ b/base/prefs/pref_value_store_unittest.cc
@@ -237,7 +237,7 @@ class PrefValueStoreTest : public testing::Test {
default_pref::kDefaultValue);
}
- void ExpectValueChangeNotifications(const char* name) {
+ void ExpectValueChangeNotifications(const std::string& name) {
EXPECT_CALL(pref_notifier_, OnPreferenceChanged(name));
EXPECT_CALL(*sync_associator_, ProcessPrefChange(name));
}
diff --git a/base/prefs/scoped_user_pref_update.cc b/base/prefs/scoped_user_pref_update.cc
index 7871c75..1440a57 100644
--- a/base/prefs/scoped_user_pref_update.cc
+++ b/base/prefs/scoped_user_pref_update.cc
@@ -11,10 +11,8 @@
namespace subtle {
ScopedUserPrefUpdateBase::ScopedUserPrefUpdateBase(PrefService* service,
- const char* path)
- : service_(service),
- path_(path),
- value_(NULL) {
+ const std::string& path)
+ : service_(service), path_(path), value_(NULL) {
DCHECK(service_->CalledOnValidThread());
}
@@ -25,7 +23,7 @@ ScopedUserPrefUpdateBase::~ScopedUserPrefUpdateBase() {
base::Value* ScopedUserPrefUpdateBase::GetValueOfType(base::Value::Type type) {
DCHECK(CalledOnValidThread());
if (!value_)
- value_ = service_->GetMutableUserPref(path_.c_str(), type);
+ value_ = service_->GetMutableUserPref(path_, type);
return value_;
}
diff --git a/base/prefs/scoped_user_pref_update.h b/base/prefs/scoped_user_pref_update.h
index 82d6739..f8bebfe 100644
--- a/base/prefs/scoped_user_pref_update.h
+++ b/base/prefs/scoped_user_pref_update.h
@@ -33,7 +33,7 @@ namespace subtle {
// PrefService::ReportUserPrefChanged.
class BASE_PREFS_EXPORT ScopedUserPrefUpdateBase : public base::NonThreadSafe {
protected:
- ScopedUserPrefUpdateBase(PrefService* service, const char* path);
+ ScopedUserPrefUpdateBase(PrefService* service, const std::string& path);
// Calls Notify().
~ScopedUserPrefUpdateBase();
@@ -66,7 +66,7 @@ class BASE_PREFS_EXPORT ScopedUserPrefUpdateBase : public base::NonThreadSafe {
template <typename T, base::Value::Type type_enum_value>
class ScopedUserPrefUpdate : public subtle::ScopedUserPrefUpdateBase {
public:
- ScopedUserPrefUpdate(PrefService* service, const char* path)
+ ScopedUserPrefUpdate(PrefService* service, const std::string& path)
: ScopedUserPrefUpdateBase(service, path) {}
// Triggers an update notification if Get() was called.
diff --git a/base/prefs/testing_pref_service.h b/base/prefs/testing_pref_service.h
index 2f6d494..40fd66a 100644
--- a/base/prefs/testing_pref_service.h
+++ b/base/prefs/testing_pref_service.h
@@ -27,25 +27,25 @@ class TestingPrefServiceBase : public SuperPrefService {
// Read the value of a preference from the managed layer. Returns NULL if the
// preference is not defined at the managed layer.
- const base::Value* GetManagedPref(const char* path) const;
+ const base::Value* GetManagedPref(const std::string& path) const;
// Set a preference on the managed layer and fire observers if the preference
// changed. Assumes ownership of |value|.
- void SetManagedPref(const char* path, base::Value* value);
+ void SetManagedPref(const std::string& path, base::Value* value);
// Clear the preference on the managed layer and fire observers if the
// preference has been defined previously.
- void RemoveManagedPref(const char* path);
+ void RemoveManagedPref(const std::string& path);
// Similar to the above, but for user preferences.
- const base::Value* GetUserPref(const char* path) const;
- void SetUserPref(const char* path, base::Value* value);
- void RemoveUserPref(const char* path);
+ const base::Value* GetUserPref(const std::string& path) const;
+ void SetUserPref(const std::string& path, base::Value* value);
+ void RemoveUserPref(const std::string& path);
// Similar to the above, but for recommended policy preferences.
- const base::Value* GetRecommendedPref(const char* path) const;
- void SetRecommendedPref(const char* path, base::Value* value);
- void RemoveRecommendedPref(const char* path);
+ const base::Value* GetRecommendedPref(const std::string& path) const;
+ void SetRecommendedPref(const std::string& path, base::Value* value);
+ void RemoveRecommendedPref(const std::string& path);
// Do-nothing implementation for TestingPrefService.
static void HandleReadError(PersistentPrefStore::PrefReadError error) {}
@@ -62,14 +62,15 @@ class TestingPrefServiceBase : public SuperPrefService {
// Reads the value of the preference indicated by |path| from |pref_store|.
// Returns NULL if the preference was not found.
const base::Value* GetPref(TestingPrefStore* pref_store,
- const char* path) const;
+ const std::string& path) const;
// Sets the value for |path| in |pref_store|.
- void SetPref(TestingPrefStore* pref_store, const char* path,
+ void SetPref(TestingPrefStore* pref_store,
+ const std::string& path,
base::Value* value);
// Removes the preference identified by |path| from |pref_store|.
- void RemovePref(TestingPrefStore* pref_store, const char* path);
+ void RemovePref(TestingPrefStore* pref_store, const std::string& path);
// Pointers to the pref stores our value store uses.
scoped_refptr<TestingPrefStore> managed_prefs_;
@@ -110,88 +111,83 @@ TestingPrefServiceBase<
SuperPrefService, ConstructionPrefRegistry>::~TestingPrefServiceBase() {
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
+template <class SuperPrefService, class ConstructionPrefRegistry>
const base::Value* TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::GetManagedPref(
- const char* path) const {
+ SuperPrefService,
+ ConstructionPrefRegistry>::GetManagedPref(const std::string& path) const {
return GetPref(managed_prefs_.get(), path);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::SetManagedPref(
- const char* path, base::Value* value) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ SetManagedPref(const std::string& path, base::Value* value) {
SetPref(managed_prefs_.get(), path, value);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::RemoveManagedPref(
- const char* path) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ RemoveManagedPref(const std::string& path) {
RemovePref(managed_prefs_.get(), path);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-const base::Value* TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::GetUserPref(
- const char* path) const {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+const base::Value*
+TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::GetUserPref(
+ const std::string& path) const {
return GetPref(user_prefs_.get(), path);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::SetUserPref(
- const char* path, base::Value* value) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ SetUserPref(const std::string& path, base::Value* value) {
SetPref(user_prefs_.get(), path, value);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::RemoveUserPref(
- const char* path) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ RemoveUserPref(const std::string& path) {
RemovePref(user_prefs_.get(), path);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-const base::Value* TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::GetRecommendedPref(
- const char* path) const {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+const base::Value*
+TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ GetRecommendedPref(const std::string& path) const {
return GetPref(recommended_prefs_, path);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::SetRecommendedPref(
- const char* path, base::Value* value) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ SetRecommendedPref(const std::string& path, base::Value* value) {
SetPref(recommended_prefs_.get(), path, value);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::RemoveRecommendedPref(
- const char* path) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ RemoveRecommendedPref(const std::string& path) {
RemovePref(recommended_prefs_.get(), path);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-const base::Value* TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::GetPref(
- TestingPrefStore* pref_store, const char* path) const {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+const base::Value*
+TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::GetPref(
+ TestingPrefStore* pref_store,
+ const std::string& path) const {
const base::Value* res;
return pref_store->GetValue(path, &res) ? res : NULL;
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::SetPref(
- TestingPrefStore* pref_store, const char* path, base::Value* value) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ SetPref(TestingPrefStore* pref_store,
+ const std::string& path,
+ base::Value* value) {
pref_store->SetValue(path, value);
}
-template<class SuperPrefService, class ConstructionPrefRegistry>
-void TestingPrefServiceBase<
- SuperPrefService, ConstructionPrefRegistry>::RemovePref(
- TestingPrefStore* pref_store, const char* path) {
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ RemovePref(TestingPrefStore* pref_store, const std::string& path) {
pref_store->RemoveValue(path);
}