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 <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return iter_update_url->second->installation_mode; | 106 return iter_update_url->second->installation_mode; |
107 } | 107 } |
108 // Fall back to default installation mode setting. | 108 // Fall back to default installation mode setting. |
109 return default_settings_->installation_mode; | 109 return default_settings_->installation_mode; |
110 } | 110 } |
111 | 111 |
112 std::unique_ptr<base::DictionaryValue> | 112 std::unique_ptr<base::DictionaryValue> |
113 ExtensionManagement::GetForceInstallList() const { | 113 ExtensionManagement::GetForceInstallList() const { |
114 std::unique_ptr<base::DictionaryValue> install_list( | 114 std::unique_ptr<base::DictionaryValue> install_list( |
115 new base::DictionaryValue()); | 115 new base::DictionaryValue()); |
116 for (SettingsIdMap::const_iterator it = settings_by_id_.begin(); | 116 for (const auto& entry : settings_by_id_) { |
117 it != settings_by_id_.end(); | 117 if (entry.second->installation_mode == INSTALLATION_FORCED) { |
118 ++it) { | 118 ExternalPolicyLoader::AddExtension(install_list.get(), entry.first, |
119 if (it->second->installation_mode == INSTALLATION_FORCED) { | 119 entry.second->update_url); |
120 ExternalPolicyLoader::AddExtension( | |
121 install_list.get(), it->first, it->second->update_url); | |
122 } | 120 } |
123 } | 121 } |
124 return install_list; | 122 return install_list; |
125 } | 123 } |
126 | 124 |
127 std::unique_ptr<base::DictionaryValue> | 125 std::unique_ptr<base::DictionaryValue> |
128 ExtensionManagement::GetRecommendedInstallList() const { | 126 ExtensionManagement::GetRecommendedInstallList() const { |
129 std::unique_ptr<base::DictionaryValue> install_list( | 127 std::unique_ptr<base::DictionaryValue> install_list( |
130 new base::DictionaryValue()); | 128 new base::DictionaryValue()); |
131 for (SettingsIdMap::const_iterator it = settings_by_id_.begin(); | 129 for (const auto& entry : settings_by_id_) { |
132 it != settings_by_id_.end(); | 130 if (entry.second->installation_mode == INSTALLATION_RECOMMENDED) { |
133 ++it) { | 131 ExternalPolicyLoader::AddExtension(install_list.get(), entry.first, |
134 if (it->second->installation_mode == INSTALLATION_RECOMMENDED) { | 132 entry.second->update_url); |
135 ExternalPolicyLoader::AddExtension( | |
136 install_list.get(), it->first, it->second->update_url); | |
137 } | 133 } |
138 } | 134 } |
139 return install_list; | 135 return install_list; |
140 } | 136 } |
141 | 137 |
142 bool ExtensionManagement::IsInstallationExplicitlyAllowed( | 138 bool ExtensionManagement::IsInstallationExplicitlyAllowed( |
143 const ExtensionId& id) const { | 139 const ExtensionId& id) const { |
144 SettingsIdMap::const_iterator it = settings_by_id_.find(id); | 140 auto it = settings_by_id_.find(id); |
145 // No settings explicitly specified for |id|. | 141 // No settings explicitly specified for |id|. |
146 if (it == settings_by_id_.end()) | 142 if (it == settings_by_id_.end()) |
147 return false; | 143 return false; |
148 // Checks if the extension is on the automatically installed list or | 144 // Checks if the extension is on the automatically installed list or |
149 // install white-list. | 145 // install white-list. |
150 InstallationMode mode = it->second->installation_mode; | 146 InstallationMode mode = it->second->installation_mode; |
151 return mode == INSTALLATION_FORCED || mode == INSTALLATION_RECOMMENDED || | 147 return mode == INSTALLATION_FORCED || mode == INSTALLATION_RECOMMENDED || |
152 mode == INSTALLATION_ALLOWED; | 148 mode == INSTALLATION_ALLOWED; |
153 } | 149 } |
154 | 150 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 } | 434 } |
439 | 435 |
440 void ExtensionManagement::NotifyExtensionManagementPrefChanged() { | 436 void ExtensionManagement::NotifyExtensionManagementPrefChanged() { |
441 for (auto& observer : observer_list_) | 437 for (auto& observer : observer_list_) |
442 observer.OnExtensionManagementSettingsChanged(); | 438 observer.OnExtensionManagementSettingsChanged(); |
443 } | 439 } |
444 | 440 |
445 internal::IndividualSettings* ExtensionManagement::AccessById( | 441 internal::IndividualSettings* ExtensionManagement::AccessById( |
446 const ExtensionId& id) { | 442 const ExtensionId& id) { |
447 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; | 443 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; |
448 SettingsIdMap::iterator it = settings_by_id_.find(id); | 444 std::unique_ptr<internal::IndividualSettings>& settings = settings_by_id_[id]; |
449 if (it == settings_by_id_.end()) { | 445 if (!settings) { |
450 std::unique_ptr<internal::IndividualSettings> settings( | 446 settings = |
451 new internal::IndividualSettings(default_settings_.get())); | 447 base::MakeUnique<internal::IndividualSettings>(default_settings_.get()); |
452 it = settings_by_id_.add(id, std::move(settings)).first; | |
453 } | 448 } |
454 return it->second; | 449 return settings.get(); |
455 } | 450 } |
456 | 451 |
457 internal::IndividualSettings* ExtensionManagement::AccessByUpdateUrl( | 452 internal::IndividualSettings* ExtensionManagement::AccessByUpdateUrl( |
458 const std::string& update_url) { | 453 const std::string& update_url) { |
459 DCHECK(GURL(update_url).is_valid()) << "Invalid update URL: " << update_url; | 454 DCHECK(GURL(update_url).is_valid()) << "Invalid update URL: " << update_url; |
460 SettingsUpdateUrlMap::iterator it = settings_by_update_url_.find(update_url); | 455 std::unique_ptr<internal::IndividualSettings>& settings = |
461 if (it == settings_by_update_url_.end()) { | 456 settings_by_update_url_[update_url]; |
462 std::unique_ptr<internal::IndividualSettings> settings( | 457 if (!settings) { |
463 new internal::IndividualSettings(default_settings_.get())); | 458 settings = |
464 it = settings_by_update_url_.add(update_url, std::move(settings)).first; | 459 base::MakeUnique<internal::IndividualSettings>(default_settings_.get()); |
465 } | 460 } |
466 return it->second; | 461 return settings.get(); |
467 } | 462 } |
468 | 463 |
469 ExtensionManagement* ExtensionManagementFactory::GetForBrowserContext( | 464 ExtensionManagement* ExtensionManagementFactory::GetForBrowserContext( |
470 content::BrowserContext* context) { | 465 content::BrowserContext* context) { |
471 return static_cast<ExtensionManagement*>( | 466 return static_cast<ExtensionManagement*>( |
472 GetInstance()->GetServiceForBrowserContext(context, true)); | 467 GetInstance()->GetServiceForBrowserContext(context, true)); |
473 } | 468 } |
474 | 469 |
475 ExtensionManagementFactory* ExtensionManagementFactory::GetInstance() { | 470 ExtensionManagementFactory* ExtensionManagementFactory::GetInstance() { |
476 return base::Singleton<ExtensionManagementFactory>::get(); | 471 return base::Singleton<ExtensionManagementFactory>::get(); |
(...skipping 20 matching lines...) Expand all Loading... |
497 content::BrowserContext* context) const { | 492 content::BrowserContext* context) const { |
498 return chrome::GetBrowserContextRedirectedInIncognito(context); | 493 return chrome::GetBrowserContextRedirectedInIncognito(context); |
499 } | 494 } |
500 | 495 |
501 void ExtensionManagementFactory::RegisterProfilePrefs( | 496 void ExtensionManagementFactory::RegisterProfilePrefs( |
502 user_prefs::PrefRegistrySyncable* user_prefs) { | 497 user_prefs::PrefRegistrySyncable* user_prefs) { |
503 user_prefs->RegisterDictionaryPref(pref_names::kExtensionManagement); | 498 user_prefs->RegisterDictionaryPref(pref_names::kExtensionManagement); |
504 } | 499 } |
505 | 500 |
506 } // namespace extensions | 501 } // namespace extensions |
OLD | NEW |