OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 #include <vector> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/values.h" | |
14 #include "extensions/common/extension.h" | |
15 #include "extensions/common/manifest.h" | |
16 #include "extensions/common/url_pattern_set.h" | |
17 | |
18 class PrefService; | |
19 | |
20 namespace extensions { | |
21 | |
22 // Tracks the management policies that affect extensions and provides interfaces | |
23 // for observing and obtaining the global settings for all extensions, as well | |
24 // as per-extension settings. | |
25 class ExtensionManagement { | |
26 public: | |
27 // Installation mode for extensions, default is INSTALLATION_ALLOWED. | |
28 // * INSTALLATION_ALLOWED: Extension can be installed. | |
29 // * INSTALLATION_BLOCKED: Extension cannot be installed. | |
30 // * INSTALLATION_FORCED: Extension will be installed automatically | |
31 // and cannot be disabled. | |
32 // * INSTALLATION_RECOMMENDED: Extension will be installed automatically but | |
33 // can be disabled. | |
34 enum InstallationMode { | |
35 INSTALLATION_ALLOWED = 0, | |
36 INSTALLATION_BLOCKED, | |
37 INSTALLATION_FORCED, | |
38 INSTALLATION_RECOMMENDED, | |
39 }; | |
40 | |
41 // Class to hold extension management settings for one or a group of | |
42 // extensions. Settings can be applied to an individual extension identified | |
43 // by an ID, a group of extensions with specific |update_url| or all | |
44 // extensions at once. | |
45 struct IndividualSettings { | |
46 void Reset(); | |
47 | |
48 InstallationMode installation_mode; | |
49 std::string update_url; | |
Finnur
2014/09/03 13:04:01
nit: document.
binjin
2014/09/03 14:31:55
Done.
| |
50 }; | |
51 | |
52 // Global extension management settings, applicable to all extensions. | |
53 struct GlobalSettings { | |
54 GlobalSettings(); | |
55 ~GlobalSettings(); | |
56 | |
57 void Reset(); | |
58 | |
59 URLPatternSet install_sources; | |
60 bool has_restricted_install_sources; | |
61 | |
62 std::vector<Manifest::Type> allowed_types; | |
63 bool has_restricted_allowed_types; | |
Finnur
2014/09/03 13:04:01
nit: document all these.
binjin
2014/09/03 14:31:55
Done.
| |
64 }; | |
65 | |
66 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap; | |
67 | |
68 explicit ExtensionManagement(PrefService* pref_service); | |
69 virtual ~ExtensionManagement(); | |
70 | |
71 // Load all extension management preferences from |pref_service|, and | |
72 // refresh the settings. | |
73 void Refresh(); | |
74 | |
75 // Helper function to read |settings_by_id_| with |id| as key. Returns a | |
76 // constant reference to default settings if |id| does not exist. | |
77 const IndividualSettings& ReadById(const ExtensionId& id) const; | |
78 | |
79 // Returns a constant reference to |global_settings_|. | |
80 const GlobalSettings& ReadGlobalSettings() const; | |
81 | |
82 private: | |
83 // Load preference with name |pref_name| and expected type |expected_type|. | |
84 // 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 | |
86 // be loaded from or has the wrong type. | |
87 const base::Value* LoadPreference(const char* pref_name, | |
88 bool force_managed, | |
89 base::Value::Type expected_type); | |
90 | |
91 // 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 | |
93 // |id| yet. | |
94 IndividualSettings* AccessById(const ExtensionId& id); | |
95 | |
96 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for | |
97 // it. | |
98 SettingsIdMap settings_by_id_; | |
99 IndividualSettings default_settings_; | |
100 GlobalSettings global_settings_; | |
Finnur
2014/09/03 13:04:01
nit: Document.
In my experience, this only invit
binjin
2014/09/03 14:31:55
Done.
| |
101 | |
102 PrefService* pref_service_; | |
103 | |
104 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); | |
105 }; | |
106 | |
107 } // namespace extensions | |
108 | |
109 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | |
OLD | NEW |