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

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

Issue 500043003: Add PolicyProvider to ExtensionManagement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-1
Patch Set: fixes to #3 Created 6 years, 3 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> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/singleton.h"
15 #include "base/observer_list.h"
16 #include "base/prefs/pref_change_registrar.h"
13 #include "base/values.h" 17 #include "base/values.h"
18 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
19 #include "components/keyed_service/core/keyed_service.h"
20 #include "extensions/browser/management_policy.h"
14 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
15 #include "extensions/common/manifest.h" 22 #include "extensions/common/manifest.h"
16 #include "extensions/common/url_pattern_set.h" 23 #include "extensions/common/url_pattern_set.h"
17 24
18 class PrefService; 25 class PrefService;
19 26
27 namespace content {
28 class BrowserContext;
29 } // namespace content
30
20 namespace extensions { 31 namespace extensions {
21 32
22 // Tracks the management policies that affect extensions and provides interfaces 33 // Tracks the management policies that affect extensions and provides interfaces
23 // for observing and obtaining the global settings for all extensions, as well 34 // for observing and obtaining the global settings for all extensions, as well
24 // as per-extension settings. 35 // as per-extension settings.
25 class ExtensionManagement { 36 class ExtensionManagement : public KeyedService {
26 public: 37 public:
38 // Observer class for extension management settings changes.
39 class Observer {
40 public:
41 virtual ~Observer() {}
42
43 // Will be called when an extension management preference changes.
44 virtual void OnExtensionManagementSettingsChanged() = 0;
45 };
46
27 // Installation mode for extensions, default is INSTALLATION_ALLOWED. 47 // Installation mode for extensions, default is INSTALLATION_ALLOWED.
28 // * INSTALLATION_ALLOWED: Extension can be installed. 48 // * INSTALLATION_ALLOWED: Extension can be installed.
29 // * INSTALLATION_BLOCKED: Extension cannot be installed. 49 // * INSTALLATION_BLOCKED: Extension cannot be installed.
30 // * INSTALLATION_FORCED: Extension will be installed automatically 50 // * INSTALLATION_FORCED: Extension will be installed automatically
31 // and cannot be disabled. 51 // and cannot be disabled.
32 // * INSTALLATION_RECOMMENDED: Extension will be installed automatically but 52 // * INSTALLATION_RECOMMENDED: Extension will be installed automatically but
33 // can be disabled. 53 // can be disabled.
34 enum InstallationMode { 54 enum InstallationMode {
35 INSTALLATION_ALLOWED = 0, 55 INSTALLATION_ALLOWED = 0,
36 INSTALLATION_BLOCKED, 56 INSTALLATION_BLOCKED,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // only of |has_restricted_allowed_types| is set to true. 91 // only of |has_restricted_allowed_types| is set to true.
72 std::vector<Manifest::Type> allowed_types; 92 std::vector<Manifest::Type> allowed_types;
73 bool has_restricted_allowed_types; 93 bool has_restricted_allowed_types;
74 }; 94 };
75 95
76 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap; 96 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap;
77 97
78 explicit ExtensionManagement(PrefService* pref_service); 98 explicit ExtensionManagement(PrefService* pref_service);
79 virtual ~ExtensionManagement(); 99 virtual ~ExtensionManagement();
80 100
81 // Load all extension management preferences from |pref_service|, and 101 void AddObserver(Observer* observer);
82 // refresh the settings. 102 void RemoveObserver(Observer* observer);
83 void Refresh(); 103
104 // Get the ManagementPolicy::Provider controlled by extension management
105 // policy settings.
106 ManagementPolicy::Provider* GetProvider();
107
108 // Checks if extensions are blacklisted by default, by policy. When true,
109 // this means that even extensions without an ID should be blacklisted (e.g.
110 // from the command line, or when loaded as an unpacked extension).
111 bool BlacklistedByDefault();
84 112
85 // Helper function to read |settings_by_id_| with |id| as key. Returns a 113 // Helper function to read |settings_by_id_| with |id| as key. Returns a
86 // constant reference to default settings if |id| does not exist. 114 // constant reference to default settings if |id| does not exist.
87 const IndividualSettings& ReadById(const ExtensionId& id) const; 115 const IndividualSettings& ReadById(const ExtensionId& id) const;
88 116
89 // Returns a constant reference to |global_settings_|. 117 // Returns a constant reference to |global_settings_|.
90 const GlobalSettings& ReadGlobalSettings() const; 118 const GlobalSettings& ReadGlobalSettings() const;
91 119
92 private: 120 private:
121 // Load all extension management preferences from |pref_service|, and
122 // refresh the settings.
123 void Refresh();
124
93 // Load preference with name |pref_name| and expected type |expected_type|. 125 // Load preference with name |pref_name| and expected type |expected_type|.
94 // If |force_managed| is true, only loading from the managed preference store 126 // If |force_managed| is true, only loading from the managed preference store
95 // is allowed. Returns NULL if the preference is not present, not allowed to 127 // is allowed. Returns NULL if the preference is not present, not allowed to
96 // be loaded from or has the wrong type. 128 // be loaded from or has the wrong type.
97 const base::Value* LoadPreference(const char* pref_name, 129 const base::Value* LoadPreference(const char* pref_name,
98 bool force_managed, 130 bool force_managed,
99 base::Value::Type expected_type); 131 base::Value::Type expected_type);
100 132
133 void OnExtensionPrefChanged();
134 void NotifyExtensionManagementPrefChanged();
135
101 // Helper function to access |settings_by_id_| with |id| as key. 136 // Helper function to access |settings_by_id_| with |id| as key.
102 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for 137 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for
103 // |id| yet. 138 // |id| yet.
104 IndividualSettings* AccessById(const ExtensionId& id); 139 IndividualSettings* AccessById(const ExtensionId& id);
105 140
106 // A map containing all IndividualSettings applied to an individual extension 141 // A map containing all IndividualSettings applied to an individual extension
107 // identified by extension ID. The extension ID is used as index key of the 142 // identified by extension ID. The extension ID is used as index key of the
108 // map. 143 // map.
109 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for 144 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for
110 // it. 145 // it.
111 SettingsIdMap settings_by_id_; 146 SettingsIdMap settings_by_id_;
112 147
113 // The default IndividualSettings. 148 // The default IndividualSettings.
114 // For extension settings applied to an individual extension(identified by 149 // For extension settings applied to an individual extension(identified by
115 // extension ID) or a group of extension(with specified extension update URL), 150 // extension ID) or a group of extension(with specified extension update URL),
116 // all unspecified part will take value from |default_settings_|. 151 // all unspecified part will take value from |default_settings_|.
117 // For all other extensions, all settings from |default_settings_| will be 152 // For all other extensions, all settings from |default_settings_| will be
118 // enforced. 153 // enforced.
119 IndividualSettings default_settings_; 154 IndividualSettings default_settings_;
120 155
121 // Extension settings applicable to all extensions. 156 // Extension settings applicable to all extensions.
122 GlobalSettings global_settings_; 157 GlobalSettings global_settings_;
123 158
124 PrefService* pref_service_; 159 PrefService* pref_service_;
125 160
161 ObserverList<Observer, true> observer_list_;
162 PrefChangeRegistrar pref_change_registrar_;
163 scoped_ptr<ManagementPolicy::Provider> provider_;
164
126 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); 165 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement);
127 }; 166 };
128 167
168 class ExtensionManagementFactory : public BrowserContextKeyedServiceFactory {
169 public:
170 static ExtensionManagement* GetForBrowserContext(
171 content::BrowserContext* context);
172 static ExtensionManagementFactory* GetInstance();
173
174 private:
175 friend struct DefaultSingletonTraits<ExtensionManagementFactory>;
176
177 ExtensionManagementFactory();
178 virtual ~ExtensionManagementFactory();
179
180 // BrowserContextKeyedServiceExtensionManagementFactory:
181 virtual KeyedService* BuildServiceInstanceFor(
182 content::BrowserContext* context) const OVERRIDE;
183
184 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory);
185 };
186
129 } // namespace extensions 187 } // namespace extensions
130 188
131 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ 189 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698