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

Side by Side Diff: chrome/browser/ui/prefs/prefs_tab_helper.cc

Issue 747013003: Various optimizations to reduce the number of temporary allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restored the other StringPrintf. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" 5 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/prefs/overlay_user_pref_store.h" 9 #include "base/prefs/overlay_user_pref_store.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 #endif // !defined(OS_ANDROID) 124 #endif // !defined(OS_ANDROID)
125 125
126 // Registers |obs| to observe per-script font prefs under the path |map_name|. 126 // Registers |obs| to observe per-script font prefs under the path |map_name|.
127 // On android, there's no exposed way to change these prefs, so we can save 127 // On android, there's no exposed way to change these prefs, so we can save
128 // ~715KB of heap and some startup cycles by avoiding observing these prefs 128 // ~715KB of heap and some startup cycles by avoiding observing these prefs
129 // since they will never change. 129 // since they will never change.
130 void RegisterFontFamilyMapObserver( 130 void RegisterFontFamilyMapObserver(
131 PrefChangeRegistrar* registrar, 131 PrefChangeRegistrar* registrar,
132 const char* map_name, 132 const char* map_name,
133 const PrefChangeRegistrar::NamedChangeCallback& obs) { 133 const PrefChangeRegistrar::NamedChangeCallback& obs) {
134 bool result = StartsWithASCII(map_name, "webkit.webprefs.", true); 134 DCHECK(StartsWithASCII(map_name, "webkit.webprefs.", true));
135 DCHECK(result); 135
136 std::string pref_name;
137 pref_name.reserve(512); // Reduces number of grows.
Nico 2014/12/03 20:44:31 likewise
136 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 138 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
137 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 139 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
138 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); 140 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
139 registrar->Add(pref_name.c_str(), obs); 141 registrar->Add(pref_name, obs);
140 } 142 }
141 } 143 }
142 144
143 #if defined(OS_WIN) 145 #if defined(OS_WIN)
144 // On Windows with antialising we want to use an alternate fixed font like 146 // On Windows with antialising we want to use an alternate fixed font like
145 // Consolas, which looks much better than Courier New. 147 // Consolas, which looks much better than Courier New.
146 bool ShouldUseAlternateDefaultFixedFont(const std::string& script) { 148 bool ShouldUseAlternateDefaultFixedFont(const std::string& script) {
147 if (!StartsWithASCII(script, "courier", false)) 149 if (!StartsWithASCII(script, "courier", false))
148 return false; 150 return false;
149 UINT smooth_type = 0; 151 UINT smooth_type = 0;
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 // is normally okay since WebKit does the desired fallback behavior regardless 627 // is normally okay since WebKit does the desired fallback behavior regardless
626 // of whether the empty string is passed or the pref is not passed at all. But 628 // of whether the empty string is passed or the pref is not passed at all. But
627 // if the pref has changed from non-empty to the empty string, we must let 629 // if the pref has changed from non-empty to the empty string, we must let
628 // WebKit know. 630 // WebKit know.
629 std::string generic_family; 631 std::string generic_family;
630 std::string script; 632 std::string script;
631 if (pref_names_util::ParseFontNamePrefPath(pref_name, 633 if (pref_names_util::ParseFontNamePrefPath(pref_name,
632 &generic_family, 634 &generic_family,
633 &script)) { 635 &script)) {
634 PrefService* prefs = GetProfile()->GetPrefs(); 636 PrefService* prefs = GetProfile()->GetPrefs();
635 std::string pref_value = prefs->GetString(pref_name.c_str()); 637 std::string pref_value = prefs->GetString(pref_name);
636 if (pref_value.empty()) { 638 if (pref_value.empty()) {
637 WebPreferences web_prefs = 639 WebPreferences web_prefs =
638 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); 640 web_contents_->GetRenderViewHost()->GetWebkitPreferences();
639 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); 641 OverrideFontFamily(&web_prefs, generic_family, script, std::string());
640 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); 642 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs);
641 return; 643 return;
642 } 644 }
643 } 645 }
644 } 646 }
645 647
646 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { 648 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) {
647 #if !defined(OS_ANDROID) 649 #if !defined(OS_ANDROID)
648 OnFontFamilyPrefChanged(pref_name); 650 OnFontFamilyPrefChanged(pref_name);
649 #endif 651 #endif
650 652
651 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); 653 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged();
652 } 654 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698