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

Side by Side Diff: chrome/browser/policy/configuration_policy_pref_store.cc

Issue 7057009: Convert list policy to string preference. (DefaultSearchProviderEncodings). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review, rebase Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/policy/configuration_policy_pref_store.h" 5 #include "chrome/browser/policy/configuration_policy_pref_store.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // ownership of |value| in the case that the policy is recognized. 92 // ownership of |value| in the case that the policy is recognized.
93 bool ApplyDownloadDirPolicy(ConfigurationPolicyType policy, Value* value); 93 bool ApplyDownloadDirPolicy(ConfigurationPolicyType policy, Value* value);
94 94
95 // Processes file-selection dialogs policy. Returns true if the specified 95 // Processes file-selection dialogs policy. Returns true if the specified
96 // policy is the file-selection dialogs policy. 96 // policy is the file-selection dialogs policy.
97 // ApplyFileSelectionDialogsPolicy assumes the ownership of |value| in the 97 // ApplyFileSelectionDialogsPolicy assumes the ownership of |value| in the
98 // case that the policy is recognized. 98 // case that the policy is recognized.
99 bool ApplyFileSelectionDialogsPolicy(ConfigurationPolicyType policy, 99 bool ApplyFileSelectionDialogsPolicy(ConfigurationPolicyType policy,
100 Value* value); 100 Value* value);
101 101
102 // Processes default search provider policies. Returns true if the specified
103 // policy is a default search provider related policy. In that case,
104 // ApplyDefaultSearchPolicy takes ownership of |value|.
105 bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value);
106
102 // Make sure that the |path| if present in |prefs_|. If not, set it to 107 // Make sure that the |path| if present in |prefs_|. If not, set it to
103 // a blank string. 108 // a blank string.
104 void EnsureStringPrefExists(const std::string& path); 109 void EnsureStringPrefExists(const std::string& path);
105 110
106 // If the required entries for default search are specified and valid, 111 // If the required entries for default search are specified and valid,
107 // finalizes the policy-specified configuration by initializing the 112 // finalizes the policy-specified configuration by initializing the
108 // unspecified map entries. Otherwise wipes all default search related 113 // unspecified map entries. Otherwise wipes all default search related
109 // map entries from |prefs_|. 114 // map entries from |prefs_|.
110 void FinalizeDefaultSearchPolicySettings(); 115 void FinalizeDefaultSearchPolicySettings();
111 116
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword, 284 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword,
280 prefs::kDefaultSearchProviderKeyword }, 285 prefs::kDefaultSearchProviderKeyword },
281 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL, 286 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL,
282 prefs::kDefaultSearchProviderSearchURL }, 287 prefs::kDefaultSearchProviderSearchURL },
283 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL, 288 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL,
284 prefs::kDefaultSearchProviderSuggestURL }, 289 prefs::kDefaultSearchProviderSuggestURL },
285 { Value::TYPE_STRING, kPolicyDefaultSearchProviderInstantURL, 290 { Value::TYPE_STRING, kPolicyDefaultSearchProviderInstantURL,
286 prefs::kDefaultSearchProviderInstantURL }, 291 prefs::kDefaultSearchProviderInstantURL },
287 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, 292 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL,
288 prefs::kDefaultSearchProviderIconURL }, 293 prefs::kDefaultSearchProviderIconURL },
289 { Value::TYPE_STRING, kPolicyDefaultSearchProviderEncodings, 294 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings,
290 prefs::kDefaultSearchProviderEncodings }, 295 prefs::kDefaultSearchProviderEncodings },
291 }; 296 };
292 297
293 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( 298 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper(
294 ConfigurationPolicyProvider* provider) { 299 ConfigurationPolicyProvider* provider) {
295 if (!provider->Provide(this)) 300 if (!provider->Provide(this))
296 LOG(WARNING) << "Failed to get policy from provider."; 301 LOG(WARNING) << "Failed to get policy from provider.";
297 FinalizeProxyPolicySettings(); 302 FinalizeProxyPolicySettings();
298 FinalizeDefaultSearchPolicySettings(); 303 FinalizeDefaultSearchPolicySettings();
299 } 304 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 339
335 if (ApplyAutofillPolicy(policy, value)) 340 if (ApplyAutofillPolicy(policy, value))
336 return; 341 return;
337 342
338 if (ApplyDownloadDirPolicy(policy, value)) 343 if (ApplyDownloadDirPolicy(policy, value))
339 return; 344 return;
340 345
341 if (ApplyFileSelectionDialogsPolicy(policy, value)) 346 if (ApplyFileSelectionDialogsPolicy(policy, value))
342 return; 347 return;
343 348
344 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, 349 if (ApplyDefaultSearchPolicy(policy, value))
345 arraysize(kDefaultSearchPolicyMap)))
346 return; 350 return;
347 351
348 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, 352 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap,
349 arraysize(kSimplePolicyMap))) 353 arraysize(kSimplePolicyMap)))
350 return; 354 return;
351 355
352 // Other policy implementations go here. 356 // Other policy implementations go here.
353 NOTIMPLEMENTED(); 357 NOTIMPLEMENTED();
354 delete value; 358 delete value;
355 } 359 }
356 360
357 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap( 361 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap(
358 const PolicyToPreferenceMapEntry* map, int table_size) { 362 const PolicyToPreferenceMapEntry* map, int table_size) {
359 bool found_any = false; 363 bool found_any = false;
360 for (int i = 0; i < table_size; ++i) { 364 for (int i = 0; i < table_size; ++i) {
361 if (prefs_.RemoveValue(map[i].preference_path)) 365 if (prefs_.RemoveValue(map[i].preference_path))
362 found_any = true; 366 found_any = true;
363 } 367 }
364 return found_any; 368 return found_any;
365 } 369 }
366 370
367 bool ConfigurationPolicyPrefKeeper::ApplyPolicyFromMap( 371 bool ConfigurationPolicyPrefKeeper::ApplyPolicyFromMap(
368 ConfigurationPolicyType policy, 372 ConfigurationPolicyType policy,
369 Value* value, 373 Value* value,
370 const PolicyToPreferenceMapEntry* map, 374 const PolicyToPreferenceMapEntry* map,
371 int size) { 375 int size) {
372 for (int current = 0; current < size; ++current) { 376 for (int current = 0; current < size; ++current) {
373 if (map[current].policy_type == policy) { 377 if (map[current].policy_type == policy) {
374 DCHECK_EQ(map[current].value_type, value->GetType()) 378 DCHECK_EQ(map[current].value_type, value->GetType())
375 << "mismatch in provided and expected policy value for preferences" 379 << "mismatch in provided and expected policy value for preferences "
376 << map[current].preference_path << ". expected = " 380 << map[current].preference_path << ". expected = "
377 << map[current].value_type << ", actual = "<< value->GetType(); 381 << map[current].value_type << ", actual = "<< value->GetType();
378 prefs_.SetValue(map[current].preference_path, value); 382 prefs_.SetValue(map[current].preference_path, value);
379 return true; 383 return true;
380 } 384 }
381 } 385 }
382 return false; 386 return false;
383 } 387 }
384 388
385 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( 389 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (!allow_file_selection_dialogs) { 471 if (!allow_file_selection_dialogs) {
468 prefs_.SetValue(prefs::kPromptForDownload, 472 prefs_.SetValue(prefs::kPromptForDownload,
469 Value::CreateBooleanValue(false)); 473 Value::CreateBooleanValue(false));
470 } 474 }
471 return true; 475 return true;
472 } 476 }
473 // We are not interested in this policy. 477 // We are not interested in this policy.
474 return false; 478 return false;
475 } 479 }
476 480
481 bool ConfigurationPolicyPrefKeeper::ApplyDefaultSearchPolicy(
482 ConfigurationPolicyType policy,
483 Value* value) {
484 // The DefaultSearchProviderEncodings policy has type list, but the related
485 // preference has type string. Convert one into the other here, using
486 // ';' as a separator.
487 if (policy == kPolicyDefaultSearchProviderEncodings) {
488 ListValue* list;
489 if (!value->GetAsList(&list)) {
490 NOTREACHED()
491 << "mismatch in provided and expected policy value for preferences "
492 << prefs::kDefaultSearchProviderEncodings << ". expected = "
493 << Value::TYPE_LIST << ", actual = "<< value->GetType();
494 return false;
495 }
496 ListValue::const_iterator iter(list->begin());
497 ListValue::const_iterator end(list->end());
498 std::string encodings;
499 for (; iter != end; ++iter) {
500 std::string s;
501 if ((*iter)->GetAsString(&s)) {
502 if (!encodings.empty())
503 encodings.push_back(';');
504 encodings.append(s);
505 } else {
506 NOTREACHED();
507 }
508 }
509 // We own |value|.
510 delete value;
511 prefs_.SetValue(prefs::kDefaultSearchProviderEncodings,
512 Value::CreateStringValue(encodings));
513 return true;
514 }
515
516 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap,
517 arraysize(kDefaultSearchPolicyMap))) {
518 return true;
519 }
520 return false;
521 }
522
477 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( 523 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists(
478 const std::string& path) { 524 const std::string& path) {
479 std::string value; 525 std::string value;
480 if (!prefs_.GetString(path, &value)) 526 if (!prefs_.GetString(path, &value))
481 prefs_.SetString(path, value); 527 prefs_.SetString(path, value);
482 } 528 }
483 529
484 namespace { 530 namespace {
485 531
486 // Implementation of SearchTermsData just for validation. 532 // Implementation of SearchTermsData just for validation.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 } 722 }
677 return true; 723 return true;
678 } 724 }
679 725
680 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { 726 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() {
681 ProxyPrefs::ProxyMode mode; 727 ProxyPrefs::ProxyMode mode;
682 if (HasProxyPolicy(kPolicyProxyMode)) { 728 if (HasProxyPolicy(kPolicyProxyMode)) {
683 std::string string_mode; 729 std::string string_mode;
684 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode)); 730 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode));
685 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) { 731 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) {
686 LOG(WARNING) << "A centrally-administered policy specifies a value for" 732 LOG(WARNING) << "A centrally-administered policy specifies a value for "
687 << "the ProxyMode policy that isn't recognized."; 733 << "the ProxyMode policy that isn't recognized.";
688 return; 734 return;
689 } 735 }
690 } else if (HasProxyPolicy(kPolicyProxyServerMode)) { 736 } else if (HasProxyPolicy(kPolicyProxyServerMode)) {
691 int int_mode = 0; 737 int int_mode = 0;
692 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode)); 738 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode));
693 switch (int_mode) { 739 switch (int_mode) {
694 case kPolicyNoProxyServerMode: 740 case kPolicyNoProxyServerMode:
695 mode = ProxyPrefs::MODE_DIRECT; 741 mode = ProxyPrefs::MODE_DIRECT;
696 break; 742 break;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, 936 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING,
891 key::kDefaultSearchProviderKeyword }, 937 key::kDefaultSearchProviderKeyword },
892 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, 938 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING,
893 key::kDefaultSearchProviderSearchURL }, 939 key::kDefaultSearchProviderSearchURL },
894 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, 940 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING,
895 key::kDefaultSearchProviderSuggestURL }, 941 key::kDefaultSearchProviderSuggestURL },
896 { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING, 942 { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING,
897 key::kDefaultSearchProviderInstantURL }, 943 key::kDefaultSearchProviderInstantURL },
898 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, 944 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING,
899 key::kDefaultSearchProviderIconURL }, 945 key::kDefaultSearchProviderIconURL },
900 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, 946 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_LIST,
901 key::kDefaultSearchProviderEncodings }, 947 key::kDefaultSearchProviderEncodings },
902 { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode }, 948 { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode },
903 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode }, 949 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode },
904 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, 950 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer },
905 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, 951 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl },
906 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, 952 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList },
907 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, 953 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN,
908 key::kAlternateErrorPagesEnabled }, 954 key::kAlternateErrorPagesEnabled },
909 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, 955 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN,
910 key::kSearchSuggestEnabled }, 956 key::kSearchSuggestEnabled },
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 // Update the initialization flag. 1099 // Update the initialization flag.
1054 if (!initialization_complete_ && 1100 if (!initialization_complete_ &&
1055 provider_->IsInitializationComplete()) { 1101 provider_->IsInitializationComplete()) {
1056 initialization_complete_ = true; 1102 initialization_complete_ = true;
1057 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 1103 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1058 OnInitializationCompleted(true)); 1104 OnInitializationCompleted(true));
1059 } 1105 }
1060 } 1106 }
1061 1107
1062 } // namespace policy 1108 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698