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

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

Issue 602803002: Refactor ExtensionManagement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-fix
Patch Set: fix addressing #7 Created 6 years, 2 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
OLDNEW
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.h" 5 #include "chrome/browser/extensions/extension_management.h"
6 6
7 #include <algorithm>
8 #include <string>
9 #include <vector>
10
7 #include "base/bind.h" 11 #include "base/bind.h"
8 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
9 #include "base/logging.h" 13 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
12 #include "chrome/browser/extensions/extension_management_constants.h" 16 #include "chrome/browser/extensions/extension_management_constants.h"
17 #include "chrome/browser/extensions/extension_management_internal.h"
13 #include "chrome/browser/extensions/external_policy_loader.h" 18 #include "chrome/browser/extensions/external_policy_loader.h"
14 #include "chrome/browser/extensions/external_provider_impl.h" 19 #include "chrome/browser/extensions/external_provider_impl.h"
15 #include "chrome/browser/extensions/standard_management_policy_provider.h" 20 #include "chrome/browser/extensions/standard_management_policy_provider.h"
16 #include "chrome/browser/profiles/incognito_helpers.h" 21 #include "chrome/browser/profiles/incognito_helpers.h"
17 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
18 #include "components/crx_file/id_util.h" 23 #include "components/crx_file/id_util.h"
19 #include "components/keyed_service/content/browser_context_dependency_manager.h" 24 #include "components/keyed_service/content/browser_context_dependency_manager.h"
20 #include "components/pref_registry/pref_registry_syncable.h" 25 #include "components/pref_registry/pref_registry_syncable.h"
21 #include "extensions/browser/pref_names.h" 26 #include "extensions/browser/pref_names.h"
22 #include "extensions/common/url_pattern.h" 27 #include "extensions/common/url_pattern.h"
23 #include "url/gurl.h" 28 #include "url/gurl.h"
24 29
25 namespace extensions { 30 namespace extensions {
26 31
27 namespace {
28
29 const char kMalformedPreferenceWarning[] =
30 "Malformed extension management preference.";
31
32 enum Scope {
33 // Parses the default settings.
34 SCOPE_DEFAULT = 0,
35 // Parses the settings for an extension with specified extension ID.
36 SCOPE_INDIVIDUAL,
37 };
38
39 // Parse the individual settings for |settings|. |dict| is the a
40 // sub-dictionary in extension management preference and |scope| represents
41 // the applicable range of the settings, a single extension, a group of
42 // extensions or default settings.
43 // Note that in case of parsing errors, |settings| will NOT be left untouched.
44 bool ParseIndividualSettings(
45 const base::DictionaryValue* dict,
46 Scope scope,
47 ExtensionManagement::IndividualSettings* settings) {
48 std::string installation_mode;
49 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode,
50 &installation_mode)) {
51 if (installation_mode == schema_constants::kAllowed) {
52 settings->installation_mode = ExtensionManagement::INSTALLATION_ALLOWED;
53 } else if (installation_mode == schema_constants::kBlocked) {
54 settings->installation_mode = ExtensionManagement::INSTALLATION_BLOCKED;
55 } else if (installation_mode == schema_constants::kForceInstalled) {
56 settings->installation_mode = ExtensionManagement::INSTALLATION_FORCED;
57 } else if (installation_mode == schema_constants::kNormalInstalled) {
58 settings->installation_mode =
59 ExtensionManagement::INSTALLATION_RECOMMENDED;
60 } else {
61 // Invalid value for 'installation_mode'.
62 LOG(WARNING) << kMalformedPreferenceWarning;
63 return false;
64 }
65 }
66
67 if (settings->installation_mode == ExtensionManagement::INSTALLATION_FORCED ||
68 settings->installation_mode ==
69 ExtensionManagement::INSTALLATION_RECOMMENDED) {
70 if (scope != SCOPE_INDIVIDUAL) {
71 // Only individual extensions are allowed to be automatically installed.
72 LOG(WARNING) << kMalformedPreferenceWarning;
73 return false;
74 }
75 std::string update_url;
76 if (dict->GetStringWithoutPathExpansion(schema_constants::kUpdateUrl,
77 &update_url) &&
78 GURL(update_url).is_valid()) {
79 settings->update_url = update_url;
80 } else {
81 // No valid update URL for extension.
82 LOG(WARNING) << kMalformedPreferenceWarning;
83 return false;
84 }
85 }
86
87 return true;
88 }
89
90 } // namespace
91
92 ExtensionManagement::IndividualSettings::IndividualSettings() {
93 Reset();
94 }
95
96 ExtensionManagement::IndividualSettings::~IndividualSettings() {
97 }
98
99 void ExtensionManagement::IndividualSettings::Reset() {
100 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED;
101 update_url.clear();
102 }
103
104 ExtensionManagement::GlobalSettings::GlobalSettings() {
105 Reset();
106 }
107
108 ExtensionManagement::GlobalSettings::~GlobalSettings() {
109 }
110
111 void ExtensionManagement::GlobalSettings::Reset() {
112 has_restricted_install_sources = false;
113 install_sources.ClearPatterns();
114 has_restricted_allowed_types = false;
115 allowed_types.clear();
116 }
117
118 ExtensionManagement::ExtensionManagement(PrefService* pref_service) 32 ExtensionManagement::ExtensionManagement(PrefService* pref_service)
119 : pref_service_(pref_service) { 33 : pref_service_(pref_service) {
120 pref_change_registrar_.Init(pref_service_); 34 pref_change_registrar_.Init(pref_service_);
121 base::Closure pref_change_callback = base::Bind( 35 base::Closure pref_change_callback = base::Bind(
122 &ExtensionManagement::OnExtensionPrefChanged, base::Unretained(this)); 36 &ExtensionManagement::OnExtensionPrefChanged, base::Unretained(this));
123 pref_change_registrar_.Add(pref_names::kInstallAllowList, 37 pref_change_registrar_.Add(pref_names::kInstallAllowList,
124 pref_change_callback); 38 pref_change_callback);
125 pref_change_registrar_.Add(pref_names::kInstallDenyList, 39 pref_change_registrar_.Add(pref_names::kInstallDenyList,
126 pref_change_callback); 40 pref_change_callback);
127 pref_change_registrar_.Add(pref_names::kInstallForceList, 41 pref_change_registrar_.Add(pref_names::kInstallForceList,
128 pref_change_callback); 42 pref_change_callback);
129 pref_change_registrar_.Add(pref_names::kAllowedInstallSites, 43 pref_change_registrar_.Add(pref_names::kAllowedInstallSites,
130 pref_change_callback); 44 pref_change_callback);
131 pref_change_registrar_.Add(pref_names::kAllowedTypes, pref_change_callback); 45 pref_change_registrar_.Add(pref_names::kAllowedTypes, pref_change_callback);
132 pref_change_registrar_.Add(pref_names::kExtensionManagement, 46 pref_change_registrar_.Add(pref_names::kExtensionManagement,
133 pref_change_callback); 47 pref_change_callback);
48 // Note that both |global_settings_| and |default_settings_| will be null
49 // before first call to Refresh(), so in order to resolve this, Refresh() must
50 // be called in the initialization of ExtensionManagement.
134 Refresh(); 51 Refresh();
135 provider_.reset(new StandardManagementPolicyProvider(this)); 52 provider_.reset(new StandardManagementPolicyProvider(this));
136 } 53 }
137 54
138 ExtensionManagement::~ExtensionManagement() { 55 ExtensionManagement::~ExtensionManagement() {
139 } 56 }
140 57
141 void ExtensionManagement::AddObserver(Observer* observer) { 58 void ExtensionManagement::AddObserver(Observer* observer) {
142 observer_list_.AddObserver(observer); 59 observer_list_.AddObserver(observer);
143 } 60 }
144 61
145 void ExtensionManagement::RemoveObserver(Observer* observer) { 62 void ExtensionManagement::RemoveObserver(Observer* observer) {
146 observer_list_.RemoveObserver(observer); 63 observer_list_.RemoveObserver(observer);
147 } 64 }
148 65
149 ManagementPolicy::Provider* ExtensionManagement::GetProvider() { 66 ManagementPolicy::Provider* ExtensionManagement::GetProvider() const {
150 return provider_.get(); 67 return provider_.get();
151 } 68 }
152 69
153 bool ExtensionManagement::BlacklistedByDefault() { 70 bool ExtensionManagement::BlacklistedByDefault() const {
154 return default_settings_.installation_mode == INSTALLATION_BLOCKED; 71 return default_settings_->installation_mode == INSTALLATION_BLOCKED;
72 }
73
74 ExtensionManagement::InstallationMode ExtensionManagement::GetInstallationMode(
75 const ExtensionId& id) const {
76 return ReadById(id)->installation_mode;
155 } 77 }
156 78
157 scoped_ptr<base::DictionaryValue> ExtensionManagement::GetForceInstallList() 79 scoped_ptr<base::DictionaryValue> ExtensionManagement::GetForceInstallList()
158 const { 80 const {
159 scoped_ptr<base::DictionaryValue> forcelist(new base::DictionaryValue()); 81 scoped_ptr<base::DictionaryValue> forcelist(new base::DictionaryValue());
160 for (SettingsIdMap::const_iterator it = settings_by_id_.begin(); 82 for (SettingsIdMap::const_iterator it = settings_by_id_.begin();
161 it != settings_by_id_.end(); 83 it != settings_by_id_.end();
162 ++it) { 84 ++it) {
163 if (it->second.installation_mode == INSTALLATION_FORCED) { 85 if (it->second->installation_mode == INSTALLATION_FORCED) {
164 ExternalPolicyLoader::AddExtension( 86 ExternalPolicyLoader::AddExtension(
165 forcelist.get(), it->first, it->second.update_url); 87 forcelist.get(), it->first, it->second->update_url);
166 } 88 }
167 } 89 }
168 return forcelist.Pass(); 90 return forcelist.Pass();
169 } 91 }
170 92
171 bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const { 93 bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const {
172 return ReadById(id).installation_mode != INSTALLATION_BLOCKED; 94 return ReadById(id)->installation_mode != INSTALLATION_BLOCKED;
173 } 95 }
174 96
175 bool ExtensionManagement::IsOffstoreInstallAllowed(const GURL& url, 97 bool ExtensionManagement::IsOffstoreInstallAllowed(
176 const GURL& referrer_url) { 98 const GURL& url,
99 const GURL& referrer_url) const {
177 // No allowed install sites specified, disallow by default. 100 // No allowed install sites specified, disallow by default.
178 if (!global_settings_.has_restricted_install_sources) 101 if (!global_settings_->has_restricted_install_sources)
179 return false; 102 return false;
180 103
181 const extensions::URLPatternSet& url_patterns = 104 const URLPatternSet& url_patterns = global_settings_->install_sources;
182 global_settings_.install_sources;
183 105
184 if (!url_patterns.MatchesURL(url)) 106 if (!url_patterns.MatchesURL(url))
185 return false; 107 return false;
186 108
187 // The referrer URL must also be whitelisted, unless the URL has the file 109 // The referrer URL must also be whitelisted, unless the URL has the file
188 // scheme (there's no referrer for those URLs). 110 // scheme (there's no referrer for those URLs).
189 return url.SchemeIsFile() || url_patterns.MatchesURL(referrer_url); 111 return url.SchemeIsFile() || url_patterns.MatchesURL(referrer_url);
190 } 112 }
191 113
192 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( 114 bool ExtensionManagement::IsAllowedManifestType(
193 const ExtensionId& id) const { 115 Manifest::Type manifest_type) const {
194 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; 116 if (!global_settings_->has_restricted_allowed_types)
195 SettingsIdMap::const_iterator it = settings_by_id_.find(id); 117 return true;
196 if (it != settings_by_id_.end()) 118 const std::vector<Manifest::Type>& allowed_types =
197 return it->second; 119 global_settings_->allowed_types;
198 return default_settings_; 120 return std::find(allowed_types.begin(), allowed_types.end(), manifest_type) !=
199 } 121 allowed_types.end();
200
201 const ExtensionManagement::GlobalSettings&
202 ExtensionManagement::ReadGlobalSettings() const {
203 return global_settings_;
204 } 122 }
205 123
206 void ExtensionManagement::Refresh() { 124 void ExtensionManagement::Refresh() {
207 // Load all extension management settings preferences. 125 // Load all extension management settings preferences.
208 const base::ListValue* allowed_list_pref = 126 const base::ListValue* allowed_list_pref =
209 static_cast<const base::ListValue*>(LoadPreference( 127 static_cast<const base::ListValue*>(LoadPreference(
210 pref_names::kInstallAllowList, true, base::Value::TYPE_LIST)); 128 pref_names::kInstallAllowList, true, base::Value::TYPE_LIST));
211 // Allow user to use preference to block certain extensions. Note that policy 129 // Allow user to use preference to block certain extensions. Note that policy
212 // managed forcelist or whitelist will always override this. 130 // managed forcelist or whitelist will always override this.
213 const base::ListValue* denied_list_pref = 131 const base::ListValue* denied_list_pref =
214 static_cast<const base::ListValue*>(LoadPreference( 132 static_cast<const base::ListValue*>(LoadPreference(
215 pref_names::kInstallDenyList, false, base::Value::TYPE_LIST)); 133 pref_names::kInstallDenyList, false, base::Value::TYPE_LIST));
216 const base::DictionaryValue* forced_list_pref = 134 const base::DictionaryValue* forced_list_pref =
217 static_cast<const base::DictionaryValue*>(LoadPreference( 135 static_cast<const base::DictionaryValue*>(LoadPreference(
218 pref_names::kInstallForceList, true, base::Value::TYPE_DICTIONARY)); 136 pref_names::kInstallForceList, true, base::Value::TYPE_DICTIONARY));
219 const base::ListValue* install_sources_pref = 137 const base::ListValue* install_sources_pref =
220 static_cast<const base::ListValue*>(LoadPreference( 138 static_cast<const base::ListValue*>(LoadPreference(
221 pref_names::kAllowedInstallSites, true, base::Value::TYPE_LIST)); 139 pref_names::kAllowedInstallSites, true, base::Value::TYPE_LIST));
222 const base::ListValue* allowed_types_pref = 140 const base::ListValue* allowed_types_pref =
223 static_cast<const base::ListValue*>(LoadPreference( 141 static_cast<const base::ListValue*>(LoadPreference(
224 pref_names::kAllowedTypes, true, base::Value::TYPE_LIST)); 142 pref_names::kAllowedTypes, true, base::Value::TYPE_LIST));
225 const base::DictionaryValue* dict_pref = 143 const base::DictionaryValue* dict_pref =
226 static_cast<const base::DictionaryValue*>( 144 static_cast<const base::DictionaryValue*>(
227 LoadPreference(pref_names::kExtensionManagement, 145 LoadPreference(pref_names::kExtensionManagement,
228 true, 146 true,
229 base::Value::TYPE_DICTIONARY)); 147 base::Value::TYPE_DICTIONARY));
230 148
231 // Reset all settings. 149 // Reset all settings.
232 global_settings_.Reset(); 150 global_settings_.reset(new internal::GlobalSettings());
233 settings_by_id_.clear(); 151 settings_by_id_.clear();
234 default_settings_.Reset(); 152 default_settings_.reset(new internal::IndividualSettings());
235 153
236 // Parse default settings. 154 // Parse default settings.
237 const base::StringValue wildcard("*"); 155 const base::StringValue wildcard("*");
238 if (denied_list_pref && 156 if (denied_list_pref &&
239 denied_list_pref->Find(wildcard) != denied_list_pref->end()) { 157 denied_list_pref->Find(wildcard) != denied_list_pref->end()) {
240 default_settings_.installation_mode = INSTALLATION_BLOCKED; 158 default_settings_->installation_mode = INSTALLATION_BLOCKED;
241 } 159 }
242 160
243 const base::DictionaryValue* subdict = NULL; 161 const base::DictionaryValue* subdict = NULL;
244 if (dict_pref && 162 if (dict_pref &&
245 dict_pref->GetDictionary(schema_constants::kWildcard, &subdict)) { 163 dict_pref->GetDictionary(schema_constants::kWildcard, &subdict)) {
246 if (!ParseIndividualSettings(subdict, SCOPE_DEFAULT, &default_settings_)) { 164 if (!default_settings_->Parse(
165 subdict, internal::IndividualSettings::SCOPE_DEFAULT)) {
247 LOG(WARNING) << "Default extension management settings parsing error."; 166 LOG(WARNING) << "Default extension management settings parsing error.";
248 default_settings_.Reset(); 167 default_settings_->Reset();
249 } 168 }
250 169
251 // Settings from new preference have higher priority over legacy ones. 170 // Settings from new preference have higher priority over legacy ones.
252 const base::ListValue* list_value = NULL; 171 const base::ListValue* list_value = NULL;
253 if (subdict->GetList(schema_constants::kInstallSources, &list_value)) 172 if (subdict->GetList(schema_constants::kInstallSources, &list_value))
254 install_sources_pref = list_value; 173 install_sources_pref = list_value;
255 if (subdict->GetList(schema_constants::kAllowedTypes, &list_value)) 174 if (subdict->GetList(schema_constants::kAllowedTypes, &list_value))
256 allowed_types_pref = list_value; 175 allowed_types_pref = list_value;
257 } 176 }
258 177
(...skipping 19 matching lines...) Expand all
278 if (forced_list_pref) { 197 if (forced_list_pref) {
279 std::string update_url; 198 std::string update_url;
280 for (base::DictionaryValue::Iterator it(*forced_list_pref); !it.IsAtEnd(); 199 for (base::DictionaryValue::Iterator it(*forced_list_pref); !it.IsAtEnd();
281 it.Advance()) { 200 it.Advance()) {
282 if (!crx_file::id_util::IdIsValid(it.key())) 201 if (!crx_file::id_util::IdIsValid(it.key()))
283 continue; 202 continue;
284 const base::DictionaryValue* dict_value = NULL; 203 const base::DictionaryValue* dict_value = NULL;
285 if (it.value().GetAsDictionary(&dict_value) && 204 if (it.value().GetAsDictionary(&dict_value) &&
286 dict_value->GetStringWithoutPathExpansion( 205 dict_value->GetStringWithoutPathExpansion(
287 ExternalProviderImpl::kExternalUpdateUrl, &update_url)) { 206 ExternalProviderImpl::kExternalUpdateUrl, &update_url)) {
288 IndividualSettings* by_id = AccessById(it.key()); 207 internal::IndividualSettings* by_id = AccessById(it.key());
289 by_id->installation_mode = INSTALLATION_FORCED; 208 by_id->installation_mode = INSTALLATION_FORCED;
290 by_id->update_url = update_url; 209 by_id->update_url = update_url;
291 } 210 }
292 } 211 }
293 } 212 }
294 213
295 if (install_sources_pref) { 214 if (install_sources_pref) {
296 global_settings_.has_restricted_install_sources = true; 215 global_settings_->has_restricted_install_sources = true;
297 for (base::ListValue::const_iterator it = install_sources_pref->begin(); 216 for (base::ListValue::const_iterator it = install_sources_pref->begin();
298 it != install_sources_pref->end(); ++it) { 217 it != install_sources_pref->end(); ++it) {
299 std::string url_pattern; 218 std::string url_pattern;
300 if ((*it)->GetAsString(&url_pattern)) { 219 if ((*it)->GetAsString(&url_pattern)) {
301 URLPattern entry(URLPattern::SCHEME_ALL); 220 URLPattern entry(URLPattern::SCHEME_ALL);
302 if (entry.Parse(url_pattern) == URLPattern::PARSE_SUCCESS) { 221 if (entry.Parse(url_pattern) == URLPattern::PARSE_SUCCESS) {
303 global_settings_.install_sources.AddPattern(entry); 222 global_settings_->install_sources.AddPattern(entry);
304 } else { 223 } else {
305 LOG(WARNING) << "Invalid URL pattern in for preference " 224 LOG(WARNING) << "Invalid URL pattern in for preference "
306 << pref_names::kAllowedInstallSites << ": " 225 << pref_names::kAllowedInstallSites << ": "
307 << url_pattern << "."; 226 << url_pattern << ".";
308 } 227 }
309 } 228 }
310 } 229 }
311 } 230 }
312 231
313 if (allowed_types_pref) { 232 if (allowed_types_pref) {
314 global_settings_.has_restricted_allowed_types = true; 233 global_settings_->has_restricted_allowed_types = true;
315 for (base::ListValue::const_iterator it = allowed_types_pref->begin(); 234 for (base::ListValue::const_iterator it = allowed_types_pref->begin();
316 it != allowed_types_pref->end(); ++it) { 235 it != allowed_types_pref->end(); ++it) {
317 int int_value; 236 int int_value;
318 std::string string_value; 237 std::string string_value;
319 if ((*it)->GetAsInteger(&int_value) && int_value >= 0 && 238 if ((*it)->GetAsInteger(&int_value) && int_value >= 0 &&
320 int_value < Manifest::Type::NUM_LOAD_TYPES) { 239 int_value < Manifest::Type::NUM_LOAD_TYPES) {
321 global_settings_.allowed_types.push_back( 240 global_settings_->allowed_types.push_back(
322 static_cast<Manifest::Type>(int_value)); 241 static_cast<Manifest::Type>(int_value));
323 } else if ((*it)->GetAsString(&string_value)) { 242 } else if ((*it)->GetAsString(&string_value)) {
324 Manifest::Type manifest_type = 243 Manifest::Type manifest_type =
325 schema_constants::GetManifestType(string_value); 244 schema_constants::GetManifestType(string_value);
326 if (manifest_type != Manifest::TYPE_UNKNOWN) 245 if (manifest_type != Manifest::TYPE_UNKNOWN)
327 global_settings_.allowed_types.push_back(manifest_type); 246 global_settings_->allowed_types.push_back(manifest_type);
328 } 247 }
329 } 248 }
330 } 249 }
331 250
332 if (dict_pref) { 251 if (dict_pref) {
333 // Parse new extension management preference. 252 // Parse new extension management preference.
334 for (base::DictionaryValue::Iterator iter(*dict_pref); !iter.IsAtEnd(); 253 for (base::DictionaryValue::Iterator iter(*dict_pref); !iter.IsAtEnd();
335 iter.Advance()) { 254 iter.Advance()) {
336 if (iter.key() == schema_constants::kWildcard) 255 if (iter.key() == schema_constants::kWildcard)
337 continue; 256 continue;
338 if (!iter.value().GetAsDictionary(&subdict)) { 257 if (!iter.value().GetAsDictionary(&subdict))
339 LOG(WARNING) << kMalformedPreferenceWarning;
340 continue; 258 continue;
341 }
342 if (StartsWithASCII(iter.key(), schema_constants::kUpdateUrlPrefix, true)) 259 if (StartsWithASCII(iter.key(), schema_constants::kUpdateUrlPrefix, true))
343 continue; 260 continue;
344 const std::string& extension_id = iter.key(); 261 const std::string& extension_id = iter.key();
345 if (!crx_file::id_util::IdIsValid(extension_id)) { 262 if (!crx_file::id_util::IdIsValid(extension_id)) {
346 LOG(WARNING) << kMalformedPreferenceWarning; 263 LOG(WARNING) << "Invalid extension ID : " << extension_id << ".";
347 continue; 264 continue;
348 } 265 }
349 IndividualSettings* by_id = AccessById(extension_id); 266 internal::IndividualSettings* by_id = AccessById(extension_id);
350 if (!ParseIndividualSettings(subdict, SCOPE_INDIVIDUAL, by_id)) { 267 if (!by_id->Parse(subdict,
351 settings_by_id_.erase(settings_by_id_.find(extension_id)); 268 internal::IndividualSettings::SCOPE_INDIVIDUAL)) {
269 settings_by_id_.erase(extension_id);
352 LOG(WARNING) << "Malformed Extension Management settings for " 270 LOG(WARNING) << "Malformed Extension Management settings for "
353 << extension_id << "."; 271 << extension_id << ".";
354 } 272 }
355 } 273 }
356 } 274 }
357 } 275 }
358 276
359 const base::Value* ExtensionManagement::LoadPreference( 277 const base::Value* ExtensionManagement::LoadPreference(
360 const char* pref_name, 278 const char* pref_name,
361 bool force_managed, 279 bool force_managed,
(...skipping 12 matching lines...) Expand all
374 void ExtensionManagement::OnExtensionPrefChanged() { 292 void ExtensionManagement::OnExtensionPrefChanged() {
375 Refresh(); 293 Refresh();
376 NotifyExtensionManagementPrefChanged(); 294 NotifyExtensionManagementPrefChanged();
377 } 295 }
378 296
379 void ExtensionManagement::NotifyExtensionManagementPrefChanged() { 297 void ExtensionManagement::NotifyExtensionManagementPrefChanged() {
380 FOR_EACH_OBSERVER( 298 FOR_EACH_OBSERVER(
381 Observer, observer_list_, OnExtensionManagementSettingsChanged()); 299 Observer, observer_list_, OnExtensionManagementSettingsChanged());
382 } 300 }
383 301
384 ExtensionManagement::IndividualSettings* ExtensionManagement::AccessById( 302 const internal::IndividualSettings* ExtensionManagement::ReadById(
303 const ExtensionId& id) const {
304 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id;
305 SettingsIdMap::const_iterator it = settings_by_id_.find(id);
306 if (it != settings_by_id_.end())
307 return it->second;
308 return default_settings_.get();
309 }
310
311 const internal::GlobalSettings* ExtensionManagement::ReadGlobalSettings()
312 const {
313 return global_settings_.get();
314 }
315
316 internal::IndividualSettings* ExtensionManagement::AccessById(
385 const ExtensionId& id) { 317 const ExtensionId& id) {
386 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; 318 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id;
387 SettingsIdMap::iterator it = settings_by_id_.find(id); 319 SettingsIdMap::iterator it = settings_by_id_.find(id);
388 if (it == settings_by_id_.end()) 320 if (it == settings_by_id_.end()) {
389 it = settings_by_id_.insert(std::make_pair(id, default_settings_)).first; 321 scoped_ptr<internal::IndividualSettings> settings(
390 return &it->second; 322 new internal::IndividualSettings(*default_settings_));
323 it = settings_by_id_.add(id, settings.Pass()).first;
324 }
325 return it->second;
391 } 326 }
392 327
393 ExtensionManagement* ExtensionManagementFactory::GetForBrowserContext( 328 ExtensionManagement* ExtensionManagementFactory::GetForBrowserContext(
394 content::BrowserContext* context) { 329 content::BrowserContext* context) {
395 return static_cast<ExtensionManagement*>( 330 return static_cast<ExtensionManagement*>(
396 GetInstance()->GetServiceForBrowserContext(context, true)); 331 GetInstance()->GetServiceForBrowserContext(context, true));
397 } 332 }
398 333
399 ExtensionManagementFactory* ExtensionManagementFactory::GetInstance() { 334 ExtensionManagementFactory* ExtensionManagementFactory::GetInstance() {
400 return Singleton<ExtensionManagementFactory>::get(); 335 return Singleton<ExtensionManagementFactory>::get();
(...skipping 20 matching lines...) Expand all
421 } 356 }
422 357
423 void ExtensionManagementFactory::RegisterProfilePrefs( 358 void ExtensionManagementFactory::RegisterProfilePrefs(
424 user_prefs::PrefRegistrySyncable* user_prefs) { 359 user_prefs::PrefRegistrySyncable* user_prefs) {
425 user_prefs->RegisterDictionaryPref( 360 user_prefs->RegisterDictionaryPref(
426 pref_names::kExtensionManagement, 361 pref_names::kExtensionManagement,
427 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 362 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
428 } 363 }
429 364
430 } // namespace extensions 365 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_management.h ('k') | chrome/browser/extensions/extension_management_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698