OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 ExtensionPrefStore; | 19 class ExtensionPrefValueMap; |
20 | 20 |
21 // Class for managing global and per-extension preferences. | 21 // Class for managing global and per-extension preferences. |
22 // | 22 // |
23 // This class distinguishes the following kinds of preferences: | 23 // This class distinguishes the following kinds of preferences: |
24 // - global preferences: | 24 // - global preferences: |
25 // internal state for the extension system in general, not associated | 25 // internal state for the extension system in general, not associated |
26 // with an individual extension, such as lastUpdateTime. | 26 // with an individual extension, such as lastUpdateTime. |
27 // - per-extension preferences: | 27 // - per-extension preferences: |
28 // meta-preferences describing properties of the extension like | 28 // meta-preferences describing properties of the extension like |
29 // installation time, whether the extension is enabled, etc. | 29 // installation time, whether the extension is enabled, etc. |
(...skipping 22 matching lines...) Expand all Loading... |
52 // application. | 52 // application. |
53 // Do not remove items or re-order this enum as it is used in preferences | 53 // Do not remove items or re-order this enum as it is used in preferences |
54 // and histograms. | 54 // and histograms. |
55 enum LaunchType { | 55 enum LaunchType { |
56 LAUNCH_PINNED, | 56 LAUNCH_PINNED, |
57 LAUNCH_REGULAR, | 57 LAUNCH_REGULAR, |
58 LAUNCH_FULLSCREEN, | 58 LAUNCH_FULLSCREEN, |
59 LAUNCH_WINDOW | 59 LAUNCH_WINDOW |
60 }; | 60 }; |
61 | 61 |
| 62 // Does not assume ownership of |prefs| and |incognito_prefs|. |
62 explicit ExtensionPrefs(PrefService* prefs, | 63 explicit ExtensionPrefs(PrefService* prefs, |
63 const FilePath& root_dir, | 64 const FilePath& root_dir, |
64 ExtensionPrefStore* extension_pref_store); | 65 ExtensionPrefValueMap* extension_pref_value_map); |
65 ~ExtensionPrefs(); | 66 ~ExtensionPrefs(); |
66 | 67 |
67 // Returns a copy of the Extensions prefs. | 68 // Returns a copy of the Extensions prefs. |
68 // TODO(erikkay) Remove this so that external consumers don't need to be | 69 // TODO(erikkay) Remove this so that external consumers don't need to be |
69 // aware of the internal structure of the preferences. | 70 // aware of the internal structure of the preferences. |
70 DictionaryValue* CopyCurrentExtensions(); | 71 DictionaryValue* CopyCurrentExtensions(); |
71 | 72 |
72 // Returns true if the specified extension has an entry in prefs | 73 // Returns true if the specified extension has an entry in prefs |
73 // and its killbit is on. | 74 // and its killbit is on. |
74 bool IsExtensionKilled(const std::string& id); | 75 bool IsExtensionKilled(const std::string& id); |
(...skipping 20 matching lines...) Expand all Loading... |
95 void OnExtensionUninstalled(const std::string& extension_id, | 96 void OnExtensionUninstalled(const std::string& extension_id, |
96 const Extension::Location& location, | 97 const Extension::Location& location, |
97 bool external_uninstall); | 98 bool external_uninstall); |
98 | 99 |
99 // Returns the state (enabled/disabled) of the given extension. | 100 // Returns the state (enabled/disabled) of the given extension. |
100 Extension::State GetExtensionState(const std::string& extension_id) const; | 101 Extension::State GetExtensionState(const std::string& extension_id) const; |
101 | 102 |
102 // Called to change the extension's state when it is enabled/disabled. | 103 // Called to change the extension's state when it is enabled/disabled. |
103 void SetExtensionState(const Extension* extension, Extension::State); | 104 void SetExtensionState(const Extension* extension, Extension::State); |
104 | 105 |
105 // Returns all installed and enabled extensions | 106 // Returns all installed extensions |
106 void GetEnabledExtensions(ExtensionIdSet* out) const; | 107 void GetExtensions(ExtensionIdSet* out) const; |
107 | 108 |
108 // Getter and setter for browser action visibility. | 109 // Getter and setter for browser action visibility. |
109 bool GetBrowserActionVisibility(const Extension* extension); | 110 bool GetBrowserActionVisibility(const Extension* extension); |
110 void SetBrowserActionVisibility(const Extension* extension, bool visible); | 111 void SetBrowserActionVisibility(const Extension* extension, bool visible); |
111 | 112 |
112 // Did the extension ask to escalate its permission during an upgrade? | 113 // Did the extension ask to escalate its permission during an upgrade? |
113 bool DidExtensionEscalatePermissions(const std::string& id); | 114 bool DidExtensionEscalatePermissions(const std::string& id); |
114 | 115 |
115 // If |did_escalate| is true, the preferences for |extension| will be set to | 116 // If |did_escalate| is true, the preferences for |extension| will be set to |
116 // require the install warning when the user tries to enable. | 117 // require the install warning when the user tries to enable. |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // of the extension is available. | 260 // of the extension is available. |
260 void SetUpdateUrlData(const std::string& extension_id, | 261 void SetUpdateUrlData(const std::string& extension_id, |
261 const std::string& data); | 262 const std::string& data); |
262 std::string GetUpdateUrlData(const std::string& extension_id); | 263 std::string GetUpdateUrlData(const std::string& extension_id); |
263 | 264 |
264 // Sets a preference value that is controlled by the extension. In other | 265 // Sets a preference value that is controlled by the extension. In other |
265 // words, this is not a pref value *about* the extension but something | 266 // words, this is not a pref value *about* the extension but something |
266 // global the extension wants to override. | 267 // global the extension wants to override. |
267 void SetExtensionControlledPref(const std::string& extension_id, | 268 void SetExtensionControlledPref(const std::string& extension_id, |
268 const std::string& pref_key, | 269 const std::string& pref_key, |
| 270 bool incognito, |
269 Value* value); | 271 Value* value); |
270 | 272 |
271 static void RegisterUserPrefs(PrefService* prefs); | 273 static void RegisterUserPrefs(PrefService* prefs); |
272 | 274 |
273 // The underlying PrefService. | 275 // The underlying PrefService. |
274 PrefService* pref_service() const { return prefs_; } | 276 PrefService* pref_service() const { return prefs_; } |
275 | 277 |
276 protected: | 278 protected: |
277 // For unit testing. Enables injecting an artificial clock that is used | 279 // For unit testing. Enables injecting an artificial clock that is used |
278 // to query the current time, when an extension is installed. | 280 // to query the current time, when an extension is installed. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 const std::string& pref_key, | 333 const std::string& pref_key, |
332 const std::set<std::string>& added_values); | 334 const std::set<std::string>& added_values); |
333 | 335 |
334 // Ensures and returns a mutable dictionary for extension |id|'s prefs. | 336 // Ensures and returns a mutable dictionary for extension |id|'s prefs. |
335 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); | 337 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); |
336 | 338 |
337 // Same as above, but returns NULL if it doesn't exist. | 339 // Same as above, but returns NULL if it doesn't exist. |
338 DictionaryValue* GetExtensionPref(const std::string& id) const; | 340 DictionaryValue* GetExtensionPref(const std::string& id) const; |
339 | 341 |
340 // Returns the dictionary of preferences controlled by the specified extension | 342 // Returns the dictionary of preferences controlled by the specified extension |
341 // or NULL if unknown. All entries in the dictionary contain non-expanded | 343 // or creates a new one. All entries in the dictionary contain non-expanded |
342 // paths. | 344 // paths. |
343 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; | 345 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const; |
344 | 346 |
345 // Serializes the data and schedules a persistent save via the |PrefService|. | 347 // Serializes the data and schedules a persistent save via the |PrefService|. |
346 // Additionally fires a PREF_CHANGED notification with the top-level | 348 // Additionally fires a PREF_CHANGED notification with the top-level |
347 // |kExtensionsPref| path set. | 349 // |kExtensionsPref| path set. |
348 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. | 350 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. |
349 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to | 351 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to |
350 // the mutable extension dictionary. | 352 // the mutable extension dictionary. |
351 void SavePrefsAndNotify(); | 353 void SavePrefsAndNotify(); |
(...skipping 13 matching lines...) Expand all Loading... |
365 base::Time GetInstallTime(const std::string& extension_id) const; | 367 base::Time GetInstallTime(const std::string& extension_id) const; |
366 | 368 |
367 // Fix missing preference entries in the extensions that are were introduced | 369 // Fix missing preference entries in the extensions that are were introduced |
368 // in a later Chrome version. | 370 // in a later Chrome version. |
369 void FixMissingPrefs(const ExtensionIdSet& extension_ids); | 371 void FixMissingPrefs(const ExtensionIdSet& extension_ids); |
370 | 372 |
371 // Installs the persistent extension preferences into |prefs_|'s extension | 373 // Installs the persistent extension preferences into |prefs_|'s extension |
372 // pref store. | 374 // pref store. |
373 void InitPrefStore(); | 375 void InitPrefStore(); |
374 | 376 |
375 // Returns the extension controlled preference value of the extension that was | 377 // The pref service specific to this set of extension prefs. Owned by profile. |
376 // installed most recently. | |
377 const Value* GetWinningExtensionControlledPrefValue( | |
378 const std::string& key) const; | |
379 | |
380 // Executes UpdatePrefStore for all |pref_keys|. | |
381 void UpdatePrefStore(const PrefKeySet& pref_keys); | |
382 | |
383 // Finds the most recently installed extension that defines a preference | |
384 // for |pref_key|, then stores its value in the PrefValueStore's extension | |
385 // pref store and sends notifications to observers in case the value changed. | |
386 void UpdatePrefStore(const std::string& pref_key); | |
387 | |
388 // Retrieves a list of preference keys that the specified extension | |
389 // intends to manage. Keys are always appended, |out| is not cleared. | |
390 void GetExtensionControlledPrefKeys(const std::string& extension_id, | |
391 PrefKeySet *out) const; | |
392 | |
393 // The pref service specific to this set of extension prefs. | |
394 PrefService* prefs_; | 378 PrefService* prefs_; |
395 | 379 |
396 // Base extensions install directory. | 380 // Base extensions install directory. |
397 FilePath install_directory_; | 381 FilePath install_directory_; |
398 | 382 |
399 // Used to manipulate extension preferences. | 383 // Weak pointer, owned by Profile. |
400 ExtensionPrefStore* pref_store_; | 384 ExtensionPrefValueMap* extension_pref_value_map_; |
401 | 385 |
402 // The URLs of all of the toolstrips. | 386 // The URLs of all of the toolstrips. |
403 URLList shelf_order_; | 387 URLList shelf_order_; |
404 | 388 |
405 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 389 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
406 }; | 390 }; |
407 | 391 |
408 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 392 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
OLD | NEW |