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

Side by Side Diff: chrome/browser/extensions/extension_management.h

Issue 602803002: Refactor ExtensionManagement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-fix
Patch Set: fix Created 6 years, 2 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
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 CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string>
10 #include <vector>
11 9
12 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
15 #include "base/observer_list.h" 14 #include "base/observer_list.h"
16 #include "base/prefs/pref_change_registrar.h" 15 #include "base/prefs/pref_change_registrar.h"
17 #include "base/values.h"
18 #include "components/keyed_service/content/browser_context_keyed_service_factory .h" 16 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
19 #include "components/keyed_service/core/keyed_service.h" 17 #include "components/keyed_service/core/keyed_service.h"
20 #include "extensions/browser/management_policy.h" 18 #include "extensions/browser/management_policy.h"
21 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
22 #include "extensions/common/manifest.h" 20 #include "extensions/common/manifest.h"
23 #include "extensions/common/url_pattern_set.h"
24 21
25 class GURL; 22 class GURL;
26 class PrefService; 23 class PrefService;
27 24
25 namespace base {
26 class DictionaryValue;
27 } // namespace base
28
28 namespace content { 29 namespace content {
29 class BrowserContext; 30 class BrowserContext;
30 } // namespace content 31 } // namespace content
31 32
32 namespace extensions { 33 namespace extensions {
33 34
35 namespace internal {
36 struct IndividualSettings;
37 struct GlobalSettings;
38 } // namespace internal
39
34 // Tracks the management policies that affect extensions and provides interfaces 40 // Tracks the management policies that affect extensions and provides interfaces
35 // for observing and obtaining the global settings for all extensions, as well 41 // for observing and obtaining the global settings for all extensions, as well
36 // as per-extension settings. 42 // as per-extension settings.
37 class ExtensionManagement : public KeyedService { 43 class ExtensionManagement : public KeyedService {
38 public: 44 public:
39 // Observer class for extension management settings changes. 45 // Observer class for extension management settings changes.
40 class Observer { 46 class Observer {
41 public: 47 public:
42 virtual ~Observer() {} 48 virtual ~Observer() {}
43 49
44 // Will be called when an extension management preference changes. 50 // Will be called when then extension management setting changed.
Joao da Silva 2014/09/25 08:53:51 Called when the extension management settings chan
binjin 2014/09/25 13:19:19 Done.
45 virtual void OnExtensionManagementSettingsChanged() = 0; 51 virtual void OnExtensionManagementSettingsChanged() = 0;
46 }; 52 };
47 53
48 // Installation mode for extensions, default is INSTALLATION_ALLOWED. 54 // Installation mode for extensions, default is INSTALLATION_ALLOWED.
49 // * INSTALLATION_ALLOWED: Extension can be installed. 55 // * INSTALLATION_ALLOWED: Extension can be installed.
50 // * INSTALLATION_BLOCKED: Extension cannot be installed. 56 // * INSTALLATION_BLOCKED: Extension cannot be installed.
51 // * INSTALLATION_FORCED: Extension will be installed automatically 57 // * INSTALLATION_FORCED: Extension will be installed automatically
52 // and cannot be disabled. 58 // and cannot be disabled.
53 // * INSTALLATION_RECOMMENDED: Extension will be installed automatically but 59 // * INSTALLATION_RECOMMENDED: Extension will be installed automatically but
54 // can be disabled. 60 // can be disabled.
55 enum InstallationMode { 61 enum InstallationMode {
56 INSTALLATION_ALLOWED = 0, 62 INSTALLATION_ALLOWED = 0,
57 INSTALLATION_BLOCKED, 63 INSTALLATION_BLOCKED,
58 INSTALLATION_FORCED, 64 INSTALLATION_FORCED,
59 INSTALLATION_RECOMMENDED, 65 INSTALLATION_RECOMMENDED,
60 }; 66 };
61 67
62 // Class to hold extension management settings for one or a group of
63 // extensions. Settings can be applied to an individual extension identified
64 // by an ID, a group of extensions with specific |update_url| or all
65 // extensions at once.
66 struct IndividualSettings {
67 IndividualSettings();
68 ~IndividualSettings();
69
70 void Reset();
71
72 // Extension installation mode. Setting this to INSTALLATION_FORCED or
73 // INSTALLATION_RECOMMENDED will enable extension auto-loading (only
74 // applicable to single extension), and in this case the |update_url| must
75 // be specified, containing the update URL for this extension.
76 // Note that |update_url| will be ignored for INSTALLATION_ALLOWED and
77 // INSTALLATION_BLOCKED installation mode.
78 // These settings will override the default settings, and unspecified
79 // settings will take value from default settings.
80 InstallationMode installation_mode;
81 std::string update_url;
82 };
83
84 // Global extension management settings, applicable to all extensions.
85 struct GlobalSettings {
86 GlobalSettings();
87 ~GlobalSettings();
88
89 void Reset();
90
91 // Settings specifying which URLs are allowed to install extensions, will be
92 // enforced only if |has_restricted_install_sources| is set to true.
93 URLPatternSet install_sources;
94 bool has_restricted_install_sources;
95
96 // Settings specifying all allowed app/extension types, will be enforced
97 // only of |has_restricted_allowed_types| is set to true.
98 std::vector<Manifest::Type> allowed_types;
99 bool has_restricted_allowed_types;
100 };
101
102 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap;
103
104 explicit ExtensionManagement(PrefService* pref_service); 68 explicit ExtensionManagement(PrefService* pref_service);
105 virtual ~ExtensionManagement(); 69 virtual ~ExtensionManagement();
106 70
107 void AddObserver(Observer* observer); 71 void AddObserver(Observer* observer);
108 void RemoveObserver(Observer* observer); 72 void RemoveObserver(Observer* observer);
109 73
110 // Get the ManagementPolicy::Provider controlled by extension management 74 // Get the ManagementPolicy::Provider controlled by extension management
111 // policy settings. 75 // policy settings.
112 ManagementPolicy::Provider* GetProvider(); 76 ManagementPolicy::Provider* GetProvider() const;
113 77
114 // Checks if extensions are blacklisted by default, by policy. When true, 78 // Checks if extensions are blacklisted by default, by policy. When true,
115 // this means that even extensions without an ID should be blacklisted (e.g. 79 // this means that even extensions without an ID should be blacklisted (e.g.
116 // from the command line, or when loaded as an unpacked extension). 80 // from the command line, or when loaded as an unpacked extension).
117 bool BlacklistedByDefault(); 81 bool BlacklistedByDefault() const;
82
83 // Returns installation mode for an extension.
84 InstallationMode GetInstallationMode(const ExtensionId &id) const;
118 85
119 // Returns the force install list, in format specified by 86 // Returns the force install list, in format specified by
120 // ExternalPolicyLoader::AddExtension(). 87 // ExternalPolicyLoader::AddExtension().
121 scoped_ptr<base::DictionaryValue> GetForceInstallList() const; 88 scoped_ptr<base::DictionaryValue> GetForceInstallList() const;
122 89
123 // Returns if an extension with id |id| is allowed to install or not. 90 // Returns if an extension with id |id| is allowed to install or not.
124 bool IsInstallationAllowed(const ExtensionId& id) const; 91 bool IsInstallationAllowed(const ExtensionId& id) const;
125 92
126 // Returns true if an extension download should be allowed to proceed. 93 // Returns true if an extension download should be allowed to proceed.
127 bool IsOffstoreInstallAllowed(const GURL& url, const GURL& referrer_url); 94 bool IsOffstoreInstallAllowed(const GURL& url,
95 const GURL& referrer_url) const;
128 96
129 // Helper function to read |settings_by_id_| with |id| as key. Returns a 97 // Returns true if an extension with manifest type |manifest_type| is
130 // constant reference to default settings if |id| does not exist. 98 // allowed to be installed.
131 const IndividualSettings& ReadById(const ExtensionId& id) const; 99 bool IsAllowedManifestType(Manifest::Type manifest_type) const;
132
133 // Returns a constant reference to |global_settings_|.
134 const GlobalSettings& ReadGlobalSettings() const;
135 100
136 private: 101 private:
102 typedef std::map<ExtensionId, linked_ptr<internal::IndividualSettings> >
103 SettingsIdMap;
Joao da Silva 2014/09/25 08:53:51 I'm guessing that the linked_ptrs are used so that
binjin 2014/09/25 13:19:18 Done. But without extension_management_internal.h
104 friend class ExtensionManagementServiceTest;
105
137 // Load all extension management preferences from |pref_service|, and 106 // Load all extension management preferences from |pref_service|, and
138 // refresh the settings. 107 // refresh the settings.
139 void Refresh(); 108 void Refresh();
140 109
141 // Load preference with name |pref_name| and expected type |expected_type|. 110 // Load preference with name |pref_name| and expected type |expected_type|.
142 // If |force_managed| is true, only loading from the managed preference store 111 // If |force_managed| is true, only loading from the managed preference store
143 // is allowed. Returns NULL if the preference is not present, not allowed to 112 // is allowed. Returns NULL if the preference is not present, not allowed to
144 // be loaded from or has the wrong type. 113 // be loaded from or has the wrong type.
145 const base::Value* LoadPreference(const char* pref_name, 114 const base::Value* LoadPreference(const char* pref_name,
146 bool force_managed, 115 bool force_managed,
147 base::Value::Type expected_type); 116 base::Value::Type expected_type);
Joao da Silva 2014/09/25 08:53:51 #include "base/values.h"
binjin 2014/09/25 13:19:18 Done.
148 117
149 void OnExtensionPrefChanged(); 118 void OnExtensionPrefChanged();
150 void NotifyExtensionManagementPrefChanged(); 119 void NotifyExtensionManagementPrefChanged();
151 120
121 // Helper function to read |settings_by_id_| with |id| as key. Returns a
122 // constant reference to default settings if |id| does not exist.
123 linked_ptr<const internal::IndividualSettings> ReadById(
Joao da Silva 2014/09/25 08:53:51 Return an IndividualSettings* here
binjin 2014/09/25 13:19:18 Done.
124 const ExtensionId& id) const;
125
126 // Returns a constant reference to |global_settings_|.
127 linked_ptr<const internal::GlobalSettings> ReadGlobalSettings() const;
Joao da Silva 2014/09/25 08:53:51 Same here
binjin 2014/09/25 13:19:18 Done.
128
152 // Helper function to access |settings_by_id_| with |id| as key. 129 // Helper function to access |settings_by_id_| with |id| as key.
153 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for 130 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for
154 // |id| yet. 131 // |id| yet.
155 IndividualSettings* AccessById(const ExtensionId& id); 132 linked_ptr<internal::IndividualSettings> AccessById(const ExtensionId& id);
Joao da Silva 2014/09/25 08:53:51 And here
binjin 2014/09/25 13:19:18 Done.
156 133
157 // A map containing all IndividualSettings applied to an individual extension 134 // A map containing all IndividualSettings applied to an individual extension
158 // identified by extension ID. The extension ID is used as index key of the 135 // identified by extension ID. The extension ID is used as index key of the
159 // map. 136 // map.
160 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for 137 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for
161 // it. 138 // it.
162 SettingsIdMap settings_by_id_; 139 SettingsIdMap settings_by_id_;
163 140
164 // The default IndividualSettings. 141 // The default IndividualSettings.
165 // For extension settings applied to an individual extension (identified by 142 // For extension settings applied to an individual extension (identified by
166 // extension ID) or a group of extension (with specified extension update 143 // extension ID) or a group of extension (with specified extension update
167 // URL), all unspecified part will take value from |default_settings_|. 144 // URL), all unspecified part will take value from |default_settings_|.
168 // For all other extensions, all settings from |default_settings_| will be 145 // For all other extensions, all settings from |default_settings_| will be
169 // enforced. 146 // enforced.
170 IndividualSettings default_settings_; 147 linked_ptr<internal::IndividualSettings> default_settings_;
Joao da Silva 2014/09/25 08:53:51 scoped_ptr works here. Actually, there is no need
binjin 2014/09/25 13:19:18 Done.
171 148
172 // Extension settings applicable to all extensions. 149 // Extension settings applicable to all extensions.
173 GlobalSettings global_settings_; 150 linked_ptr<internal::GlobalSettings> global_settings_;
Joao da Silva 2014/09/25 08:53:51 Same here.
binjin 2014/09/25 13:19:18 Done.
174 151
175 PrefService* pref_service_; 152 PrefService* pref_service_;
176 153
177 ObserverList<Observer, true> observer_list_; 154 ObserverList<Observer, true> observer_list_;
178 PrefChangeRegistrar pref_change_registrar_; 155 PrefChangeRegistrar pref_change_registrar_;
179 scoped_ptr<ManagementPolicy::Provider> provider_; 156 scoped_ptr<ManagementPolicy::Provider> provider_;
180 157
181 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); 158 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement);
182 }; 159 };
183 160
(...skipping 16 matching lines...) Expand all
200 content::BrowserContext* context) const OVERRIDE; 177 content::BrowserContext* context) const OVERRIDE;
201 virtual void RegisterProfilePrefs( 178 virtual void RegisterProfilePrefs(
202 user_prefs::PrefRegistrySyncable* registry) OVERRIDE; 179 user_prefs::PrefRegistrySyncable* registry) OVERRIDE;
203 180
204 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory); 181 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory);
205 }; 182 };
206 183
207 } // namespace extensions 184 } // namespace extensions
208 185
209 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ 186 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_management.cc » ('j') | chrome/browser/extensions/extension_management.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698