| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_EXTENSION_PREF_STORE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 class DictionaryValue; | 23 class DictionaryValue; |
| 24 class Extension; | 24 class Extension; |
| 25 class PrefService; | 25 class PrefService; |
| 26 class Profile; | 26 class Profile; |
| 27 class Value; | 27 class Value; |
| 28 | 28 |
| 29 // This PrefStore keeps track of preferences set by extensions: for example, | 29 // This PrefStore keeps track of preferences set by extensions: for example, |
| 30 // proxy settings. A stack of relevant extensions is stored in order of | 30 // proxy settings. A stack of relevant extensions is stored in order of |
| 31 // their addition to this PrefStore. For each preference, the last-added | 31 // their addition to this PrefStore. For each preference, the last-added |
| 32 // enabled extension that tries to set it overrules any others. | 32 // enabled extension that tries to set it overrules any others. |
| 33 // | |
| 34 // TODO(battre): The ExtensionPrefStore has an issue if it serves for storing | |
| 35 // extension preferences in the local-state (shared among all profiles on a | |
| 36 // machine). In this context, there is no meaningful definition of a precedence | |
| 37 // order as the same extensions can be installed in different profiles. | |
| 38 // One instance would override the preferences of another instance. Also it is | |
| 39 // unclear how settings should be removed in this case. For this reason we | |
| 40 // (pamg, battre) decided to not support the ExtensionPrefStore for local-state. | |
| 41 // This needs to be enforced by the code. | |
| 42 class ExtensionPrefStore : public PrefStore, | 33 class ExtensionPrefStore : public PrefStore, |
| 43 public NotificationObserver { | 34 public NotificationObserver { |
| 44 public: | 35 public: |
| 45 // Maps preference paths to their values. | 36 // Maps preference paths to their values. |
| 46 typedef std::map<const char*, Value*> PrefValueMap; | 37 typedef std::map<const char*, Value*> PrefValueMap; |
| 47 | 38 |
| 48 // The type passed as Details for an EXTENSION_PREF_CHANGED notification. | 39 // The type passed as Details for an EXTENSION_PREF_CHANGED notification. |
| 49 // The nested pairs are <extension, <pref_path, pref_value> >. This is here, | 40 // The nested pairs are <extension, <pref_path, pref_value> >. This is here, |
| 50 // rather than in (say) notification_type.h, to keep the dependency on | 41 // rather than in (say) notification_type.h, to keep the dependency on |
| 51 // std::pair out of the many places that include notification_type.h. | 42 // std::pair out of the many places that include notification_type.h. |
| 52 typedef std::pair<const Extension*, std::pair<const char*, Value*> > | 43 typedef std::pair<const Extension*, std::pair<const char*, Value*> > |
| 53 ExtensionPrefDetails; | 44 ExtensionPrefDetails; |
| 54 | 45 |
| 46 // The local-state ExtensionPrefStore (shared among all profiles on a |
| 47 // machine), indicated by a NULL |profile|, is prohibited from storing |
| 48 // preferences. Since extensions are installed per profile, allowing them to |
| 49 // control machine-wide settings could lead to unsolvable conflicts, and |
| 50 // should not be necessary anyway. |
| 55 ExtensionPrefStore(Profile* profile, PrefNotifier::PrefStoreType type); | 51 ExtensionPrefStore(Profile* profile, PrefNotifier::PrefStoreType type); |
| 56 virtual ~ExtensionPrefStore(); | 52 virtual ~ExtensionPrefStore(); |
| 57 | 53 |
| 58 // Begins tracking the preference and value an extension wishes to set. This | 54 // Begins tracking the preference and value an extension wishes to set. This |
| 59 // must be called each time an extension API tries to set a preference. | 55 // must be called each time an extension API tries to set a preference. |
| 60 // The ExtensionPrefStore will take ownership of the |pref_value|. | 56 // The ExtensionPrefStore will take ownership of the |pref_value|. |
| 61 virtual void InstallExtensionPref(const Extension* extension, | 57 virtual void InstallExtensionPref(const Extension* extension, |
| 62 const char* pref_path, | 58 const char* pref_path, |
| 63 Value* pref_value); | 59 Value* pref_value); |
| 64 | 60 |
| 65 // Removes an extension and all its preference settings from this PrefStore. | 61 // Removes an extension and all its preference settings from this PrefStore. |
| 66 // This must be called when an extension is uninstalled or disabled. | 62 // This must be called when an extension is uninstalled or disabled. |
| 67 virtual void UninstallExtension(const Extension* extension); | 63 virtual void UninstallExtension(const Extension* extension); |
| 68 | 64 |
| 69 // PrefStore methods: | 65 // PrefStore methods: |
| 70 virtual DictionaryValue* prefs() const { return prefs_.get(); } | 66 virtual DictionaryValue* prefs() const { return prefs_.get(); } |
| 71 | 67 |
| 72 virtual PrefReadError ReadPrefs() { return PREF_READ_ERROR_NONE; } | 68 virtual PrefReadError ReadPrefs() { return PREF_READ_ERROR_NONE; } |
| 73 | 69 |
| 74 protected: | 70 protected: |
| 75 // Returns a vector of the extension IDs in the extension_stack_. | 71 // Returns a vector of the extension IDs in the extension_stack_. |
| 76 // This should only be accessed by subclasses for unit-testing. | 72 // This should only be accessed by subclasses for unit-testing. |
| 77 void GetExtensionIDs(std::vector<std::string>* result); | 73 void GetExtensionIDs(std::vector<std::string>* result); |
| 78 | 74 |
| 79 // Returns the applicable pref service from the profile (if we have one) or | 75 // For PrefService injection for unit-testing |
| 80 // the browser's local state. This should only be accessed or overridden by | |
| 81 // subclasses for unit-testing. | |
| 82 virtual PrefService* GetPrefService(); | 76 virtual PrefService* GetPrefService(); |
| 83 | 77 |
| 84 // The following functions delegate to | 78 // The following functions delegate to |
| 85 // profile_->GetExtensionsService()->extension_prefs() | 79 // profile_->GetExtensionsService()->extension_prefs() |
| 86 // and are defined here only for injection in case of unit tests. | 80 // and are defined here only for injection in case of unit tests. |
| 87 virtual void PersistExtensionPrecedences( | 81 virtual void PersistExtensionPrecedences( |
| 88 const std::vector<std::string>& precedence); | 82 const std::vector<std::string>& precedence); |
| 89 virtual void GetExtensionPrecedences( | 83 virtual void GetExtensionPrecedences( |
| 90 std::vector<std::string>* precedence) const; | 84 std::vector<std::string>* precedence) const; |
| 91 | 85 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // extensions. | 143 // extensions. |
| 150 Profile* profile_; | 144 Profile* profile_; |
| 151 | 145 |
| 152 // My PrefStore type, assigned by the PrefValueStore. | 146 // My PrefStore type, assigned by the PrefValueStore. |
| 153 PrefNotifier::PrefStoreType type_; | 147 PrefNotifier::PrefStoreType type_; |
| 154 | 148 |
| 155 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefStore); | 149 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefStore); |
| 156 }; | 150 }; |
| 157 | 151 |
| 158 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | 152 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ |
| OLD | NEW |