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

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: Removed two calls to string::reserve(). 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;
Nico 2014/12/03 21:16:46 This too
136 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 137 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
137 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 138 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
138 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); 139 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
139 registrar->Add(pref_name.c_str(), obs); 140 registrar->Add(pref_name, obs);
Peter Kasting 2014/12/03 21:21:03 My same question from the other file applies here.
140 } 141 }
141 } 142 }
142 143
143 #if defined(OS_WIN) 144 #if defined(OS_WIN)
144 // On Windows with antialising we want to use an alternate fixed font like 145 // On Windows with antialising we want to use an alternate fixed font like
145 // Consolas, which looks much better than Courier New. 146 // Consolas, which looks much better than Courier New.
146 bool ShouldUseAlternateDefaultFixedFont(const std::string& script) { 147 bool ShouldUseAlternateDefaultFixedFont(const std::string& script) {
147 if (!StartsWithASCII(script, "courier", false)) 148 if (!StartsWithASCII(script, "courier", false))
148 return false; 149 return false;
149 UINT smooth_type = 0; 150 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 626 // 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 627 // 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 628 // if the pref has changed from non-empty to the empty string, we must let
628 // WebKit know. 629 // WebKit know.
629 std::string generic_family; 630 std::string generic_family;
630 std::string script; 631 std::string script;
631 if (pref_names_util::ParseFontNamePrefPath(pref_name, 632 if (pref_names_util::ParseFontNamePrefPath(pref_name,
632 &generic_family, 633 &generic_family,
633 &script)) { 634 &script)) {
634 PrefService* prefs = GetProfile()->GetPrefs(); 635 PrefService* prefs = GetProfile()->GetPrefs();
635 std::string pref_value = prefs->GetString(pref_name.c_str()); 636 std::string pref_value = prefs->GetString(pref_name);
636 if (pref_value.empty()) { 637 if (pref_value.empty()) {
637 WebPreferences web_prefs = 638 WebPreferences web_prefs =
638 web_contents_->GetRenderViewHost()->GetWebkitPreferences(); 639 web_contents_->GetRenderViewHost()->GetWebkitPreferences();
639 OverrideFontFamily(&web_prefs, generic_family, script, std::string()); 640 OverrideFontFamily(&web_prefs, generic_family, script, std::string());
640 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs); 641 web_contents_->GetRenderViewHost()->UpdateWebkitPreferences(web_prefs);
641 return; 642 return;
642 } 643 }
643 } 644 }
644 } 645 }
645 646
646 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) { 647 void PrefsTabHelper::OnWebPrefChanged(const std::string& pref_name) {
647 #if !defined(OS_ANDROID) 648 #if !defined(OS_ANDROID)
648 OnFontFamilyPrefChanged(pref_name); 649 OnFontFamilyPrefChanged(pref_name);
649 #endif 650 #endif
650 651
651 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged(); 652 web_contents_->GetRenderViewHost()->OnWebkitPreferencesChanged();
652 } 653 }
OLDNEW
« chrome/browser/themes/theme_properties.cc ('K') | « chrome/browser/themes/theme_properties.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698