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

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 to head for commit 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 return static_cast<gfx::PlatformFontWin*>(font.platform_font())-> 80 return static_cast<gfx::PlatformFontWin*>(font.platform_font())->
81 GetLocalizedFontName(); 81 GetLocalizedFontName();
82 } 82 }
83 #endif 83 #endif
84 return font_name; 84 return font_name;
85 } 85 }
86 86
87 // Registers |obs| to observe per-script font prefs under the path |map_name|. 87 // Registers |obs| to observe per-script font prefs under the path |map_name|.
88 void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar, 88 void RegisterFontFamilyMapObserver(PrefChangeRegistrar* registrar,
89 const char* map_name, 89 const char* map_name,
90 content::NotificationObserver* obs) { 90 PrefObserver* obs) {
91 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) { 91 for (size_t i = 0; i < prefs::kWebKitScriptsForFontFamilyMapsLength; ++i) {
92 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i]; 92 const char* script = prefs::kWebKitScriptsForFontFamilyMaps[i];
93 std::string pref_name = base::StringPrintf("%s.%s", map_name, script); 93 std::string pref_name = base::StringPrintf("%s.%s", map_name, script);
94 registrar->Add(pref_name.c_str(), obs); 94 registrar->Add(pref_name.c_str(), obs);
95 } 95 }
96 } 96 }
97 97
98 } // namespace 98 } // namespace
99 99
100 FontSettingsEventRouter::FontSettingsEventRouter( 100 FontSettingsEventRouter::FontSettingsEventRouter(
(...skipping 24 matching lines...) Expand all
125 prefs::kWebKitFixedFontFamilyMap, this); 125 prefs::kWebKitFixedFontFamilyMap, this);
126 RegisterFontFamilyMapObserver(&registrar_, 126 RegisterFontFamilyMapObserver(&registrar_,
127 prefs::kWebKitCursiveFontFamilyMap, this); 127 prefs::kWebKitCursiveFontFamilyMap, this);
128 RegisterFontFamilyMapObserver(&registrar_, 128 RegisterFontFamilyMapObserver(&registrar_,
129 prefs::kWebKitFantasyFontFamilyMap, this); 129 prefs::kWebKitFantasyFontFamilyMap, this);
130 RegisterFontFamilyMapObserver(&registrar_, 130 RegisterFontFamilyMapObserver(&registrar_,
131 prefs::kWebKitPictographFontFamilyMap, this); 131 prefs::kWebKitPictographFontFamilyMap, this);
132 } 132 }
133 133
134 void FontSettingsEventRouter::AddPrefToObserve(const char* pref_name, 134 void FontSettingsEventRouter::AddPrefToObserve(const char* pref_name,
135 const char* event_name, 135 const char* event_name,
136 const char* key) { 136 const char* key) {
137 registrar_.Add(pref_name, this); 137 registrar_.Add(pref_name, this);
138 pref_event_map_[pref_name] = std::make_pair(event_name, key); 138 pref_event_map_[pref_name] = std::make_pair(event_name, key);
139 } 139 }
140 140
141 void FontSettingsEventRouter::Observe( 141 void FontSettingsEventRouter::OnPreferenceChanged(
142 int type, 142 PrefServiceBase* pref_service,
143 const content::NotificationSource& source, 143 const std::string& pref_name) {
144 const content::NotificationDetails& details) {
145 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type);
146
147 PrefService* pref_service = content::Source<PrefService>(source).ptr();
148 bool incognito = (pref_service != profile_->GetPrefs()); 144 bool incognito = (pref_service != profile_->GetPrefs());
149 // We're only observing pref changes on the regular profile. 145 // We're only observing pref changes on the regular profile.
150 DCHECK(!incognito); 146 DCHECK(!incognito);
151 const std::string& pref_name =
152 *content::Details<const std::string>(details).ptr();
153 147
154 PrefEventMap::iterator iter = pref_event_map_.find(pref_name); 148 PrefEventMap::iterator iter = pref_event_map_.find(pref_name);
155 if (iter != pref_event_map_.end()) { 149 if (iter != pref_event_map_.end()) {
156 const std::string& event_name = iter->second.first; 150 const std::string& event_name = iter->second.first;
157 const std::string& key = iter->second.second; 151 const std::string& key = iter->second.second;
158 OnFontPrefChanged(pref_service, pref_name, event_name, key, incognito); 152 OnFontPrefChanged(pref_service, pref_name, event_name, key, incognito);
159 return; 153 return;
160 } 154 }
161 155
162 std::string generic_family; 156 std::string generic_family;
163 std::string script; 157 std::string script;
164 if (pref_names_util::ParseFontNamePrefPath(pref_name, &generic_family, 158 if (pref_names_util::ParseFontNamePrefPath(pref_name, &generic_family,
165 &script)) { 159 &script)) {
166 OnFontNamePrefChanged(pref_service, pref_name, generic_family, script, 160 OnFontNamePrefChanged(pref_service, pref_name, generic_family, script,
167 incognito); 161 incognito);
168 return; 162 return;
169 } 163 }
170 164
171 NOTREACHED(); 165 NOTREACHED();
172 } 166 }
173 167
174 void FontSettingsEventRouter::OnFontNamePrefChanged( 168 void FontSettingsEventRouter::OnFontNamePrefChanged(
175 PrefService* pref_service, 169 PrefServiceBase* pref_service,
176 const std::string& pref_name, 170 const std::string& pref_name,
177 const std::string& generic_family, 171 const std::string& generic_family,
178 const std::string& script, 172 const std::string& script,
179 bool incognito) { 173 bool incognito) {
180 const PrefService::Preference* pref = pref_service->FindPreference( 174 const PrefServiceBase::Preference* pref = pref_service->FindPreference(
181 pref_name.c_str()); 175 pref_name.c_str());
182 CHECK(pref); 176 CHECK(pref);
183 177
184 std::string font_name; 178 std::string font_name;
185 if (!pref->GetValue()->GetAsString(&font_name)) { 179 if (!pref->GetValue()->GetAsString(&font_name)) {
186 NOTREACHED(); 180 NOTREACHED();
187 return; 181 return;
188 } 182 }
189 font_name = MaybeGetLocalizedFontName(font_name); 183 font_name = MaybeGetLocalizedFontName(font_name);
190 184
191 ListValue args; 185 ListValue args;
192 DictionaryValue* dict = new DictionaryValue(); 186 DictionaryValue* dict = new DictionaryValue();
193 args.Append(dict); 187 args.Append(dict);
194 dict->SetString(kFontIdKey, font_name); 188 dict->SetString(kFontIdKey, font_name);
195 dict->SetString(kGenericFamilyKey, generic_family); 189 dict->SetString(kGenericFamilyKey, generic_family);
196 dict->SetString(kScriptKey, script); 190 dict->SetString(kScriptKey, script);
197 191
198 extensions::preference_helpers::DispatchEventToExtensions( 192 extensions::preference_helpers::DispatchEventToExtensions(
199 profile_, 193 profile_,
200 kOnFontChanged, 194 kOnFontChanged,
201 &args, 195 &args,
202 APIPermission::kFontSettings, 196 APIPermission::kFontSettings,
203 incognito, 197 incognito,
204 pref_name); 198 pref_name);
205 } 199 }
206 200
207 void FontSettingsEventRouter::OnFontPrefChanged( 201 void FontSettingsEventRouter::OnFontPrefChanged(
208 PrefService* pref_service, 202 PrefServiceBase* pref_service,
209 const std::string& pref_name, 203 const std::string& pref_name,
210 const std::string& event_name, 204 const std::string& event_name,
211 const std::string& key, 205 const std::string& key,
212 bool incognito) { 206 bool incognito) {
213 const PrefService::Preference* pref = pref_service->FindPreference( 207 const PrefServiceBase::Preference* pref = pref_service->FindPreference(
214 pref_name.c_str()); 208 pref_name.c_str());
215 CHECK(pref); 209 CHECK(pref);
216 210
217 ListValue args; 211 ListValue args;
218 DictionaryValue* dict = new DictionaryValue(); 212 DictionaryValue* dict = new DictionaryValue();
219 args.Append(dict); 213 args.Append(dict);
220 dict->Set(key, pref->GetValue()->DeepCopy()); 214 dict->Set(key, pref->GetValue()->DeepCopy());
221 215
222 extensions::preference_helpers::DispatchEventToExtensions( 216 extensions::preference_helpers::DispatchEventToExtensions(
223 profile_, 217 profile_,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 456
463 const char* SetMinimumFontSizeFunction::GetPrefName() { 457 const char* SetMinimumFontSizeFunction::GetPrefName() {
464 return prefs::kWebKitMinimumFontSize; 458 return prefs::kWebKitMinimumFontSize;
465 } 459 }
466 460
467 const char* SetMinimumFontSizeFunction::GetKey() { 461 const char* SetMinimumFontSizeFunction::GetKey() {
468 return kPixelSizeKey; 462 return kPixelSizeKey;
469 } 463 }
470 464
471 } // namespace extensions 465 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698