Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: extensions/browser/extension_prefs.h

Issue 220353002: Remove //chrome dependency from ExtensionPrefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: don't ref ContentSettingsStore if !ENABLE_EXTENSIONS Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_browser_extensions.gypi ('k') | extensions/browser/extension_prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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; 41 class ExtensionPrefsObserver;
42 class ExtensionPrefsUninstallExtension; 42 class ExtensionPrefsUninstallExtension;
43 class URLPatternSet; 43 class URLPatternSet;
44 44
45 // Class for managing global and per-extension preferences. 45 // Class for managing global and per-extension preferences.
46 // 46 //
47 // This class distinguishes the following kinds of preferences: 47 // This class distinguishes the following kinds of preferences:
48 // - global preferences: 48 // - global preferences:
49 // internal state for the extension system in general, not associated 49 // internal state for the extension system in general, not associated
50 // with an individual extension, such as lastUpdateTime. 50 // with an individual extension, such as lastUpdateTime.
51 // - per-extension preferences: 51 // - per-extension preferences:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 116
117 DictionaryPrefUpdate update_; 117 DictionaryPrefUpdate update_;
118 const std::string extension_id_; 118 const std::string extension_id_;
119 const std::string key_; 119 const std::string key_;
120 }; 120 };
121 typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY> 121 typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY>
122 ScopedDictionaryUpdate; 122 ScopedDictionaryUpdate;
123 typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST> 123 typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST>
124 ScopedListUpdate; 124 ScopedListUpdate;
125 125
126 class Observer { 126 // Creates an ExtensionPrefs object.
127 public: 127 // Does not take ownership of |prefs| or |extension_pref_value_map|.
128 // Called when the reasons for an extension being disabled have changed.
129 virtual void OnExtensionDisableReasonsChanged(
130 const std::string& extension_id,
131 int disabled_reasons) = 0;
132 };
133
134 // Creates and initializes an ExtensionPrefs object.
135 // Does not take ownership of |prefs| and |extension_pref_value_map|.
136 // If |extensions_disabled| is true, extension controlled preferences and 128 // If |extensions_disabled| is true, extension controlled preferences and
137 // content settings do not become effective. 129 // content settings do not become effective. ExtensionPrefsObservers should be
130 // included in |early_observers| if they need to observe events which occur
131 // during initialization of the ExtensionPrefs object.
138 static ExtensionPrefs* Create( 132 static ExtensionPrefs* Create(
139 PrefService* prefs, 133 PrefService* prefs,
140 const base::FilePath& root_dir, 134 const base::FilePath& root_dir,
141 ExtensionPrefValueMap* extension_pref_value_map, 135 ExtensionPrefValueMap* extension_pref_value_map,
142 scoped_ptr<AppSorting> app_sorting, 136 scoped_ptr<AppSorting> app_sorting,
143 bool extensions_disabled); 137 bool extensions_disabled,
138 const std::vector<ExtensionPrefsObserver*>& early_observers);
144 139
145 // A version of Create which allows injection of a custom base::Time provider. 140 // A version of Create which allows injection of a custom base::Time provider.
146 // Use this as needed for testing. 141 // Use this as needed for testing.
147 static ExtensionPrefs* Create( 142 static ExtensionPrefs* Create(
148 PrefService* prefs, 143 PrefService* prefs,
149 const base::FilePath& root_dir, 144 const base::FilePath& root_dir,
150 ExtensionPrefValueMap* extension_pref_value_map, 145 ExtensionPrefValueMap* extension_pref_value_map,
151 scoped_ptr<AppSorting> app_sorting, 146 scoped_ptr<AppSorting> app_sorting,
152 bool extensions_disabled, 147 bool extensions_disabled,
148 const std::vector<ExtensionPrefsObserver*>& early_observers,
153 scoped_ptr<TimeProvider> time_provider); 149 scoped_ptr<TimeProvider> time_provider);
154 150
155 virtual ~ExtensionPrefs(); 151 virtual ~ExtensionPrefs();
156 152
157 // Convenience function to get the ExtensionPrefs for a BrowserContext. 153 // Convenience function to get the ExtensionPrefs for a BrowserContext.
158 static ExtensionPrefs* Get(content::BrowserContext* context); 154 static ExtensionPrefs* Get(content::BrowserContext* context);
159 155
160 // Returns all installed extensions from extension preferences provided by 156 // Returns all installed extensions from extension preferences provided by
161 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs 157 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
162 // access to the extension ID list before the ExtensionService is initialized. 158 // access to the extension ID list before the ExtensionService is initialized.
163 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service); 159 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service);
164 160
165 // Add or remove an observer from the ExtensionPrefs. 161 // Add or remove an observer from the ExtensionPrefs.
166 void AddObserver(Observer* observer); 162 void AddObserver(ExtensionPrefsObserver* observer);
167 void RemoveObserver(Observer* observer); 163 void RemoveObserver(ExtensionPrefsObserver* observer);
168 164
169 // Returns true if the specified external extension was uninstalled by the 165 // Returns true if the specified external extension was uninstalled by the
170 // user. 166 // user.
171 bool IsExternalExtensionUninstalled(const std::string& id) const; 167 bool IsExternalExtensionUninstalled(const std::string& id) const;
172 168
173 // Checks whether |extension_id| is disabled. If there's no state pref for 169 // Checks whether |extension_id| is disabled. If there's no state pref for
174 // the extension, this will return false. Generally you should use 170 // the extension, this will return false. Generally you should use
175 // ExtensionService::IsExtensionEnabled instead. 171 // ExtensionService::IsExtensionEnabled instead.
176 bool IsExtensionDisabled(const std::string& id) const; 172 bool IsExtensionDisabled(const std::string& id) const;
177 173
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 504
509 // Gets/sets the last launch time of an extension. 505 // Gets/sets the last launch time of an extension.
510 base::Time GetLastLaunchTime(const std::string& extension_id) const; 506 base::Time GetLastLaunchTime(const std::string& extension_id) const;
511 void SetLastLaunchTime(const std::string& extension_id, 507 void SetLastLaunchTime(const std::string& extension_id,
512 const base::Time& time); 508 const base::Time& time);
513 509
514 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 510 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
515 511
516 bool extensions_disabled() const { return extensions_disabled_; } 512 bool extensions_disabled() const { return extensions_disabled_; }
517 513
518 ContentSettingsStore* content_settings_store() {
519 return content_settings_store_.get();
520 }
521
522 // The underlying PrefService. 514 // The underlying PrefService.
523 PrefService* pref_service() const { return prefs_; } 515 PrefService* pref_service() const { return prefs_; }
524 516
525 // The underlying AppSorting. 517 // The underlying AppSorting.
526 AppSorting* app_sorting() const { return app_sorting_.get(); } 518 AppSorting* app_sorting() const { return app_sorting_.get(); }
527 519
528 // Describes the URLs that are able to install extensions. See 520 // Describes the URLs that are able to install extensions. See
529 // pref_names::kAllowedInstallSites for more information. 521 // pref_names::kAllowedInstallSites for more information.
530 URLPatternSet GetAllowedInstallSites(); 522 URLPatternSet GetAllowedInstallSites();
531 523
(...skipping 29 matching lines...) Expand all
561 DISABLE_REASON_REMOVE, 553 DISABLE_REASON_REMOVE,
562 DISABLE_REASON_CLEAR 554 DISABLE_REASON_CLEAR
563 }; 555 };
564 556
565 // See the Create methods. 557 // See the Create methods.
566 ExtensionPrefs(PrefService* prefs, 558 ExtensionPrefs(PrefService* prefs,
567 const base::FilePath& root_dir, 559 const base::FilePath& root_dir,
568 ExtensionPrefValueMap* extension_pref_value_map, 560 ExtensionPrefValueMap* extension_pref_value_map,
569 scoped_ptr<AppSorting> app_sorting, 561 scoped_ptr<AppSorting> app_sorting,
570 scoped_ptr<TimeProvider> time_provider, 562 scoped_ptr<TimeProvider> time_provider,
571 bool extensions_disabled); 563 bool extensions_disabled,
564 const std::vector<ExtensionPrefsObserver*>& early_observers);
572 565
573 // Converts absolute paths in the pref to paths relative to the 566 // Converts absolute paths in the pref to paths relative to the
574 // install_directory_. 567 // install_directory_.
575 void MakePathsRelative(); 568 void MakePathsRelative();
576 569
577 // Converts internal relative paths to be absolute. Used for export to 570 // Converts internal relative paths to be absolute. Used for export to
578 // consumers who expect full paths. 571 // consumers who expect full paths.
579 void MakePathsAbsolute(base::DictionaryValue* dict); 572 void MakePathsAbsolute(base::DictionaryValue* dict);
580 573
581 // Helper function used by GetInstalledExtensionInfo() and 574 // Helper function used by GetInstalledExtensionInfo() and
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 // by a newly installed extension. Work is broken up between this 655 // by a newly installed extension. Work is broken up between this
663 // function and FinishExtensionInfoPrefs() to accomodate delayed 656 // function and FinishExtensionInfoPrefs() to accomodate delayed
664 // installations. 657 // installations.
665 void PopulateExtensionInfoPrefs(const Extension* extension, 658 void PopulateExtensionInfoPrefs(const Extension* extension,
666 const base::Time install_time, 659 const base::Time install_time,
667 Extension::State initial_state, 660 Extension::State initial_state,
668 bool blacklisted_for_malware, 661 bool blacklisted_for_malware,
669 const std::string& install_parameter, 662 const std::string& install_parameter,
670 base::DictionaryValue* extension_dict); 663 base::DictionaryValue* extension_dict);
671 664
665 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
666
672 // Helper function to complete initialization of the values in 667 // Helper function to complete initialization of the values in
673 // |extension_dict| for an extension install. Also see 668 // |extension_dict| for an extension install. Also see
674 // PopulateExtensionInfoPrefs(). 669 // PopulateExtensionInfoPrefs().
675 void FinishExtensionInfoPrefs( 670 void FinishExtensionInfoPrefs(
676 const std::string& extension_id, 671 const std::string& extension_id,
677 const base::Time install_time, 672 const base::Time install_time,
678 bool needs_sort_ordinal, 673 bool needs_sort_ordinal,
679 const syncer::StringOrdinal& suggested_page_ordinal, 674 const syncer::StringOrdinal& suggested_page_ordinal,
680 base::DictionaryValue* extension_dict); 675 base::DictionaryValue* extension_dict);
681 676
682 // The pref service specific to this set of extension prefs. Owned by the 677 // The pref service specific to this set of extension prefs. Owned by the
683 // BrowserContext. 678 // BrowserContext.
684 PrefService* prefs_; 679 PrefService* prefs_;
685 680
686 // Base extensions install directory. 681 // Base extensions install directory.
687 base::FilePath install_directory_; 682 base::FilePath install_directory_;
688 683
689 // Weak pointer, owned by BrowserContext. 684 // Weak pointer, owned by BrowserContext.
690 ExtensionPrefValueMap* extension_pref_value_map_; 685 ExtensionPrefValueMap* extension_pref_value_map_;
691 686
692 // Contains all the logic for handling the order for various extension 687 // Contains all the logic for handling the order for various extension
693 // properties. 688 // properties.
694 scoped_ptr<AppSorting> app_sorting_; 689 scoped_ptr<AppSorting> app_sorting_;
695 690
696 scoped_refptr<ContentSettingsStore> content_settings_store_;
697
698 scoped_ptr<TimeProvider> time_provider_; 691 scoped_ptr<TimeProvider> time_provider_;
699 692
700 bool extensions_disabled_; 693 bool extensions_disabled_;
701 694
702 ObserverList<Observer> observer_list_; 695 ObserverList<ExtensionPrefsObserver> observer_list_;
703 696
704 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); 697 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
705 }; 698 };
706 699
707 } // namespace extensions 700 } // namespace extensions
708 701
709 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ 702 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
OLDNEW
« no previous file with comments | « chrome/chrome_browser_extensions.gypi ('k') | extensions/browser/extension_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698