Chromium Code Reviews| Index: chrome/browser/extensions/extension_prefs.h |
| diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h |
| index 6245edac68f2ea73e5c6496f1088e1acb0f99533..57e4c479e2653ffd4c09bafc443129bab7da5b8a 100644 |
| --- a/chrome/browser/extensions/extension_prefs.h |
| +++ b/chrome/browser/extensions/extension_prefs.h |
| @@ -17,8 +17,19 @@ |
| #include "googleurl/src/gurl.h" |
| // Class for managing global and per-extension preferences. |
| -// This class is instantiated by ExtensionsService, so it should be accessed |
| -// from there. |
| +// This class should be accessed via ExtensionsService. |
|
Aaron Boodman
2010/12/03 08:58:10
This last sentence no longer seems useful. It can
battre (please use the other)
2010/12/03 19:32:58
Done.
|
| +// |
| +// This class distinguishes the following kinds of preferences: |
| +// - global preferences: |
| +// internal state for the extension system in general, not associated |
| +// with an individual extension, such as lastUpdateTime. |
| +// - per-extension preferences: |
| +// meta-preferences describing properties of the extension like |
| +// installation time, whether the extension is enabled, etc. |
| +// - extension controlled preferences: |
| +// global preferences that an individual extension wants to set; |
| +// these are arbitrary preferences that are controlled by other |
| +// sub-systems. |
|
Aaron Boodman
2010/12/03 08:58:10
A quick example might clarify things here.
Also,
battre (please use the other)
2010/12/03 19:32:58
Done.
|
| class ExtensionPrefs { |
| public: |
| // Key name for a preference that keeps track of per-extension settings. This |
| @@ -28,6 +39,12 @@ class ExtensionPrefs { |
| typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; |
| + // Vector containing identifiers for preferences. |
| + typedef std::vector<std::string> PrefKeySet; |
| + |
| + // Vector containing identifiers for extensions. |
| + typedef std::vector<std::string> ExtensionIdSet; |
| + |
| // This enum is used for the launch type the user wants to use for an |
| // application. |
| // Do not remove items or re-order this enum as it is used in preferences |
| @@ -39,7 +56,8 @@ class ExtensionPrefs { |
| LAUNCH_WINDOW |
| }; |
| - explicit ExtensionPrefs(PrefService* prefs, const FilePath& root_dir_); |
| + explicit ExtensionPrefs(Profile* profile, |
| + const FilePath& root_dir); |
| ~ExtensionPrefs(); |
| // Returns a copy of the Extensions prefs. |
| @@ -74,11 +92,14 @@ class ExtensionPrefs { |
| bool external_uninstall); |
| // Returns the state (enabled/disabled) of the given extension. |
| - Extension::State GetExtensionState(const std::string& extension_id); |
| + Extension::State GetExtensionState(const std::string& extension_id) const; |
| // Called to change the extension's state when it is enabled/disabled. |
| void SetExtensionState(const Extension* extension, Extension::State); |
| + // Returns all installed and enabled extensions |
| + void GetEnabledExtensions(ExtensionIdSet* out) const; |
| + |
| // Getter and setter for browser action visibility. |
| bool GetBrowserActionVisibility(const Extension* extension); |
| void SetBrowserActionVisibility(const Extension* extension, bool visible); |
| @@ -232,11 +253,23 @@ class ExtensionPrefs { |
| const std::string& data); |
| std::string GetUpdateUrlData(const std::string& extension_id); |
| + // Sets a preference value that is controlled by the extension. In other |
| + // words, this is not a pref value *about* the extension but something |
| + // global the extension wants to override. |
| + void SetExtensionControlledPref(const std::string& extension_id, |
| + const std::string& pref_key, |
| + Value* value); |
| + |
| static void RegisterUserPrefs(PrefService* prefs); |
| // The underlying PrefService. |
| PrefService* pref_service() const { return prefs_; } |
| + protected: |
| + // For unit testing. Enables injecting an artificial clock that is used |
| + // to query the current time, when an extension is installed. |
| + virtual base::Time GetCurrentTime() const; |
| + |
| private: |
| // Converts absolute paths in the pref to paths relative to the |
| // install_directory_. |
| @@ -296,6 +329,11 @@ class ExtensionPrefs { |
| // Same as above, but returns NULL if it doesn't exist. |
| DictionaryValue* GetExtensionPref(const std::string& id) const; |
| + // Returns the dictionary of preferences controlled by the specified extension |
| + // or NULL if unknown. All entries in the dictionary contain non-expanded |
| + // paths. |
| + DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; |
| + |
| // Serializes the data and schedules a persistent save via the |PrefService|. |
| // Additionally fires a PREF_CHANGED notification with the top-level |
| // |kExtensionsPref| path set. |
| @@ -313,6 +351,37 @@ class ExtensionPrefs { |
| base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; |
| void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); |
| + // Helper method to acquire the installation time of an extension. |
| + base::Time GetInstallTime(const std::string& extension_id) const; |
| + |
| + // Fix missing preference entries in the extensions that are were introduced |
| + // in a later Chrome version. |
| + void FixMissingPrefs(const ExtensionIdSet& extension_ids); |
| + |
| + // Installs the persistent extension preferences into |prefs_|'s extension |
|
Aaron Boodman
2010/12/03 08:58:10
It seems like what this thing really does is intia
battre (please use the other)
2010/12/03 19:32:58
Done.
|
| + // pref store. |
| + void InstallPersistedExtensionControlledPrefs(); |
| + |
| + // Returns the extension controlled preference value of the extension that was |
| + // installed most recently. |
| + const Value* WinningExtensionControlledPrefValue( |
|
Aaron Boodman
2010/12/03 08:58:10
Method names should be verbs, so "GetWinning...",
battre (please use the other)
2010/12/03 19:32:58
I have changed it to GetWinning. GetMostRecent doe
|
| + const std::string& key) const; |
| + |
| + // Executes UpdateWinningPref for all |pref_keys|. |
| + void UpdateWinningPrefs(const PrefKeySet& pref_keys); |
|
Aaron Boodman
2010/12/03 08:58:10
UpdatePrefStore?
battre (please use the other)
2010/12/03 19:32:58
Done.
|
| + |
| + // Finds the most recently installed extension that defines a preference |
| + // for |pref_key|, then store its value in the PrefValueStore's extension pref |
| + // store and send notifications to observers in case the value changed. |
| + void UpdateWinningPref(const std::string& pref_key); |
|
Aaron Boodman
2010/12/03 08:58:10
Also UpdatePrefStore? (method overload)
battre (please use the other)
2010/12/03 19:32:58
Done.
|
| + |
| + // Retrieves a list of preference keys that the specified extension |
| + // intents to manage. Keys are always appended, |out| is not cleared. |
|
Aaron Boodman
2010/12/03 08:58:10
s/intents/intends
battre (please use the other)
2010/12/03 19:32:58
Done.
|
| + void GetExtensionControlledPrefKeys(const std::string& extension_id, |
| + PrefKeySet *out) const; |
| + |
| + Profile* profile_; |
| + |
| // The pref service specific to this set of extension prefs. |
| PrefService* prefs_; |