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

Side by Side Diff: chrome/browser/extensions/api/font_settings/font_settings_api.cc

Issue 11345008: Remove content::NotificationObserver dependency from most Prefs code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge LKGR. Created 8 years, 1 month 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 | Annotate | Revision Log
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 // Font Settings Extension API implementation. 5 // Font Settings Extension API implementation.
6 6
7 #include "chrome/browser/extensions/api/font_settings/font_settings_api.h" 7 #include "chrome/browser/extensions/api/font_settings/font_settings_api.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return static_cast<gfx::PlatformFontWin*>(font.platform_font())-> 96 return static_cast<gfx::PlatformFontWin*>(font.platform_font())->
97 GetLocalizedFontName(); 97 GetLocalizedFontName();
98 } 98 }
99 #endif 99 #endif
100 return font_name; 100 return font_name;
101 } 101 }
102 102
103 // Registers |obs| to observe per-script font prefs under the path |map_name|. 103 // Registers |obs| to observe per-script font prefs under the path |map_name|.
104 void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar, 104 void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar,
105 const char* map_name, 105 const char* map_name,
106 content::NotificationObserver* obs) { 106 PrefObserver* obs) {
107 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 107 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
108 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 108 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
109 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); 109 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
110 registrar->Add(pref_name.c_str(), obs); 110 registrar->Add(pref_name.c_str(), obs);
111 } 111 }
112 } 112 }
113 113
114 } // namespace 114 } // namespace
115 115
116 FontSettingsEventRouter::FontSettingsEventRouter( 116 FontSettingsEventRouter::FontSettingsEventRouter(
(...skipping 24 matching lines...) Expand all
141 prefs::kWebKitFixedFontFamilyMap, this); 141 prefs::kWebKitFixedFontFamilyMap, this);
142 RegisterFontFamilyMapObserver(&registrar_, 142 RegisterFontFamilyMapObserver(&registrar_,
143 prefs::kWebKitCursiveFontFamilyMap, this); 143 prefs::kWebKitCursiveFontFamilyMap, this);
144 RegisterFontFamilyMapObserver(&registrar_, 144 RegisterFontFamilyMapObserver(&registrar_,
145 prefs::kWebKitFantasyFontFamilyMap, this); 145 prefs::kWebKitFantasyFontFamilyMap, this);
146 RegisterFontFamilyMapObserver(&registrar_, 146 RegisterFontFamilyMapObserver(&registrar_,
147 prefs::kWebKitPictographFontFamilyMap, this); 147 prefs::kWebKitPictographFontFamilyMap, this);
148 } 148 }
149 149
150 void FontSettingsEventRouter::AddPrefToObserve(const char* pref_name, 150 void FontSettingsEventRouter::AddPrefToObserve(const char* pref_name,
151 const char* event_name, 151 const char* event_name,
152 const char* key) { 152 const char* key) {
153 registrar_.Add(pref_name, this); 153 registrar_.Add(pref_name, this);
154 pref_event_map_[pref_name] = std::make_pair(event_name, key); 154 pref_event_map_[pref_name] = std::make_pair(event_name, key);
155 } 155 }
156 156
157 void FontSettingsEventRouter::Observe( 157 void FontSettingsEventRouter::OnPreferenceChanged(
158 int type, 158 PrefServiceBase* pref_service,
159 const content::NotificationSource& source, 159 const std::string& pref_name) {
160 const content::NotificationDetails& details) {
161 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type);
162
163 PrefService* pref_service = content::Source<PrefService>(source).ptr();
164 bool incognito = (pref_service != profile_->GetPrefs()); 160 bool incognito = (pref_service != profile_->GetPrefs());
165 // We're only observing pref changes on the regular profile. 161 // We're only observing pref changes on the regular profile.
166 DCHECK(!incognito); 162 DCHECK(!incognito);
167 const std::string& pref_name =
168 *content::Details<const std::string>(details).ptr();
169 163
170 PrefEventMap::iterator iter = pref_event_map_.find(pref_name); 164 PrefEventMap::iterator iter = pref_event_map_.find(pref_name);
171 if (iter != pref_event_map_.end()) { 165 if (iter != pref_event_map_.end()) {
172 const std::string& event_name = iter->second.first; 166 const std::string& event_name = iter->second.first;
173 const std::string& key = iter->second.second; 167 const std::string& key = iter->second.second;
174 OnFontPrefChanged(pref_service, pref_name, event_name, key, incognito); 168 OnFontPrefChanged(pref_service, pref_name, event_name, key, incognito);
175 return; 169 return;
176 } 170 }
177 171
178 std::string generic_family; 172 std::string generic_family;
179 std::string script; 173 std::string script;
180 if (ParseFontNamePrefPath(pref_name, &generic_family, &script)) { 174 if (ParseFontNamePrefPath(pref_name, &generic_family, &script)) {
181 OnFontNamePrefChanged(pref_service, pref_name, generic_family, script, 175 OnFontNamePrefChanged(static_cast<PrefService*>(pref_service), pref_name,
182 incognito); 176 generic_family, script, incognito);
183 return; 177 return;
184 } 178 }
185 179
186 NOTREACHED(); 180 NOTREACHED();
187 } 181 }
188 182
189 void FontSettingsEventRouter::OnFontNamePrefChanged( 183 void FontSettingsEventRouter::OnFontNamePrefChanged(
190 PrefService* pref_service, 184 PrefService* pref_service,
191 const std::string& pref_name, 185 const std::string& pref_name,
192 const std::string& generic_family, 186 const std::string& generic_family,
(...skipping 20 matching lines...) Expand all
213 extensions::preference_helpers::DispatchEventToExtensions( 207 extensions::preference_helpers::DispatchEventToExtensions(
214 profile_, 208 profile_,
215 kOnFontChanged, 209 kOnFontChanged,
216 &args, 210 &args,
217 APIPermission::kFontSettings, 211 APIPermission::kFontSettings,
218 incognito, 212 incognito,
219 pref_name); 213 pref_name);
220 } 214 }
221 215
222 void FontSettingsEventRouter::OnFontPrefChanged( 216 void FontSettingsEventRouter::OnFontPrefChanged(
223 PrefService* pref_service, 217 PrefServiceBase* pref_service,
224 const std::string& pref_name, 218 const std::string& pref_name,
225 const std::string& event_name, 219 const std::string& event_name,
226 const std::string& key, 220 const std::string& key,
227 bool incognito) { 221 bool incognito) {
228 const PrefService::Preference* pref = pref_service->FindPreference( 222 const PrefServiceBase::Preference* pref = pref_service->FindPreference(
229 pref_name.c_str()); 223 pref_name.c_str());
230 CHECK(pref); 224 CHECK(pref);
231 225
232 ListValue args; 226 ListValue args;
233 DictionaryValue* dict = new DictionaryValue(); 227 DictionaryValue* dict = new DictionaryValue();
234 args.Append(dict); 228 args.Append(dict);
235 dict->Set(key, pref->GetValue()->DeepCopy()); 229 dict->Set(key, pref->GetValue()->DeepCopy());
236 230
237 extensions::preference_helpers::DispatchEventToExtensions( 231 extensions::preference_helpers::DispatchEventToExtensions(
238 profile_, 232 profile_,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 471
478 const char* SetMinimumFontSizeFunction::GetPrefName() { 472 const char* SetMinimumFontSizeFunction::GetPrefName() {
479 return prefs::kWebKitMinimumFontSize; 473 return prefs::kWebKitMinimumFontSize;
480 } 474 }
481 475
482 const char* SetMinimumFontSizeFunction::GetKey() { 476 const char* SetMinimumFontSizeFunction::GetKey() {
483 return kPixelSizeKey; 477 return kPixelSizeKey;
484 } 478 }
485 479
486 } // namespace extensions 480 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698