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

Side by Side Diff: chrome/browser/extensions/api/preference/preference_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 #include "chrome/browser/extensions/api/preference/preference_api.h" 5 #include "chrome/browser/extensions/api/preference/preference_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 registrar_.Init(profile_->GetPrefs()); 246 registrar_.Init(profile_->GetPrefs());
247 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs()); 247 incognito_registrar_.Init(profile_->GetOffTheRecordPrefs());
248 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { 248 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) {
249 registrar_.Add(kPrefMapping[i].browser_pref, this); 249 registrar_.Add(kPrefMapping[i].browser_pref, this);
250 incognito_registrar_.Add(kPrefMapping[i].browser_pref, this); 250 incognito_registrar_.Add(kPrefMapping[i].browser_pref, this);
251 } 251 }
252 } 252 }
253 253
254 PreferenceEventRouter::~PreferenceEventRouter() { } 254 PreferenceEventRouter::~PreferenceEventRouter() { }
255 255
256 void PreferenceEventRouter::Observe( 256 void PreferenceEventRouter::OnPreferenceChanged(PrefServiceBase* service,
257 int type, 257 const std::string& pref_name) {
258 const content::NotificationSource& source, 258 OnPrefChanged(service, pref_name);
259 const content::NotificationDetails& details) {
260 DCHECK_EQ(chrome::NOTIFICATION_PREF_CHANGED, type);
261 OnPrefChanged(content::Source<PrefService>(source).ptr(),
262 *content::Details<const std::string>(details).ptr());
263 } 259 }
264 260
265 void PreferenceEventRouter::OnPrefChanged(PrefService* pref_service, 261 void PreferenceEventRouter::OnPrefChanged(PrefServiceBase* pref_service,
266 const std::string& browser_pref) { 262 const std::string& browser_pref) {
267 bool incognito = (pref_service != profile_->GetPrefs()); 263 bool incognito = (pref_service != profile_->GetPrefs());
268 264
269 std::string event_name; 265 std::string event_name;
270 APIPermission::ID permission = APIPermission::kInvalid; 266 APIPermission::ID permission = APIPermission::kInvalid;
271 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( 267 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref(
272 browser_pref, &event_name, &permission); 268 browser_pref, &event_name, &permission);
273 DCHECK(rv); 269 DCHECK(rv);
274 270
275 ListValue args; 271 ListValue args;
276 DictionaryValue* dict = new DictionaryValue(); 272 DictionaryValue* dict = new DictionaryValue();
277 args.Append(dict); 273 args.Append(dict);
278 const PrefService::Preference* pref = 274 const PrefServiceBase::Preference* pref =
279 pref_service->FindPreference(browser_pref.c_str()); 275 pref_service->FindPreference(browser_pref.c_str());
280 CHECK(pref); 276 CHECK(pref);
281 ExtensionService* extension_service = profile_->GetExtensionService(); 277 ExtensionService* extension_service = profile_->GetExtensionService();
282 PrefTransformerInterface* transformer = 278 PrefTransformerInterface* transformer =
283 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 279 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
284 Value* transformed_value = 280 Value* transformed_value =
285 transformer->BrowserToExtensionPref(pref->GetValue()); 281 transformer->BrowserToExtensionPref(pref->GetValue());
286 if (!transformed_value) { 282 if (!transformed_value) {
287 LOG(ERROR) << 283 LOG(ERROR) <<
288 ExtensionErrorUtils::FormatErrorMessage(kConversionErrorMessage, 284 ExtensionErrorUtils::FormatErrorMessage(kConversionErrorMessage,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (!ValidateBrowserPref(pref_key, &browser_pref)) 506 if (!ValidateBrowserPref(pref_key, &browser_pref))
511 return false; 507 return false;
512 508
513 extensions::ExtensionPrefs* prefs = 509 extensions::ExtensionPrefs* prefs =
514 profile_->GetExtensionService()->extension_prefs(); 510 profile_->GetExtensionService()->extension_prefs();
515 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 511 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
516 return true; 512 return true;
517 } 513 }
518 514
519 } // namespace extensions 515 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/preference/preference_api.h ('k') | chrome/browser/extensions/component_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698