| OLD | NEW |
| 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/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 const std::string& pref_key, | 369 const std::string& pref_key, |
| 370 bool* from_incognito) { | 370 bool* from_incognito) { |
| 371 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key.c_str())) | 371 DCHECK(extension_prefs()->pref_service()->FindPreference(pref_key.c_str())) |
| 372 << "Extension controlled preference key " << pref_key | 372 << "Extension controlled preference key " << pref_key |
| 373 << " not registered."; | 373 << " not registered."; |
| 374 | 374 |
| 375 return extension_pref_value_map()->DoesExtensionControlPref( | 375 return extension_pref_value_map()->DoesExtensionControlPref( |
| 376 extension_id, pref_key, from_incognito); | 376 extension_id, pref_key, from_incognito); |
| 377 } | 377 } |
| 378 | 378 |
| 379 PreferenceAPI::PreferenceAPI(Profile* profile) : profile_(profile) { | 379 PreferenceAPI::PreferenceAPI(content::BrowserContext* context) |
| 380 : profile_(Profile::FromBrowserContext(context)) { |
| 380 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { | 381 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { |
| 381 std::string event_name; | 382 std::string event_name; |
| 382 APIPermission::ID permission = APIPermission::kInvalid; | 383 APIPermission::ID permission = APIPermission::kInvalid; |
| 383 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( | 384 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( |
| 384 kPrefMapping[i].browser_pref, &event_name, &permission); | 385 kPrefMapping[i].browser_pref, &event_name, &permission); |
| 385 DCHECK(rv); | 386 DCHECK(rv); |
| 386 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 387 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( |
| 387 this, event_name); | 388 this, event_name); |
| 388 } | 389 } |
| 389 extension_prefs()->content_settings_store()->AddObserver(this); | 390 extension_prefs()->content_settings_store()->AddObserver(this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 401 | 402 |
| 402 static base::LazyInstance<ProfileKeyedAPIFactory<PreferenceAPI> > | 403 static base::LazyInstance<ProfileKeyedAPIFactory<PreferenceAPI> > |
| 403 g_factory = LAZY_INSTANCE_INITIALIZER; | 404 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 404 | 405 |
| 405 // static | 406 // static |
| 406 ProfileKeyedAPIFactory<PreferenceAPI>* PreferenceAPI::GetFactoryInstance() { | 407 ProfileKeyedAPIFactory<PreferenceAPI>* PreferenceAPI::GetFactoryInstance() { |
| 407 return g_factory.Pointer(); | 408 return g_factory.Pointer(); |
| 408 } | 409 } |
| 409 | 410 |
| 410 // static | 411 // static |
| 411 PreferenceAPI* PreferenceAPI::Get(Profile* profile) { | 412 PreferenceAPI* PreferenceAPI::Get(content::BrowserContext* context) { |
| 412 return ProfileKeyedAPIFactory<PreferenceAPI>::GetForProfile(profile); | 413 return ProfileKeyedAPIFactory<PreferenceAPI>::GetForProfile(context); |
| 413 } | 414 } |
| 414 | 415 |
| 415 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) { | 416 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 416 preference_event_router_.reset(new PreferenceEventRouter(profile_)); | 417 preference_event_router_.reset(new PreferenceEventRouter(profile_)); |
| 417 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 418 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); |
| 418 } | 419 } |
| 419 | 420 |
| 420 // static | 421 // static |
| 421 void PreferenceAPI::LoadExtensionControlledPrefs( | 422 void PreferenceAPI::LoadExtensionControlledPrefs( |
| 422 ExtensionPrefs* prefs, | 423 ExtensionPrefs* prefs, |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 std::string browser_pref; | 733 std::string browser_pref; |
| 733 if (!ValidateBrowserPref(pref_key, &browser_pref)) | 734 if (!ValidateBrowserPref(pref_key, &browser_pref)) |
| 734 return false; | 735 return false; |
| 735 | 736 |
| 736 PreferenceAPI::Get(GetProfile()) | 737 PreferenceAPI::Get(GetProfile()) |
| 737 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); | 738 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); |
| 738 return true; | 739 return true; |
| 739 } | 740 } |
| 740 | 741 |
| 741 } // namespace extensions | 742 } // namespace extensions |
| OLD | NEW |