| 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 #ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
| 11 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" | 11 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" |
| 12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" | |
| 13 #include "chrome/browser/extensions/chrome_extension_function.h" | 12 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 14 #include "content/public/browser/notification_observer.h" | 13 #include "content/public/browser/notification_observer.h" |
| 14 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 15 #include "extensions/browser/event_router.h" | 15 #include "extensions/browser/event_router.h" |
| 16 #include "extensions/browser/extension_prefs_scope.h" | 16 #include "extensions/browser/extension_prefs_scope.h" |
| 17 | 17 |
| 18 class ExtensionPrefValueMap; | 18 class ExtensionPrefValueMap; |
| 19 class PrefService; | 19 class PrefService; |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class Value; | 22 class Value; |
| 23 } | 23 } |
| 24 | 24 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 const std::string& pref_key, | 82 const std::string& pref_key, |
| 83 bool* from_incognito); | 83 bool* from_incognito); |
| 84 | 84 |
| 85 protected: | 85 protected: |
| 86 // Virtual for testing. | 86 // Virtual for testing. |
| 87 virtual ExtensionPrefs* extension_prefs() = 0; | 87 virtual ExtensionPrefs* extension_prefs() = 0; |
| 88 virtual ExtensionPrefValueMap* extension_pref_value_map() = 0; | 88 virtual ExtensionPrefValueMap* extension_pref_value_map() = 0; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 class PreferenceAPI : public PreferenceAPIBase, | 91 class PreferenceAPI : public PreferenceAPIBase, |
| 92 public ProfileKeyedAPI, | 92 public BrowserContextKeyedAPI, |
| 93 public EventRouter::Observer, | 93 public EventRouter::Observer, |
| 94 public ContentSettingsStore::Observer { | 94 public ContentSettingsStore::Observer { |
| 95 public: | 95 public: |
| 96 explicit PreferenceAPI(content::BrowserContext* context); | 96 explicit PreferenceAPI(content::BrowserContext* context); |
| 97 virtual ~PreferenceAPI(); | 97 virtual ~PreferenceAPI(); |
| 98 | 98 |
| 99 // BrowserContextKeyedService implementation. | 99 // BrowserContextKeyedService implementation. |
| 100 virtual void Shutdown() OVERRIDE; | 100 virtual void Shutdown() OVERRIDE; |
| 101 | 101 |
| 102 // ProfileKeyedAPI implementation. | 102 // BrowserContextKeyedAPI implementation. |
| 103 static ProfileKeyedAPIFactory<PreferenceAPI>* GetFactoryInstance(); | 103 static BrowserContextKeyedAPIFactory<PreferenceAPI>* GetFactoryInstance(); |
| 104 | 104 |
| 105 // Convenience method to get the PreferenceAPI for a profile. | 105 // Convenience method to get the PreferenceAPI for a profile. |
| 106 static PreferenceAPI* Get(content::BrowserContext* context); | 106 static PreferenceAPI* Get(content::BrowserContext* context); |
| 107 | 107 |
| 108 // EventRouter::Observer implementation. | 108 // EventRouter::Observer implementation. |
| 109 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; | 109 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| 110 | 110 |
| 111 // Loads the preferences controlled by the specified extension from their | 111 // Loads the preferences controlled by the specified extension from their |
| 112 // dictionary and sets them in the |value_map|. | 112 // dictionary and sets them in the |value_map|. |
| 113 static void LoadExtensionControlledPrefs(ExtensionPrefs* prefs, | 113 static void LoadExtensionControlledPrefs(ExtensionPrefs* prefs, |
| 114 ExtensionPrefValueMap* value_map, | 114 ExtensionPrefValueMap* value_map, |
| 115 const std::string& extension_id, | 115 const std::string& extension_id, |
| 116 ExtensionPrefsScope scope); | 116 ExtensionPrefsScope scope); |
| 117 | 117 |
| 118 // Store extension controlled preference values in the |value_map|, | 118 // Store extension controlled preference values in the |value_map|, |
| 119 // which then informs the subscribers (ExtensionPrefStores) about the winning | 119 // which then informs the subscribers (ExtensionPrefStores) about the winning |
| 120 // values. | 120 // values. |
| 121 static void InitExtensionControlledPrefs(ExtensionPrefs* prefs, | 121 static void InitExtensionControlledPrefs(ExtensionPrefs* prefs, |
| 122 ExtensionPrefValueMap* value_map); | 122 ExtensionPrefValueMap* value_map); |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 friend class ProfileKeyedAPIFactory<PreferenceAPI>; | 125 friend class BrowserContextKeyedAPIFactory<PreferenceAPI>; |
| 126 | 126 |
| 127 // ContentSettingsStore::Observer implementation. | 127 // ContentSettingsStore::Observer implementation. |
| 128 virtual void OnContentSettingChanged(const std::string& extension_id, | 128 virtual void OnContentSettingChanged(const std::string& extension_id, |
| 129 bool incognito) OVERRIDE; | 129 bool incognito) OVERRIDE; |
| 130 | 130 |
| 131 // Clears incognito session-only content settings for all extensions. | 131 // Clears incognito session-only content settings for all extensions. |
| 132 void ClearIncognitoSessionOnlyContentSettings(); | 132 void ClearIncognitoSessionOnlyContentSettings(); |
| 133 | 133 |
| 134 // PreferenceAPIBase implementation. | 134 // PreferenceAPIBase implementation. |
| 135 virtual ExtensionPrefs* extension_prefs() OVERRIDE; | 135 virtual ExtensionPrefs* extension_prefs() OVERRIDE; |
| 136 virtual ExtensionPrefValueMap* extension_pref_value_map() OVERRIDE; | 136 virtual ExtensionPrefValueMap* extension_pref_value_map() OVERRIDE; |
| 137 | 137 |
| 138 Profile* profile_; | 138 Profile* profile_; |
| 139 | 139 |
| 140 // ProfileKeyedAPI implementation. | 140 // BrowserContextKeyedAPI implementation. |
| 141 static const char* service_name() { | 141 static const char* service_name() { |
| 142 return "PreferenceAPI"; | 142 return "PreferenceAPI"; |
| 143 } | 143 } |
| 144 static const bool kServiceIsNULLWhileTesting = true; | 144 static const bool kServiceIsNULLWhileTesting = true; |
| 145 static const bool kServiceRedirectedInIncognito = true; | 145 static const bool kServiceRedirectedInIncognito = true; |
| 146 | 146 |
| 147 // Created lazily upon OnListenerAdded. | 147 // Created lazily upon OnListenerAdded. |
| 148 scoped_ptr<PreferenceEventRouter> preference_event_router_; | 148 scoped_ptr<PreferenceEventRouter> preference_event_router_; |
| 149 | 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(PreferenceAPI); | 150 DISALLOW_COPY_AND_ASSIGN(PreferenceAPI); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 protected: | 218 protected: |
| 219 virtual ~ClearPreferenceFunction(); | 219 virtual ~ClearPreferenceFunction(); |
| 220 | 220 |
| 221 // ExtensionFunction: | 221 // ExtensionFunction: |
| 222 virtual bool RunImpl() OVERRIDE; | 222 virtual bool RunImpl() OVERRIDE; |
| 223 }; | 223 }; |
| 224 | 224 |
| 225 } // namespace extensions | 225 } // namespace extensions |
| 226 | 226 |
| 227 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ | 227 #endif // CHROME_BROWSER_EXTENSIONS_API_PREFERENCE_PREFERENCE_API_H__ |
| OLD | NEW |