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 #include "chrome/browser/extensions/extension_management_internal.h" | 5 #include "chrome/browser/extensions/extension_management_internal.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "base/version.h" | |
9 #include "chrome/browser/extensions/extension_management_constants.h" | 10 #include "chrome/browser/extensions/extension_management_constants.h" |
10 #include "extensions/common/url_pattern_set.h" | 11 #include "extensions/common/url_pattern_set.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 namespace extensions { | 14 namespace extensions { |
14 | 15 |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
17 namespace { | 18 namespace { |
18 const char kMalformedPreferenceWarning[] = | 19 const char kMalformedPreferenceWarning[] = |
19 "Malformed extension management preference."; | 20 "Malformed extension management preference."; |
20 } // namespace | 21 } // namespace |
21 | 22 |
22 IndividualSettings::IndividualSettings() { | 23 IndividualSettings::IndividualSettings() { |
23 Reset(); | 24 Reset(); |
24 } | 25 } |
25 | 26 |
27 // Initializes from default settings. | |
28 IndividualSettings::IndividualSettings( | |
29 const IndividualSettings* default_settings) { | |
30 installation_mode = default_settings->installation_mode; | |
31 update_url = default_settings->installation_mode; | |
32 blocked_permissions = default_settings->blocked_permissions; | |
33 // We are not initializing |minimum_version_required| from |default_settings| | |
34 // here since it's not applicable to default settings. | |
35 } | |
36 | |
26 IndividualSettings::~IndividualSettings() { | 37 IndividualSettings::~IndividualSettings() { |
27 } | 38 } |
Finnur
2014/11/19 10:16:25
Can you initialize installation_mode here?
binjin
2014/11/19 13:36:10
In a destructor? I assume you mean Parse(), the pu
| |
28 | 39 |
29 bool IndividualSettings::Parse(const base::DictionaryValue* dict, | 40 bool IndividualSettings::Parse(const base::DictionaryValue* dict, |
30 ParsingScope scope) { | 41 ParsingScope scope) { |
31 std::string installation_mode_str; | 42 std::string installation_mode_str; |
32 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, | 43 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, |
33 &installation_mode_str)) { | 44 &installation_mode_str)) { |
34 if (installation_mode_str == schema_constants::kAllowed) { | 45 if (installation_mode_str == schema_constants::kAllowed) { |
35 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 46 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
36 } else if (installation_mode_str == schema_constants::kBlocked) { | 47 } else if (installation_mode_str == schema_constants::kBlocked) { |
37 installation_mode = ExtensionManagement::INSTALLATION_BLOCKED; | 48 installation_mode = ExtensionManagement::INSTALLATION_BLOCKED; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 APIPermissionSet::kDisallowInternalPermissions, | 122 APIPermissionSet::kDisallowInternalPermissions, |
112 &permissions_parsed, | 123 &permissions_parsed, |
113 &error, | 124 &error, |
114 nullptr)) { | 125 nullptr)) { |
115 LOG(WARNING) << error; | 126 LOG(WARNING) << error; |
116 } | 127 } |
117 APIPermissionSet::Union( | 128 APIPermissionSet::Union( |
118 permissions_to_merge_from, permissions_parsed, &blocked_permissions); | 129 permissions_to_merge_from, permissions_parsed, &blocked_permissions); |
119 } | 130 } |
120 | 131 |
132 // Parses the minimum version settings. | |
133 std::string minimum_version_required_str; | |
134 if (scope == SCOPE_INDIVIDUAL && | |
135 dict->GetStringWithoutPathExpansion( | |
136 schema_constants::kMinimumVersionRequired, | |
137 &minimum_version_required_str)) { | |
138 scoped_ptr<base::Version> version( | |
139 new Version(minimum_version_required_str)); | |
140 // We accept a general version string here. Note that count of components in | |
141 // version string of extensions is limited to 4. | |
142 if (!version->IsValid()) | |
143 LOG(WARNING) << kMalformedPreferenceWarning; | |
144 else | |
145 minimum_version_required = version.Pass(); | |
146 } | |
147 | |
121 return true; | 148 return true; |
122 } | 149 } |
123 | 150 |
124 void IndividualSettings::Reset() { | 151 void IndividualSettings::Reset() { |
125 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 152 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
126 update_url.clear(); | 153 update_url.clear(); |
127 blocked_permissions.clear(); | 154 blocked_permissions.clear(); |
128 } | 155 } |
129 | 156 |
130 GlobalSettings::GlobalSettings() { | 157 GlobalSettings::GlobalSettings() { |
131 Reset(); | 158 Reset(); |
132 } | 159 } |
133 | 160 |
134 GlobalSettings::~GlobalSettings() { | 161 GlobalSettings::~GlobalSettings() { |
135 } | 162 } |
136 | 163 |
137 void GlobalSettings::Reset() { | 164 void GlobalSettings::Reset() { |
138 has_restricted_install_sources = false; | 165 has_restricted_install_sources = false; |
139 install_sources.ClearPatterns(); | 166 install_sources.ClearPatterns(); |
140 has_restricted_allowed_types = false; | 167 has_restricted_allowed_types = false; |
141 allowed_types.clear(); | 168 allowed_types.clear(); |
142 } | 169 } |
143 | 170 |
144 } // namespace internal | 171 } // namespace internal |
145 | 172 |
146 } // namespace extensions | 173 } // namespace extensions |
OLD | NEW |