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

Side by Side Diff: chrome/browser/prefs/chrome_command_line_pref_store.cc

Issue 2419733005: Extract a base class from CommandLinePrefStore (Closed)
Patch Set: nit in comment Created 4 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
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/prefs/command_line_pref_store.h" 5 #include "chrome/browser/prefs/chrome_command_line_pref_store.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/common/ash_switches.h" 13 #include "ash/common/ash_switches.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
18 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
20 #include "base/values.h" 19 #include "base/values.h"
21 #include "build/build_config.h" 20 #include "build/build_config.h"
22 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
26 #include "components/proxy_config/proxy_config_dictionary.h" 25 #include "components/proxy_config/proxy_config_dictionary.h"
27 #include "components/proxy_config/proxy_config_pref_names.h" 26 #include "components/proxy_config/proxy_config_pref_names.h"
28 #include "components/ssl_config/ssl_config_prefs.h" 27 #include "components/ssl_config/ssl_config_prefs.h"
29 #include "components/ssl_config/ssl_config_switches.h" 28 #include "components/ssl_config/ssl_config_switches.h"
30 #include "content/public/common/content_switches.h" 29 #include "content/public/common/content_switches.h"
31 #include "ui/base/ui_base_switches.h" 30 #include "ui/base/ui_base_switches.h"
32 #include "ui/display/display_switches.h" 31 #include "ui/display/display_switches.h"
33 32
34 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
35 #include "chromeos/chromeos_switches.h" 34 #include "chromeos/chromeos_switches.h"
36 #endif 35 #endif
37 36
38 const CommandLinePrefStore::StringSwitchToPreferenceMapEntry 37 const CommandLinePrefStore::SwitchToPreferenceMapEntry
39 CommandLinePrefStore::string_switch_map_[] = { 38 ChromeCommandLinePrefStore::string_switch_map_[] = {
40 { switches::kLang, prefs::kApplicationLocale }, 39 { switches::kLang, prefs::kApplicationLocale },
41 { data_reduction_proxy::switches::kDataReductionProxy, 40 { data_reduction_proxy::switches::kDataReductionProxy,
42 data_reduction_proxy::prefs::kDataReductionProxy }, 41 data_reduction_proxy::prefs::kDataReductionProxy },
43 { switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist }, 42 { switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist },
44 { switches::kSSLVersionMin, ssl_config::prefs::kSSLVersionMin }, 43 { switches::kSSLVersionMin, ssl_config::prefs::kSSLVersionMin },
45 { switches::kSSLVersionMax, ssl_config::prefs::kSSLVersionMax }, 44 { switches::kSSLVersionMax, ssl_config::prefs::kSSLVersionMax },
46 #if defined(OS_ANDROID) 45 #if defined(OS_ANDROID)
47 { switches::kAuthAndroidNegotiateAccountType, 46 { switches::kAuthAndroidNegotiateAccountType,
48 prefs::kAuthAndroidNegotiateAccountType }, 47 prefs::kAuthAndroidNegotiateAccountType },
49 #endif 48 #endif
50 }; 49 };
51 50
52 const CommandLinePrefStore::PathSwitchToPreferenceMapEntry 51 const CommandLinePrefStore::SwitchToPreferenceMapEntry
53 CommandLinePrefStore::path_switch_map_[] = { 52 ChromeCommandLinePrefStore::path_switch_map_[] = {
54 { switches::kDiskCacheDir, prefs::kDiskCacheDir }, 53 { switches::kDiskCacheDir, prefs::kDiskCacheDir },
55 }; 54 };
56 55
57 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry 56 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry
58 CommandLinePrefStore::boolean_switch_map_[] = { 57 ChromeCommandLinePrefStore::boolean_switch_map_[] = {
59 {switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true}, 58 {switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true},
60 {switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled, 59 {switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled,
61 true}, 60 true},
62 {switches::kAllowOutdatedPlugins, prefs::kPluginsAllowOutdated, true}, 61 {switches::kAllowOutdatedPlugins, prefs::kPluginsAllowOutdated, true},
63 {switches::kAlwaysAuthorizePlugins, prefs::kPluginsAlwaysAuthorize, 62 {switches::kAlwaysAuthorizePlugins, prefs::kPluginsAlwaysAuthorize,
64 true}, 63 true},
65 {switches::kNoPings, prefs::kEnableHyperlinkAuditing, false}, 64 {switches::kNoPings, prefs::kEnableHyperlinkAuditing, false},
66 {switches::kNoReferrers, prefs::kEnableReferrers, false}, 65 {switches::kNoReferrers, prefs::kEnableReferrers, false},
67 {switches::kAllowRunningInsecureContent, 66 {switches::kAllowRunningInsecureContent,
68 prefs::kWebKitAllowRunningInsecureContent, true}, 67 prefs::kWebKitAllowRunningInsecureContent, true},
69 {switches::kAllowCrossOriginAuthPrompt, 68 {switches::kAllowCrossOriginAuthPrompt,
70 prefs::kAllowCrossOriginAuthPrompt, true}, 69 prefs::kAllowCrossOriginAuthPrompt, true},
71 {switches::kDisablePrintPreview, prefs::kPrintPreviewDisabled, true}, 70 {switches::kDisablePrintPreview, prefs::kPrintPreviewDisabled, true},
72 #if defined(OS_CHROMEOS) 71 #if defined(OS_CHROMEOS)
73 {chromeos::switches::kEnableTouchpadThreeFingerClick, 72 {chromeos::switches::kEnableTouchpadThreeFingerClick,
74 prefs::kEnableTouchpadThreeFingerClick, true}, 73 prefs::kEnableTouchpadThreeFingerClick, true},
75 {switches::kEnableUnifiedDesktop, 74 {switches::kEnableUnifiedDesktop,
76 prefs::kUnifiedDesktopEnabledByDefault, true}, 75 prefs::kUnifiedDesktopEnabledByDefault, true},
77 #endif 76 #endif
78 {switches::kUnsafePacUrl, prefs::kPacHttpsUrlStrippingEnabled, false}, 77 {switches::kUnsafePacUrl, prefs::kPacHttpsUrlStrippingEnabled, false},
79 }; 78 };
80 79
81 const CommandLinePrefStore::IntegerSwitchToPreferenceMapEntry 80 const CommandLinePrefStore::SwitchToPreferenceMapEntry
82 CommandLinePrefStore::integer_switch_map_[] = { 81 ChromeCommandLinePrefStore::integer_switch_map_[] = {
83 { switches::kDiskCacheSize, prefs::kDiskCacheSize }, 82 { switches::kDiskCacheSize, prefs::kDiskCacheSize },
84 { switches::kMediaCacheSize, prefs::kMediaCacheSize }, 83 { switches::kMediaCacheSize, prefs::kMediaCacheSize },
85 }; 84 };
86 85
87 CommandLinePrefStore::CommandLinePrefStore( 86 ChromeCommandLinePrefStore::ChromeCommandLinePrefStore(
88 const base::CommandLine* command_line) 87 const base::CommandLine* command_line)
89 : command_line_(command_line) { 88 : CommandLinePrefStore(command_line) {
90 ApplySimpleSwitches(); 89 ApplySimpleSwitches();
91 ApplyProxyMode(); 90 ApplyProxyMode();
92 ValidateProxySwitches(); 91 ValidateProxySwitches();
93 ApplySSLSwitches(); 92 ApplySSLSwitches();
94 ApplyBackgroundModeSwitches(); 93 ApplyBackgroundModeSwitches();
95 } 94 }
96 95
97 CommandLinePrefStore::~CommandLinePrefStore() {} 96 ChromeCommandLinePrefStore::~ChromeCommandLinePrefStore() {}
98 97
99 bool CommandLinePrefStore::ValidateProxySwitches() { 98 bool ChromeCommandLinePrefStore::ValidateProxySwitches() {
100 if (command_line_->HasSwitch(switches::kNoProxyServer) && 99 if (command_line()->HasSwitch(switches::kNoProxyServer) &&
101 (command_line_->HasSwitch(switches::kProxyAutoDetect) || 100 (command_line()->HasSwitch(switches::kProxyAutoDetect) ||
102 command_line_->HasSwitch(switches::kProxyServer) || 101 command_line()->HasSwitch(switches::kProxyServer) ||
103 command_line_->HasSwitch(switches::kProxyPacUrl) || 102 command_line()->HasSwitch(switches::kProxyPacUrl) ||
104 command_line_->HasSwitch(switches::kProxyBypassList))) { 103 command_line()->HasSwitch(switches::kProxyBypassList))) {
105 LOG(WARNING) << "Additional command-line proxy switches specified when --" 104 LOG(WARNING) << "Additional command-line proxy switches specified when --"
106 << switches::kNoProxyServer << " was also specified."; 105 << switches::kNoProxyServer << " was also specified.";
107 return false; 106 return false;
108 } 107 }
109 return true; 108 return true;
110 } 109 }
111 110
112 void CommandLinePrefStore::ApplySimpleSwitches() { 111 void ChromeCommandLinePrefStore::ApplySimpleSwitches() {
113 // Look for each switch we know about and set its preference accordingly. 112 // Look for each switch we know about and set its preference accordingly.
114 for (size_t i = 0; i < arraysize(string_switch_map_); ++i) { 113 ApplyStringSwitches(string_switch_map_, arraysize(string_switch_map_));
115 if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) { 114 ApplyPathSwitches(path_switch_map_, arraysize(path_switch_map_));
116 SetValue(string_switch_map_[i].preference_path, 115 ApplyIntegerSwitches(integer_switch_map_, arraysize(integer_switch_map_));
117 base::MakeUnique<base::StringValue>( 116 ApplyBooleanSwitches(boolean_switch_map_, arraysize(boolean_switch_map_));
118 command_line_->GetSwitchValueASCII(
119 string_switch_map_[i].switch_name)),
120 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
121 }
122 }
123
124 for (size_t i = 0; i < arraysize(path_switch_map_); ++i) {
125 if (command_line_->HasSwitch(path_switch_map_[i].switch_name)) {
126 SetValue(
127 path_switch_map_[i].preference_path,
128 base::MakeUnique<base::StringValue>(
129 command_line_->GetSwitchValuePath(path_switch_map_[i].switch_name)
130 .value()),
131 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
132 }
133 }
134
135 for (size_t i = 0; i < arraysize(integer_switch_map_); ++i) {
136 if (command_line_->HasSwitch(integer_switch_map_[i].switch_name)) {
137 std::string str_value = command_line_->GetSwitchValueASCII(
138 integer_switch_map_[i].switch_name);
139 int int_value = 0;
140 if (!base::StringToInt(str_value, &int_value)) {
141 LOG(ERROR) << "The value " << str_value << " of "
142 << integer_switch_map_[i].switch_name
143 << " can not be converted to integer, ignoring!";
144 continue;
145 }
146 SetValue(integer_switch_map_[i].preference_path,
147 base::MakeUnique<base::FundamentalValue>(int_value),
148 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
149 }
150 }
151
152 for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) {
153 if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) {
154 SetValue(boolean_switch_map_[i].preference_path,
155 base::MakeUnique<base::FundamentalValue>(
156 boolean_switch_map_[i].set_value),
157 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
158 }
159 }
160 } 117 }
161 118
162 void CommandLinePrefStore::ApplyProxyMode() { 119 void ChromeCommandLinePrefStore::ApplyProxyMode() {
163 if (command_line_->HasSwitch(switches::kNoProxyServer)) { 120 if (command_line()->HasSwitch(switches::kNoProxyServer)) {
164 SetValue(proxy_config::prefs::kProxy, 121 SetValue(proxy_config::prefs::kProxy,
165 base::WrapUnique(ProxyConfigDictionary::CreateDirect()), 122 base::WrapUnique(ProxyConfigDictionary::CreateDirect()),
166 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 123 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
167 } else if (command_line_->HasSwitch(switches::kProxyPacUrl)) { 124 } else if (command_line()->HasSwitch(switches::kProxyPacUrl)) {
168 std::string pac_script_url = 125 std::string pac_script_url =
169 command_line_->GetSwitchValueASCII(switches::kProxyPacUrl); 126 command_line()->GetSwitchValueASCII(switches::kProxyPacUrl);
170 SetValue(proxy_config::prefs::kProxy, 127 SetValue(proxy_config::prefs::kProxy,
171 base::WrapUnique( 128 base::WrapUnique(
172 ProxyConfigDictionary::CreatePacScript(pac_script_url, false)), 129 ProxyConfigDictionary::CreatePacScript(pac_script_url, false)),
173 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 130 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
174 } else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) { 131 } else if (command_line()->HasSwitch(switches::kProxyAutoDetect)) {
175 SetValue(proxy_config::prefs::kProxy, 132 SetValue(proxy_config::prefs::kProxy,
176 base::WrapUnique(ProxyConfigDictionary::CreateAutoDetect()), 133 base::WrapUnique(ProxyConfigDictionary::CreateAutoDetect()),
177 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 134 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
178 } else if (command_line_->HasSwitch(switches::kProxyServer)) { 135 } else if (command_line()->HasSwitch(switches::kProxyServer)) {
179 std::string proxy_server = 136 std::string proxy_server =
180 command_line_->GetSwitchValueASCII(switches::kProxyServer); 137 command_line()->GetSwitchValueASCII(switches::kProxyServer);
181 std::string bypass_list = 138 std::string bypass_list =
182 command_line_->GetSwitchValueASCII(switches::kProxyBypassList); 139 command_line()->GetSwitchValueASCII(switches::kProxyBypassList);
183 SetValue(proxy_config::prefs::kProxy, 140 SetValue(proxy_config::prefs::kProxy,
184 base::WrapUnique(ProxyConfigDictionary::CreateFixedServers( 141 base::WrapUnique(ProxyConfigDictionary::CreateFixedServers(
185 proxy_server, bypass_list)), 142 proxy_server, bypass_list)),
186 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 143 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
187 } 144 }
188 } 145 }
189 146
190 void CommandLinePrefStore::ApplySSLSwitches() { 147 void ChromeCommandLinePrefStore::ApplySSLSwitches() {
191 if (command_line_->HasSwitch(switches::kCipherSuiteBlacklist)) { 148 if (command_line()->HasSwitch(switches::kCipherSuiteBlacklist)) {
192 std::unique_ptr<base::ListValue> list_value(new base::ListValue()); 149 std::unique_ptr<base::ListValue> list_value(new base::ListValue());
193 list_value->AppendStrings(base::SplitString( 150 list_value->AppendStrings(base::SplitString(
194 command_line_->GetSwitchValueASCII(switches::kCipherSuiteBlacklist), 151 command_line()->GetSwitchValueASCII(switches::kCipherSuiteBlacklist),
195 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)); 152 ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL));
196 SetValue(ssl_config::prefs::kCipherSuiteBlacklist, std::move(list_value), 153 SetValue(ssl_config::prefs::kCipherSuiteBlacklist, std::move(list_value),
197 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 154 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
198 } 155 }
199 } 156 }
200 157
201 void CommandLinePrefStore::ApplyBackgroundModeSwitches() { 158 void ChromeCommandLinePrefStore::ApplyBackgroundModeSwitches() {
202 if (command_line_->HasSwitch(switches::kDisableExtensions)) { 159 if (command_line()->HasSwitch(switches::kDisableExtensions)) {
203 SetValue(prefs::kBackgroundModeEnabled, 160 SetValue(prefs::kBackgroundModeEnabled,
204 base::MakeUnique<base::FundamentalValue>(false), 161 base::MakeUnique<base::FundamentalValue>(false),
205 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 162 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
206 } 163 }
207 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698