| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ | 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ |
| 6 #define EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ | 6 #define EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 class BrowserContext; | 31 class BrowserContext; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace user_prefs { | 34 namespace user_prefs { |
| 35 class PrefRegistrySyncable; | 35 class PrefRegistrySyncable; |
| 36 } | 36 } |
| 37 | 37 |
| 38 namespace extensions { | 38 namespace extensions { |
| 39 | 39 |
| 40 class AppSorting; | 40 class AppSorting; |
| 41 class ContentSettingsStore; | |
| 42 class ExtensionPrefsUninstallExtension; | 41 class ExtensionPrefsUninstallExtension; |
| 43 class URLPatternSet; | 42 class URLPatternSet; |
| 44 | 43 |
| 45 // Class for managing global and per-extension preferences. | 44 // Class for managing global and per-extension preferences. |
| 46 // | 45 // |
| 47 // This class distinguishes the following kinds of preferences: | 46 // This class distinguishes the following kinds of preferences: |
| 48 // - global preferences: | 47 // - global preferences: |
| 49 // internal state for the extension system in general, not associated | 48 // internal state for the extension system in general, not associated |
| 50 // with an individual extension, such as lastUpdateTime. | 49 // with an individual extension, such as lastUpdateTime. |
| 51 // - per-extension preferences: | 50 // - per-extension preferences: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY> | 120 typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY> |
| 122 ScopedDictionaryUpdate; | 121 ScopedDictionaryUpdate; |
| 123 typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST> | 122 typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST> |
| 124 ScopedListUpdate; | 123 ScopedListUpdate; |
| 125 | 124 |
| 126 class Observer { | 125 class Observer { |
| 127 public: | 126 public: |
| 128 // Called when the reasons for an extension being disabled have changed. | 127 // Called when the reasons for an extension being disabled have changed. |
| 129 virtual void OnExtensionDisableReasonsChanged( | 128 virtual void OnExtensionDisableReasonsChanged( |
| 130 const std::string& extension_id, | 129 const std::string& extension_id, |
| 131 int disabled_reasons) = 0; | 130 int disabled_reasons) {} |
| 131 |
| 132 // Called when an extension is registered with ExtensionPrefs. |
| 133 virtual void OnExtensionRegistered(const std::string& extension_id, |
| 134 const base::Time& install_time, |
| 135 bool is_enabled) {} |
| 136 |
| 137 // Called when an extension's prefs have been loaded. |
| 138 virtual void OnExtensionPrefsLoaded(const std::string& extension_id) {} |
| 139 |
| 140 // Called when an extension's prefs are deleted. |
| 141 virtual void OnExtensionPrefsDeleted(const std::string& extension_id) {} |
| 142 |
| 143 // Called when an extension's enabled state pref is changed. |
| 144 virtual void OnExtensionStateChanged(const std::string& extension_id, |
| 145 bool state) {} |
| 132 }; | 146 }; |
| 133 | 147 |
| 134 // Creates and initializes an ExtensionPrefs object. | 148 // Creates an ExtensionPrefs object. |
| 135 // Does not take ownership of |prefs| and |extension_pref_value_map|. | 149 // Does not take ownership of |prefs| or |extension_pref_value_map|. |
| 136 // If |extensions_disabled| is true, extension controlled preferences and | 150 // If |extensions_disabled| is true, extension controlled preferences and |
| 137 // content settings do not become effective. | 151 // content settings do not become effective. Observers should be included |
| 138 static ExtensionPrefs* Create( | 152 // in |early_observers| if they need to observe events which occur during |
| 139 PrefService* prefs, | 153 // initialization of the ExtensionPrefs object. |
| 140 const base::FilePath& root_dir, | 154 static ExtensionPrefs* Create(PrefService* prefs, |
| 141 ExtensionPrefValueMap* extension_pref_value_map, | 155 const base::FilePath& root_dir, |
| 142 scoped_ptr<AppSorting> app_sorting, | 156 ExtensionPrefValueMap* extension_pref_value_map, |
| 143 bool extensions_disabled); | 157 scoped_ptr<AppSorting> app_sorting, |
| 158 bool extensions_disabled, |
| 159 const std::vector<Observer*>& early_observers); |
| 144 | 160 |
| 145 // A version of Create which allows injection of a custom base::Time provider. | 161 // A version of Create which allows injection of a custom base::Time provider. |
| 146 // Use this as needed for testing. | 162 // Use this as needed for testing. |
| 147 static ExtensionPrefs* Create( | 163 static ExtensionPrefs* Create(PrefService* prefs, |
| 148 PrefService* prefs, | 164 const base::FilePath& root_dir, |
| 149 const base::FilePath& root_dir, | 165 ExtensionPrefValueMap* extension_pref_value_map, |
| 150 ExtensionPrefValueMap* extension_pref_value_map, | 166 scoped_ptr<AppSorting> app_sorting, |
| 151 scoped_ptr<AppSorting> app_sorting, | 167 bool extensions_disabled, |
| 152 bool extensions_disabled, | 168 const std::vector<Observer*>& early_observers, |
| 153 scoped_ptr<TimeProvider> time_provider); | 169 scoped_ptr<TimeProvider> time_provider); |
| 154 | 170 |
| 155 virtual ~ExtensionPrefs(); | 171 virtual ~ExtensionPrefs(); |
| 156 | 172 |
| 157 // Convenience function to get the ExtensionPrefs for a BrowserContext. | 173 // Convenience function to get the ExtensionPrefs for a BrowserContext. |
| 158 static ExtensionPrefs* Get(content::BrowserContext* context); | 174 static ExtensionPrefs* Get(content::BrowserContext* context); |
| 159 | 175 |
| 160 // Returns all installed extensions from extension preferences provided by | 176 // Returns all installed extensions from extension preferences provided by |
| 161 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs | 177 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs |
| 162 // access to the extension ID list before the ExtensionService is initialized. | 178 // access to the extension ID list before the ExtensionService is initialized. |
| 163 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service); | 179 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 524 |
| 509 // Gets/sets the last launch time of an extension. | 525 // Gets/sets the last launch time of an extension. |
| 510 base::Time GetLastLaunchTime(const std::string& extension_id) const; | 526 base::Time GetLastLaunchTime(const std::string& extension_id) const; |
| 511 void SetLastLaunchTime(const std::string& extension_id, | 527 void SetLastLaunchTime(const std::string& extension_id, |
| 512 const base::Time& time); | 528 const base::Time& time); |
| 513 | 529 |
| 514 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 530 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 515 | 531 |
| 516 bool extensions_disabled() const { return extensions_disabled_; } | 532 bool extensions_disabled() const { return extensions_disabled_; } |
| 517 | 533 |
| 518 ContentSettingsStore* content_settings_store() { | |
| 519 return content_settings_store_.get(); | |
| 520 } | |
| 521 | |
| 522 // The underlying PrefService. | 534 // The underlying PrefService. |
| 523 PrefService* pref_service() const { return prefs_; } | 535 PrefService* pref_service() const { return prefs_; } |
| 524 | 536 |
| 525 // The underlying AppSorting. | 537 // The underlying AppSorting. |
| 526 AppSorting* app_sorting() const { return app_sorting_.get(); } | 538 AppSorting* app_sorting() const { return app_sorting_.get(); } |
| 527 | 539 |
| 528 // Describes the URLs that are able to install extensions. See | 540 // Describes the URLs that are able to install extensions. See |
| 529 // pref_names::kAllowedInstallSites for more information. | 541 // pref_names::kAllowedInstallSites for more information. |
| 530 URLPatternSet GetAllowedInstallSites(); | 542 URLPatternSet GetAllowedInstallSites(); |
| 531 | 543 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 561 DISABLE_REASON_REMOVE, | 573 DISABLE_REASON_REMOVE, |
| 562 DISABLE_REASON_CLEAR | 574 DISABLE_REASON_CLEAR |
| 563 }; | 575 }; |
| 564 | 576 |
| 565 // See the Create methods. | 577 // See the Create methods. |
| 566 ExtensionPrefs(PrefService* prefs, | 578 ExtensionPrefs(PrefService* prefs, |
| 567 const base::FilePath& root_dir, | 579 const base::FilePath& root_dir, |
| 568 ExtensionPrefValueMap* extension_pref_value_map, | 580 ExtensionPrefValueMap* extension_pref_value_map, |
| 569 scoped_ptr<AppSorting> app_sorting, | 581 scoped_ptr<AppSorting> app_sorting, |
| 570 scoped_ptr<TimeProvider> time_provider, | 582 scoped_ptr<TimeProvider> time_provider, |
| 571 bool extensions_disabled); | 583 bool extensions_disabled, |
| 584 const std::vector<Observer*>& early_observers); |
| 572 | 585 |
| 573 // Converts absolute paths in the pref to paths relative to the | 586 // Converts absolute paths in the pref to paths relative to the |
| 574 // install_directory_. | 587 // install_directory_. |
| 575 void MakePathsRelative(); | 588 void MakePathsRelative(); |
| 576 | 589 |
| 577 // Converts internal relative paths to be absolute. Used for export to | 590 // Converts internal relative paths to be absolute. Used for export to |
| 578 // consumers who expect full paths. | 591 // consumers who expect full paths. |
| 579 void MakePathsAbsolute(base::DictionaryValue* dict); | 592 void MakePathsAbsolute(base::DictionaryValue* dict); |
| 580 | 593 |
| 581 // Helper function used by GetInstalledExtensionInfo() and | 594 // Helper function used by GetInstalledExtensionInfo() and |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 // by a newly installed extension. Work is broken up between this | 675 // by a newly installed extension. Work is broken up between this |
| 663 // function and FinishExtensionInfoPrefs() to accomodate delayed | 676 // function and FinishExtensionInfoPrefs() to accomodate delayed |
| 664 // installations. | 677 // installations. |
| 665 void PopulateExtensionInfoPrefs(const Extension* extension, | 678 void PopulateExtensionInfoPrefs(const Extension* extension, |
| 666 const base::Time install_time, | 679 const base::Time install_time, |
| 667 Extension::State initial_state, | 680 Extension::State initial_state, |
| 668 bool blacklisted_for_malware, | 681 bool blacklisted_for_malware, |
| 669 const std::string& install_parameter, | 682 const std::string& install_parameter, |
| 670 base::DictionaryValue* extension_dict); | 683 base::DictionaryValue* extension_dict); |
| 671 | 684 |
| 685 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map); |
| 686 |
| 672 // Helper function to complete initialization of the values in | 687 // Helper function to complete initialization of the values in |
| 673 // |extension_dict| for an extension install. Also see | 688 // |extension_dict| for an extension install. Also see |
| 674 // PopulateExtensionInfoPrefs(). | 689 // PopulateExtensionInfoPrefs(). |
| 675 void FinishExtensionInfoPrefs( | 690 void FinishExtensionInfoPrefs( |
| 676 const std::string& extension_id, | 691 const std::string& extension_id, |
| 677 const base::Time install_time, | 692 const base::Time install_time, |
| 678 bool needs_sort_ordinal, | 693 bool needs_sort_ordinal, |
| 679 const syncer::StringOrdinal& suggested_page_ordinal, | 694 const syncer::StringOrdinal& suggested_page_ordinal, |
| 680 base::DictionaryValue* extension_dict); | 695 base::DictionaryValue* extension_dict); |
| 681 | 696 |
| 682 // The pref service specific to this set of extension prefs. Owned by the | 697 // The pref service specific to this set of extension prefs. Owned by the |
| 683 // BrowserContext. | 698 // BrowserContext. |
| 684 PrefService* prefs_; | 699 PrefService* prefs_; |
| 685 | 700 |
| 686 // Base extensions install directory. | 701 // Base extensions install directory. |
| 687 base::FilePath install_directory_; | 702 base::FilePath install_directory_; |
| 688 | 703 |
| 689 // Weak pointer, owned by BrowserContext. | 704 // Weak pointer, owned by BrowserContext. |
| 690 ExtensionPrefValueMap* extension_pref_value_map_; | 705 ExtensionPrefValueMap* extension_pref_value_map_; |
| 691 | 706 |
| 692 // Contains all the logic for handling the order for various extension | 707 // Contains all the logic for handling the order for various extension |
| 693 // properties. | 708 // properties. |
| 694 scoped_ptr<AppSorting> app_sorting_; | 709 scoped_ptr<AppSorting> app_sorting_; |
| 695 | 710 |
| 696 scoped_refptr<ContentSettingsStore> content_settings_store_; | |
| 697 | |
| 698 scoped_ptr<TimeProvider> time_provider_; | 711 scoped_ptr<TimeProvider> time_provider_; |
| 699 | 712 |
| 700 bool extensions_disabled_; | 713 bool extensions_disabled_; |
| 701 | 714 |
| 702 ObserverList<Observer> observer_list_; | 715 ObserverList<Observer> observer_list_; |
| 703 | 716 |
| 704 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 717 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
| 705 }; | 718 }; |
| 706 | 719 |
| 707 } // namespace extensions | 720 } // namespace extensions |
| 708 | 721 |
| 709 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ | 722 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ |
| OLD | NEW |