Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Unified Diff: base/prefs/pref_service.cc

Issue 753603002: Change preference APIs to take std::string instead of const char*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed all calls to c_str() in prefs. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/prefs/pref_service.h ('k') | base/prefs/pref_value_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/prefs/pref_service.cc
diff --git a/base/prefs/pref_service.cc b/base/prefs/pref_service.cc
index 88fe9382b62b576ca64420dd78c837afc7a4e79e..66323a1e152c25b7df7f66deac6dd8d3994de4dc 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(
« no previous file with comments | « base/prefs/pref_service.h ('k') | base/prefs/pref_value_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698