Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / prefs / command_line_pref_store.cc
blobb06fd163f1d02c0fa8405f1009785d3151c61904
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
3 // found in the LICENSE file.
5 #include "chrome/browser/prefs/command_line_pref_store.h"
7 #include <string>
8 #include <vector>
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_split.h"
14 #include "base/values.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h"
17 #include "components/proxy_config/proxy_config_dictionary.h"
18 #include "components/proxy_config/proxy_config_pref_names.h"
19 #include "ui/base/ui_base_switches.h"
21 #if defined(OS_CHROMEOS)
22 #include "chromeos/chromeos_switches.h"
23 #endif
25 const CommandLinePrefStore::StringSwitchToPreferenceMapEntry
26 CommandLinePrefStore::string_switch_map_[] = {
27 { switches::kLang, prefs::kApplicationLocale },
28 { data_reduction_proxy::switches::kDataReductionProxy,
29 data_reduction_proxy::prefs::kDataReductionProxy },
30 { switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist },
31 { switches::kSSLVersionMin, prefs::kSSLVersionMin },
32 { switches::kSSLVersionMax, prefs::kSSLVersionMax },
33 { switches::kSSLVersionFallbackMin, prefs::kSSLVersionFallbackMin },
34 #if defined(OS_ANDROID)
35 { switches::kAuthAndroidNegotiateAccountType,
36 prefs::kAuthAndroidNegotiateAccountType },
37 #endif
40 const CommandLinePrefStore::PathSwitchToPreferenceMapEntry
41 CommandLinePrefStore::path_switch_map_[] = {
42 { switches::kDiskCacheDir, prefs::kDiskCacheDir },
45 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
46 CommandLinePrefStore::boolean_switch_map_[] = {
47 { switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true },
48 { switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled,
49 true },
50 { switches::kAllowOutdatedPlugins, prefs::kPluginsAllowOutdated, true },
51 { switches::kAlwaysAuthorizePlugins, prefs::kPluginsAlwaysAuthorize,
52 true },
53 { switches::kNoPings, prefs::kEnableHyperlinkAuditing, false },
54 { switches::kNoReferrers, prefs::kEnableReferrers, false },
55 { switches::kAllowRunningInsecureContent,
56 prefs::kWebKitAllowRunningInsecureContent, true },
57 { switches::kNoDisplayingInsecureContent,
58 prefs::kWebKitAllowDisplayingInsecureContent, false },
59 { switches::kAllowCrossOriginAuthPrompt,
60 prefs::kAllowCrossOriginAuthPrompt, true },
61 { switches::kDisablePrintPreview, prefs::kPrintPreviewDisabled, true },
62 #if defined(OS_CHROMEOS)
63 { chromeos::switches::kEnableTouchpadThreeFingerClick,
64 prefs::kEnableTouchpadThreeFingerClick, true },
65 #endif
66 { switches::kDisableAsyncDns, prefs::kBuiltInDnsClientEnabled, false },
69 const CommandLinePrefStore::IntegerSwitchToPreferenceMapEntry
70 CommandLinePrefStore::integer_switch_map_[] = {
71 { switches::kDiskCacheSize, prefs::kDiskCacheSize },
72 { switches::kMediaCacheSize, prefs::kMediaCacheSize },
75 CommandLinePrefStore::CommandLinePrefStore(
76 const base::CommandLine* command_line)
77 : command_line_(command_line) {
78 ApplySimpleSwitches();
79 ApplyProxyMode();
80 ValidateProxySwitches();
81 ApplySSLSwitches();
82 ApplyBackgroundModeSwitches();
85 CommandLinePrefStore::~CommandLinePrefStore() {}
87 bool CommandLinePrefStore::ValidateProxySwitches() {
88 if (command_line_->HasSwitch(switches::kNoProxyServer) &&
89 (command_line_->HasSwitch(switches::kProxyAutoDetect) ||
90 command_line_->HasSwitch(switches::kProxyServer) ||
91 command_line_->HasSwitch(switches::kProxyPacUrl) ||
92 command_line_->HasSwitch(switches::kProxyBypassList))) {
93 LOG(WARNING) << "Additional command-line proxy switches specified when --"
94 << switches::kNoProxyServer << " was also specified.";
95 return false;
97 return true;
100 void CommandLinePrefStore::ApplySimpleSwitches() {
101 // Look for each switch we know about and set its preference accordingly.
102 for (size_t i = 0; i < arraysize(string_switch_map_); ++i) {
103 if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) {
104 SetValue(string_switch_map_[i].preference_path,
105 make_scoped_ptr(
106 new base::StringValue(command_line_->GetSwitchValueASCII(
107 string_switch_map_[i].switch_name))),
108 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
112 for (size_t i = 0; i < arraysize(path_switch_map_); ++i) {
113 if (command_line_->HasSwitch(path_switch_map_[i].switch_name)) {
114 SetValue(
115 path_switch_map_[i].preference_path,
116 make_scoped_ptr(new base::StringValue(
117 command_line_->GetSwitchValuePath(path_switch_map_[i].switch_name)
118 .value())),
119 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
123 for (size_t i = 0; i < arraysize(integer_switch_map_); ++i) {
124 if (command_line_->HasSwitch(integer_switch_map_[i].switch_name)) {
125 std::string str_value = command_line_->GetSwitchValueASCII(
126 integer_switch_map_[i].switch_name);
127 int int_value = 0;
128 if (!base::StringToInt(str_value, &int_value)) {
129 LOG(ERROR) << "The value " << str_value << " of "
130 << integer_switch_map_[i].switch_name
131 << " can not be converted to integer, ignoring!";
132 continue;
134 SetValue(integer_switch_map_[i].preference_path,
135 make_scoped_ptr(new base::FundamentalValue(int_value)),
136 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
140 for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) {
141 if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) {
142 SetValue(boolean_switch_map_[i].preference_path,
143 make_scoped_ptr(new base::FundamentalValue(
144 boolean_switch_map_[i].set_value)),
145 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
150 void CommandLinePrefStore::ApplyProxyMode() {
151 if (command_line_->HasSwitch(switches::kNoProxyServer)) {
152 SetValue(proxy_config::prefs::kProxy,
153 make_scoped_ptr(ProxyConfigDictionary::CreateDirect()),
154 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
155 } else if (command_line_->HasSwitch(switches::kProxyPacUrl)) {
156 std::string pac_script_url =
157 command_line_->GetSwitchValueASCII(switches::kProxyPacUrl);
158 SetValue(proxy_config::prefs::kProxy,
159 make_scoped_ptr(
160 ProxyConfigDictionary::CreatePacScript(pac_script_url, false)),
161 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
162 } else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) {
163 SetValue(proxy_config::prefs::kProxy,
164 make_scoped_ptr(ProxyConfigDictionary::CreateAutoDetect()),
165 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
166 } else if (command_line_->HasSwitch(switches::kProxyServer)) {
167 std::string proxy_server =
168 command_line_->GetSwitchValueASCII(switches::kProxyServer);
169 std::string bypass_list =
170 command_line_->GetSwitchValueASCII(switches::kProxyBypassList);
171 SetValue(proxy_config::prefs::kProxy,
172 make_scoped_ptr(ProxyConfigDictionary::CreateFixedServers(
173 proxy_server, bypass_list)),
174 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
178 void CommandLinePrefStore::ApplySSLSwitches() {
179 if (command_line_->HasSwitch(switches::kCipherSuiteBlacklist)) {
180 scoped_ptr<base::ListValue> list_value(new base::ListValue());
181 list_value->AppendStrings(base::SplitString(
182 command_line_->GetSwitchValueASCII(switches::kCipherSuiteBlacklist),
183 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL));
184 SetValue(prefs::kCipherSuiteBlacklist, list_value.Pass(),
185 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
189 void CommandLinePrefStore::ApplyBackgroundModeSwitches() {
190 if (command_line_->HasSwitch(switches::kDisableExtensions)) {
191 SetValue(prefs::kBackgroundModeEnabled,
192 make_scoped_ptr(new base::FundamentalValue(false)),
193 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);