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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // finalizes the policy-specified configuration by initializing the | 99 // finalizes the policy-specified configuration by initializing the |
100 // unspecified map entries. Otherwise wipes all default search related | 100 // unspecified map entries. Otherwise wipes all default search related |
101 // map entries from |prefs_|. | 101 // map entries from |prefs_|. |
102 void FinalizeDefaultSearchPolicySettings(); | 102 void FinalizeDefaultSearchPolicySettings(); |
103 | 103 |
104 // If the required entries for the proxy settings are specified and valid, | 104 // If the required entries for the proxy settings are specified and valid, |
105 // finalizes the policy-specified configuration by initializing the | 105 // finalizes the policy-specified configuration by initializing the |
106 // respective values in |prefs_|. | 106 // respective values in |prefs_|. |
107 void FinalizeProxyPolicySettings(); | 107 void FinalizeProxyPolicySettings(); |
108 | 108 |
109 // Returns true if the policy values stored in proxy_* represent a valid | 109 // Returns true if the policy values stored in proxy_* represent a valid proxy |
110 // proxy configuration. | 110 // configuration, including the case in which there is no configuration at |
| 111 // all. |
111 bool CheckProxySettings(); | 112 bool CheckProxySettings(); |
112 | 113 |
113 // Assumes CheckProxySettings returns true and applies the values stored | 114 // Assumes CheckProxySettings returns true and applies the values stored |
114 // in proxy_*. | 115 // in proxy_*. |
115 void ApplyProxySettings(); | 116 void ApplyProxySettings(); |
116 | 117 |
117 bool HasProxyPolicy(ConfigurationPolicyType policy) const; | 118 bool HasProxyPolicy(ConfigurationPolicyType policy) const; |
118 | 119 |
119 // Temporary cache that stores values until FinalizeProxyPolicySettings() | 120 // Temporary cache that stores values until FinalizeProxyPolicySettings() |
120 // is called. | 121 // is called. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 return false; | 357 return false; |
357 } | 358 } |
358 | 359 |
359 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( | 360 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( |
360 ConfigurationPolicyType policy, | 361 ConfigurationPolicyType policy, |
361 Value* value) { | 362 Value* value) { |
362 // We only collect the values until we have sufficient information when | 363 // We only collect the values until we have sufficient information when |
363 // FinalizeProxyPolicySettings() is called to determine whether the presented | 364 // FinalizeProxyPolicySettings() is called to determine whether the presented |
364 // values were correct and apply them in that case. | 365 // values were correct and apply them in that case. |
365 if (policy == kPolicyProxyMode || | 366 if (policy == kPolicyProxyMode || |
| 367 policy == kPolicyProxyServerMode || |
366 policy == kPolicyProxyServer || | 368 policy == kPolicyProxyServer || |
367 policy == kPolicyProxyPacUrl || | 369 policy == kPolicyProxyPacUrl || |
368 policy == kPolicyProxyBypassList) { | 370 policy == kPolicyProxyBypassList) { |
369 delete proxy_policies_[policy]; | 371 delete proxy_policies_[policy]; |
370 proxy_policies_[policy] = value; | 372 proxy_policies_[policy] = value; |
371 return true; | 373 return true; |
372 } | 374 } |
373 // We are not interested in this policy. | 375 // We are not interested in this policy. |
374 return false; | 376 return false; |
375 } | 377 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 if (CheckProxySettings()) | 487 if (CheckProxySettings()) |
486 ApplyProxySettings(); | 488 ApplyProxySettings(); |
487 | 489 |
488 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), | 490 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), |
489 proxy_policies_.end()); | 491 proxy_policies_.end()); |
490 proxy_policies_.clear(); | 492 proxy_policies_.clear(); |
491 } | 493 } |
492 | 494 |
493 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { | 495 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { |
494 bool mode = HasProxyPolicy(kPolicyProxyMode); | 496 bool mode = HasProxyPolicy(kPolicyProxyMode); |
| 497 bool server_mode = HasProxyPolicy(kPolicyProxyServerMode); // deprecated |
495 bool server = HasProxyPolicy(kPolicyProxyServer); | 498 bool server = HasProxyPolicy(kPolicyProxyServer); |
496 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); | 499 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); |
497 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); | 500 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); |
498 | 501 |
499 if ((server || pac_url || bypass_list) && !mode) { | 502 if ((server || pac_url || bypass_list) && !(mode || server_mode)) { |
500 LOG(WARNING) << "A centrally-administered policy defines proxy setting" | 503 LOG(WARNING) << "A centrally-administered policy defines proxy setting" |
501 << " details without setting a proxy mode."; | 504 << " details without setting a proxy mode."; |
502 return false; | 505 return false; |
503 } | 506 } |
504 | 507 |
505 if (!mode) | 508 // If there's a server mode, convert it into a mode. |
| 509 std::string mode_value; |
| 510 if (mode) { |
| 511 if (server_mode) |
| 512 LOG(WARNING) << "Both ProxyMode and ProxyServerMode policies defined, " |
| 513 << "ignoring ProxyMode."; |
| 514 if (!proxy_policies_[kPolicyProxyMode]->GetAsString(&mode_value)) { |
| 515 LOG(WARNING) << "Invalid ProxyMode value."; |
| 516 return false; |
| 517 } |
| 518 } else if (server_mode) { |
| 519 int server_mode_value; |
| 520 if (!proxy_policies_[kPolicyProxyServerMode]->GetAsInteger( |
| 521 &server_mode_value)) { |
| 522 LOG(WARNING) << "Invalid ProxyServerMode value."; |
| 523 return false; |
| 524 } |
| 525 |
| 526 switch (server_mode_value) { |
| 527 case kPolicyNoProxyServerMode: |
| 528 mode_value = ProxyPrefs::kDirectProxyModeName; |
| 529 break; |
| 530 case kPolicyAutoDetectProxyServerMode: |
| 531 mode_value = ProxyPrefs::kAutoDetectProxyModeName; |
| 532 break; |
| 533 case kPolicyManuallyConfiguredProxyServerMode: |
| 534 if (server && pac_url) { |
| 535 LOG(WARNING) << "A centrally-administered policy dictates that" |
| 536 << " both fixed proxy servers and a .pac url. should" |
| 537 << " be used for proxy configuration."; |
| 538 return false; |
| 539 } |
| 540 if (!server && !pac_url) { |
| 541 LOG(WARNING) << "A centrally-administered policy dictates that the" |
| 542 << " proxy settings should use either fixed proxy" |
| 543 << " servers or a .pac url, but specifies neither."; |
| 544 return false; |
| 545 } |
| 546 if (pac_url) |
| 547 mode_value = ProxyPrefs::kPacScriptProxyModeName; |
| 548 else |
| 549 mode_value = ProxyPrefs::kFixedServersProxyModeName; |
| 550 break; |
| 551 case kPolicyUseSystemProxyServerMode: |
| 552 mode_value = ProxyPrefs::kSystemProxyModeName; |
| 553 break; |
| 554 default: |
| 555 LOG(WARNING) << "Invalid proxy mode " << server_mode_value; |
| 556 return false; |
| 557 } |
| 558 } |
| 559 |
| 560 // If neither ProxyMode nor ProxyServerMode are specified, mode_value will be |
| 561 // empty and the proxy shouldn't be configured at all. |
| 562 if (mode_value.empty()) |
506 return true; | 563 return true; |
507 | 564 |
508 int mode_value; | 565 if (mode_value == ProxyPrefs::kDirectProxyModeName) { |
509 if (!proxy_policies_[kPolicyProxyMode]->GetAsInteger(&mode_value)) { | 566 if (server || pac_url || bypass_list) { |
510 LOG(WARNING) << "Invalid proxy mode value."; | 567 LOG(WARNING) << "A centrally-administered policy disables the use of" |
| 568 << " a proxy but also specifies an explicit proxy" |
| 569 << " configuration."; |
| 570 return false; |
| 571 } |
| 572 } else if (mode_value == ProxyPrefs::kAutoDetectProxyModeName) { |
| 573 if (server || bypass_list || pac_url) { |
| 574 LOG(WARNING) << "A centrally-administered policy dictates that a proxy" |
| 575 << " shall be auto configured but specifies fixed proxy" |
| 576 << " servers, a by-pass list or a .pac script URL."; |
| 577 return false; |
| 578 } |
| 579 } else if (mode_value == ProxyPrefs::kPacScriptProxyModeName) { |
| 580 if (server || bypass_list) { |
| 581 LOG(WARNING) << "A centrally-administered policy dictates that a .pac" |
| 582 << " script URL should be used for proxy configuration but" |
| 583 << " also specifies policies required only for fixed" |
| 584 << " proxy servers."; |
| 585 return false; |
| 586 } |
| 587 } else if (mode_value == ProxyPrefs::kFixedServersProxyModeName) { |
| 588 if (pac_url) { |
| 589 LOG(WARNING) << "A centrally-administered policy dictates that" |
| 590 << " fixed proxy servers should be used but also" |
| 591 << " specifies a .pac script URL."; |
| 592 return false; |
| 593 } |
| 594 } else if (mode_value == ProxyPrefs::kSystemProxyModeName) { |
| 595 if (server || pac_url || bypass_list) { |
| 596 LOG(WARNING) << "A centrally-administered policy dictates that the" |
| 597 << " system proxy settings should be used but also " |
| 598 << " specifies an explicit proxy configuration."; |
| 599 return false; |
| 600 } |
| 601 } else { |
| 602 LOG(WARNING) << "Invalid proxy mode " << mode_value; |
511 return false; | 603 return false; |
512 } | 604 } |
513 | |
514 switch (mode_value) { | |
515 case kPolicyNoProxyServerMode: | |
516 if (server || pac_url || bypass_list) { | |
517 LOG(WARNING) << "A centrally-administered policy disables the use of" | |
518 << " a proxy but also specifies an explicit proxy" | |
519 << " configuration."; | |
520 return false; | |
521 } | |
522 break; | |
523 case kPolicyAutoDetectProxyMode: | |
524 if (server || bypass_list || pac_url) { | |
525 LOG(WARNING) << "A centrally-administered policy dictates that a proxy" | |
526 << " shall be auto configured but specifies fixed proxy" | |
527 << " servers, a by-pass list or a .pac script URL."; | |
528 return false; | |
529 } | |
530 break; | |
531 case kPolicyManuallyConfiguredProxyMode: | |
532 if (server && pac_url) { | |
533 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
534 << " system proxy settings should use both a fixed" | |
535 << " proxy server and a .pac url."; | |
536 return false; | |
537 } | |
538 if (!server && !pac_url) { | |
539 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
540 << " system proxy settings should use either a fixed" | |
541 << " proxy server or a .pac url, but specifies neither."; | |
542 return false; | |
543 } | |
544 break; | |
545 case kPolicyUseSystemProxyMode: | |
546 if (server || pac_url || bypass_list) { | |
547 LOG(WARNING) << "A centrally-administered policy dictates that the" | |
548 << " system proxy settings should be used but also " | |
549 << " specifies an explicit proxy configuration."; | |
550 return false; | |
551 } | |
552 break; | |
553 default: | |
554 LOG(WARNING) << "Invalid proxy mode " << mode_value; | |
555 return false; | |
556 } | |
557 return true; | 605 return true; |
558 } | 606 } |
559 | 607 |
560 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { | 608 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { |
561 if (!HasProxyPolicy(kPolicyProxyMode)) | 609 ProxyPrefs::ProxyMode mode; |
| 610 if (HasProxyPolicy(kPolicyProxyMode)) { |
| 611 std::string string_mode; |
| 612 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode)); |
| 613 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) { |
| 614 LOG(WARNING) << "A centrally-administered policy specifies a value for" |
| 615 << "the ProxyMode policy that isn't recognized."; |
| 616 return; |
| 617 } |
| 618 } else if (HasProxyPolicy(kPolicyProxyServerMode)) { |
| 619 int int_mode = 0; |
| 620 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode)); |
| 621 switch (int_mode) { |
| 622 case kPolicyNoProxyServerMode: |
| 623 mode = ProxyPrefs::MODE_DIRECT; |
| 624 break; |
| 625 case kPolicyAutoDetectProxyServerMode: |
| 626 mode = ProxyPrefs::MODE_AUTO_DETECT; |
| 627 break; |
| 628 case kPolicyManuallyConfiguredProxyServerMode: |
| 629 mode = ProxyPrefs::MODE_FIXED_SERVERS; |
| 630 if (HasProxyPolicy(kPolicyProxyPacUrl)) |
| 631 mode = ProxyPrefs::MODE_PAC_SCRIPT; |
| 632 break; |
| 633 case kPolicyUseSystemProxyServerMode: |
| 634 mode = ProxyPrefs::MODE_SYSTEM; |
| 635 break; |
| 636 default: |
| 637 mode = ProxyPrefs::MODE_DIRECT; |
| 638 NOTREACHED(); |
| 639 } |
| 640 } else { |
562 return; | 641 return; |
563 | |
564 int int_mode; | |
565 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsInteger(&int_mode)); | |
566 ProxyPrefs::ProxyMode mode; | |
567 switch (int_mode) { | |
568 case kPolicyNoProxyServerMode: | |
569 mode = ProxyPrefs::MODE_DIRECT; | |
570 break; | |
571 case kPolicyAutoDetectProxyMode: | |
572 mode = ProxyPrefs::MODE_AUTO_DETECT; | |
573 break; | |
574 case kPolicyManuallyConfiguredProxyMode: | |
575 mode = ProxyPrefs::MODE_FIXED_SERVERS; | |
576 if (HasProxyPolicy(kPolicyProxyPacUrl)) | |
577 mode = ProxyPrefs::MODE_PAC_SCRIPT; | |
578 break; | |
579 case kPolicyUseSystemProxyMode: | |
580 mode = ProxyPrefs::MODE_SYSTEM; | |
581 break; | |
582 default: | |
583 mode = ProxyPrefs::MODE_DIRECT; | |
584 NOTREACHED(); | |
585 } | 642 } |
586 prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode)); | 643 prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode)); |
587 | 644 |
588 if (HasProxyPolicy(kPolicyProxyServer)) { | 645 if (HasProxyPolicy(kPolicyProxyServer)) { |
589 prefs_.SetValue(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]); | 646 prefs_.SetValue(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]); |
590 proxy_policies_[kPolicyProxyServer] = NULL; | 647 proxy_policies_[kPolicyProxyServer] = NULL; |
591 } else { | 648 } else { |
592 prefs_.SetValue(prefs::kProxyServer, Value::CreateNullValue()); | 649 prefs_.SetValue(prefs::kProxyServer, Value::CreateNullValue()); |
593 } | 650 } |
594 if (HasProxyPolicy(kPolicyProxyPacUrl)) { | 651 if (HasProxyPolicy(kPolicyProxyPacUrl)) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, | 760 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, |
704 key::kDefaultSearchProviderSearchURL }, | 761 key::kDefaultSearchProviderSearchURL }, |
705 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, | 762 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, |
706 key::kDefaultSearchProviderSuggestURL }, | 763 key::kDefaultSearchProviderSuggestURL }, |
707 { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING, | 764 { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING, |
708 key::kDefaultSearchProviderInstantURL }, | 765 key::kDefaultSearchProviderInstantURL }, |
709 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, | 766 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, |
710 key::kDefaultSearchProviderIconURL }, | 767 key::kDefaultSearchProviderIconURL }, |
711 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, | 768 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, |
712 key::kDefaultSearchProviderEncodings }, | 769 key::kDefaultSearchProviderEncodings }, |
713 { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode }, | 770 { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode }, |
| 771 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode }, |
714 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, | 772 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, |
715 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, | 773 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, |
716 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, | 774 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, |
717 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, | 775 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, |
718 key::kAlternateErrorPagesEnabled }, | 776 key::kAlternateErrorPagesEnabled }, |
719 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, | 777 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, |
720 key::kSearchSuggestEnabled }, | 778 key::kSearchSuggestEnabled }, |
721 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, | 779 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, |
722 key::kDnsPrefetchingEnabled }, | 780 key::kDnsPrefetchingEnabled }, |
723 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, | 781 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 // Update the initialization flag. | 870 // Update the initialization flag. |
813 if (!initialization_complete_ && | 871 if (!initialization_complete_ && |
814 provider_->IsInitializationComplete()) { | 872 provider_->IsInitializationComplete()) { |
815 initialization_complete_ = true; | 873 initialization_complete_ = true; |
816 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | 874 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, |
817 OnInitializationCompleted()); | 875 OnInitializationCompleted()); |
818 } | 876 } |
819 } | 877 } |
820 | 878 |
821 } // namespace policy | 879 } // namespace policy |
OLD | NEW |