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

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

Issue 5958014: Policy: Add ProxyMode and deprecate ProxyServerMode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 9 years, 11 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 return false; 357 return false;
358 } 358 }
359 359
360 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( 360 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy(
361 ConfigurationPolicyType policy, 361 ConfigurationPolicyType policy,
362 Value* value) { 362 Value* value) {
363 // We only collect the values until we have sufficient information when 363 // We only collect the values until we have sufficient information when
364 // FinalizeProxyPolicySettings() is called to determine whether the presented 364 // FinalizeProxyPolicySettings() is called to determine whether the presented
365 // values were correct and apply them in that case. 365 // values were correct and apply them in that case.
366 if (policy == kPolicyProxyMode || 366 if (policy == kPolicyProxyMode ||
367 policy == kPolicyProxyServerMode ||
367 policy == kPolicyProxyServer || 368 policy == kPolicyProxyServer ||
368 policy == kPolicyProxyPacUrl || 369 policy == kPolicyProxyPacUrl ||
369 policy == kPolicyProxyBypassList) { 370 policy == kPolicyProxyBypassList) {
370 delete proxy_policies_[policy]; 371 delete proxy_policies_[policy];
371 proxy_policies_[policy] = value; 372 proxy_policies_[policy] = value;
372 return true; 373 return true;
373 } 374 }
374 // We are not interested in this policy. 375 // We are not interested in this policy.
375 return false; 376 return false;
376 } 377 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 if (CheckProxySettings()) 485 if (CheckProxySettings())
485 ApplyProxySettings(); 486 ApplyProxySettings();
486 487
487 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), 488 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(),
488 proxy_policies_.end()); 489 proxy_policies_.end());
489 proxy_policies_.clear(); 490 proxy_policies_.clear();
490 } 491 }
491 492
492 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { 493 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() {
493 bool mode = HasProxyPolicy(kPolicyProxyMode); 494 bool mode = HasProxyPolicy(kPolicyProxyMode);
495 bool server_mode = HasProxyPolicy(kPolicyProxyServerMode); // deprecated
494 bool server = HasProxyPolicy(kPolicyProxyServer); 496 bool server = HasProxyPolicy(kPolicyProxyServer);
495 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); 497 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl);
496 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); 498 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList);
497 499
498 if ((server || pac_url || bypass_list) && !mode) { 500 if ((server || pac_url || bypass_list) && !(mode || server_mode)) {
499 LOG(WARNING) << "A centrally-administered policy defines proxy setting" 501 LOG(WARNING) << "A centrally-administered policy defines proxy setting"
500 << " details without setting a proxy mode."; 502 << " details without setting a proxy mode.";
501 return false; 503 return false;
502 } 504 }
503 505
504 if (!mode) 506 // If there's a server mode, convert it into a mode.
505 return true; 507 std::string mode_value;
508 if (mode) {
509 if (!proxy_policies_[kPolicyProxyMode]->GetAsString(&mode_value)) {
510 LOG(WARNING) << "Invalid ProxyMode value.";
511 return false;
512 }
gfeher 2011/01/11 16:46:51 Warning if both mode and server_mode is defined?
danno 2011/01/12 09:32:33 Done.
513 } else if (server_mode) {
514 int server_mode_value;
515 if (!proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(
516 &server_mode_value)) {
517 LOG(WARNING) << "Invalid ProxyServerMode value.";
518 return false;
519 }
506 520
507 int mode_value; 521 switch (server_mode_value) {
508 if (!proxy_policies_[kPolicyProxyMode]->GetAsInteger(&mode_value)) { 522 case kPolicyNoProxyServerMode:
509 LOG(WARNING) << "Invalid proxy mode value."; 523 mode_value = ProxyPrefs::kDirectProxyModeName;
510 return false; 524 break;
525 case kPolicyAutoDetectProxyServerMode:
526 mode_value = ProxyPrefs::kAutoDetectProxyModeName;
527 break;
528 case kPolicyManuallyConfiguredProxyServerMode:
529 if (server && pac_url) {
530 LOG(WARNING) << "A centrally-administered policy dictates that"
531 << " both fixed proxy servers and a .pac url. should"
532 << " be used for proxy configuration.";
533 return false;
534 }
535 if (!server && !pac_url) {
536 LOG(WARNING) << "A centrally-administered policy dictates that the"
537 << " proxy settings should use either fixed proxy"
538 << " servers or a .pac url, but specifies neither.";
539 return false;
540 }
541 if (pac_url)
542 mode_value = ProxyPrefs::kPacScriptProxyModeName;
543 else
544 mode_value = ProxyPrefs::kFixedServersProxyModeName;
545 break;
546 case kPolicyUseSystemProxyServerMode:
547 mode_value = ProxyPrefs::kSystemProxyModeName;
548 break;
549 default:
550 LOG(WARNING) << "Invalid proxy mode " << server_mode_value;
551 return false;
552 }
511 } 553 }
512 554
513 switch (mode_value) { 555 if (!mode_value.empty()) {
gfeher 2011/01/11 16:46:51 Please add a comment to explain what does an empty
danno 2011/01/12 09:32:33 Done.
514 case kPolicyNoProxyServerMode: 556 if (mode_value == ProxyPrefs::kDirectProxyModeName) {
515 if (server || pac_url || bypass_list) { 557 if (server || pac_url || bypass_list) {
516 LOG(WARNING) << "A centrally-administered policy disables the use of" 558 LOG(WARNING) << "A centrally-administered policy disables the use of"
517 << " a proxy but also specifies an explicit proxy" 559 << " a proxy but also specifies an explicit proxy"
518 << " configuration."; 560 << " configuration.";
519 return false; 561 return false;
520 } 562 }
521 break; 563 } else if (mode_value == ProxyPrefs::kAutoDetectProxyModeName) {
522 case kPolicyAutoDetectProxyMode:
523 if (server || bypass_list || pac_url) { 564 if (server || bypass_list || pac_url) {
524 LOG(WARNING) << "A centrally-administered policy dictates that a proxy" 565 LOG(WARNING) << "A centrally-administered policy dictates that a proxy"
525 << " shall be auto configured but specifies fixed proxy" 566 << " shall be auto configured but specifies fixed proxy"
526 << " servers, a by-pass list or a .pac script URL."; 567 << " servers, a by-pass list or a .pac script URL.";
527 return false; 568 return false;
528 } 569 }
529 break; 570 } else if (mode_value == ProxyPrefs::kPacScriptProxyModeName) {
530 case kPolicyManuallyConfiguredProxyMode: 571 if (server || bypass_list) {
531 if (server && pac_url) { 572 LOG(WARNING) << "A centrally-administered policy dictates that a .pac"
532 LOG(WARNING) << "A centrally-administered policy dictates that the" 573 << " script URL should be used for proxy configuration but"
533 << " system proxy settings should use both a fixed" 574 << " also specifies policies required only for fixed"
534 << " proxy server and a .pac url."; 575 << " proxy servers.";
535 return false; 576 return false;
536 } 577 }
537 if (!server && !pac_url) { 578 } else if (mode_value == ProxyPrefs::kFixedServersProxyModeName) {
538 LOG(WARNING) << "A centrally-administered policy dictates that the" 579 if (pac_url) {
539 << " system proxy settings should use either a fixed" 580 LOG(WARNING) << "A centrally-administered policy dictates that"
540 << " proxy server or a .pac url, but specifies neither."; 581 << " fixed proxy servers should be used but also"
582 << " specifies a .pac script URL.";
541 return false; 583 return false;
542 } 584 }
543 break; 585 } else if (mode_value == ProxyPrefs::kSystemProxyModeName) {
544 case kPolicyUseSystemProxyMode:
545 if (server || pac_url || bypass_list) { 586 if (server || pac_url || bypass_list) {
546 LOG(WARNING) << "A centrally-administered policy dictates that the" 587 LOG(WARNING) << "A centrally-administered policy dictates that the"
547 << " system proxy settings should be used but also " 588 << " system proxy settings should be used but also "
548 << " specifies an explicit proxy configuration."; 589 << " specifies an explicit proxy configuration.";
549 return false; 590 return false;
550 } 591 }
551 break; 592 } else {
552 default:
553 LOG(WARNING) << "Invalid proxy mode " << mode_value; 593 LOG(WARNING) << "Invalid proxy mode " << mode_value;
554 return false; 594 return false;
595 }
555 } 596 }
556 return true; 597 return true;
557 } 598 }
558 599
559 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { 600 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() {
560 if (!HasProxyPolicy(kPolicyProxyMode)) 601 ProxyPrefs::ProxyMode mode;
602 if (HasProxyPolicy(kPolicyProxyMode)) {
603 std::string string_mode;
604 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode));
605 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) {
606 LOG(WARNING) << "A centrally-administered policy specifies a value for"
607 << "the ProxyMode policy that isn't recognized.";
608 return;
609 }
610 } else if (HasProxyPolicy(kPolicyProxyServerMode)) {
611 int int_mode = 0;
612 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode));
613 switch (int_mode) {
614 case kPolicyNoProxyServerMode:
615 mode = ProxyPrefs::MODE_DIRECT;
616 break;
617 case kPolicyAutoDetectProxyServerMode:
618 mode = ProxyPrefs::MODE_AUTO_DETECT;
619 break;
620 case kPolicyManuallyConfiguredProxyServerMode:
621 mode = ProxyPrefs::MODE_FIXED_SERVERS;
622 if (HasProxyPolicy(kPolicyProxyPacUrl))
623 mode = ProxyPrefs::MODE_PAC_SCRIPT;
624 break;
625 case kPolicyUseSystemProxyServerMode:
626 mode = ProxyPrefs::MODE_SYSTEM;
627 break;
628 default:
629 mode = ProxyPrefs::MODE_DIRECT;
630 NOTREACHED();
631 }
632 } else {
561 return; 633 return;
562
563 int int_mode;
564 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsInteger(&int_mode));
565 ProxyPrefs::ProxyMode mode;
566 switch (int_mode) {
567 case kPolicyNoProxyServerMode:
568 mode = ProxyPrefs::MODE_DIRECT;
569 break;
570 case kPolicyAutoDetectProxyMode:
571 mode = ProxyPrefs::MODE_AUTO_DETECT;
572 break;
573 case kPolicyManuallyConfiguredProxyMode:
574 mode = ProxyPrefs::MODE_FIXED_SERVERS;
575 if (HasProxyPolicy(kPolicyProxyPacUrl))
576 mode = ProxyPrefs::MODE_PAC_SCRIPT;
577 break;
578 case kPolicyUseSystemProxyMode:
579 mode = ProxyPrefs::MODE_SYSTEM;
580 break;
581 default:
582 mode = ProxyPrefs::MODE_DIRECT;
583 NOTREACHED();
584 } 634 }
585 prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode)); 635 prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode));
586 636
587 if (HasProxyPolicy(kPolicyProxyServer)) { 637 if (HasProxyPolicy(kPolicyProxyServer)) {
588 prefs_.SetValue(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]); 638 prefs_.SetValue(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]);
589 proxy_policies_[kPolicyProxyServer] = NULL; 639 proxy_policies_[kPolicyProxyServer] = NULL;
590 } else { 640 } else {
591 prefs_.SetValue(prefs::kProxyServer, Value::CreateNullValue()); 641 prefs_.SetValue(prefs::kProxyServer, Value::CreateNullValue());
592 } 642 }
593 if (HasProxyPolicy(kPolicyProxyPacUrl)) { 643 if (HasProxyPolicy(kPolicyProxyPacUrl)) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, 750 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING,
701 key::kDefaultSearchProviderKeyword }, 751 key::kDefaultSearchProviderKeyword },
702 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, 752 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING,
703 key::kDefaultSearchProviderSearchURL }, 753 key::kDefaultSearchProviderSearchURL },
704 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, 754 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING,
705 key::kDefaultSearchProviderSuggestURL }, 755 key::kDefaultSearchProviderSuggestURL },
706 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, 756 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING,
707 key::kDefaultSearchProviderIconURL }, 757 key::kDefaultSearchProviderIconURL },
708 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, 758 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING,
709 key::kDefaultSearchProviderEncodings }, 759 key::kDefaultSearchProviderEncodings },
710 { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode }, 760 { kPolicyProxyMode, Value::TYPE_STRING, key::kProxyMode },
761 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode },
711 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, 762 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer },
712 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, 763 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl },
713 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, 764 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList },
714 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, 765 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN,
715 key::kAlternateErrorPagesEnabled }, 766 key::kAlternateErrorPagesEnabled },
716 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, 767 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN,
717 key::kSearchSuggestEnabled }, 768 key::kSearchSuggestEnabled },
718 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, 769 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN,
719 key::kDnsPrefetchingEnabled }, 770 key::kDnsPrefetchingEnabled },
720 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, 771 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy },
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 // Update the initialization flag. 860 // Update the initialization flag.
810 if (!initialization_complete_ && 861 if (!initialization_complete_ &&
811 provider_->IsInitializationComplete()) { 862 provider_->IsInitializationComplete()) {
812 initialization_complete_ = true; 863 initialization_complete_ = true;
813 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 864 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
814 OnInitializationCompleted()); 865 OnInitializationCompleted());
815 } 866 }
816 } 867 }
817 868
818 } // namespace policy 869 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698