OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line_pref_store.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_number_conversions.h" |
8 #include "base/string_split.h" | 9 #include "base/string_split.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 11 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
13 #include "ui/base/ui_base_switches.h" | 14 #include "ui/base/ui_base_switches.h" |
14 | 15 |
15 const CommandLinePrefStore::StringSwitchToPreferenceMapEntry | 16 const CommandLinePrefStore::StringSwitchToPreferenceMapEntry |
16 CommandLinePrefStore::string_switch_map_[] = { | 17 CommandLinePrefStore::string_switch_map_[] = { |
17 { switches::kLang, prefs::kApplicationLocale }, | 18 { switches::kLang, prefs::kApplicationLocale }, |
18 { switches::kAuthSchemes, prefs::kAuthSchemes }, | 19 { switches::kAuthSchemes, prefs::kAuthSchemes }, |
19 { switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist }, | 20 { switches::kAuthServerWhitelist, prefs::kAuthServerWhitelist }, |
20 { switches::kAuthNegotiateDelegateWhitelist, | 21 { switches::kAuthNegotiateDelegateWhitelist, |
21 prefs::kAuthNegotiateDelegateWhitelist }, | 22 prefs::kAuthNegotiateDelegateWhitelist }, |
22 { switches::kGSSAPILibraryName, prefs::kGSSAPILibraryName }, | 23 { switches::kGSSAPILibraryName, prefs::kGSSAPILibraryName }, |
| 24 { switches::kDiskCacheDir, prefs::kDiskCacheDir }, |
23 }; | 25 }; |
24 | 26 |
25 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry | 27 const CommandLinePrefStore::BooleanSwitchToPreferenceMapEntry |
26 CommandLinePrefStore::boolean_switch_map_[] = { | 28 CommandLinePrefStore::boolean_switch_map_[] = { |
27 { switches::kDisableAuthNegotiateCnameLookup, | 29 { switches::kDisableAuthNegotiateCnameLookup, |
28 prefs::kDisableAuthNegotiateCnameLookup, true }, | 30 prefs::kDisableAuthNegotiateCnameLookup, true }, |
29 { switches::kEnableAuthNegotiatePort, prefs::kEnableAuthNegotiatePort, | 31 { switches::kEnableAuthNegotiatePort, prefs::kEnableAuthNegotiatePort, |
30 true }, | 32 true }, |
31 { switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true }, | 33 { switches::kDisable3DAPIs, prefs::kDisable3DAPIs, true }, |
32 { switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled, | 34 { switches::kEnableCloudPrintProxy, prefs::kCloudPrintProxyEnabled, |
33 true }, | 35 true }, |
34 { switches::kAllowOutdatedPlugins, prefs::kPluginsAllowOutdated, true }, | 36 { switches::kAllowOutdatedPlugins, prefs::kPluginsAllowOutdated, true }, |
35 { switches::kAlwaysAuthorizePlugins, prefs::kPluginsAlwaysAuthorize, | 37 { switches::kAlwaysAuthorizePlugins, prefs::kPluginsAlwaysAuthorize, |
36 true }, | 38 true }, |
37 { switches::kNoPings, prefs::kEnableHyperlinkAuditing, false }, | 39 { switches::kNoPings, prefs::kEnableHyperlinkAuditing, false }, |
38 { switches::kNoReferrers, prefs::kEnableReferrers, false }, | 40 { switches::kNoReferrers, prefs::kEnableReferrers, false }, |
39 { switches::kAllowRunningInsecureContent, | 41 { switches::kAllowRunningInsecureContent, |
40 prefs::kWebKitAllowRunningInsecureContent, true }, | 42 prefs::kWebKitAllowRunningInsecureContent, true }, |
41 { switches::kNoDisplayingInsecureContent, | 43 { switches::kNoDisplayingInsecureContent, |
42 prefs::kWebKitAllowDisplayingInsecureContent, false }, | 44 prefs::kWebKitAllowDisplayingInsecureContent, false }, |
43 { switches::kAllowCrossOriginAuthPrompt, | 45 { switches::kAllowCrossOriginAuthPrompt, |
44 prefs::kAllowCrossOriginAuthPrompt, true }, | 46 prefs::kAllowCrossOriginAuthPrompt, true }, |
45 { switches::kDisableSSL3, prefs::kSSL3Enabled, false }, | 47 { switches::kDisableSSL3, prefs::kSSL3Enabled, false }, |
46 { switches::kDisableTLS1, prefs::kTLS1Enabled, false }, | 48 { switches::kDisableTLS1, prefs::kTLS1Enabled, false }, |
47 }; | 49 }; |
48 | 50 |
| 51 const CommandLinePrefStore::IntegerSwitchToPreferenceMapEntry |
| 52 CommandLinePrefStore::integer_switch_map_[] = { |
| 53 { switches::kDiskCacheSize, prefs::kDiskCacheSize }, |
| 54 { switches::kMediaCacheSize, prefs::kMediaCacheSize }, |
| 55 }; |
| 56 |
49 CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line) | 57 CommandLinePrefStore::CommandLinePrefStore(const CommandLine* command_line) |
50 : command_line_(command_line) { | 58 : command_line_(command_line) { |
51 ApplySimpleSwitches(); | 59 ApplySimpleSwitches(); |
52 ApplyProxyMode(); | 60 ApplyProxyMode(); |
53 ValidateProxySwitches(); | 61 ValidateProxySwitches(); |
54 ApplySSLSwitches(); | 62 ApplySSLSwitches(); |
55 } | 63 } |
56 | 64 |
57 CommandLinePrefStore::~CommandLinePrefStore() {} | 65 CommandLinePrefStore::~CommandLinePrefStore() {} |
58 | 66 |
59 void CommandLinePrefStore::ApplySimpleSwitches() { | 67 void CommandLinePrefStore::ApplySimpleSwitches() { |
60 // Look for each switch we know about and set its preference accordingly. | 68 // Look for each switch we know about and set its preference accordingly. |
61 for (size_t i = 0; i < arraysize(string_switch_map_); ++i) { | 69 for (size_t i = 0; i < arraysize(string_switch_map_); ++i) { |
62 if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) { | 70 if (command_line_->HasSwitch(string_switch_map_[i].switch_name)) { |
63 Value* value = Value::CreateStringValue(command_line_-> | 71 Value* value = Value::CreateStringValue(command_line_-> |
64 GetSwitchValueASCII(string_switch_map_[i].switch_name)); | 72 GetSwitchValueASCII(string_switch_map_[i].switch_name)); |
65 SetValue(string_switch_map_[i].preference_path, value); | 73 SetValue(string_switch_map_[i].preference_path, value); |
66 } | 74 } |
67 } | 75 } |
68 | 76 |
| 77 for (size_t i = 0; i < arraysize(integer_switch_map_); ++i) { |
| 78 if (command_line_->HasSwitch(integer_switch_map_[i].switch_name)) { |
| 79 std::string str_value = command_line_->GetSwitchValueASCII( |
| 80 integer_switch_map_[i].switch_name); |
| 81 int int_value = 0; |
| 82 if (!base::StringToInt(str_value, &int_value)) { |
| 83 LOG(ERROR) << "The value " << str_value << " of " |
| 84 << integer_switch_map_[i].switch_name |
| 85 << " can not be converted to integer, ignoring!"; |
| 86 continue; |
| 87 } |
| 88 Value* value = Value::CreateIntegerValue(int_value); |
| 89 SetValue(integer_switch_map_[i].preference_path, value); |
| 90 } |
| 91 } |
| 92 |
69 for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) { | 93 for (size_t i = 0; i < arraysize(boolean_switch_map_); ++i) { |
70 if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) { | 94 if (command_line_->HasSwitch(boolean_switch_map_[i].switch_name)) { |
71 Value* value = Value::CreateBooleanValue( | 95 Value* value = Value::CreateBooleanValue( |
72 boolean_switch_map_[i].set_value); | 96 boolean_switch_map_[i].set_value); |
73 SetValue(boolean_switch_map_[i].preference_path, value); | 97 SetValue(boolean_switch_map_[i].preference_path, value); |
74 } | 98 } |
75 } | 99 } |
76 } | 100 } |
77 | 101 |
78 bool CommandLinePrefStore::ValidateProxySwitches() { | 102 bool CommandLinePrefStore::ValidateProxySwitches() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 std::vector<std::string> cipher_strings; | 142 std::vector<std::string> cipher_strings; |
119 base::SplitString(cipher_suites, ',', &cipher_strings); | 143 base::SplitString(cipher_suites, ',', &cipher_strings); |
120 base::ListValue* list_value = new base::ListValue(); | 144 base::ListValue* list_value = new base::ListValue(); |
121 for (std::vector<std::string>::const_iterator it = cipher_strings.begin(); | 145 for (std::vector<std::string>::const_iterator it = cipher_strings.begin(); |
122 it != cipher_strings.end(); ++it) { | 146 it != cipher_strings.end(); ++it) { |
123 list_value->Append(base::Value::CreateStringValue(*it)); | 147 list_value->Append(base::Value::CreateStringValue(*it)); |
124 } | 148 } |
125 SetValue(prefs::kCipherSuiteBlacklist, list_value); | 149 SetValue(prefs::kCipherSuiteBlacklist, list_value); |
126 } | 150 } |
127 } | 151 } |
OLD | NEW |