summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-23 11:52:44 +0000
committerjoaodasilva@chromium.org <joaodasilva@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-23 11:52:44 +0000
commit6e11fb622aec8af66c696947cc845683494281b8 (patch)
tree905433f89522f9ff623b85158788cc5ff9e9f29e /chrome
parent18b5f68419a1d3d7f04caab6a909702500aaa065 (diff)
downloadchromium_src-6e11fb622aec8af66c696947cc845683494281b8.zip
chromium_src-6e11fb622aec8af66c696947cc845683494281b8.tar.gz
chromium_src-6e11fb622aec8af66c696947cc845683494281b8.tar.bz2
Convert list policy to string preference. (DefaultSearchProviderEncodings).
Also adapted the unit_tests. BUG=None TEST=None Review URL: http://codereview.chromium.org/7057009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/policy/config_dir_policy_provider_unittest.cc2
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store.cc58
-rw-r--r--chrome/browser/policy/configuration_policy_pref_store_unittest.cc23
-rw-r--r--chrome/browser/policy/configuration_policy_provider_mac_unittest.cc2
-rw-r--r--chrome/browser/policy/configuration_policy_provider_win_unittest.cc2
5 files changed, 68 insertions, 19 deletions
diff --git a/chrome/browser/policy/config_dir_policy_provider_unittest.cc b/chrome/browser/policy/config_dir_policy_provider_unittest.cc
index 51b8beb..a5c3216 100644
--- a/chrome/browser/policy/config_dir_policy_provider_unittest.cc
+++ b/chrome/browser/policy/config_dir_policy_provider_unittest.cc
@@ -258,7 +258,7 @@ INSTANTIATE_TEST_CASE_P(
ValueTestParams::ForStringPolicy(
kPolicyDefaultSearchProviderIconURL,
key::kDefaultSearchProviderIconURL),
- ValueTestParams::ForStringPolicy(
+ ValueTestParams::ForListPolicy(
kPolicyDefaultSearchProviderEncodings,
key::kDefaultSearchProviderEncodings),
ValueTestParams::ForStringPolicy(
diff --git a/chrome/browser/policy/configuration_policy_pref_store.cc b/chrome/browser/policy/configuration_policy_pref_store.cc
index a3b2295..c94863d 100644
--- a/chrome/browser/policy/configuration_policy_pref_store.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store.cc
@@ -99,6 +99,11 @@ class ConfigurationPolicyPrefKeeper
bool ApplyFileSelectionDialogsPolicy(ConfigurationPolicyType policy,
Value* value);
+ // Processes default search provider policies. Returns true if the specified
+ // policy is a default search provider related policy. In that case,
+ // ApplyDefaultSearchPolicy takes ownership of |value|.
+ bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value);
+
// Make sure that the |path| if present in |prefs_|. If not, set it to
// a blank string.
void EnsureStringPrefExists(const std::string& path);
@@ -286,7 +291,7 @@ const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry
prefs::kDefaultSearchProviderInstantURL },
{ Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL,
prefs::kDefaultSearchProviderIconURL },
- { Value::TYPE_STRING, kPolicyDefaultSearchProviderEncodings,
+ { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings,
prefs::kDefaultSearchProviderEncodings },
};
@@ -341,8 +346,7 @@ void ConfigurationPolicyPrefKeeper::Apply(ConfigurationPolicyType policy,
if (ApplyFileSelectionDialogsPolicy(policy, value))
return;
- if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap,
- arraysize(kDefaultSearchPolicyMap)))
+ if (ApplyDefaultSearchPolicy(policy, value))
return;
if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap,
@@ -372,7 +376,7 @@ bool ConfigurationPolicyPrefKeeper::ApplyPolicyFromMap(
for (int current = 0; current < size; ++current) {
if (map[current].policy_type == policy) {
DCHECK_EQ(map[current].value_type, value->GetType())
- << "mismatch in provided and expected policy value for preferences"
+ << "mismatch in provided and expected policy value for preferences "
<< map[current].preference_path << ". expected = "
<< map[current].value_type << ", actual = "<< value->GetType();
prefs_.SetValue(map[current].preference_path, value);
@@ -474,6 +478,48 @@ bool ConfigurationPolicyPrefKeeper::ApplyFileSelectionDialogsPolicy(
return false;
}
+bool ConfigurationPolicyPrefKeeper::ApplyDefaultSearchPolicy(
+ ConfigurationPolicyType policy,
+ Value* value) {
+ // The DefaultSearchProviderEncodings policy has type list, but the related
+ // preference has type string. Convert one into the other here, using
+ // ';' as a separator.
+ if (policy == kPolicyDefaultSearchProviderEncodings) {
+ ListValue* list;
+ if (!value->GetAsList(&list)) {
+ NOTREACHED()
+ << "mismatch in provided and expected policy value for preferences "
+ << prefs::kDefaultSearchProviderEncodings << ". expected = "
+ << Value::TYPE_LIST << ", actual = "<< value->GetType();
+ return false;
+ }
+ ListValue::const_iterator iter(list->begin());
+ ListValue::const_iterator end(list->end());
+ std::string encodings;
+ for (; iter != end; ++iter) {
+ std::string s;
+ if ((*iter)->GetAsString(&s)) {
+ if (!encodings.empty())
+ encodings.push_back(';');
+ encodings.append(s);
+ } else {
+ NOTREACHED();
+ }
+ }
+ // We own |value|.
+ delete value;
+ prefs_.SetValue(prefs::kDefaultSearchProviderEncodings,
+ Value::CreateStringValue(encodings));
+ return true;
+ }
+
+ if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap,
+ arraysize(kDefaultSearchPolicyMap))) {
+ return true;
+ }
+ return false;
+}
+
void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists(
const std::string& path) {
std::string value;
@@ -683,7 +729,7 @@ void ConfigurationPolicyPrefKeeper::ApplyProxySettings() {
std::string string_mode;
CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode));
if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) {
- LOG(WARNING) << "A centrally-administered policy specifies a value for"
+ LOG(WARNING) << "A centrally-administered policy specifies a value for "
<< "the ProxyMode policy that isn't recognized.";
return;
}
@@ -897,7 +943,7 @@ ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() {
key::kDefaultSearchProviderInstantURL },
{ kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING,
key::kDefaultSearchProviderIconURL },
- { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING,
+ { kPolicyDefaultSearchProviderEncodings, Value::TYPE_LIST,
key::kDefaultSearchProviderEncodings },
{ kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode },
{ kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode },
diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
index f018077..b7f77dd 100644
--- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc
@@ -555,7 +555,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) {
const char* const icon_url = "http://test.com/icon.jpg";
const char* const name = "MyName";
const char* const keyword = "MyKeyword";
- const char* const encodings = "UTF-16;UTF-8";
+ ListValue* encodings = new ListValue();
+ encodings->Append(Value::CreateStringValue("UTF-16"));
+ encodings->Append(Value::CreateStringValue("UTF-8"));
MockConfigurationPolicyProvider provider;
provider.AddPolicy(kPolicyDefaultSearchProviderEnabled,
Value::CreateBooleanValue(true));
@@ -569,8 +571,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) {
Value::CreateStringValue(suggest_url));
provider.AddPolicy(kPolicyDefaultSearchProviderIconURL,
Value::CreateStringValue(icon_url));
- provider.AddPolicy(kPolicyDefaultSearchProviderEncodings,
- Value::CreateStringValue(encodings));
+ provider.AddPolicy(kPolicyDefaultSearchProviderEncodings, encodings);
scoped_refptr<ConfigurationPolicyPrefStore> store(
new ConfigurationPolicyPrefStore(&provider));
@@ -598,7 +599,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) {
EXPECT_EQ(PrefStore::READ_OK,
store->GetValue(prefs::kDefaultSearchProviderEncodings, &value));
- EXPECT_TRUE(StringValue(encodings).Equals(value));
+ EXPECT_TRUE(StringValue("UTF-16;UTF-8").Equals(value));
}
// Checks that if the default search policy is missing, that no elements of the
@@ -608,7 +609,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) {
const char* const icon_url = "http://test.com/icon.jpg";
const char* const name = "MyName";
const char* const keyword = "MyKeyword";
- const char* const encodings = "UTF-16;UTF-8";
+ ListValue* encodings = new ListValue();
+ encodings->Append(Value::CreateStringValue("UTF-16"));
+ encodings->Append(Value::CreateStringValue("UTF-8"));
MockConfigurationPolicyProvider provider;
provider.AddPolicy(kPolicyDefaultSearchProviderEnabled,
Value::CreateBooleanValue(true));
@@ -620,8 +623,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) {
Value::CreateStringValue(suggest_url));
provider.AddPolicy(kPolicyDefaultSearchProviderIconURL,
Value::CreateStringValue(icon_url));
- provider.AddPolicy(kPolicyDefaultSearchProviderEncodings,
- Value::CreateStringValue(encodings));
+ provider.AddPolicy(kPolicyDefaultSearchProviderEncodings, encodings);
scoped_refptr<ConfigurationPolicyPrefStore> store(
new ConfigurationPolicyPrefStore(&provider));
@@ -648,7 +650,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) {
const char* const icon_url = "http://test.com/icon.jpg";
const char* const name = "MyName";
const char* const keyword = "MyKeyword";
- const char* const encodings = "UTF-16;UTF-8";
+ ListValue* encodings = new ListValue();
+ encodings->Append(Value::CreateStringValue("UTF-16"));
+ encodings->Append(Value::CreateStringValue("UTF-8"));
MockConfigurationPolicyProvider provider;
provider.AddPolicy(kPolicyDefaultSearchProviderEnabled,
Value::CreateBooleanValue(true));
@@ -662,8 +666,7 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) {
Value::CreateStringValue(suggest_url));
provider.AddPolicy(kPolicyDefaultSearchProviderIconURL,
Value::CreateStringValue(icon_url));
- provider.AddPolicy(kPolicyDefaultSearchProviderEncodings,
- Value::CreateStringValue(encodings));
+ provider.AddPolicy(kPolicyDefaultSearchProviderEncodings, encodings);
scoped_refptr<ConfigurationPolicyPrefStore> store(
new ConfigurationPolicyPrefStore(&provider));
diff --git a/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc b/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc
index d22b1f1..53669c8 100644
--- a/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_provider_mac_unittest.cc
@@ -232,7 +232,7 @@ INSTANTIATE_TEST_CASE_P(
PolicyTestParams::ForStringPolicy(
kPolicyDefaultSearchProviderIconURL,
key::kDefaultSearchProviderIconURL),
- PolicyTestParams::ForStringPolicy(
+ PolicyTestParams::ForListPolicy(
kPolicyDefaultSearchProviderEncodings,
key::kDefaultSearchProviderEncodings),
PolicyTestParams::ForStringPolicy(
diff --git a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc
index 46efbbb..4817d0f 100644
--- a/chrome/browser/policy/configuration_policy_provider_win_unittest.cc
+++ b/chrome/browser/policy/configuration_policy_provider_win_unittest.cc
@@ -390,7 +390,7 @@ INSTANTIATE_TEST_CASE_P(
PolicyTestParams::ForStringPolicy(
kPolicyDefaultSearchProviderIconURL,
key::kDefaultSearchProviderIconURL),
- PolicyTestParams::ForStringPolicy(
+ PolicyTestParams::ForListPolicy(
kPolicyDefaultSearchProviderEncodings,
key::kDefaultSearchProviderEncodings),
PolicyTestParams::ForStringPolicy(