Chromium Code Reviews| 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_PREFS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/linked_ptr.h" | 13 #include "base/linked_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 | 18 |
| 19 // Class for managing global and per-extension preferences. | 19 // Class for managing global and per-extension preferences. |
| 20 // This class is instantiated by ExtensionsService, so it should be accessed | 20 // This class is instantiated by ExtensionsService, so it should be accessed |
| 21 // from there. | 21 // from there. |
| 22 // | |
| 23 // This class distinguishes the following kinds of preferences: | |
| 24 // - global preferences: | |
| 25 // not associated with extensions | |
| 26 // - per-extension preferences: | |
| 27 // meta-preferences describing properties of the extension like | |
| 28 // installation time, whether the extension is enabled, etc. | |
| 29 // - extension controlled preferences: | |
| 30 // global preferences that an individual extension wants to set | |
|
Mattias Nissler (ping if slow)
2010/11/18 16:30:33
Maybe not that these are arbitrary preferences (fr
battre (please use the other)
2010/11/18 16:47:33
Done.
| |
| 31 // | |
|
Mattias Nissler (ping if slow)
2010/11/18 16:30:33
Remove newline.
battre (please use the other)
2010/11/18 16:47:33
Done.
| |
| 22 class ExtensionPrefs { | 32 class ExtensionPrefs { |
| 23 public: | 33 public: |
| 24 // Key name for a preference that keeps track of per-extension settings. This | 34 // Key name for a preference that keeps track of per-extension settings. This |
| 25 // is a dictionary object read from the Preferences file, keyed off of | 35 // is a dictionary object read from the Preferences file, keyed off of |
| 26 // extension ids. | 36 // extension ids. |
| 27 static const char kExtensionsPref[]; | 37 static const char kExtensionsPref[]; |
| 28 | 38 |
| 29 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; | 39 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; |
| 30 | 40 |
| 31 // This enum is used for the launch type the user wants to use for an | 41 // This enum is used for the launch type the user wants to use for an |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 void OnExtensionInstalled(const Extension* extension, | 76 void OnExtensionInstalled(const Extension* extension, |
| 67 Extension::State initial_state, | 77 Extension::State initial_state, |
| 68 bool initial_incognito_enabled); | 78 bool initial_incognito_enabled); |
| 69 | 79 |
| 70 // Called when an extension is uninstalled, so that prefs get cleaned up. | 80 // Called when an extension is uninstalled, so that prefs get cleaned up. |
| 71 void OnExtensionUninstalled(const std::string& extension_id, | 81 void OnExtensionUninstalled(const std::string& extension_id, |
| 72 const Extension::Location& location, | 82 const Extension::Location& location, |
| 73 bool external_uninstall); | 83 bool external_uninstall); |
| 74 | 84 |
| 75 // Returns the state (enabled/disabled) of the given extension. | 85 // Returns the state (enabled/disabled) of the given extension. |
| 76 Extension::State GetExtensionState(const std::string& extension_id); | 86 Extension::State GetExtensionState(const std::string& extension_id) const; |
| 77 | 87 |
| 78 // Called to change the extension's state when it is enabled/disabled. | 88 // Called to change the extension's state when it is enabled/disabled. |
| 79 void SetExtensionState(const Extension* extension, Extension::State); | 89 void SetExtensionState(const Extension* extension, Extension::State); |
| 80 | 90 |
| 81 // Did the extension ask to escalate its permission during an upgrade? | 91 // Did the extension ask to escalate its permission during an upgrade? |
| 82 bool DidExtensionEscalatePermissions(const std::string& id); | 92 bool DidExtensionEscalatePermissions(const std::string& id); |
| 83 | 93 |
| 84 // If |did_escalate| is true, the preferences for |extension| will be set to | 94 // If |did_escalate| is true, the preferences for |extension| will be set to |
| 85 // require the install warning when the user tries to enable. | 95 // require the install warning when the user tries to enable. |
| 86 void SetDidExtensionEscalatePermissions(const Extension* extension, | 96 void SetDidExtensionEscalatePermissions(const Extension* extension, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 // highest current application launch index found. | 197 // highest current application launch index found. |
| 188 int GetNextAppLaunchIndex(); | 198 int GetNextAppLaunchIndex(); |
| 189 | 199 |
| 190 // The extension's update URL data. If not empty, the ExtensionUpdater | 200 // The extension's update URL data. If not empty, the ExtensionUpdater |
| 191 // will append a ap= parameter to the URL when checking if a new version | 201 // will append a ap= parameter to the URL when checking if a new version |
| 192 // of the extension is available. | 202 // of the extension is available. |
| 193 void SetUpdateUrlData(const std::string& extension_id, | 203 void SetUpdateUrlData(const std::string& extension_id, |
| 194 const std::string& data); | 204 const std::string& data); |
| 195 std::string GetUpdateUrlData(const std::string& extension_id); | 205 std::string GetUpdateUrlData(const std::string& extension_id); |
| 196 | 206 |
| 207 // Sets a preference value that is controlled by the extension. In other | |
| 208 // words, this is not a pref value *about* the extension but something | |
| 209 // global the extension wants to override. | |
| 210 void SetExtensionControlledPref(const std::string& extension_id, | |
| 211 const std::string& pref_key, | |
| 212 Value* value); | |
| 213 | |
| 197 static void RegisterUserPrefs(PrefService* prefs); | 214 static void RegisterUserPrefs(PrefService* prefs); |
| 198 | 215 |
| 199 // The underlying PrefService. | 216 // The underlying PrefService. |
| 200 PrefService* pref_service() const { return prefs_; } | 217 PrefService* pref_service() const { return prefs_; } |
| 201 | 218 |
| 219 protected: | |
| 220 // For unit testing | |
|
Mattias Nissler (ping if slow)
2010/11/18 16:30:33
Missing period.
And I think this deserves a more
battre (please use the other)
2010/11/18 16:47:33
Done.
| |
| 221 base::Time GetCurrentTime() const; | |
| 222 | |
| 202 private: | 223 private: |
| 203 // Converts absolute paths in the pref to paths relative to the | 224 // Converts absolute paths in the pref to paths relative to the |
| 204 // install_directory_. | 225 // install_directory_. |
| 205 void MakePathsRelative(); | 226 void MakePathsRelative(); |
| 206 | 227 |
| 207 // Converts internal relative paths to be absolute. Used for export to | 228 // Converts internal relative paths to be absolute. Used for export to |
| 208 // consumers who expect full paths. | 229 // consumers who expect full paths. |
| 209 void MakePathsAbsolute(DictionaryValue* dict); | 230 void MakePathsAbsolute(DictionaryValue* dict); |
| 210 | 231 |
| 211 // Sets the pref |key| for extension |id| to |value|. | 232 // Sets the pref |key| for extension |id| to |value|. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 233 bool ReadExtensionPrefInteger(const std::string& extension_id, | 254 bool ReadExtensionPrefInteger(const std::string& extension_id, |
| 234 const std::string& pref_key, | 255 const std::string& pref_key, |
| 235 int* out_value); | 256 int* out_value); |
| 236 | 257 |
| 237 // Ensures and returns a mutable dictionary for extension |id|'s prefs. | 258 // Ensures and returns a mutable dictionary for extension |id|'s prefs. |
| 238 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); | 259 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); |
| 239 | 260 |
| 240 // Same as above, but returns NULL if it doesn't exist. | 261 // Same as above, but returns NULL if it doesn't exist. |
| 241 DictionaryValue* GetExtensionPref(const std::string& id) const; | 262 DictionaryValue* GetExtensionPref(const std::string& id) const; |
| 242 | 263 |
| 264 // Returns the dictionary of preferences controlled by the specified extension | |
| 265 // or NULL if unknown. All entries in the dictionary contain non-expanded | |
| 266 // paths. | |
| 267 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; | |
| 268 | |
| 243 // Serializes the data and schedules a persistent save via the |PrefService|. | 269 // Serializes the data and schedules a persistent save via the |PrefService|. |
| 244 // Additionally fires a PREF_CHANGED notification with the top-level | 270 // Additionally fires a PREF_CHANGED notification with the top-level |
| 245 // |kExtensionsPref| path set. | 271 // |kExtensionsPref| path set. |
| 246 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. | 272 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. |
| 247 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to | 273 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to |
| 248 // the mutable extension dictionary. | 274 // the mutable extension dictionary. |
| 249 void SavePrefsAndNotify(); | 275 void SavePrefsAndNotify(); |
| 250 | 276 |
| 251 // Checks if kPrefBlacklist is set to true in the DictionaryValue. | 277 // Checks if kPrefBlacklist is set to true in the DictionaryValue. |
| 252 // Return false if the value is false or kPrefBlacklist does not exist. | 278 // Return false if the value is false or kPrefBlacklist does not exist. |
| 253 // This is used to decide if an extension is blacklisted. | 279 // This is used to decide if an extension is blacklisted. |
| 254 bool IsBlacklistBitSet(DictionaryValue* ext); | 280 bool IsBlacklistBitSet(DictionaryValue* ext); |
| 255 | 281 |
| 256 // Helper methods for the public last ping day functions. | 282 // Helper methods for the public last ping day functions. |
| 257 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; | 283 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; |
| 258 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); | 284 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); |
| 259 | 285 |
| 286 // Helper method to acquire the installation time of an extension | |
| 287 base::Time GetInstallTime(const DictionaryValue* extension) const; | |
|
Mattias Nissler (ping if slow)
2010/11/18 16:30:33
Why is that parameter a DictionaryValue*? I'd expe
battre (please use the other)
2010/11/18 16:47:33
It is a simple helper method and we need to compar
| |
| 288 | |
| 289 // Installs the persistent extension preferences into prefs_'s extension | |
|
Mattias Nissler (ping if slow)
2010/11/18 16:30:33
|pref_|'s
battre (please use the other)
2010/11/18 16:47:33
Done.
| |
| 290 // pref store. | |
| 291 void InstallPersistedExtensionControlledPrefs(); | |
| 292 | |
| 293 // Returns the extension controlled preference value of the extension that was | |
| 294 // installed most recently. | |
| 295 const Value* WinningExtensionControlledPrefValue(const std::string& key) | |
|
Mattias Nissler (ping if slow)
2010/11/18 16:30:33
Again, why a Value* and not an extension ID?
battre (please use the other)
2010/11/18 16:47:33
this time it is "...Controlle*d*PrefValue", not "C
| |
| 296 const; | |
| 297 | |
| 298 // Store the WinningExtensionControlledPrefValue in the PrefValueStore's | |
|
Mattias Nissler (ping if slow)
2010/11/18 16:30:33
what value? ;) Maybe say it in prose :)
battre (please use the other)
2010/11/18 16:47:33
Done.
| |
| 299 // extension pref store and send notifications to provider in case of | |
| 300 // a changed value. | |
| 301 void UpdateWinningPref(const std::string& pref_key); | |
| 302 | |
| 303 // Retrieves a list of preference keys that the specified extension | |
| 304 // intents to manage. | |
| 305 void GetExtensionControlledPrefKeys(const std::string& extension_id, | |
| 306 std::vector<std::string> *out) const; | |
| 307 | |
| 260 // The pref service specific to this set of extension prefs. | 308 // The pref service specific to this set of extension prefs. |
| 261 PrefService* prefs_; | 309 PrefService* prefs_; |
| 262 | 310 |
| 263 // Base extensions install directory. | 311 // Base extensions install directory. |
| 264 FilePath install_directory_; | 312 FilePath install_directory_; |
| 265 | 313 |
| 266 // The URLs of all of the toolstrips. | 314 // The URLs of all of the toolstrips. |
| 267 URLList shelf_order_; | 315 URLList shelf_order_; |
| 268 | 316 |
| 269 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 317 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 270 }; | 318 }; |
| 271 | 319 |
| 272 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 320 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| OLD | NEW |