Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / prefs / command_line_pref_store.cc
blob8e0cab281d6734a78b56128766766bd8764ec14c
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 "ui/base/ui_base_switches.h"
20 #if defined(OS_CHROMEOS)
21 #include "chromeos/chromeos_switches.h"
22 #endif
24 const CommandLinePrefStore::StringSwitchToPreferenceMapEntry
25 CommandLinePrefStore::string_switch_map_[] = {
26 { switches::kLang, prefs::kApplicationLocale },
27 { data_reduction_proxy::switches::kDataReductionProxy,
28 data_reduction_proxy::prefs::kDataReductionProxy },
29 { switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist },
30 { switches::kSSLVersionMin, prefs::kSSLVersionMin },
31 { switches::kSSLVersionMax, prefs::kSSLVersionMax },
32 { switches::kSSLVersionFallbackMin, prefs::kSSLVersionFallbackMin },
33 #if defined(OS_ANDROID)
34 { switches::kAuthAndroidNegotiateAccountType,
35 prefs::kAuthAndroidNegotiateAccountType },
36 #endif
39 const CommandLinePrefStore::PathSwitchToPreferenceMapEntry
40 CommandLinePrefStore::path_switch_map_[] = {
41 { switches::kDiskCacheDir, prefs::kDiskCacheDir },
44 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
45 CommandLinePrefStore::boolean_switch_map_[] = {
46 { switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true },
47 { switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled,
48 true },
49 { switches::kAllowOutdatedPlugins, prefs::kPluginsAllowOutdated, true },
50 { switches::kAlwaysAuthorizePlugins, prefs::kPluginsAlwaysAuthorize,
51 true },
52 { switches::kNoPings, prefs::kEnableHyperlinkAuditing, false },
53 { switches::kNoReferrers, prefs::kEnableReferrers, false },
54 { switches::kAllowRunningInsecureContent,
55 prefs::kWebKitAllowRunningInsecureContent, true },
56 { switches::kNoDisplayingInsecureContent,
57 prefs::kWebKitAllowDisplayingInsecureContent, false },
58 { switches::kAllowCrossOriginAuthPrompt,
59 prefs::kAllowCrossOriginAuthPrompt, true },
60 { switches::kDisablePrintPreview, prefs::kPrintPreviewDisabled, true },
61 #if defined(OS_CHROMEOS)
62 { chromeos::switches::kEnableTouchpadThreeFingerClick,
63 prefs::kEnableTouchpadThreeFingerClick, true },
64 #endif
65 { switches::kDisableAsyncDns, prefs::kBuiltInDnsClientEnabled, false },
68 const CommandLinePrefStore::IntegerSwitchToPreferenceMapEntry
69 CommandLinePrefStore::integer_switch_map_[] = {
70 { switches::kDiskCacheSize, prefs::kDiskCacheSize },
71 { switches::kMediaCacheSize, prefs::kMediaCacheSize },
74 CommandLinePrefStore::CommandLinePrefStore(
75 const base::CommandLine* command_line)
76 : command_line_(command_line) {
77 ApplySimpleSwitches();
78 ApplyProxyMode();
79 ValidateProxySwitches();
80 ApplySSLSwitches();
81 ApplyBackgroundModeSwitches();
84 CommandLinePrefStore::~CommandLinePrefStore() {}
86 bool CommandLinePrefStore::ValidateProxySwitches() {
87 if (command_line_->HasSwitch(switches::kNoProxyServer) &&
88 (command_line_->HasSwitch(switches::kProxyAutoDetect) ||
89 command_line_->HasSwitch(switches::kProxyServer) ||
90 command_line_->HasSwitch(switches::kProxyPacUrl) ||
91 command_line_->HasSwitch(switches::kProxyBypassList))) {
92 LOG(WARNING) << "Additional command-line proxy switches specified when --"
93 << switches::kNoProxyServer << " was also specified.";
94 return false;
96 return true;
99 void CommandLinePrefStore::ApplySimpleSwitches() {
100 // Look for each switch we know about and set its preference accordingly.
101 for (size_t i = 0; i < arraysize(string_switch_map_); ++i) {
102 if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) {
103 SetValue(string_switch_map_[i].preference_path,
104 make_scoped_ptr(
105 new base::StringValue(command_line_->GetSwitchValueASCII(
106 string_switch_map_[i].switch_name))),
107 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
111 for (size_t i = 0; i < arraysize(path_switch_map_); ++i) {
112 if (command_line_->HasSwitch(path_switch_map_[i].switch_name)) {
113 SetValue(
114 path_switch_map_[i].preference_path,
115 make_scoped_ptr(new base::StringValue(
116 command_line_->GetSwitchValuePath(path_switch_map_[i].switch_name)
117 .value())),
118 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
122 for (size_t i = 0; i < arraysize(integer_switch_map_); ++i) {
123 if (command_line_->HasSwitch(integer_switch_map_[i].switch_name)) {
124 std::string str_value = command_line_->GetSwitchValueASCII(
125 integer_switch_map_[i].switch_name);
126 int int_value = 0;
127 if (!base::StringToInt(str_value, &int_value)) {
128 LOG(ERROR) << "The value " << str_value << " of "
129 << integer_switch_map_[i].switch_name
130 << " can not be converted to integer, ignoring!";
131 continue;
133 SetValue(integer_switch_map_[i].preference_path,
134 make_scoped_ptr(new base::FundamentalValue(int_value)),
135 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
139 for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) {
140 if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) {
141 SetValue(boolean_switch_map_[i].preference_path,
142 make_scoped_ptr(new base::FundamentalValue(
143 boolean_switch_map_[i].set_value)),
144 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
149 void CommandLinePrefStore::ApplyProxyMode() {
150 if (command_line_->HasSwitch(switches::kNoProxyServer)) {
151 SetValue(prefs::kProxy,
152 make_scoped_ptr(ProxyConfigDictionary::CreateDirect()),
153 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
154 } else if (command_line_->HasSwitch(switches::kProxyPacUrl)) {
155 std::string pac_script_url =
156 command_line_->GetSwitchValueASCII(switches::kProxyPacUrl);
157 SetValue(prefs::kProxy,
158 make_scoped_ptr(
159 ProxyConfigDictionary::CreatePacScript(pac_script_url, false)),
160 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
161 } else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) {
162 SetValue(prefs::kProxy,
163 make_scoped_ptr(ProxyConfigDictionary::CreateAutoDetect()),
164 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
165 } else if (command_line_->HasSwitch(switches::kProxyServer)) {
166 std::string proxy_server =
167 command_line_->GetSwitchValueASCII(switches::kProxyServer);
168 std::string bypass_list =
169 command_line_->GetSwitchValueASCII(switches::kProxyBypassList);
170 SetValue(prefs::kProxy,
171 make_scoped_ptr(ProxyConfigDictionary::CreateFixedServers(
172 proxy_server, bypass_list)),
173 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
177 void CommandLinePrefStore::ApplySSLSwitches() {
178 if (command_line_->HasSwitch(switches::kCipherSuiteBlacklist)) {
179 scoped_ptr<base::ListValue> list_value(new base::ListValue());
180 list_value->AppendStrings(base::SplitString(
181 command_line_->GetSwitchValueASCII(switches::kCipherSuiteBlacklist),
182 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL));
183 SetValue(prefs::kCipherSuiteBlacklist, list_value.Pass(),
184 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
188 void CommandLinePrefStore::ApplyBackgroundModeSwitches() {
189 if (command_line_->HasSwitch(switches::kDisableExtensions)) {
190 SetValue(prefs::kBackgroundModeEnabled,
191 make_scoped_ptr(new base::FundamentalValue(false)),
192 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);