| 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_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 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" | 16 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" |
| 17 #include "chrome/browser/extensions/extension_prefs_scope.h" | 17 #include "chrome/browser/extensions/extension_prefs_scope.h" |
| 18 #include "chrome/browser/extensions/extension_scoped_prefs.h" | 18 #include "chrome/browser/extensions/extension_scoped_prefs.h" |
| 19 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | 19 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "extensions/common/url_pattern_set.h" | 21 #include "extensions/common/url_pattern_set.h" |
| 22 #include "sync/api/string_ordinal.h" | 22 #include "sync/api/string_ordinal.h" |
| 23 | 23 |
| 24 class ExtensionPrefValueMap; | 24 class ExtensionPrefValueMap; |
| 25 class ExtensionSorting; | 25 class ExtensionSorting; |
| 26 class PrefService; | 26 class PrefService; |
| 27 class PrefServiceSyncable; |
| 27 | 28 |
| 28 namespace extensions { | 29 namespace extensions { |
| 29 class ExtensionPrefsUninstallExtension; | 30 class ExtensionPrefsUninstallExtension; |
| 30 class URLPatternSet; | 31 class URLPatternSet; |
| 31 struct ExtensionOmniboxSuggestion; | 32 struct ExtensionOmniboxSuggestion; |
| 32 | 33 |
| 33 // Class for managing global and per-extension preferences. | 34 // Class for managing global and per-extension preferences. |
| 34 // | 35 // |
| 35 // This class distinguishes the following kinds of preferences: | 36 // This class distinguishes the following kinds of preferences: |
| 36 // - global preferences: | 37 // - global preferences: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // By default, returns the current time (base::Time::Now()). | 86 // By default, returns the current time (base::Time::Now()). |
| 86 virtual base::Time GetCurrentTime() const; | 87 virtual base::Time GetCurrentTime() const; |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 DISALLOW_COPY_AND_ASSIGN(TimeProvider); | 90 DISALLOW_COPY_AND_ASSIGN(TimeProvider); |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 // Creates and initializes an ExtensionPrefs object. | 93 // Creates and initializes an ExtensionPrefs object. |
| 93 // Does not take ownership of |prefs| and |extension_pref_value_map|. | 94 // Does not take ownership of |prefs| and |extension_pref_value_map|. |
| 94 static scoped_ptr<ExtensionPrefs> Create( | 95 static scoped_ptr<ExtensionPrefs> Create( |
| 95 PrefService* prefs, | 96 PrefServiceSyncable* prefs, |
| 96 const FilePath& root_dir, | 97 const FilePath& root_dir, |
| 97 ExtensionPrefValueMap* extension_pref_value_map, | 98 ExtensionPrefValueMap* extension_pref_value_map, |
| 98 bool extensions_disabled); | 99 bool extensions_disabled); |
| 99 | 100 |
| 100 // A version of Create which allows injection of a custom base::Time provider. | 101 // A version of Create which allows injection of a custom base::Time provider. |
| 101 // Use this as needed for testing. | 102 // Use this as needed for testing. |
| 102 static scoped_ptr<ExtensionPrefs> Create( | 103 static scoped_ptr<ExtensionPrefs> Create( |
| 103 PrefService* prefs, | 104 PrefServiceSyncable* prefs, |
| 104 const FilePath& root_dir, | 105 const FilePath& root_dir, |
| 105 ExtensionPrefValueMap* extension_pref_value_map, | 106 ExtensionPrefValueMap* extension_pref_value_map, |
| 106 bool extensions_disabled, | 107 bool extensions_disabled, |
| 107 scoped_ptr<TimeProvider> time_provider); | 108 scoped_ptr<TimeProvider> time_provider); |
| 108 | 109 |
| 109 virtual ~ExtensionPrefs(); | 110 virtual ~ExtensionPrefs(); |
| 110 | 111 |
| 111 // Returns all installed extensions from extension preferences provided by | 112 // Returns all installed extensions from extension preferences provided by |
| 112 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs | 113 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs |
| 113 // access to the extension ID list before the ExtensionService is initialized. | 114 // access to the extension ID list before the ExtensionService is initialized. |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 bool IsFromBookmark(const std::string& extension_id) const; | 479 bool IsFromBookmark(const std::string& extension_id) const; |
| 479 | 480 |
| 480 // Returns true if the extension was installed as a default app. | 481 // Returns true if the extension was installed as a default app. |
| 481 bool WasInstalledByDefault(const std::string& extension_id) const; | 482 bool WasInstalledByDefault(const std::string& extension_id) const; |
| 482 | 483 |
| 483 // Helper method to acquire the installation time of an extension. | 484 // Helper method to acquire the installation time of an extension. |
| 484 // Returns base::Time() if the installation time could not be parsed or | 485 // Returns base::Time() if the installation time could not be parsed or |
| 485 // found. | 486 // found. |
| 486 base::Time GetInstallTime(const std::string& extension_id) const; | 487 base::Time GetInstallTime(const std::string& extension_id) const; |
| 487 | 488 |
| 488 static void RegisterUserPrefs(PrefService* prefs); | 489 static void RegisterUserPrefs(PrefServiceSyncable* prefs); |
| 489 | 490 |
| 490 ContentSettingsStore* content_settings_store() { | 491 ContentSettingsStore* content_settings_store() { |
| 491 return content_settings_store_.get(); | 492 return content_settings_store_.get(); |
| 492 } | 493 } |
| 493 | 494 |
| 494 // The underlying PrefService. | 495 // The underlying PrefService. |
| 495 PrefService* pref_service() const { return prefs_; } | 496 PrefServiceSyncable* pref_service() const { return prefs_; } |
| 496 | 497 |
| 497 // The underlying ExtensionSorting. | 498 // The underlying ExtensionSorting. |
| 498 ExtensionSorting* extension_sorting() const { | 499 ExtensionSorting* extension_sorting() const { |
| 499 return extension_sorting_.get(); | 500 return extension_sorting_.get(); |
| 500 } | 501 } |
| 501 | 502 |
| 502 // Describes the URLs that are able to install extensions. See | 503 // Describes the URLs that are able to install extensions. See |
| 503 // prefs::kExtensionAllowedInstallSites for more information. | 504 // prefs::kExtensionAllowedInstallSites for more information. |
| 504 URLPatternSet GetAllowedInstallSites(); | 505 URLPatternSet GetAllowedInstallSites(); |
| 505 | 506 |
| 506 // Schedules garbage collection of an extension's on-disk data on the next | 507 // Schedules garbage collection of an extension's on-disk data on the next |
| 507 // start of this ExtensionService. Applies only to extensions with isolated | 508 // start of this ExtensionService. Applies only to extensions with isolated |
| 508 // storage. | 509 // storage. |
| 509 void SetNeedsStorageGarbageCollection(bool value); | 510 void SetNeedsStorageGarbageCollection(bool value); |
| 510 bool NeedsStorageGarbageCollection(); | 511 bool NeedsStorageGarbageCollection(); |
| 511 | 512 |
| 512 // Used by ShellWindowGeometryCache to persist its cache. These methods | 513 // Used by ShellWindowGeometryCache to persist its cache. These methods |
| 513 // should not be called directly. | 514 // should not be called directly. |
| 514 const base::DictionaryValue* GetGeometryCache( | 515 const base::DictionaryValue* GetGeometryCache( |
| 515 const std::string& extension_id) const; | 516 const std::string& extension_id) const; |
| 516 void SetGeometryCache(const std::string& extension_id, | 517 void SetGeometryCache(const std::string& extension_id, |
| 517 scoped_ptr<base::DictionaryValue> cache); | 518 scoped_ptr<base::DictionaryValue> cache); |
| 518 | 519 |
| 519 private: | 520 private: |
| 520 friend class ExtensionPrefsBlacklistedExtensions; // Unit test. | 521 friend class ExtensionPrefsBlacklistedExtensions; // Unit test. |
| 521 friend class ExtensionPrefsUninstallExtension; // Unit test. | 522 friend class ExtensionPrefsUninstallExtension; // Unit test. |
| 522 | 523 |
| 523 // See the Create methods. | 524 // See the Create methods. |
| 524 ExtensionPrefs(PrefService* prefs, | 525 ExtensionPrefs(PrefServiceSyncable* prefs, |
| 525 const FilePath& root_dir, | 526 const FilePath& root_dir, |
| 526 ExtensionPrefValueMap* extension_pref_value_map, | 527 ExtensionPrefValueMap* extension_pref_value_map, |
| 527 scoped_ptr<TimeProvider> time_provider); | 528 scoped_ptr<TimeProvider> time_provider); |
| 528 | 529 |
| 529 // If |extensions_disabled| is true, extension controlled preferences and | 530 // If |extensions_disabled| is true, extension controlled preferences and |
| 530 // content settings do not become effective. | 531 // content settings do not become effective. |
| 531 void Init(bool extensions_disabled); | 532 void Init(bool extensions_disabled); |
| 532 | 533 |
| 533 // extensions::ContentSettingsStore::Observer methods: | 534 // extensions::ContentSettingsStore::Observer methods: |
| 534 virtual void OnContentSettingChanged(const std::string& extension_id, | 535 virtual void OnContentSettingChanged(const std::string& extension_id, |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 // |extension_dict| for an extension install. Also see | 635 // |extension_dict| for an extension install. Also see |
| 635 // PopulateExtensionInfoPrefs(). | 636 // PopulateExtensionInfoPrefs(). |
| 636 void FinishExtensionInfoPrefs( | 637 void FinishExtensionInfoPrefs( |
| 637 const std::string& extension_id, | 638 const std::string& extension_id, |
| 638 const base::Time install_time, | 639 const base::Time install_time, |
| 639 bool needs_sort_ordinal, | 640 bool needs_sort_ordinal, |
| 640 const syncer::StringOrdinal& suggested_page_ordinal, | 641 const syncer::StringOrdinal& suggested_page_ordinal, |
| 641 DictionaryValue* extension_dict); | 642 DictionaryValue* extension_dict); |
| 642 | 643 |
| 643 // The pref service specific to this set of extension prefs. Owned by profile. | 644 // The pref service specific to this set of extension prefs. Owned by profile. |
| 644 PrefService* prefs_; | 645 PrefServiceSyncable* prefs_; |
| 645 | 646 |
| 646 // Base extensions install directory. | 647 // Base extensions install directory. |
| 647 FilePath install_directory_; | 648 FilePath install_directory_; |
| 648 | 649 |
| 649 // Weak pointer, owned by Profile. | 650 // Weak pointer, owned by Profile. |
| 650 ExtensionPrefValueMap* extension_pref_value_map_; | 651 ExtensionPrefValueMap* extension_pref_value_map_; |
| 651 | 652 |
| 652 // Contains all the logic for handling the order for various extension | 653 // Contains all the logic for handling the order for various extension |
| 653 // properties. | 654 // properties. |
| 654 scoped_ptr<ExtensionSorting> extension_sorting_; | 655 scoped_ptr<ExtensionSorting> extension_sorting_; |
| 655 | 656 |
| 656 scoped_refptr<ContentSettingsStore> content_settings_store_; | 657 scoped_refptr<ContentSettingsStore> content_settings_store_; |
| 657 | 658 |
| 658 scoped_ptr<TimeProvider> time_provider_; | 659 scoped_ptr<TimeProvider> time_provider_; |
| 659 | 660 |
| 660 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 661 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 661 }; | 662 }; |
| 662 | 663 |
| 663 } // namespace extensions | 664 } // namespace extensions |
| 664 | 665 |
| 665 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 666 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
| OLD | NEW |