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

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

Issue 499313002: Add ExtensionManagement class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: fixes to #11 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_management.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Extension installation mode. Setting this to INSTALLATION_FORCED or
49 // INSTALLATION_RECOMMENDED will enable extension auto-loading (only
50 // applicable to single extension), and in this case the |update_url| must
51 // be specified, containing the update URL for this extension.
52 // Note that |update_url| will be ignored for INSTALLATION_ALLOWED and
53 // INSTALLATION_BLOCKED installation mode.
54 InstallationMode installation_mode;
55 std::string update_url;
56 };
57
58 // Global extension management settings, applicable to all extensions.
59 struct GlobalSettings {
60 GlobalSettings();
61 ~GlobalSettings();
62
63 void Reset();
64
65 // Settings specifying which URLs are allowed to install extensions, will be
66 // enforced only if |has_restricted_install_sources| is set to true.
67 URLPatternSet install_sources;
68 bool has_restricted_install_sources;
69
70 // Settings specifying all allowed app/extension types, will be enforced
71 // only of |has_restricted_allowed_types| is set to true.
72 std::vector<Manifest::Type> allowed_types;
73 bool has_restricted_allowed_types;
74 };
75
76 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap;
77
78 explicit ExtensionManagement(PrefService* pref_service);
79 virtual ~ExtensionManagement();
80
81 // Load all extension management preferences from |pref_service|, and
82 // refresh the settings.
83 void Refresh();
84
85 // Helper function to read |settings_by_id_| with |id| as key. Returns a
86 // constant reference to default settings if |id| does not exist.
87 const IndividualSettings& ReadById(const ExtensionId& id) const;
88
89 // Returns a constant reference to |global_settings_|.
90 const GlobalSettings& ReadGlobalSettings() const;
91
92 private:
93 // Load preference with name |pref_name| and expected type |expected_type|.
94 // 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
96 // be loaded from or has the wrong type.
97 const base::Value* LoadPreference(const char* pref_name,
98 bool force_managed,
99 base::Value::Type expected_type);
100
101 // 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
103 // |id| yet.
104 IndividualSettings* AccessById(const ExtensionId& id);
105
106 // 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
108 // map.
109 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for
110 // it.
111 SettingsIdMap settings_by_id_;
112
113 // The default IndividualSettings.
114 // For extension settings applied to an individual extension(identified by
115 // extension ID) or a group of extension(with specified extension update URL),
Finnur 2014/09/03 14:56:59 nit: space before ( (two occurrences)
116 // all unspecified part will take value from |default_settings_|.
117 // For all other extensions, all settings from |default_settings_| will be
118 // enforced.
119 IndividualSettings default_settings_;
120
121 // Extension settings applicable to all extensions.
122 GlobalSettings global_settings_;
123
124 PrefService* pref_service_;
125
126 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement);
127 };
128
129 } // namespace extensions
130
131 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_management.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698