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

Unified Diff: chrome/browser/extensions/extension_management.cc

Issue 2144313002: Plumbing for login apps device policy to extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_management.cc
diff --git a/chrome/browser/extensions/extension_management.cc b/chrome/browser/extensions/extension_management.cc
index 1e8904b00fe0916a33dc1cc589e455a6678c71cc..0c319cb6be91245fb04e2620cb1f629cb9ab0627 100644
--- a/chrome/browser/extensions/extension_management.cc
+++ b/chrome/browser/extensions/extension_management.cc
@@ -36,13 +36,16 @@
#include "extensions/common/url_pattern.h"
#include "url/gurl.h"
+#if defined(OS_CHROMEOS)
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#endif
+
namespace extensions {
-ExtensionManagement::ExtensionManagement(PrefService* pref_service)
- : pref_service_(pref_service) {
+ExtensionManagement::ExtensionManagement(Profile* profile) : profile_(profile) {
TRACE_EVENT0("browser,startup",
"ExtensionManagement::ExtensionManagement::ctor");
- pref_change_registrar_.Init(pref_service_);
+ pref_change_registrar_.Init(profile_->GetPrefs());
base::Closure pref_change_callback = base::Bind(
&ExtensionManagement::OnExtensionPrefChanged, base::Unretained(this));
pref_change_registrar_.Add(pref_names::kInstallAllowList,
@@ -51,6 +54,8 @@ ExtensionManagement::ExtensionManagement(PrefService* pref_service)
pref_change_callback);
pref_change_registrar_.Add(pref_names::kInstallForceList,
pref_change_callback);
+ pref_change_registrar_.Add(pref_names::kInstallLoginList,
+ pref_change_callback);
pref_change_registrar_.Add(pref_names::kAllowedInstallSites,
pref_change_callback);
pref_change_registrar_.Add(pref_names::kAllowedTypes, pref_change_callback);
@@ -71,7 +76,7 @@ ExtensionManagement::~ExtensionManagement() {
void ExtensionManagement::Shutdown() {
pref_change_registrar_.RemoveAll();
- pref_service_ = nullptr;
+ profile_ = nullptr;
}
void ExtensionManagement::AddObserver(Observer* observer) {
@@ -110,29 +115,26 @@ ExtensionManagement::InstallationMode ExtensionManagement::GetInstallationMode(
}
std::unique_ptr<base::DictionaryValue>
-ExtensionManagement::GetForceInstallList() const {
- std::unique_ptr<base::DictionaryValue> install_list(
- new base::DictionaryValue());
+ExtensionManagement::GetInstallListByMode(
+ InstallationMode installation_mode) const {
+ auto extension_dict = base::MakeUnique<base::DictionaryValue>();
for (const auto& entry : settings_by_id_) {
- if (entry.second->installation_mode == INSTALLATION_FORCED) {
- ExternalPolicyLoader::AddExtension(install_list.get(), entry.first,
+ if (entry.second->installation_mode == installation_mode) {
+ ExternalPolicyLoader::AddExtension(extension_dict.get(), entry.first,
entry.second->update_url);
}
}
- return install_list;
+ return extension_dict;
+}
+
+std::unique_ptr<base::DictionaryValue>
+ExtensionManagement::GetForceInstallList() const {
+ return GetInstallListByMode(INSTALLATION_FORCED);
}
std::unique_ptr<base::DictionaryValue>
ExtensionManagement::GetRecommendedInstallList() const {
- std::unique_ptr<base::DictionaryValue> install_list(
- new base::DictionaryValue());
- for (const auto& entry : settings_by_id_) {
- if (entry.second->installation_mode == INSTALLATION_RECOMMENDED) {
- ExternalPolicyLoader::AddExtension(install_list.get(), entry.first,
- entry.second->update_url);
- }
- }
- return install_list;
+ return GetInstallListByMode(INSTALLATION_RECOMMENDED);
}
bool ExtensionManagement::IsInstallationExplicitlyAllowed(
@@ -255,6 +257,11 @@ void ExtensionManagement::Refresh() {
const base::DictionaryValue* forced_list_pref =
static_cast<const base::DictionaryValue*>(LoadPreference(
pref_names::kInstallForceList, true, base::Value::Type::DICTIONARY));
+#if defined(OS_CHROMEOS)
+ const base::DictionaryValue* login_list_pref =
+ static_cast<const base::DictionaryValue*>(LoadPreference(
+ pref_names::kInstallLoginList, true, base::Value::Type::DICTIONARY));
+#endif
const base::ListValue* install_sources_pref =
static_cast<const base::ListValue*>(LoadPreference(
pref_names::kAllowedInstallSites, true, base::Value::Type::LIST));
@@ -315,22 +322,11 @@ void ExtensionManagement::Refresh() {
}
}
- if (forced_list_pref) {
- std::string update_url;
- for (base::DictionaryValue::Iterator it(*forced_list_pref); !it.IsAtEnd();
- it.Advance()) {
- if (!crx_file::id_util::IdIsValid(it.key()))
- continue;
- const base::DictionaryValue* dict_value = NULL;
- if (it.value().GetAsDictionary(&dict_value) &&
- dict_value->GetStringWithoutPathExpansion(
- ExternalProviderImpl::kExternalUpdateUrl, &update_url)) {
- internal::IndividualSettings* by_id = AccessById(it.key());
- by_id->installation_mode = INSTALLATION_FORCED;
- by_id->update_url = update_url;
- }
- }
- }
+ UpdateForcedExtensions(forced_list_pref);
+#if defined(OS_CHROMEOS)
+ if (chromeos::ProfileHelper::IsSigninProfile(profile_))
achuithb 2017/02/21 16:17:25 This is a change from Denis's CL. Please note tha
+ UpdateForcedExtensions(login_list_pref);
+#endif
if (install_sources_pref) {
global_settings_->has_restricted_install_sources = true;
@@ -415,10 +411,10 @@ const base::Value* ExtensionManagement::LoadPreference(
const char* pref_name,
bool force_managed,
base::Value::Type expected_type) {
- if (!pref_service_)
+ if (!profile_)
return nullptr;
const PrefService::Preference* pref =
- pref_service_->FindPreference(pref_name);
+ profile_->GetPrefs()->FindPreference(pref_name);
if (pref && !pref->IsDefaultValue() &&
(!force_managed || pref->IsManaged())) {
const base::Value* value = pref->GetValue();
@@ -438,6 +434,27 @@ void ExtensionManagement::NotifyExtensionManagementPrefChanged() {
observer.OnExtensionManagementSettingsChanged();
}
+void ExtensionManagement::UpdateForcedExtensions(
+ const base::DictionaryValue* extension_dict) {
+ if (!extension_dict)
+ return;
+
+ std::string update_url;
+ for (base::DictionaryValue::Iterator it(*extension_dict); !it.IsAtEnd();
+ it.Advance()) {
+ if (!crx_file::id_util::IdIsValid(it.key()))
+ continue;
+ const base::DictionaryValue* dict_value = nullptr;
+ if (it.value().GetAsDictionary(&dict_value) &&
+ dict_value->GetStringWithoutPathExpansion(
+ ExternalProviderImpl::kExternalUpdateUrl, &update_url)) {
+ internal::IndividualSettings* by_id = AccessById(it.key());
+ by_id->installation_mode = INSTALLATION_FORCED;
+ by_id->update_url = update_url;
+ }
+ }
+}
+
internal::IndividualSettings* ExtensionManagement::AccessById(
const ExtensionId& id) {
DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id;
@@ -484,8 +501,7 @@ KeyedService* ExtensionManagementFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
TRACE_EVENT0("browser,startup",
"ExtensionManagementFactory::BuildServiceInstanceFor");
- return new ExtensionManagement(
- Profile::FromBrowserContext(context)->GetPrefs());
+ return new ExtensionManagement(Profile::FromBrowserContext(context));
}
content::BrowserContext* ExtensionManagementFactory::GetBrowserContextToUse(

Powered by Google App Engine
This is Rietveld 408576698