Chromium Code Reviews| Index: chrome/browser/extensions/api/font_settings/font_settings_api.cc |
| diff --git a/chrome/browser/extensions/api/font_settings/font_settings_api.cc b/chrome/browser/extensions/api/font_settings/font_settings_api.cc |
| index cf01a958e33df9ba0d82949357627cf7e80edca3..66176ef85b5e0b5213ce506f1d7522218f211aa7 100644 |
| --- a/chrome/browser/extensions/api/font_settings/font_settings_api.cc |
| +++ b/chrome/browser/extensions/api/font_settings/font_settings_api.cc |
| @@ -61,8 +61,8 @@ std::string GetFontNamePrefPath(fonts::GenericFamily generic_family_enum, |
| script = prefs::kWebKitCommonScript; |
| std::string generic_family = fonts::ToString(generic_family_enum); |
| return base::StringPrintf(kWebKitFontPrefFormat, |
| - generic_family.c_str(), |
| - script.c_str()); |
| + generic_family, |
| + script); |
| } |
| // Returns the localized name of a font so that it can be matched within the |
| @@ -83,11 +83,14 @@ std::string MaybeGetLocalizedFontName(const std::string& font_name) { |
| void RegisterFontFamilyMapObserver( |
| PrefChangeRegistrar* registrar, |
| const char* map_name, |
| - const PrefChangeRegistrar::NamedChangeCallback& callback) { |
| + const PrefChangeRegistrar::NamedChangeCallback& callback, |
| + std::string* pref_name) { |
| for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { |
| const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; |
| - std::string pref_name = base::StringPrintf("%s.%s", map_name, script); |
| - registrar->Add(pref_name.c_str(), callback); |
| + pref_name->assign(map_name); |
| + pref_name->append(1, '.'); |
| + pref_name->append(script); |
|
Nico
2014/12/01 17:05:15
This kind of change does not lgtm. The previous co
Peter Kasting
2014/12/01 23:09:17
FWIW, I actually find the new code significantly m
Nico
2014/12/01 23:19:06
Huh, this is very surprising to me. I thought prin
Peter Kasting
2014/12/01 23:35:30
We have quite a few in our codebase, but I think i
cmumford
2014/12/03 17:28:29
I wonder if creating a variadic template function
|
| + registrar->Add(*pref_name, callback); |
| } |
| } |
| @@ -110,21 +113,23 @@ FontSettingsEventRouter::FontSettingsEventRouter( |
| PrefChangeRegistrar::NamedChangeCallback callback = |
| base::Bind(&FontSettingsEventRouter::OnFontFamilyMapPrefChanged, |
| base::Unretained(this)); |
| - RegisterFontFamilyMapObserver(®istrar_, |
| - prefs::kWebKitStandardFontFamilyMap, callback); |
| - RegisterFontFamilyMapObserver(®istrar_, |
| - prefs::kWebKitSerifFontFamilyMap, callback); |
| - RegisterFontFamilyMapObserver(®istrar_, |
| - prefs::kWebKitSansSerifFontFamilyMap, callback); |
| - RegisterFontFamilyMapObserver(®istrar_, |
| - prefs::kWebKitFixedFontFamilyMap, callback); |
| - RegisterFontFamilyMapObserver(®istrar_, |
| - prefs::kWebKitCursiveFontFamilyMap, callback); |
| - RegisterFontFamilyMapObserver(®istrar_, |
| - prefs::kWebKitFantasyFontFamilyMap, callback); |
| - RegisterFontFamilyMapObserver(®istrar_, |
| - prefs::kWebKitPictographFontFamilyMap, |
| - callback); |
| + |
| + std::string pref_name; |
| + pref_name.reserve(500); |
| + RegisterFontFamilyMapObserver( |
| + ®istrar_, prefs::kWebKitStandardFontFamilyMap, callback, &pref_name); |
| + RegisterFontFamilyMapObserver(®istrar_, prefs::kWebKitSerifFontFamilyMap, |
| + callback, &pref_name); |
| + RegisterFontFamilyMapObserver( |
| + ®istrar_, prefs::kWebKitSansSerifFontFamilyMap, callback, &pref_name); |
| + RegisterFontFamilyMapObserver(®istrar_, prefs::kWebKitFixedFontFamilyMap, |
| + callback, &pref_name); |
| + RegisterFontFamilyMapObserver(®istrar_, prefs::kWebKitCursiveFontFamilyMap, |
| + callback, &pref_name); |
| + RegisterFontFamilyMapObserver(®istrar_, prefs::kWebKitFantasyFontFamilyMap, |
| + callback, &pref_name); |
| + RegisterFontFamilyMapObserver( |
| + ®istrar_, prefs::kWebKitPictographFontFamilyMap, callback, &pref_name); |
| } |
| FontSettingsEventRouter::~FontSettingsEventRouter() {} |
| @@ -156,7 +161,7 @@ void FontSettingsEventRouter::OnFontNamePrefChanged( |
| const std::string& generic_family, |
| const std::string& script) { |
| const PrefService::Preference* pref = registrar_.prefs()->FindPreference( |
| - pref_name.c_str()); |
| + pref_name); |
| CHECK(pref); |
| std::string font_name; |
| @@ -187,7 +192,7 @@ void FontSettingsEventRouter::OnFontPrefChanged( |
| const std::string& key, |
| const std::string& pref_name) { |
| const PrefService::Preference* pref = registrar_.prefs()->FindPreference( |
| - pref_name.c_str()); |
| + pref_name); |
| CHECK(pref); |
| base::ListValue args; |
| @@ -235,10 +240,10 @@ bool FontSettingsClearFontFunction::RunSync() { |
| // Ensure |pref_path| really is for a registered per-script font pref. |
| EXTENSION_FUNCTION_VALIDATE( |
| - GetProfile()->GetPrefs()->FindPreference(pref_path.c_str())); |
| + GetProfile()->GetPrefs()->FindPreference(pref_path)); |
| PreferenceAPI::Get(GetProfile())->RemoveExtensionControlledPref( |
| - extension_id(), pref_path.c_str(), kExtensionPrefsScopeRegular); |
| + extension_id(), pref_path, kExtensionPrefsScopeRegular); |
| return true; |
| } |
| @@ -252,7 +257,7 @@ bool FontSettingsGetFontFunction::RunSync() { |
| PrefService* prefs = GetProfile()->GetPrefs(); |
| const PrefService::Preference* pref = |
| - prefs->FindPreference(pref_path.c_str()); |
| + prefs->FindPreference(pref_path); |
| std::string font_name; |
| EXTENSION_FUNCTION_VALIDATE( |
| @@ -288,11 +293,11 @@ bool FontSettingsSetFontFunction::RunSync() { |
| // Ensure |pref_path| really is for a registered font pref. |
| EXTENSION_FUNCTION_VALIDATE( |
| - GetProfile()->GetPrefs()->FindPreference(pref_path.c_str())); |
| + GetProfile()->GetPrefs()->FindPreference(pref_path)); |
| PreferenceAPI::Get(GetProfile())->SetExtensionControlledPref( |
| extension_id(), |
| - pref_path.c_str(), |
| + pref_path, |
| kExtensionPrefsScopeRegular, |
| new base::StringValue(params->details.font_id)); |
| return true; |