Chromium Code Reviews| 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 // Service class to listen to prefs changes, hold preference settings, and | |
| 23 // provide interfaces for monitoring and obtaining these settings. | |
|
Joao da Silva
2014/09/02 19:34:02
This comment is very generic and a bit misleading.
binjin
2014/09/02 20:02:56
Done.
| |
| 24 class ExtensionManagement { | |
| 25 public: | |
| 26 // Installation mode for extensions, default is INSTALLATION_ALLOWED. | |
| 27 // * INSTALLATION_ALLOWED: Extension can be installed. | |
| 28 // * INSTALLATION_BLOCKED: Extension cannot be installed. | |
| 29 // * INSTALLATION_FORCED: Extension will be installed automatically | |
| 30 // and cannot be disabled. | |
| 31 // * INSTALLATION_RECOMMENDED: Extension will be installed automatically but | |
| 32 // can be disabled. | |
| 33 enum InstallationMode { | |
| 34 INSTALLATION_ALLOWED = 0, | |
| 35 INSTALLATION_BLOCKED, | |
| 36 INSTALLATION_FORCED, | |
| 37 INSTALLATION_RECOMMENDED, | |
| 38 }; | |
| 39 | |
| 40 // Class to hold extension management settings for one or a group of | |
| 41 // extensions. Settings can be applied to an individual extension identified | |
| 42 // by an ID, a group of extensions with specific |update_url| or all | |
| 43 // extensions at once. | |
| 44 struct IndividualSettings { | |
| 45 void Reset(); | |
| 46 | |
| 47 InstallationMode installation_mode; | |
| 48 std::string update_url; | |
| 49 }; | |
| 50 | |
| 51 // Global extension management settings, applicable to all extensions. | |
| 52 struct GlobalSettings { | |
| 53 GlobalSettings(); | |
| 54 ~GlobalSettings(); | |
| 55 | |
| 56 void Reset(); | |
| 57 | |
| 58 scoped_ptr<URLPatternSet> install_sources; | |
|
Joao da Silva
2014/09/02 19:34:02
Why is this in a scoped_ptr and not just a URLPatt
binjin
2014/09/02 20:02:56
Done.
| |
| 59 scoped_ptr<std::vector<Manifest::Type> > allowed_types; | |
|
Joao da Silva
2014/09/02 19:34:02
Same here: why isn't this just a vector?
If it's
binjin
2014/09/02 20:02:56
Done.
| |
| 60 }; | |
| 61 | |
| 62 typedef std::map<ExtensionId, IndividualSettings> SettingsIdMap; | |
| 63 | |
| 64 explicit ExtensionManagement(PrefService* pref_service); | |
| 65 virtual ~ExtensionManagement(); | |
| 66 | |
| 67 // Load all extension management preferences from |pref_service|, and | |
| 68 // refresh the settings. | |
| 69 void Refresh(); | |
|
Joao da Silva
2014/09/02 19:34:02
I don't think this should be public. The Extension
binjin
2014/09/02 20:02:56
Yes, it's part of the following CL, I will remove
| |
| 70 | |
| 71 // Helper function to read |settings_by_id_| with |id| as key. Returns a | |
| 72 // constant reference to default settings if |id| does not exist. | |
| 73 const IndividualSettings& ReadById(const ExtensionId& id) const; | |
| 74 | |
| 75 // Returns a constant reference to |global_settings_|. | |
| 76 const GlobalSettings& ReadGlobalSettings() const; | |
|
Joao da Silva
2014/09/02 19:34:02
I think it would be simpler to have accessors for
binjin
2014/09/02 20:02:56
I prefer to keep this structure, there are plenty
Joao da Silva
2014/09/03 09:20:40
Right, and they are all managed by this class. So
| |
| 77 | |
| 78 private: | |
| 79 // Load preference with name |pref_name| and expected type |expected_type|. | |
| 80 // If |force_managed| is true, only loading from the managed preference store | |
| 81 // is allowed. Returns NULL if the preference is not present, not allowed to | |
| 82 // be loaded from or has the wrong type. | |
| 83 const base::Value* LoadPreference(const char* pref_name, | |
| 84 bool force_managed, | |
|
Joao da Silva
2014/09/02 19:34:02
Why do we force managed for some prefs only?
binjin
2014/09/02 20:02:56
I think it might be useful for user (not admin) to
| |
| 85 base::Value::Type expected_type); | |
| 86 | |
| 87 // Helper function to access |settings_by_id_| with |id| as key. | |
| 88 // Adds a new IndividualSettings entry to |settings_by_id_| if none exists for | |
| 89 // |id| yet. | |
| 90 IndividualSettings* AccessById(const ExtensionId& id); | |
| 91 | |
| 92 // TODO(binjin): Add |settings_by_update_url_|, and implement mechanism for | |
| 93 // it. | |
| 94 SettingsIdMap settings_by_id_; | |
| 95 IndividualSettings default_settings_; | |
| 96 GlobalSettings global_settings_; | |
| 97 | |
| 98 PrefService* pref_service_; | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(ExtensionManagement); | |
| 101 }; | |
| 102 | |
| 103 } // namespace extensions | |
| 104 | |
| 105 | |
|
Joao da Silva
2014/09/02 19:34:02
nit: single newline here
binjin
2014/09/02 20:02:56
Done.
| |
| 106 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_ | |
| OLD | NEW |