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.h" | 5 #include "chrome/browser/extensions/extension_management.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 // Parse the individual settings for |settings|. |dict| is the a | 39 // Parse the individual settings for |settings|. |dict| is the a |
40 // sub-dictionary in extension management preference and |scope| represents | 40 // sub-dictionary in extension management preference and |scope| represents |
41 // the applicable range of the settings, a single extension, a group of | 41 // the applicable range of the settings, a single extension, a group of |
42 // extensions or default settings. | 42 // extensions or default settings. |
43 // Note that in case of parsing errors, |settings| will NOT be left untouched. | 43 // Note that in case of parsing errors, |settings| will NOT be left untouched. |
44 bool ParseIndividualSettings( | 44 bool ParseIndividualSettings( |
45 const base::DictionaryValue* dict, | 45 const base::DictionaryValue* dict, |
46 Scope scope, | 46 Scope scope, |
47 ExtensionManagement::IndividualSettings* settings) { | 47 ExtensionManagement::IndividualSettings* settings) { |
48 settings->Reset(); | |
49 | |
50 std::string installation_mode; | 48 std::string installation_mode; |
51 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, | 49 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, |
52 &installation_mode)) { | 50 &installation_mode)) { |
53 if (installation_mode == schema_constants::kAllowed) { | 51 if (installation_mode == schema_constants::kAllowed) { |
54 settings->installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 52 settings->installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
55 } else if (installation_mode == schema_constants::kBlocked) { | 53 } else if (installation_mode == schema_constants::kBlocked) { |
56 settings->installation_mode = ExtensionManagement::INSTALLATION_BLOCKED; | 54 settings->installation_mode = ExtensionManagement::INSTALLATION_BLOCKED; |
57 } else if (installation_mode == schema_constants::kForceInstalled) { | 55 } else if (installation_mode == schema_constants::kForceInstalled) { |
58 settings->installation_mode = ExtensionManagement::INSTALLATION_FORCED; | 56 settings->installation_mode = ExtensionManagement::INSTALLATION_FORCED; |
59 } else if (installation_mode == schema_constants::kNormalInstalled) { | 57 } else if (installation_mode == schema_constants::kNormalInstalled) { |
(...skipping 24 matching lines...) Expand all Loading... |
84 LOG(WARNING) << kMalformedPreferenceWarning; | 82 LOG(WARNING) << kMalformedPreferenceWarning; |
85 return false; | 83 return false; |
86 } | 84 } |
87 } | 85 } |
88 | 86 |
89 return true; | 87 return true; |
90 } | 88 } |
91 | 89 |
92 } // namespace | 90 } // namespace |
93 | 91 |
| 92 ExtensionManagement::IndividualSettings::IndividualSettings() { |
| 93 Reset(); |
| 94 } |
| 95 |
| 96 ExtensionManagement::IndividualSettings::~IndividualSettings() { |
| 97 } |
| 98 |
94 void ExtensionManagement::IndividualSettings::Reset() { | 99 void ExtensionManagement::IndividualSettings::Reset() { |
95 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 100 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
96 update_url.clear(); | 101 update_url.clear(); |
97 } | 102 } |
98 | 103 |
99 ExtensionManagement::GlobalSettings::GlobalSettings() { | 104 ExtensionManagement::GlobalSettings::GlobalSettings() { |
100 Reset(); | 105 Reset(); |
101 } | 106 } |
102 | 107 |
103 ExtensionManagement::GlobalSettings::~GlobalSettings() { | 108 ExtensionManagement::GlobalSettings::~GlobalSettings() { |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 if (dict_pref) { | 332 if (dict_pref) { |
328 // Parse new extension management preference. | 333 // Parse new extension management preference. |
329 for (base::DictionaryValue::Iterator iter(*dict_pref); !iter.IsAtEnd(); | 334 for (base::DictionaryValue::Iterator iter(*dict_pref); !iter.IsAtEnd(); |
330 iter.Advance()) { | 335 iter.Advance()) { |
331 if (iter.key() == schema_constants::kWildcard) | 336 if (iter.key() == schema_constants::kWildcard) |
332 continue; | 337 continue; |
333 if (!iter.value().GetAsDictionary(&subdict)) { | 338 if (!iter.value().GetAsDictionary(&subdict)) { |
334 LOG(WARNING) << kMalformedPreferenceWarning; | 339 LOG(WARNING) << kMalformedPreferenceWarning; |
335 continue; | 340 continue; |
336 } | 341 } |
337 if (StartsWithASCII( | 342 if (StartsWithASCII(iter.key(), schema_constants::kUpdateUrlPrefix, true)) |
338 iter.key(), schema_constants::kUpdateUrlPrefix, true)) | |
339 continue; | 343 continue; |
340 const std::string& extension_id = iter.key(); | 344 const std::string& extension_id = iter.key(); |
341 if (!crx_file::id_util::IdIsValid(extension_id)) { | 345 if (!crx_file::id_util::IdIsValid(extension_id)) { |
342 LOG(WARNING) << kMalformedPreferenceWarning; | 346 LOG(WARNING) << kMalformedPreferenceWarning; |
343 continue; | 347 continue; |
344 } | 348 } |
345 IndividualSettings by_id; | 349 IndividualSettings* by_id = AccessById(extension_id); |
346 if (ParseIndividualSettings(subdict, SCOPE_INDIVIDUAL, &by_id)) { | 350 if (!ParseIndividualSettings(subdict, SCOPE_INDIVIDUAL, by_id)) { |
347 *AccessById(extension_id) = by_id; | 351 settings_by_id_.erase(settings_by_id_.find(extension_id)); |
348 } else { | |
349 LOG(WARNING) << "Malformed Extension Management settings for " | 352 LOG(WARNING) << "Malformed Extension Management settings for " |
350 << iter.key() << "."; | 353 << extension_id << "."; |
351 } | 354 } |
352 } | 355 } |
353 } | 356 } |
354 } | 357 } |
355 | 358 |
356 const base::Value* ExtensionManagement::LoadPreference( | 359 const base::Value* ExtensionManagement::LoadPreference( |
357 const char* pref_name, | 360 const char* pref_name, |
358 bool force_managed, | 361 bool force_managed, |
359 base::Value::Type expected_type) { | 362 base::Value::Type expected_type) { |
360 const PrefService::Preference* pref = | 363 const PrefService::Preference* pref = |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 } | 421 } |
419 | 422 |
420 void ExtensionManagementFactory::RegisterProfilePrefs( | 423 void ExtensionManagementFactory::RegisterProfilePrefs( |
421 user_prefs::PrefRegistrySyncable* user_prefs) { | 424 user_prefs::PrefRegistrySyncable* user_prefs) { |
422 user_prefs->RegisterDictionaryPref( | 425 user_prefs->RegisterDictionaryPref( |
423 pref_names::kExtensionManagement, | 426 pref_names::kExtensionManagement, |
424 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 427 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
425 } | 428 } |
426 | 429 |
427 } // namespace extensions | 430 } // namespace extensions |
OLD | NEW |