diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 14:02:24 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-14 14:02:24 +0000 |
commit | e410b5f18f1e98c64a1a617ea3c73b49ce9388a7 (patch) | |
tree | 34f01ba4152399555acd13b1962ecd8ba4a4033d /chrome/browser/extensions/external_policy_loader.cc | |
parent | 6644f3ae3288b60f310d1b4310b6bfa9c2e7cce3 (diff) | |
download | chromium_src-e410b5f18f1e98c64a1a617ea3c73b49ce9388a7.zip chromium_src-e410b5f18f1e98c64a1a617ea3c73b49ce9388a7.tar.gz chromium_src-e410b5f18f1e98c64a1a617ea3c73b49ce9388a7.tar.bz2 |
Switch prefs::kExtensionInstallForceList to be a dictionary.
This makes lots of code easier. The conversion from policy to prefs is
now done in the right place, reporting errors in about:policy.
BUG=chromium:166067
TEST=unit tests.
Review URL: https://codereview.chromium.org/11566024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173151 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/external_policy_loader.cc')
-rw-r--r-- | chrome/browser/extensions/external_policy_loader.cc | 63 |
1 files changed, 16 insertions, 47 deletions
diff --git a/chrome/browser/extensions/external_policy_loader.cc b/chrome/browser/extensions/external_policy_loader.cc index 6df0304c..e3eaa38 100644 --- a/chrome/browser/extensions/external_policy_loader.cc +++ b/chrome/browser/extensions/external_policy_loader.cc @@ -5,39 +5,19 @@ #include "chrome/browser/extensions/external_policy_loader.h" #include "base/logging.h" +#include "base/stringprintf.h" #include "base/values.h" +#include "chrome/browser/extensions/external_provider_impl.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" -#include "chrome/common/extensions/extension.h" #include "chrome/common/pref_names.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" -#include "googleurl/src/gurl.h" namespace extensions { -namespace { - -// Check an extension ID and an URL to be syntactically correct. -bool CheckExtension(const std::string& id, const std::string& update_url) { - GURL url(update_url); - if (!url.is_valid()) { - LOG(WARNING) << "Policy specifies invalid update URL for external " - << "extension: " << update_url; - return false; - } - if (!Extension::IdIsValid(id)) { - LOG(WARNING) << "Policy specifies invalid ID for external " - << "extension: " << id; - return false; - } - return true; -} - -} // namespace - ExternalPolicyLoader::ExternalPolicyLoader(Profile* profile) : profile_(profile) { pref_change_registrar_.Init(profile_->GetPrefs()); @@ -49,31 +29,13 @@ ExternalPolicyLoader::ExternalPolicyLoader(Profile* profile) content::Source<Profile>(profile_)); } -void ExternalPolicyLoader::StartLoading() { - const ListValue* forcelist = - profile_->GetPrefs()->GetList(prefs::kExtensionInstallForceList); - DictionaryValue* result = new DictionaryValue(); - if (forcelist != NULL) { - std::string extension_desc; - for (ListValue::const_iterator it = forcelist->begin(); - it != forcelist->end(); ++it) { - if (!(*it)->GetAsString(&extension_desc)) { - LOG(WARNING) << "Failed to read forcelist string."; - } else { - // Each string item of the list has the following form: - // extension_id_code;extension_update_url - // The update URL might also contain semicolons. - size_t pos = extension_desc.find(';'); - std::string id = extension_desc.substr(0, pos); - std::string update_url = extension_desc.substr(pos+1); - if (CheckExtension(id, update_url)) { - result->SetString(id + ".external_update_url", update_url); - } - } - } - } - prefs_.reset(result); - LoadFinished(); +// static +void ExternalPolicyLoader::AddExtension(base::DictionaryValue* dict, + const std::string& extension_id, + const std::string& update_url) { + dict->SetString(base::StringPrintf("%s.%s", extension_id.c_str(), + ExternalProviderImpl::kExternalUpdateUrl), + update_url); } void ExternalPolicyLoader::Observe( @@ -90,4 +52,11 @@ void ExternalPolicyLoader::Observe( } } +void ExternalPolicyLoader::StartLoading() { + const DictionaryValue* forcelist = + profile_->GetPrefs()->GetDictionary(prefs::kExtensionInstallForceList); + prefs_.reset(forcelist ? forcelist->DeepCopy() : NULL); + LoadFinished(); +} + } // namespace extensions |