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

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: 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 #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 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
261 const std::string* pref_key =
262 content::Details<const std::string>(details).ptr();
263 OnPrefChanged(content::Source<PrefService>(source).ptr(), *pref_key);
264 } else {
265 NOTREACHED();
266 }
267 } 259 }
268 260
269 void PreferenceEventRouter::OnPrefChanged(PrefService* pref_service, 261 void PreferenceEventRouter::OnPrefChanged(PrefServiceBase* pref_service,
270 const std::string& browser_pref) { 262 const std::string& browser_pref) {
271 bool incognito = (pref_service != profile_->GetPrefs()); 263 bool incognito = (pref_service != profile_->GetPrefs());
272 264
273 std::string event_name; 265 std::string event_name;
274 APIPermission::ID permission = APIPermission::kInvalid; 266 APIPermission::ID permission = APIPermission::kInvalid;
275 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( 267 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref(
276 browser_pref, &event_name, &permission); 268 browser_pref, &event_name, &permission);
277 DCHECK(rv); 269 DCHECK(rv);
278 270
279 ListValue args; 271 ListValue args;
280 DictionaryValue* dict = new DictionaryValue(); 272 DictionaryValue* dict = new DictionaryValue();
281 args.Append(dict); 273 args.Append(dict);
282 const PrefService::Preference* pref = 274 const PrefServiceBase::Preference* pref =
283 pref_service->FindPreference(browser_pref.c_str()); 275 pref_service->FindPreference(browser_pref.c_str());
284 CHECK(pref); 276 CHECK(pref);
285 ExtensionService* extension_service = profile_->GetExtensionService(); 277 ExtensionService* extension_service = profile_->GetExtensionService();
286 PrefTransformerInterface* transformer = 278 PrefTransformerInterface* transformer =
287 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref); 279 PrefMapping::GetInstance()->FindTransformerForBrowserPref(browser_pref);
288 Value* transformed_value = 280 Value* transformed_value =
289 transformer->BrowserToExtensionPref(pref->GetValue()); 281 transformer->BrowserToExtensionPref(pref->GetValue());
290 if (!transformed_value) { 282 if (!transformed_value) {
291 LOG(ERROR) << 283 LOG(ERROR) <<
292 ExtensionErrorUtils::FormatErrorMessage(kConversionErrorMessage, 284 ExtensionErrorUtils::FormatErrorMessage(kConversionErrorMessage,
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (!ValidateBrowserPref(pref_key, &browser_pref)) 506 if (!ValidateBrowserPref(pref_key, &browser_pref))
515 return false; 507 return false;
516 508
517 extensions::ExtensionPrefs* prefs = 509 extensions::ExtensionPrefs* prefs =
518 profile_->GetExtensionService()->extension_prefs(); 510 profile_->GetExtensionService()->extension_prefs();
519 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 511 prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
520 return true; 512 return true;
521 } 513 }
522 514
523 } // namespace extensions 515 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698