OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 MigrateDataReductionProxyOffProxyPrefsHelper(prefs); | 88 MigrateDataReductionProxyOffProxyPrefsHelper(prefs); |
89 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.ProxyPrefMigrationResult", | 89 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.ProxyPrefMigrationResult", |
90 proxy_pref_status, | 90 proxy_pref_status, |
91 DataReductionProxyChromeSettings::PROXY_PREF_MAX); | 91 DataReductionProxyChromeSettings::PROXY_PREF_MAX); |
92 } | 92 } |
93 | 93 |
94 DataReductionProxyChromeSettings::ProxyPrefMigrationResult | 94 DataReductionProxyChromeSettings::ProxyPrefMigrationResult |
95 DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefsHelper( | 95 DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefsHelper( |
96 PrefService* prefs) { | 96 PrefService* prefs) { |
97 base::DictionaryValue* dict = | 97 base::DictionaryValue* dict = |
98 (base::DictionaryValue*)prefs->GetUserPrefValue(prefs::kProxy); | 98 (base::DictionaryValue*)prefs->GetUserPrefValue(ProxyPrefs::kProxy); |
99 if (!dict) | 99 if (!dict) |
100 return PROXY_PREF_NOT_CLEARED; | 100 return PROXY_PREF_NOT_CLEARED; |
101 | 101 |
102 // Clear empty "proxy" dictionary created by a bug. See http://crbug/448172. | 102 // Clear empty "proxy" dictionary created by a bug. See http://crbug/448172. |
103 if (dict->empty()) { | 103 if (dict->empty()) { |
104 prefs->ClearPref(prefs::kProxy); | 104 prefs->ClearPref(ProxyPrefs::kProxy); |
105 return PROXY_PREF_CLEARED_EMPTY; | 105 return PROXY_PREF_CLEARED_EMPTY; |
106 } | 106 } |
107 | 107 |
108 std::string mode; | 108 std::string mode; |
109 if (!dict->GetString("mode", &mode)) | 109 if (!dict->GetString("mode", &mode)) |
110 return PROXY_PREF_NOT_CLEARED; | 110 return PROXY_PREF_NOT_CLEARED; |
111 // Clear "system" proxy entry since this is the default. This entry was | 111 // Clear "system" proxy entry since this is the default. This entry was |
112 // created by bug (http://crbug/448172). | 112 // created by bug (http://crbug/448172). |
113 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) { | 113 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) { |
114 prefs->ClearPref(prefs::kProxy); | 114 prefs->ClearPref(ProxyPrefs::kProxy); |
115 return PROXY_PREF_CLEARED_MODE_SYSTEM; | 115 return PROXY_PREF_CLEARED_MODE_SYSTEM; |
116 } | 116 } |
117 | 117 |
118 // From M36 to M40, the DRP was configured using MODE_FIXED_SERVERS in the | 118 // From M36 to M40, the DRP was configured using MODE_FIXED_SERVERS in the |
119 // proxy pref. | 119 // proxy pref. |
120 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) == mode) { | 120 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) == mode) { |
121 std::string proxy_server; | 121 std::string proxy_server; |
122 if (!dict->GetString("server", &proxy_server)) | 122 if (!dict->GetString("server", &proxy_server)) |
123 return PROXY_PREF_NOT_CLEARED; | 123 return PROXY_PREF_NOT_CLEARED; |
124 net::ProxyConfig::ProxyRules proxy_rules; | 124 net::ProxyConfig::ProxyRules proxy_rules; |
125 proxy_rules.ParseFromString(proxy_server); | 125 proxy_rules.ParseFromString(proxy_server); |
126 // Clear the proxy pref if it matches a currently configured Data Reduction | 126 // Clear the proxy pref if it matches a currently configured Data Reduction |
127 // Proxy, or if the proxy host ends with ".googlezip.net", in order to | 127 // Proxy, or if the proxy host ends with ".googlezip.net", in order to |
128 // ensure that any DRP in the pref is cleared even if the DRP configuration | 128 // ensure that any DRP in the pref is cleared even if the DRP configuration |
129 // was changed. See http://crbug.com/476610. | 129 // was changed. See http://crbug.com/476610. |
130 ProxyPrefMigrationResult rv; | 130 ProxyPrefMigrationResult rv; |
131 if (Config()->ContainsDataReductionProxy(proxy_rules)) | 131 if (Config()->ContainsDataReductionProxy(proxy_rules)) |
132 rv = PROXY_PREF_CLEARED_DRP; | 132 rv = PROXY_PREF_CLEARED_DRP; |
133 else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules)) | 133 else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules)) |
134 rv = PROXY_PREF_CLEARED_GOOGLEZIP; | 134 rv = PROXY_PREF_CLEARED_GOOGLEZIP; |
135 else | 135 else |
136 return PROXY_PREF_NOT_CLEARED; | 136 return PROXY_PREF_NOT_CLEARED; |
137 | 137 |
138 prefs->ClearPref(prefs::kProxy); | 138 prefs->ClearPref(ProxyPrefs::kProxy); |
139 return rv; | 139 return rv; |
140 } | 140 } |
141 | 141 |
142 // Before M35, the DRP was configured using a PAC script base64 encoded into a | 142 // Before M35, the DRP was configured using a PAC script base64 encoded into a |
143 // PAC url. | 143 // PAC url. |
144 if (ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT) == mode) { | 144 if (ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT) == mode) { |
145 std::string pac_url; | 145 std::string pac_url; |
146 std::string pac_script; | 146 std::string pac_script; |
147 if (!dict->GetString("pac_url", &pac_url) || | 147 if (!dict->GetString("pac_url", &pac_url) || |
148 !GetEmbeddedPacScript(pac_url, &pac_script)) { | 148 !GetEmbeddedPacScript(pac_url, &pac_script)) { |
149 return PROXY_PREF_NOT_CLEARED; | 149 return PROXY_PREF_NOT_CLEARED; |
150 } | 150 } |
151 | 151 |
152 // In M35 and earlier, the way of specifying the DRP in a PAC script would | 152 // In M35 and earlier, the way of specifying the DRP in a PAC script would |
153 // always include the port number after the host even if the port number | 153 // always include the port number after the host even if the port number |
154 // could be implied, so searching for ".googlezip.net:" in the PAC script | 154 // could be implied, so searching for ".googlezip.net:" in the PAC script |
155 // indicates whether there's a proxy in that PAC script with a host of the | 155 // indicates whether there's a proxy in that PAC script with a host of the |
156 // form "*.googlezip.net". | 156 // form "*.googlezip.net". |
157 if (pac_script.find(".googlezip.net:") == std::string::npos) | 157 if (pac_script.find(".googlezip.net:") == std::string::npos) |
158 return PROXY_PREF_NOT_CLEARED; | 158 return PROXY_PREF_NOT_CLEARED; |
159 | 159 |
160 prefs->ClearPref(prefs::kProxy); | 160 prefs->ClearPref(ProxyPrefs::kProxy); |
161 return PROXY_PREF_CLEARED_PAC_GOOGLEZIP; | 161 return PROXY_PREF_CLEARED_PAC_GOOGLEZIP; |
162 } | 162 } |
163 | 163 |
164 return PROXY_PREF_NOT_CLEARED; | 164 return PROXY_PREF_NOT_CLEARED; |
165 } | 165 } |
166 | 166 |
167 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() | 167 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() |
168 : data_reduction_proxy::DataReductionProxySettings() { | 168 : data_reduction_proxy::DataReductionProxySettings() { |
169 } | 169 } |
170 | 170 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 #elif defined(OS_OPENBSD) | 230 #elif defined(OS_OPENBSD) |
231 return data_reduction_proxy::Client::CHROME_OPENBSD; | 231 return data_reduction_proxy::Client::CHROME_OPENBSD; |
232 #elif defined(OS_SOLARIS) | 232 #elif defined(OS_SOLARIS) |
233 return data_reduction_proxy::Client::CHROME_SOLARIS; | 233 return data_reduction_proxy::Client::CHROME_SOLARIS; |
234 #elif defined(OS_QNX) | 234 #elif defined(OS_QNX) |
235 return data_reduction_proxy::Client::CHROME_QNX; | 235 return data_reduction_proxy::Client::CHROME_QNX; |
236 #else | 236 #else |
237 return data_reduction_proxy::Client::UNKNOWN; | 237 return data_reduction_proxy::Client::UNKNOWN; |
238 #endif | 238 #endif |
239 } | 239 } |
OLD | NEW |