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

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

Issue 10908226: Introduces a search term extraction mechanism working for arbitrary search providers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Indent fix. Created 8 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_handler.h" 5 #include "chrome/browser/policy/configuration_policy_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Value::TYPE_STRING }, 82 Value::TYPE_STRING },
83 { key::kDefaultSearchProviderInstantURL, 83 { key::kDefaultSearchProviderInstantURL,
84 prefs::kDefaultSearchProviderInstantURL, 84 prefs::kDefaultSearchProviderInstantURL,
85 Value::TYPE_STRING }, 85 Value::TYPE_STRING },
86 { key::kDefaultSearchProviderIconURL, 86 { key::kDefaultSearchProviderIconURL,
87 prefs::kDefaultSearchProviderIconURL, 87 prefs::kDefaultSearchProviderIconURL,
88 Value::TYPE_STRING }, 88 Value::TYPE_STRING },
89 { key::kDefaultSearchProviderEncodings, 89 { key::kDefaultSearchProviderEncodings,
90 prefs::kDefaultSearchProviderEncodings, 90 prefs::kDefaultSearchProviderEncodings,
91 Value::TYPE_LIST }, 91 Value::TYPE_LIST },
92 { key::kDefaultSearchProviderAlternateURLs,
93 prefs::kDefaultSearchProviderAlternateURLs,
94 Value::TYPE_LIST },
92 }; 95 };
93 96
94 // List of entries determining which proxy policies can be specified, depending 97 // List of entries determining which proxy policies can be specified, depending
95 // on the ProxyMode. 98 // on the ProxyMode.
96 const ProxyModeValidationEntry kProxyModeValidationMap[] = { 99 const ProxyModeValidationEntry kProxyModeValidationMap[] = {
97 { ProxyPrefs::kDirectProxyModeName, 100 { ProxyPrefs::kDirectProxyModeName,
98 false, false, false, IDS_POLICY_PROXY_MODE_DISABLED_ERROR }, 101 false, false, false, IDS_POLICY_PROXY_MODE_DISABLED_ERROR },
99 { ProxyPrefs::kAutoDetectProxyModeName, 102 { ProxyPrefs::kAutoDetectProxyModeName,
100 false, false, false, IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR }, 103 false, false, false, IDS_POLICY_PROXY_MODE_AUTO_DETECT_ERROR },
101 { ProxyPrefs::kPacScriptProxyModeName, 104 { ProxyPrefs::kPacScriptProxyModeName,
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, false); 647 prefs->SetBoolean(prefs::kDefaultSearchProviderEnabled, false);
645 648
646 // If default search is disabled, the other fields are ignored. 649 // If default search is disabled, the other fields are ignored.
647 prefs->SetString(prefs::kDefaultSearchProviderName, std::string()); 650 prefs->SetString(prefs::kDefaultSearchProviderName, std::string());
648 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); 651 prefs->SetString(prefs::kDefaultSearchProviderSearchURL, std::string());
649 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); 652 prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string());
650 prefs->SetString(prefs::kDefaultSearchProviderIconURL, std::string()); 653 prefs->SetString(prefs::kDefaultSearchProviderIconURL, std::string());
651 prefs->SetString(prefs::kDefaultSearchProviderEncodings, std::string()); 654 prefs->SetString(prefs::kDefaultSearchProviderEncodings, std::string());
652 prefs->SetString(prefs::kDefaultSearchProviderKeyword, std::string()); 655 prefs->SetString(prefs::kDefaultSearchProviderKeyword, std::string());
653 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, std::string()); 656 prefs->SetString(prefs::kDefaultSearchProviderInstantURL, std::string());
657 prefs->SetValue(prefs::kDefaultSearchProviderAlternateURLs,
658 new ListValue());
654 } else { 659 } else {
655 // The search URL is required. The other entries are optional. Just make 660 // The search URL is required. The other entries are optional. Just make
656 // sure that they are all specified via policy, so that the regular prefs 661 // sure that they are all specified via policy, so that the regular prefs
657 // aren't used. 662 // aren't used.
658 const Value* dummy; 663 const Value* dummy;
659 std::string url; 664 std::string url;
660 if (DefaultSearchURLIsValid(policies, &dummy, &url)) { 665 if (DefaultSearchURLIsValid(policies, &dummy, &url)) {
661 for (std::vector<ConfigurationPolicyHandler*>::const_iterator handler = 666 for (std::vector<ConfigurationPolicyHandler*>::const_iterator handler =
662 handlers_.begin(); handler != handlers_.end(); ++handler) 667 handlers_.begin(); handler != handlers_.end(); ++handler)
663 (*handler)->ApplyPolicySettings(policies, prefs); 668 (*handler)->ApplyPolicySettings(policies, prefs);
664 669
665 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderSuggestURL); 670 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderSuggestURL);
666 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderIconURL); 671 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderIconURL);
667 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderEncodings); 672 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderEncodings);
668 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderKeyword); 673 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderKeyword);
669 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderInstantURL); 674 EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderInstantURL);
675 EnsureListPrefExists(prefs, prefs::kDefaultSearchProviderAlternateURLs);
670 676
671 // For the name and keyword, default to the host if not specified. If 677 // For the name and keyword, default to the host if not specified. If
672 // there is no host (file: URLs? Not sure), use "_" to guarantee that the 678 // there is no host (file: URLs? Not sure), use "_" to guarantee that the
673 // keyword is non-empty. 679 // keyword is non-empty.
674 std::string name, keyword; 680 std::string name, keyword;
675 std::string host(GURL(url).host()); 681 std::string host(GURL(url).host());
676 if (host.empty()) 682 if (host.empty())
677 host = "_"; 683 host = "_";
678 if (!prefs->GetString(prefs::kDefaultSearchProviderName, &name) || 684 if (!prefs->GetString(prefs::kDefaultSearchProviderName, &name) ||
679 name.empty()) 685 name.empty())
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 } 752 }
747 753
748 void DefaultSearchPolicyHandler::EnsureStringPrefExists( 754 void DefaultSearchPolicyHandler::EnsureStringPrefExists(
749 PrefValueMap* prefs, 755 PrefValueMap* prefs,
750 const std::string& path) { 756 const std::string& path) {
751 std::string value; 757 std::string value;
752 if (!prefs->GetString(path, &value)) 758 if (!prefs->GetString(path, &value))
753 prefs->SetString(path, value); 759 prefs->SetString(path, value);
754 } 760 }
755 761
762 void DefaultSearchPolicyHandler::EnsureListPrefExists(
763 PrefValueMap* prefs,
764 const std::string& path) {
765 base::Value* value;
766 base::ListValue* list_value;
767 if (!prefs->GetValue(path, &value) || !value->GetAsList(&list_value))
768 prefs->SetValue(path, new ListValue());
769 }
770
756 771
757 // ProxyPolicyHandler implementation ------------------------------------------- 772 // ProxyPolicyHandler implementation -------------------------------------------
758 773
759 // The proxy policies have the peculiarity that they are loaded from individual 774 // The proxy policies have the peculiarity that they are loaded from individual
760 // policies, but the providers then expose them through a unified 775 // policies, but the providers then expose them through a unified
761 // DictionaryValue. Once Dictionary policies are fully supported, the individual 776 // DictionaryValue. Once Dictionary policies are fully supported, the individual
762 // proxy policies will be deprecated. http://crbug.com/108996 777 // proxy policies will be deprecated. http://crbug.com/108996
763 778
764 ProxyPolicyHandler::ProxyPolicyHandler() { 779 ProxyPolicyHandler::ProxyPolicyHandler() {
765 } 780 }
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 1363
1349 void DisabledPluginsByVersionPolicyHandler::ApplyPolicySettings( 1364 void DisabledPluginsByVersionPolicyHandler::ApplyPolicySettings(
1350 const PolicyMap& policies, 1365 const PolicyMap& policies,
1351 PrefValueMap* prefs) { 1366 PrefValueMap* prefs) {
1352 const Value* value = policies.GetValue(policy_name()); 1367 const Value* value = policies.GetValue(policy_name());
1353 if (value) 1368 if (value)
1354 prefs->SetValue(prefs::kPluginsDisabledPluginsByVersion, value->DeepCopy()); 1369 prefs->SetValue(prefs::kPluginsDisabledPluginsByVersion, value->DeepCopy());
1355 } 1370 }
1356 1371
1357 } // namespace policy 1372 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698