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" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" | 17 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" |
18 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" | 18 #include "chrome/browser/extensions/api/preference/preference_api_constants.h" |
19 #include "chrome/browser/extensions/api/preference/preference_helpers.h" | 19 #include "chrome/browser/extensions/api/preference/preference_helpers.h" |
20 #include "chrome/browser/extensions/api/proxy/proxy_api.h" | 20 #include "chrome/browser/extensions/api/proxy/proxy_api.h" |
21 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "components/translate/core/common/translate_pref_names.h" | 24 #include "components/translate/core/common/translate_pref_names.h" |
25 #include "content/public/browser/notification_details.h" | 25 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
27 #include "extensions/browser/extension_pref_value_map.h" | 27 #include "extensions/browser/extension_pref_value_map.h" |
28 #include "extensions/browser/extension_pref_value_map_factory.h" | 28 #include "extensions/browser/extension_pref_value_map_factory.h" |
29 #include "extensions/browser/extension_prefs_factory.h" | 29 #include "extensions/browser/extension_prefs_factory.h" |
30 #include "extensions/browser/extension_system.h" | |
31 #include "extensions/browser/extension_system_provider.h" | 30 #include "extensions/browser/extension_system_provider.h" |
32 #include "extensions/browser/extensions_browser_client.h" | 31 #include "extensions/browser/extensions_browser_client.h" |
33 #include "extensions/browser/pref_names.h" | 32 #include "extensions/browser/pref_names.h" |
34 #include "extensions/common/error_utils.h" | 33 #include "extensions/common/error_utils.h" |
35 #include "extensions/common/permissions/api_permission.h" | 34 #include "extensions/common/permissions/api_permission.h" |
36 | 35 |
37 namespace keys = extensions::preference_api_constants; | 36 namespace keys = extensions::preference_api_constants; |
38 namespace helpers = extensions::preference_helpers; | 37 namespace helpers = extensions::preference_helpers; |
39 | 38 |
40 using base::DictionaryValue; | 39 using base::DictionaryValue; |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 405 } |
407 | 406 |
408 PreferenceAPI::PreferenceAPI(content::BrowserContext* context) | 407 PreferenceAPI::PreferenceAPI(content::BrowserContext* context) |
409 : profile_(Profile::FromBrowserContext(context)) { | 408 : profile_(Profile::FromBrowserContext(context)) { |
410 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { | 409 for (size_t i = 0; i < arraysize(kPrefMapping); ++i) { |
411 std::string event_name; | 410 std::string event_name; |
412 APIPermission::ID permission = APIPermission::kInvalid; | 411 APIPermission::ID permission = APIPermission::kInvalid; |
413 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( | 412 bool rv = PrefMapping::GetInstance()->FindEventForBrowserPref( |
414 kPrefMapping[i].browser_pref, &event_name, &permission); | 413 kPrefMapping[i].browser_pref, &event_name, &permission); |
415 DCHECK(rv); | 414 DCHECK(rv); |
416 ExtensionSystem::Get(profile_)->event_router()->RegisterObserver( | 415 EventRouter::Get(profile_)->RegisterObserver(this, event_name); |
417 this, event_name); | |
418 } | 416 } |
419 content_settings_store()->AddObserver(this); | 417 content_settings_store()->AddObserver(this); |
420 } | 418 } |
421 | 419 |
422 PreferenceAPI::~PreferenceAPI() { | 420 PreferenceAPI::~PreferenceAPI() { |
423 } | 421 } |
424 | 422 |
425 void PreferenceAPI::Shutdown() { | 423 void PreferenceAPI::Shutdown() { |
426 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 424 EventRouter::Get(profile_)->UnregisterObserver(this); |
427 if (!extension_prefs()->extensions_disabled()) | 425 if (!extension_prefs()->extensions_disabled()) |
428 ClearIncognitoSessionOnlyContentSettings(); | 426 ClearIncognitoSessionOnlyContentSettings(); |
429 content_settings_store()->RemoveObserver(this); | 427 content_settings_store()->RemoveObserver(this); |
430 } | 428 } |
431 | 429 |
432 static base::LazyInstance<BrowserContextKeyedAPIFactory<PreferenceAPI> > | 430 static base::LazyInstance<BrowserContextKeyedAPIFactory<PreferenceAPI> > |
433 g_factory = LAZY_INSTANCE_INITIALIZER; | 431 g_factory = LAZY_INSTANCE_INITIALIZER; |
434 | 432 |
435 // static | 433 // static |
436 BrowserContextKeyedAPIFactory<PreferenceAPI>* | 434 BrowserContextKeyedAPIFactory<PreferenceAPI>* |
437 PreferenceAPI::GetFactoryInstance() { | 435 PreferenceAPI::GetFactoryInstance() { |
438 return g_factory.Pointer(); | 436 return g_factory.Pointer(); |
439 } | 437 } |
440 | 438 |
441 // static | 439 // static |
442 PreferenceAPI* PreferenceAPI::Get(content::BrowserContext* context) { | 440 PreferenceAPI* PreferenceAPI::Get(content::BrowserContext* context) { |
443 return BrowserContextKeyedAPIFactory<PreferenceAPI>::Get(context); | 441 return BrowserContextKeyedAPIFactory<PreferenceAPI>::Get(context); |
444 } | 442 } |
445 | 443 |
446 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) { | 444 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) { |
447 preference_event_router_.reset(new PreferenceEventRouter(profile_)); | 445 preference_event_router_.reset(new PreferenceEventRouter(profile_)); |
448 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); | 446 EventRouter::Get(profile_)->UnregisterObserver(this); |
449 } | 447 } |
450 | 448 |
451 void PreferenceAPI::OnContentSettingChanged(const std::string& extension_id, | 449 void PreferenceAPI::OnContentSettingChanged(const std::string& extension_id, |
452 bool incognito) { | 450 bool incognito) { |
453 if (incognito) { | 451 if (incognito) { |
454 extension_prefs()->UpdateExtensionPref( | 452 extension_prefs()->UpdateExtensionPref( |
455 extension_id, | 453 extension_id, |
456 pref_names::kPrefIncognitoContentSettings, | 454 pref_names::kPrefIncognitoContentSettings, |
457 content_settings_store()->GetSettingsForExtension( | 455 content_settings_store()->GetSettingsForExtension( |
458 extension_id, kExtensionPrefsScopeIncognitoPersistent)); | 456 extension_id, kExtensionPrefsScopeIncognitoPersistent)); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) { | 705 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) { |
708 return false; | 706 return false; |
709 } | 707 } |
710 | 708 |
711 PreferenceAPI::Get(GetProfile()) | 709 PreferenceAPI::Get(GetProfile()) |
712 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); | 710 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); |
713 return true; | 711 return true; |
714 } | 712 } |
715 | 713 |
716 } // namespace extensions | 714 } // namespace extensions |
OLD | NEW |