Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 // None of the types has been fixed for backwards compatibility. | |
|
Mattias Nissler (ping if slow)
2011/05/20 16:56:16
That comment only adds confusion. If you think tha
| |
| 488 if (policy == kPolicyDefaultSearchProviderEncodings) { | |
| 489 ListValue* list; | |
| 490 if (!value->GetAsList(&list)) { | |
| 491 NOTREACHED() | |
| 492 << "mismatch in provided and expected policy value for preferences " | |
| 493 << prefs::kDefaultSearchProviderEncodings << ". expected = " | |
| 494 << Value::TYPE_LIST << ", actual = "<< value->GetType(); | |
| 495 return false; | |
| 496 } | |
| 497 ListValue::const_iterator iter(list->begin()); | |
| 498 ListValue::const_iterator end(list->end()); | |
| 499 std::string encodings; | |
| 500 for (; iter != end; ++iter) { | |
| 501 std::string s; | |
| 502 if ((*iter)->GetAsString(&s)) { | |
| 503 if (!encodings.empty()) | |
| 504 encodings.push_back(';'); | |
| 505 encodings.append(s); | |
| 506 } else { | |
| 507 NOTREACHED(); | |
| 508 } | |
| 509 } | |
| 510 // We own |value|. | |
| 511 delete value; | |
| 512 prefs_.SetValue(prefs::kDefaultSearchProviderEncodings, | |
| 513 Value::CreateStringValue(encodings)); | |
| 514 return true; | |
| 515 } | |
| 516 | |
| 517 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, | |
| 518 arraysize(kDefaultSearchPolicyMap))) { | |
| 519 return true; | |
| 520 } | |
| 521 return false; | |
| 522 } | |
| 523 | |
| 477 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( | 524 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( |
| 478 const std::string& path) { | 525 const std::string& path) { |
| 479 std::string value; | 526 std::string value; |
| 480 if (!prefs_.GetString(path, &value)) | 527 if (!prefs_.GetString(path, &value)) |
| 481 prefs_.SetString(path, value); | 528 prefs_.SetString(path, value); |
| 482 } | 529 } |
| 483 | 530 |
| 484 namespace { | 531 namespace { |
| 485 | 532 |
| 486 // Implementation of SearchTermsData just for validation. | 533 // Implementation of SearchTermsData just for validation. |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 } | 723 } |
| 677 return true; | 724 return true; |
| 678 } | 725 } |
| 679 | 726 |
| 680 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { | 727 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { |
| 681 ProxyPrefs::ProxyMode mode; | 728 ProxyPrefs::ProxyMode mode; |
| 682 if (HasProxyPolicy(kPolicyProxyMode)) { | 729 if (HasProxyPolicy(kPolicyProxyMode)) { |
| 683 std::string string_mode; | 730 std::string string_mode; |
| 684 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode)); | 731 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode)); |
| 685 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) { | 732 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) { |
| 686 LOG(WARNING) << "A centrally-administered policy specifies a value for" | 733 LOG(WARNING) << "A centrally-administered policy specifies a value for " |
| 687 << "the ProxyMode policy that isn't recognized."; | 734 << "the ProxyMode policy that isn't recognized."; |
| 688 return; | 735 return; |
| 689 } | 736 } |
| 690 } else if (HasProxyPolicy(kPolicyProxyServerMode)) { | 737 } else if (HasProxyPolicy(kPolicyProxyServerMode)) { |
| 691 int int_mode = 0; | 738 int int_mode = 0; |
| 692 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode)); | 739 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode)); |
| 693 switch (int_mode) { | 740 switch (int_mode) { |
| 694 case kPolicyNoProxyServerMode: | 741 case kPolicyNoProxyServerMode: |
| 695 mode = ProxyPrefs::MODE_DIRECT; | 742 mode = ProxyPrefs::MODE_DIRECT; |
| 696 break; | 743 break; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 890 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, | 937 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, |
| 891 key::kDefaultSearchProviderKeyword }, | 938 key::kDefaultSearchProviderKeyword }, |
| 892 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, | 939 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, |
| 893 key::kDefaultSearchProviderSearchURL }, | 940 key::kDefaultSearchProviderSearchURL }, |
| 894 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, | 941 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, |
| 895 key::kDefaultSearchProviderSuggestURL }, | 942 key::kDefaultSearchProviderSuggestURL }, |
| 896 { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING, | 943 { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING, |
| 897 key::kDefaultSearchProviderInstantURL }, | 944 key::kDefaultSearchProviderInstantURL }, |
| 898 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, | 945 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, |
| 899 key::kDefaultSearchProviderIconURL }, | 946 key::kDefaultSearchProviderIconURL }, |
| 900 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, | 947 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_LIST, |
| 901 key::kDefaultSearchProviderEncodings }, | 948 key::kDefaultSearchProviderEncodings }, |
| 902 { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode }, | 949 { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode }, |
| 903 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode }, | 950 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode }, |
| 904 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, | 951 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, |
| 905 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, | 952 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, |
| 906 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, | 953 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, |
| 907 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, | 954 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, |
| 908 key::kAlternateErrorPagesEnabled }, | 955 key::kAlternateErrorPagesEnabled }, |
| 909 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, | 956 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, |
| 910 key::kSearchSuggestEnabled }, | 957 key::kSearchSuggestEnabled }, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1053 // Update the initialization flag. | 1100 // Update the initialization flag. |
| 1054 if (!initialization_complete_ && | 1101 if (!initialization_complete_ && |
| 1055 provider_->IsInitializationComplete()) { | 1102 provider_->IsInitializationComplete()) { |
| 1056 initialization_complete_ = true; | 1103 initialization_complete_ = true; |
| 1057 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | 1104 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, |
| 1058 OnInitializationCompleted(true)); | 1105 OnInitializationCompleted(true)); |
| 1059 } | 1106 } |
| 1060 } | 1107 } |
| 1061 | 1108 |
| 1062 } // namespace policy | 1109 } // namespace policy |
| OLD | NEW |