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

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: Fix PrefNotifierImpl 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,
Mattias Nissler (ping if slow) 2012/10/31 13:29:35 nit: indentation
Jói 2012/10/31 14:56:26 Done.
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 if (type != chrome::NOTIFICATION_PREF_CHANGED) {
162 NOTREACHED();
163 return;
164 }
165
166 PrefService* pref_service = content::Source<PrefService>(source).ptr();
167 bool incognito = (pref_service != profile_->GetPrefs()); 160 bool incognito = (pref_service != profile_->GetPrefs());
168 // We're only observing pref changes on the regular profile. 161 // We're only observing pref changes on the regular profile.
169 DCHECK(!incognito); 162 DCHECK(!incognito);
170 const std::string* pref_name =
171 content::Details<const std::string>(details).ptr();
172 163
173 PrefEventMap::iterator iter = pref_event_map_.find(*pref_name); 164 PrefEventMap::iterator iter = pref_event_map_.find(pref_name);
174 if (iter != pref_event_map_.end()) { 165 if (iter != pref_event_map_.end()) {
175 const std::string& event_name = iter->second.first; 166 const std::string& event_name = iter->second.first;
176 const std::string& key = iter->second.second; 167 const std::string& key = iter->second.second;
177 OnFontPrefChanged(pref_service, *pref_name, event_name, key, incognito); 168 OnFontPrefChanged(pref_service, pref_name, event_name, key, incognito);
178 return; 169 return;
179 } 170 }
180 171
181 std::string generic_family; 172 std::string generic_family;
182 std::string script; 173 std::string script;
183 if (ParseFontNamePrefPath(*pref_name, &generic_family, &script)) { 174 if (ParseFontNamePrefPath(pref_name, &generic_family, &script)) {
184 OnFontNamePrefChanged(pref_service, *pref_name, generic_family, script, 175 OnFontNamePrefChanged(static_cast<PrefService*>(pref_service), pref_name,
Mattias Nissler (ping if slow) 2012/10/31 13:29:35 The cast is not necessary.
Jói 2012/10/31 14:56:26 It was (this is OnFontNamePrefChanged, not OnFontN
185 incognito); 176 generic_family, script, incognito);
186 return; 177 return;
187 } 178 }
188 179
189 NOTREACHED(); 180 NOTREACHED();
190 } 181 }
191 182
192 void FontSettingsEventRouter::OnFontNamePrefChanged( 183 void FontSettingsEventRouter::OnFontNamePrefChanged(
193 PrefService* pref_service, 184 PrefService* pref_service,
194 const std::string& pref_name, 185 const std::string& pref_name,
195 const std::string& generic_family, 186 const std::string& generic_family,
(...skipping 20 matching lines...) Expand all
216 extensions::preference_helpers::DispatchEventToExtensions( 207 extensions::preference_helpers::DispatchEventToExtensions(
217 profile_, 208 profile_,
218 kOnFontChanged, 209 kOnFontChanged,
219 &args, 210 &args,
220 APIPermission::kFontSettings, 211 APIPermission::kFontSettings,
221 incognito, 212 incognito,
222 pref_name); 213 pref_name);
223 } 214 }
224 215
225 void FontSettingsEventRouter::OnFontPrefChanged( 216 void FontSettingsEventRouter::OnFontPrefChanged(
226 PrefService* pref_service, 217 PrefServiceBase* pref_service,
227 const std::string& pref_name, 218 const std::string& pref_name,
228 const std::string& event_name, 219 const std::string& event_name,
229 const std::string& key, 220 const std::string& key,
230 bool incognito) { 221 bool incognito) {
231 const PrefService::Preference* pref = pref_service->FindPreference( 222 const PrefServiceBase::Preference* pref = pref_service->FindPreference(
232 pref_name.c_str()); 223 pref_name.c_str());
233 CHECK(pref); 224 CHECK(pref);
234 225
235 ListValue args; 226 ListValue args;
236 DictionaryValue* dict = new DictionaryValue(); 227 DictionaryValue* dict = new DictionaryValue();
237 args.Append(dict); 228 args.Append(dict);
238 dict->Set(key, pref->GetValue()->DeepCopy()); 229 dict->Set(key, pref->GetValue()->DeepCopy());
239 230
240 extensions::preference_helpers::DispatchEventToExtensions( 231 extensions::preference_helpers::DispatchEventToExtensions(
241 profile_, 232 profile_,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 471
481 const char* SetMinimumFontSizeFunction::GetPrefName() { 472 const char* SetMinimumFontSizeFunction::GetPrefName() {
482 return prefs::kWebKitMinimumFontSize; 473 return prefs::kWebKitMinimumFontSize;
483 } 474 }
484 475
485 const char* SetMinimumFontSizeFunction::GetKey() { 476 const char* SetMinimumFontSizeFunction::GetKey() {
486 return kPixelSizeKey; 477 return kPixelSizeKey;
487 } 478 }
488 479
489 } // namespace extensions 480 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698