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 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 OnExtensionManagementPrefChanged() = 0; | |
Joao da Silva
2014/09/03 11:52:54
Rename to "OnExtensionManagementSettingsChanged".
binjin
2014/09/03 15:31:36
Done.
| |
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 24 matching lines...) Expand all Loading... | |
61 | 81 |
62 std::vector<Manifest::Type> allowed_types; | 82 std::vector<Manifest::Type> allowed_types; |
63 bool has_restricted_allowed_types; | 83 bool has_restricted_allowed_types; |
64 }; | 84 }; |
65 | 85 |
66 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap; | 86 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap; |
67 | 87 |
68 explicit ExtensionManagement(PrefService* pref_service); | 88 explicit ExtensionManagement(PrefService* pref_service); |
69 virtual ~ExtensionManagement(); | 89 virtual ~ExtensionManagement(); |
70 | 90 |
71 // Load all extension management preferences from |pref_service|, and | 91 void AddObserver(Observer* obs); |
72 // refresh the settings. | 92 void RemoveObserver(Observer* obs); |
Joao da Silva
2014/09/03 11:52:54
Rename "obs" to "observer"
binjin
2014/09/03 15:31:36
Done.
| |
73 void Refresh(); | 93 |
94 // Get the ManagementPolicy::Provider controlled by extension management | |
95 // policy settings. | |
96 ManagementPolicy::Provider* GetProvider(); | |
97 | |
98 // Checks if extensions are blacklisted by default, by policy. When true, | |
99 // this means that even extensions without an ID should be blacklisted (e.g. | |
100 // from the command line, or when loaded as an unpacked extension). | |
101 bool BlacklistedByDefault(); | |
74 | 102 |
75 // Helper function to read |settings_by_id_| with |id| as key. Returns a | 103 // Helper function to read |settings_by_id_| with |id| as key. Returns a |
76 // constant reference to default settings if |id| does not exist. | 104 // constant reference to default settings if |id| does not exist. |
77 const IndividualSettings& ReadById(const ExtensionId& id) const; | 105 const IndividualSettings& ReadById(const ExtensionId& id) const; |
78 | 106 |
79 // Returns a constant reference to |global_settings_|. | 107 // Returns a constant reference to |global_settings_|. |
80 const GlobalSettings& ReadGlobalSettings() const; | 108 const GlobalSettings& ReadGlobalSettings() const; |
81 | 109 |
82 private: | 110 private: |
111 // Load all extension management preferences from |pref_service|, and | |
112 // refresh the settings. | |
113 void Refresh(); | |
114 | |
83 // Load preference with name |pref_name| and expected type |expected_type|. | 115 // Load preference with name |pref_name| and expected type |expected_type|. |
84 // If |force_managed| is true, only loading from the managed preference store | 116 // If |force_managed| is true, only loading from the managed preference store |
85 // is allowed. Returns NULL if the preference is not present, not allowed to | 117 // is allowed. Returns NULL if the preference is not present, not allowed to |
86 // be loaded from or has the wrong type. | 118 // be loaded from or has the wrong type. |
87 const base::Value* LoadPreference(const char* pref_name, | 119 const base::Value* LoadPreference(const char* pref_name, |
88 bool force_managed, | 120 bool force_managed, |
89 base::Value::Type expected_type); | 121 base::Value::Type expected_type); |
90 | 122 |
123 void OnExtensionPrefChanged(); | |
124 void NotifyExtensionManagementPrefChanged(); | |
125 | |
91 // Helper function to access |settings_by_id_| with |id| as key. | 126 // Helper function to access |settings_by_id_| with |id| as key. |
92 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for | 127 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for |
93 // |id| yet. | 128 // |id| yet. |
94 IndividualSettings* AccessById(const ExtensionId& id); | 129 IndividualSettings* AccessById(const ExtensionId& id); |
95 | 130 |
96 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for | 131 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for |
97 // it. | 132 // it. |
133 IndividualSettings default_settings_; | |
98 SettingsIdMap settings_by_id_; | 134 SettingsIdMap settings_by_id_; |
99 IndividualSettings default_settings_; | |
100 GlobalSettings global_settings_; | 135 GlobalSettings global_settings_; |
101 | 136 |
102 PrefService* pref_service_; | 137 PrefService* pref_service_; |
103 | 138 |
139 ObserverList<Observer> observer_list_; | |
binjin
2014/09/02 20:47:49
adding true as 2nd parameter fails the ExtensionSe
Joao da Silva
2014/09/03 11:52:54
That suggests that there is some missing cleanup a
| |
140 PrefChangeRegistrar pref_change_registrar_; | |
141 scoped_ptr<ManagementPolicy::Provider> provider_; | |
142 | |
104 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); | 143 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); |
105 }; | 144 }; |
106 | 145 |
146 class ExtensionManagementFactory : public BrowserContextKeyedServiceFactory { | |
147 public: | |
148 static ExtensionManagement* GetForBrowserContext( | |
149 content::BrowserContext* context); | |
150 static ExtensionManagementFactory* GetInstance(); | |
151 | |
152 private: | |
153 friend struct DefaultSingletonTraits<ExtensionManagementFactory>; | |
154 | |
155 ExtensionManagementFactory(); | |
156 virtual ~ExtensionManagementFactory(); | |
157 | |
158 // BrowserContextKeyedServiceExtensionManagementFactory: | |
159 virtual KeyedService* BuildServiceInstanceFor( | |
160 content::BrowserContext* context) const OVERRIDE; | |
161 | |
162 DISALLOW_COPY_AND_ASSIGN(ExtensionManagementFactory); | |
163 }; | |
164 | |
107 } // namespace extensions | 165 } // namespace extensions |
108 | 166 |
109 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | 167 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ |
OLD | NEW |