Index: chrome/browser/prefs/command_line_pref_store.cc |
diff --git a/chrome/browser/prefs/chrome_command_line_pref_store.cc b/chrome/browser/prefs/command_line_pref_store.cc |
similarity index 55% |
copy from chrome/browser/prefs/chrome_command_line_pref_store.cc |
copy to chrome/browser/prefs/command_line_pref_store.cc |
index bd91955c25a536f3c72b1e1ae897da0128dd1382..7c7f1ec45bb9b64e2cfde0302f48f91712e944aa 100644 |
--- a/chrome/browser/prefs/chrome_command_line_pref_store.cc |
+++ b/chrome/browser/prefs/command_line_pref_store.cc |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/prefs/chrome_command_line_pref_store.h" |
+#include "chrome/browser/prefs/command_line_pref_store.h" |
#include <stddef.h> |
@@ -13,6 +13,7 @@ |
#include "ash/common/ash_switches.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
+#include "base/macros.h" |
#include "base/memory/ptr_util.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_split.h" |
@@ -30,16 +31,12 @@ |
#include "ui/base/ui_base_switches.h" |
#include "ui/display/display_switches.h" |
-#if defined(OS_ANDROID) |
-#include "chrome/browser/android/preferences/command_line_pref_store_android.h" |
-#endif |
- |
#if defined(OS_CHROMEOS) |
#include "chromeos/chromeos_switches.h" |
#endif |
-const CommandLinePrefStore::SwitchToPreferenceMapEntry |
- ChromeCommandLinePrefStore::string_switch_map_[] = { |
+const CommandLinePrefStore::StringSwitchToPreferenceMapEntry |
+ CommandLinePrefStore::string_switch_map_[] = { |
{ switches::kLang, prefs::kApplicationLocale }, |
{ data_reduction_proxy::switches::kDataReductionProxy, |
data_reduction_proxy::prefs::kDataReductionProxy }, |
@@ -52,13 +49,13 @@ const CommandLinePrefStore::SwitchToPreferenceMapEntry |
#endif |
}; |
-const CommandLinePrefStore::SwitchToPreferenceMapEntry |
- ChromeCommandLinePrefStore::path_switch_map_[] = { |
+const CommandLinePrefStore::PathSwitchToPreferenceMapEntry |
+ CommandLinePrefStore::path_switch_map_[] = { |
{ switches::kDiskCacheDir, prefs::kDiskCacheDir }, |
}; |
const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry |
- ChromeCommandLinePrefStore::boolean_switch_map_[] = { |
+ CommandLinePrefStore::boolean_switch_map_[] = { |
{switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true}, |
{switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled, |
true}, |
@@ -78,18 +75,19 @@ const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry |
{switches::kEnableUnifiedDesktop, |
prefs::kUnifiedDesktopEnabledByDefault, true}, |
#endif |
+ {switches::kDisableAsyncDns, prefs::kBuiltInDnsClientEnabled, false}, |
{switches::kUnsafePacUrl, prefs::kPacHttpsUrlStrippingEnabled, false}, |
}; |
-const CommandLinePrefStore::SwitchToPreferenceMapEntry |
- ChromeCommandLinePrefStore::integer_switch_map_[] = { |
+const CommandLinePrefStore::IntegerSwitchToPreferenceMapEntry |
+ CommandLinePrefStore::integer_switch_map_[] = { |
{ switches::kDiskCacheSize, prefs::kDiskCacheSize }, |
{ switches::kMediaCacheSize, prefs::kMediaCacheSize }, |
}; |
-ChromeCommandLinePrefStore::ChromeCommandLinePrefStore( |
+CommandLinePrefStore::CommandLinePrefStore( |
const base::CommandLine* command_line) |
- : CommandLinePrefStore(command_line) { |
+ : command_line_(command_line) { |
ApplySimpleSwitches(); |
ApplyProxyMode(); |
ValidateProxySwitches(); |
@@ -97,14 +95,14 @@ ChromeCommandLinePrefStore::ChromeCommandLinePrefStore( |
ApplyBackgroundModeSwitches(); |
} |
-ChromeCommandLinePrefStore::~ChromeCommandLinePrefStore() {} |
+CommandLinePrefStore::~CommandLinePrefStore() {} |
-bool ChromeCommandLinePrefStore::ValidateProxySwitches() { |
- if (command_line()->HasSwitch(switches::kNoProxyServer) && |
- (command_line()->HasSwitch(switches::kProxyAutoDetect) || |
- command_line()->HasSwitch(switches::kProxyServer) || |
- command_line()->HasSwitch(switches::kProxyPacUrl) || |
- command_line()->HasSwitch(switches::kProxyBypassList))) { |
+bool CommandLinePrefStore::ValidateProxySwitches() { |
+ if (command_line_->HasSwitch(switches::kNoProxyServer) && |
+ (command_line_->HasSwitch(switches::kProxyAutoDetect) || |
+ command_line_->HasSwitch(switches::kProxyServer) || |
+ command_line_->HasSwitch(switches::kProxyPacUrl) || |
+ command_line_->HasSwitch(switches::kProxyBypassList))) { |
LOG(WARNING) << "Additional command-line proxy switches specified when --" |
<< switches::kNoProxyServer << " was also specified."; |
return false; |
@@ -112,38 +110,77 @@ bool ChromeCommandLinePrefStore::ValidateProxySwitches() { |
return true; |
} |
-void ChromeCommandLinePrefStore::ApplySimpleSwitches() { |
+void CommandLinePrefStore::ApplySimpleSwitches() { |
// Look for each switch we know about and set its preference accordingly. |
- ApplyStringSwitches(string_switch_map_, arraysize(string_switch_map_)); |
- ApplyPathSwitches(path_switch_map_, arraysize(path_switch_map_)); |
- ApplyIntegerSwitches(integer_switch_map_, arraysize(integer_switch_map_)); |
- ApplyBooleanSwitches(boolean_switch_map_, arraysize(boolean_switch_map_)); |
-#if defined(OS_ANDROID) |
- ::android::ApplyBlimpSwitches(this); |
-#endif |
+ for (size_t i = 0; i < arraysize(string_switch_map_); ++i) { |
+ if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) { |
+ SetValue(string_switch_map_[i].preference_path, |
+ base::MakeUnique<base::StringValue>( |
+ command_line_->GetSwitchValueASCII( |
+ string_switch_map_[i].switch_name)), |
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
+ } |
+ } |
+ |
+ for (size_t i = 0; i < arraysize(path_switch_map_); ++i) { |
+ if (command_line_->HasSwitch(path_switch_map_[i].switch_name)) { |
+ SetValue( |
+ path_switch_map_[i].preference_path, |
+ base::MakeUnique<base::StringValue>( |
+ command_line_->GetSwitchValuePath(path_switch_map_[i].switch_name) |
+ .value()), |
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
+ } |
+ } |
+ |
+ for (size_t i = 0; i < arraysize(integer_switch_map_); ++i) { |
+ if (command_line_->HasSwitch(integer_switch_map_[i].switch_name)) { |
+ std::string str_value = command_line_->GetSwitchValueASCII( |
+ integer_switch_map_[i].switch_name); |
+ int int_value = 0; |
+ if (!base::StringToInt(str_value, &int_value)) { |
+ LOG(ERROR) << "The value " << str_value << " of " |
+ << integer_switch_map_[i].switch_name |
+ << " can not be converted to integer, ignoring!"; |
+ continue; |
+ } |
+ SetValue(integer_switch_map_[i].preference_path, |
+ base::MakeUnique<base::Value>(int_value), |
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
+ } |
+ } |
+ |
+ for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) { |
+ if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) { |
+ SetValue(boolean_switch_map_[i].preference_path, |
+ base::MakeUnique<base::Value>( |
+ boolean_switch_map_[i].set_value), |
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
+ } |
+ } |
} |
-void ChromeCommandLinePrefStore::ApplyProxyMode() { |
- if (command_line()->HasSwitch(switches::kNoProxyServer)) { |
+void CommandLinePrefStore::ApplyProxyMode() { |
+ if (command_line_->HasSwitch(switches::kNoProxyServer)) { |
SetValue(proxy_config::prefs::kProxy, |
base::WrapUnique(ProxyConfigDictionary::CreateDirect()), |
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
- } else if (command_line()->HasSwitch(switches::kProxyPacUrl)) { |
+ } else if (command_line_->HasSwitch(switches::kProxyPacUrl)) { |
std::string pac_script_url = |
- command_line()->GetSwitchValueASCII(switches::kProxyPacUrl); |
+ command_line_->GetSwitchValueASCII(switches::kProxyPacUrl); |
SetValue(proxy_config::prefs::kProxy, |
base::WrapUnique( |
ProxyConfigDictionary::CreatePacScript(pac_script_url, false)), |
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
- } else if (command_line()->HasSwitch(switches::kProxyAutoDetect)) { |
+ } else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) { |
SetValue(proxy_config::prefs::kProxy, |
base::WrapUnique(ProxyConfigDictionary::CreateAutoDetect()), |
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
- } else if (command_line()->HasSwitch(switches::kProxyServer)) { |
+ } else if (command_line_->HasSwitch(switches::kProxyServer)) { |
std::string proxy_server = |
- command_line()->GetSwitchValueASCII(switches::kProxyServer); |
+ command_line_->GetSwitchValueASCII(switches::kProxyServer); |
std::string bypass_list = |
- command_line()->GetSwitchValueASCII(switches::kProxyBypassList); |
+ command_line_->GetSwitchValueASCII(switches::kProxyBypassList); |
SetValue(proxy_config::prefs::kProxy, |
base::WrapUnique(ProxyConfigDictionary::CreateFixedServers( |
proxy_server, bypass_list)), |
@@ -151,21 +188,21 @@ void ChromeCommandLinePrefStore::ApplyProxyMode() { |
} |
} |
-void ChromeCommandLinePrefStore::ApplySSLSwitches() { |
- if (command_line()->HasSwitch(switches::kCipherSuiteBlacklist)) { |
+void CommandLinePrefStore::ApplySSLSwitches() { |
+ if (command_line_->HasSwitch(switches::kCipherSuiteBlacklist)) { |
std::unique_ptr<base::ListValue> list_value(new base::ListValue()); |
list_value->AppendStrings(base::SplitString( |
- command_line()->GetSwitchValueASCII(switches::kCipherSuiteBlacklist), |
+ command_line_->GetSwitchValueASCII(switches::kCipherSuiteBlacklist), |
",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)); |
SetValue(ssl_config::prefs::kCipherSuiteBlacklist, std::move(list_value), |
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
} |
} |
-void ChromeCommandLinePrefStore::ApplyBackgroundModeSwitches() { |
- if (command_line()->HasSwitch(switches::kDisableExtensions)) { |
+void CommandLinePrefStore::ApplyBackgroundModeSwitches() { |
+ if (command_line_->HasSwitch(switches::kDisableExtensions)) { |
SetValue(prefs::kBackgroundModeEnabled, |
- base::MakeUnique<base::FundamentalValue>(false), |
+ base::MakeUnique<base::Value>(false), |
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
} |
} |