OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 return false; | 364 return false; |
365 } | 365 } |
366 | 366 |
367 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( | 367 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( |
368 ConfigurationPolicyType policy, | 368 ConfigurationPolicyType policy, |
369 Value* value) { | 369 Value* value) { |
370 // We only collect the values until we have sufficient information when | 370 // We only collect the values until we have sufficient information when |
371 // FinalizeProxyPolicySettings() is called to determine whether the presented | 371 // FinalizeProxyPolicySettings() is called to determine whether the presented |
372 // values were correct and apply them in that case. | 372 // values were correct and apply them in that case. |
373 if (policy == kPolicyProxyMode || | 373 if (policy == kPolicyProxyMode || |
374 policy == kPolicyProxyServerMode || | |
374 policy == kPolicyProxyServer || | 375 policy == kPolicyProxyServer || |
375 policy == kPolicyProxyPacUrl || | 376 policy == kPolicyProxyPacUrl || |
376 policy == kPolicyProxyBypassList) { | 377 policy == kPolicyProxyBypassList) { |
377 delete proxy_policies_[policy]; | 378 delete proxy_policies_[policy]; |
378 proxy_policies_[policy] = value; | 379 proxy_policies_[policy] = value; |
379 return true; | 380 return true; |
380 } | 381 } |
381 // We are not interested in this policy. | 382 // We are not interested in this policy. |
382 return false; | 383 return false; |
383 } | 384 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { | 491 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { |
491 if (CheckProxySettings()) | 492 if (CheckProxySettings()) |
492 ApplyProxySettings(); | 493 ApplyProxySettings(); |
493 | 494 |
494 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), | 495 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), |
495 proxy_policies_.end()); | 496 proxy_policies_.end()); |
496 proxy_policies_.clear(); | 497 proxy_policies_.clear(); |
497 } | 498 } |
498 | 499 |
499 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { | 500 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { |
500 bool mode = HasProxyPolicy(kPolicyProxyMode); | 501 bool mode = HasProxyPolicy(kPolicyProxyMode); |
battre
2011/01/03 13:19:16
Add comment "deprecated"?
danno
2011/01/07 12:24:25
Done.
| |
502 bool server_mode = HasProxyPolicy(kPolicyProxyServerMode); | |
501 bool server = HasProxyPolicy(kPolicyProxyServer); | 503 bool server = HasProxyPolicy(kPolicyProxyServer); |
502 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); | 504 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); |
503 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); | 505 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); |
504 | 506 |
505 if ((server || pac_url || bypass_list) && !mode) { | 507 if ((server || pac_url || bypass_list) && !(mode || server_mode)) { |
506 LOG(WARNING) << "A centrally-administered policy defines proxy setting" | 508 LOG(WARNING) << "A centrally-administered policy defines proxy setting" |
507 << " details without setting a proxy mode."; | 509 << " details without setting a proxy mode."; |
508 return false; | 510 return false; |
509 } | 511 } |
510 | 512 |
511 if (!mode) | 513 // If there's a server mode, convert it info a mode. |
gfeher
2011/01/03 10:30:10
Not: into
danno
2011/01/07 12:24:25
Done.
| |
512 return true; | 514 std::string mode_value; |
515 if (mode) { | |
516 if (!proxy_policies_[kPolicyProxyMode]->GetAsString(&mode_value)) { | |
517 LOG(WARNING) << "Invalid ProxyMode value."; | |
518 return false; | |
519 } | |
520 } else if (server_mode) { | |
521 int server_mode_value; | |
522 if (!proxy_policies_[kPolicyProxyServerMode]->GetAsInteger( | |
523 &server_mode_value)) { | |
524 LOG(WARNING) << "Invalid ProxyServerMode value."; | |
525 return false; | |
526 } | |
513 | 527 |
514 int mode_value; | 528 switch (server_mode_value) { |
515 if (!proxy_policies_[kPolicyProxyMode]->GetAsInteger(&mode_value)) { | 529 case kPolicyNoProxyServerMode: |
516 LOG(WARNING) << "Invalid proxy mode value."; | 530 mode_value = ProxyPrefs::kDirectProxyModeName; |
517 return false; | 531 break; |
532 case kPolicyAutoDetectProxyServerMode: | |
533 mode_value = ProxyPrefs::kAutoDetectProxyModeName; | |
534 break; | |
535 case kPolicyManuallyConfiguredProxyServerMode: | |
536 if (server && pac_url) { | |
537 LOG(WARNING) << "A centrally-administered policy dictates that" | |
538 << " both a fixed proxy server and a .pac url. should" | |
539 << " be used for proxy configuration."; | |
540 return false; | |
541 } | |
542 if (!server && !pac_url) { | |
543 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
544 << " proxy settings should use either a fixed" | |
545 << " proxy server or a .pac url, but specifies neither."; | |
546 return false; | |
547 } | |
548 if (pac_url) | |
549 mode_value = ProxyPrefs::kPacScriptProxyModeName; | |
550 else | |
551 mode_value = ProxyPrefs::kFixedServersProxyModeName; | |
552 break; | |
553 case kPolicyUseSystemProxyServerMode: | |
554 mode_value = ProxyPrefs::kSystemProxyModeName; | |
555 break; | |
556 default: | |
557 LOG(WARNING) << "Invalid proxy mode " << server_mode_value; | |
558 return false; | |
559 } | |
518 } | 560 } |
519 | 561 |
520 switch (mode_value) { | 562 if (!mode_value.empty()) { |
521 case kPolicyNoProxyServerMode: | 563 if (mode_value == ProxyPrefs::kDirectProxyModeName) { |
522 if (server || pac_url || bypass_list) { | 564 if (server || pac_url || bypass_list) { |
523 LOG(WARNING) << "A centrally-administered policy disables the use of" | 565 LOG(WARNING) << "A centrally-administered policy disables the use of" |
524 << " a proxy but also specifies an explicit proxy" | 566 << " a proxy but also specifies an explicit proxy" |
525 << " configuration."; | 567 << " configuration."; |
526 return false; | 568 return false; |
527 } | 569 } |
528 break; | 570 } else if (mode_value == ProxyPrefs::kAutoDetectProxyModeName) { |
529 case kPolicyAutoDetectProxyMode: | 571 if (server || bypass_list || pac_url) { |
530 if (server || bypass_list) { | |
531 LOG(WARNING) << "A centrally-administered policy dictates that a proxy" | 572 LOG(WARNING) << "A centrally-administered policy dictates that a proxy" |
532 << " shall be auto configured but specifies fixed proxy" | 573 << " shall be auto configured but specifies fixed proxy" |
533 << " servers or a by-pass list."; | 574 << " servers, a by-pass list or a .pac script URL."; |
534 return false; | 575 return false; |
535 } | 576 } |
536 break; | 577 } else if (mode_value == ProxyPrefs::kPacScriptProxyModeName) { |
537 case kPolicyManuallyConfiguredProxyMode: | 578 if (server || bypass_list) { |
538 if (!server) { | 579 LOG(WARNING) << "A centrally-administered policy dictates that a .pac" |
539 LOG(WARNING) << "A centrally-administered policy dictates that the" | 580 << " script URL should be used for proxy configuration but" |
540 << " system proxy settings should use fixed proxy servers" | 581 << " also specifies policies required only for fixed" |
541 << " without specifying which ones."; | 582 << " proxy servers."; |
542 return false; | 583 return false; |
543 } | 584 } |
585 } else if (mode_value == ProxyPrefs::kFixedServersProxyModeName) { | |
544 if (pac_url) { | 586 if (pac_url) { |
545 LOG(WARNING) << "A centrally-administered policy dictates that the" | 587 LOG(WARNING) << "A centrally-administered policy dictates that a" |
546 << " system proxy settings should use fixed proxy servers" | 588 << " fixed proxy server should be used but also" |
battre
2011/01/03 13:19:16
servers (plural)?
danno
2011/01/07 12:24:25
Done.
| |
547 << " but also specifies a PAC script."; | 589 << " specifies a .pac script URL."; |
548 return false; | 590 return false; |
549 } | 591 } |
550 break; | 592 } else if (mode_value == ProxyPrefs::kSystemProxyModeName) { |
551 case kPolicyUseSystemProxyMode: | |
552 if (server || pac_url || bypass_list) { | 593 if (server || pac_url || bypass_list) { |
553 LOG(WARNING) << "A centrally-administered policy dictates that the" | 594 LOG(WARNING) << "A centrally-administered policy dictates that the" |
554 << " system proxy settings should be used but also " | 595 << " system proxy settings should be used but also " |
555 << " specifies an explicit proxy configuration."; | 596 << " specifies an explicit proxy configuration."; |
556 return false; | 597 return false; |
557 } | 598 } |
558 break; | 599 } else { |
559 default: | |
560 LOG(WARNING) << "Invalid proxy mode " << mode_value; | 600 LOG(WARNING) << "Invalid proxy mode " << mode_value; |
561 return false; | 601 return false; |
602 } | |
562 } | 603 } |
563 return true; | 604 return true; |
564 } | 605 } |
565 | 606 |
566 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { | 607 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { |
567 if (!HasProxyPolicy(kPolicyProxyMode)) | |
568 return; | |
569 | |
570 int int_mode; | |
571 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsInteger(&int_mode)); | |
572 ProxyPrefs::ProxyMode mode; | 608 ProxyPrefs::ProxyMode mode; |
573 switch (int_mode) { | 609 if (HasProxyPolicy(kPolicyProxyMode)) { |
574 case kPolicyNoProxyServerMode: | 610 std::string string_mode; |
gfeher
2011/01/03 10:30:10
Why not use ProxyPrefs::StringToProxyMode here?
danno
2011/01/07 12:24:25
Done.
| |
611 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode)); | |
612 if (string_mode == std::string(ProxyPrefs::kDirectProxyModeName)) { | |
575 mode = ProxyPrefs::MODE_DIRECT; | 613 mode = ProxyPrefs::MODE_DIRECT; |
576 break; | 614 } else if (string_mode == |
577 case kPolicyAutoDetectProxyMode: | 615 std::string(ProxyPrefs::kAutoDetectProxyModeName)) { |
578 mode = ProxyPrefs::MODE_AUTO_DETECT; | 616 mode = ProxyPrefs::MODE_AUTO_DETECT; |
579 if (HasProxyPolicy(kPolicyProxyPacUrl)) | 617 } else if (string_mode == |
580 mode = ProxyPrefs::MODE_PAC_SCRIPT; | 618 std::string(ProxyPrefs::kFixedServersProxyModeName)) { |
581 break; | |
582 case kPolicyManuallyConfiguredProxyMode: | |
583 mode = ProxyPrefs::MODE_FIXED_SERVERS; | 619 mode = ProxyPrefs::MODE_FIXED_SERVERS; |
584 break; | 620 } else if (string_mode == |
585 case kPolicyUseSystemProxyMode: | 621 std::string(ProxyPrefs::kPacScriptProxyModeName)) { |
622 mode = ProxyPrefs::MODE_PAC_SCRIPT; | |
623 } else if (string_mode == | |
624 std::string(ProxyPrefs::kSystemProxyModeName)) { | |
586 mode = ProxyPrefs::MODE_SYSTEM; | 625 mode = ProxyPrefs::MODE_SYSTEM; |
587 break; | 626 } else { |
588 default: | |
589 mode = ProxyPrefs::MODE_DIRECT; | 627 mode = ProxyPrefs::MODE_DIRECT; |
590 NOTREACHED(); | 628 NOTREACHED(); |
629 } | |
630 } else if (HasProxyPolicy(kPolicyProxyServerMode)) { | |
631 int int_mode = 0; | |
632 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode)); | |
633 switch (int_mode) { | |
634 case kPolicyNoProxyServerMode: | |
635 mode = ProxyPrefs::MODE_DIRECT; | |
636 break; | |
637 case kPolicyAutoDetectProxyServerMode: | |
638 mode = ProxyPrefs::MODE_AUTO_DETECT; | |
639 break; | |
640 case kPolicyManuallyConfiguredProxyServerMode: | |
641 mode = ProxyPrefs::MODE_FIXED_SERVERS; | |
642 if (HasProxyPolicy(kPolicyProxyPacUrl)) | |
643 mode = ProxyPrefs::MODE_PAC_SCRIPT; | |
644 break; | |
645 case kPolicyUseSystemProxyServerMode: | |
646 mode = ProxyPrefs::MODE_SYSTEM; | |
647 break; | |
648 default: | |
649 mode = ProxyPrefs::MODE_DIRECT; | |
650 NOTREACHED(); | |
651 } | |
652 } else { | |
653 return; | |
591 } | 654 } |
592 prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode)); | 655 prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode)); |
593 | 656 |
594 if (HasProxyPolicy(kPolicyProxyServer)) { | 657 if (HasProxyPolicy(kPolicyProxyServer)) { |
595 prefs_.SetValue(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]); | 658 prefs_.SetValue(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]); |
596 proxy_policies_[kPolicyProxyServer] = NULL; | 659 proxy_policies_[kPolicyProxyServer] = NULL; |
597 } else { | 660 } else { |
598 prefs_.SetValue(prefs::kProxyServer, Value::CreateNullValue()); | 661 prefs_.SetValue(prefs::kProxyServer, Value::CreateNullValue()); |
599 } | 662 } |
600 if (HasProxyPolicy(kPolicyProxyPacUrl)) { | 663 if (HasProxyPolicy(kPolicyProxyPacUrl)) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, | 853 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, |
791 key::kDefaultSearchProviderKeyword }, | 854 key::kDefaultSearchProviderKeyword }, |
792 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, | 855 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, |
793 key::kDefaultSearchProviderSearchURL }, | 856 key::kDefaultSearchProviderSearchURL }, |
794 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, | 857 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, |
795 key::kDefaultSearchProviderSuggestURL }, | 858 key::kDefaultSearchProviderSuggestURL }, |
796 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, | 859 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, |
797 key::kDefaultSearchProviderIconURL }, | 860 key::kDefaultSearchProviderIconURL }, |
798 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, | 861 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, |
799 key::kDefaultSearchProviderEncodings }, | 862 key::kDefaultSearchProviderEncodings }, |
800 { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode }, | 863 { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode }, |
864 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode }, | |
801 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, | 865 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, |
802 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, | 866 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, |
803 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, | 867 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, |
804 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, | 868 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, |
805 key::kAlternateErrorPagesEnabled }, | 869 key::kAlternateErrorPagesEnabled }, |
806 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, | 870 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, |
807 key::kSearchSuggestEnabled }, | 871 key::kSearchSuggestEnabled }, |
808 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, | 872 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, |
809 key::kDnsPrefetchingEnabled }, | 873 key::kDnsPrefetchingEnabled }, |
810 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, | 874 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 // Update the initialization flag. | 960 // Update the initialization flag. |
897 if (!initialization_complete_ && | 961 if (!initialization_complete_ && |
898 provider_->IsInitializationComplete()) { | 962 provider_->IsInitializationComplete()) { |
899 initialization_complete_ = true; | 963 initialization_complete_ = true; |
900 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | 964 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, |
901 OnInitializationCompleted()); | 965 OnInitializationCompleted()); |
902 } | 966 } |
903 } | 967 } |
904 | 968 |
905 } // namespace policy | 969 } // namespace policy |
OLD | NEW |