| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 13 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 17 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 17 #include "chrome/browser/prefs/proxy_prefs.h" | 18 #include "chrome/browser/prefs/proxy_prefs.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // Searches |proxy_rules| for any Data Reduction Proxies, even if they don't | 53 // Searches |proxy_rules| for any Data Reduction Proxies, even if they don't |
| 53 // match a currently configured Data Reduction Proxy. | 54 // match a currently configured Data Reduction Proxy. |
| 54 bool ContainsDataReductionProxyDefaultHostSuffix( | 55 bool ContainsDataReductionProxyDefaultHostSuffix( |
| 55 const net::ProxyConfig::ProxyRules& proxy_rules) { | 56 const net::ProxyConfig::ProxyRules& proxy_rules) { |
| 56 return ContainsDataReductionProxyDefaultHostSuffix( | 57 return ContainsDataReductionProxyDefaultHostSuffix( |
| 57 proxy_rules.proxies_for_http) || | 58 proxy_rules.proxies_for_http) || |
| 58 ContainsDataReductionProxyDefaultHostSuffix( | 59 ContainsDataReductionProxyDefaultHostSuffix( |
| 59 proxy_rules.proxies_for_https); | 60 proxy_rules.proxies_for_https); |
| 60 } | 61 } |
| 61 | 62 |
| 63 // Extract the embedded PAC script from the given |pac_url|, and store the |
| 64 // extracted script in |pac_script|. Returns true if extraction was successful, |
| 65 // otherwise returns false. |pac_script| must not be NULL. |
| 66 bool GetEmbeddedPacScript(const std::string& pac_url, std::string* pac_script) { |
| 67 DCHECK(pac_script); |
| 68 const std::string kPacURLPrefix = |
| 69 "data:application/x-ns-proxy-autoconfig;base64,"; |
| 70 return StartsWithASCII(pac_url, kPacURLPrefix, true) && |
| 71 base::Base64Decode(pac_url.substr(kPacURLPrefix.size()), pac_script); |
| 72 } |
| 73 |
| 62 } // namespace | 74 } // namespace |
| 63 | 75 |
| 64 // The Data Reduction Proxy has been turned into a "best effort" proxy, | 76 // The Data Reduction Proxy has been turned into a "best effort" proxy, |
| 65 // meaning it is used only if the effective proxy configuration resolves to | 77 // meaning it is used only if the effective proxy configuration resolves to |
| 66 // DIRECT for a URL. It no longer can be a ProxyConfig in the proxy preference | 78 // DIRECT for a URL. It no longer can be a ProxyConfig in the proxy preference |
| 67 // hierarchy. This method removes the Data Reduction Proxy configuration from | 79 // hierarchy. This method removes the Data Reduction Proxy configuration from |
| 68 // prefs, if present. |proxy_pref_name| is the name of the proxy pref. | 80 // prefs, if present. |proxy_pref_name| is the name of the proxy pref. |
| 69 void DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefs( | 81 void DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefs( |
| 70 PrefService* prefs) { | 82 PrefService* prefs) { |
| 71 ProxyPrefMigrationResult proxy_pref_status = | 83 ProxyPrefMigrationResult proxy_pref_status = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 91 | 103 |
| 92 std::string mode; | 104 std::string mode; |
| 93 if (!dict->GetString("mode", &mode)) | 105 if (!dict->GetString("mode", &mode)) |
| 94 return PROXY_PREF_NOT_CLEARED; | 106 return PROXY_PREF_NOT_CLEARED; |
| 95 // Clear "system" proxy entry since this is the default. This entry was | 107 // Clear "system" proxy entry since this is the default. This entry was |
| 96 // created by bug (http://crbug/448172). | 108 // created by bug (http://crbug/448172). |
| 97 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) { | 109 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) { |
| 98 prefs->ClearPref(prefs::kProxy); | 110 prefs->ClearPref(prefs::kProxy); |
| 99 return PROXY_PREF_CLEARED_MODE_SYSTEM; | 111 return PROXY_PREF_CLEARED_MODE_SYSTEM; |
| 100 } | 112 } |
| 101 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) != mode) | |
| 102 return PROXY_PREF_NOT_CLEARED; | |
| 103 std::string proxy_server; | |
| 104 if (!dict->GetString("server", &proxy_server)) | |
| 105 return PROXY_PREF_NOT_CLEARED; | |
| 106 net::ProxyConfig::ProxyRules proxy_rules; | |
| 107 proxy_rules.ParseFromString(proxy_server); | |
| 108 // Clear the proxy pref if it matches a currently configured Data Reduction | |
| 109 // Proxy, or if the proxy host ends with ".googlezip.net", in order to ensure | |
| 110 // that any DRP in the pref is cleared even if the DRP configuration was | |
| 111 // changed. See http://crbug.com/476610. | |
| 112 ProxyPrefMigrationResult rv; | |
| 113 if (Config()->ContainsDataReductionProxy(proxy_rules)) | |
| 114 rv = PROXY_PREF_CLEARED_DRP; | |
| 115 else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules)) | |
| 116 rv = PROXY_PREF_CLEARED_GOOGLEZIP; | |
| 117 else | |
| 118 return PROXY_PREF_NOT_CLEARED; | |
| 119 | 113 |
| 120 prefs->ClearPref(prefs::kProxy); | 114 // From M36 to M40, the DRP was configured using MODE_FIXED_SERVERS in the |
| 121 return rv; | 115 // proxy pref. |
| 116 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) == mode) { |
| 117 std::string proxy_server; |
| 118 if (!dict->GetString("server", &proxy_server)) |
| 119 return PROXY_PREF_NOT_CLEARED; |
| 120 net::ProxyConfig::ProxyRules proxy_rules; |
| 121 proxy_rules.ParseFromString(proxy_server); |
| 122 // Clear the proxy pref if it matches a currently configured Data Reduction |
| 123 // Proxy, or if the proxy host ends with ".googlezip.net", in order to |
| 124 // ensure that any DRP in the pref is cleared even if the DRP configuration |
| 125 // was changed. See http://crbug.com/476610. |
| 126 ProxyPrefMigrationResult rv; |
| 127 if (Config()->ContainsDataReductionProxy(proxy_rules)) |
| 128 rv = PROXY_PREF_CLEARED_DRP; |
| 129 else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules)) |
| 130 rv = PROXY_PREF_CLEARED_GOOGLEZIP; |
| 131 else |
| 132 return PROXY_PREF_NOT_CLEARED; |
| 133 |
| 134 prefs->ClearPref(prefs::kProxy); |
| 135 return rv; |
| 136 } |
| 137 |
| 138 // Before M35, the DRP was configured using a PAC script base64 encoded into a |
| 139 // PAC url. |
| 140 if (ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT) == mode) { |
| 141 std::string pac_url; |
| 142 std::string pac_script; |
| 143 if (!dict->GetString("pac_url", &pac_url) || |
| 144 !GetEmbeddedPacScript(pac_url, &pac_script)) { |
| 145 return PROXY_PREF_NOT_CLEARED; |
| 146 } |
| 147 |
| 148 // In M35 and earlier, the way of specifying the DRP in a PAC script would |
| 149 // always include the port number after the host even if the port number |
| 150 // could be implied, so searching for ".googlezip.net:" in the PAC script |
| 151 // indicates whether there's a proxy in that PAC script with a host of the |
| 152 // form "*.googlezip.net". |
| 153 if (pac_script.find(".googlezip.net:") == std::string::npos) |
| 154 return PROXY_PREF_NOT_CLEARED; |
| 155 |
| 156 prefs->ClearPref(prefs::kProxy); |
| 157 return PROXY_PREF_CLEARED_PAC_GOOGLEZIP; |
| 158 } |
| 159 |
| 160 return PROXY_PREF_NOT_CLEARED; |
| 122 } | 161 } |
| 123 | 162 |
| 124 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() | 163 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() |
| 125 : data_reduction_proxy::DataReductionProxySettings() { | 164 : data_reduction_proxy::DataReductionProxySettings() { |
| 126 } | 165 } |
| 127 | 166 |
| 128 DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() { | 167 DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() { |
| 129 } | 168 } |
| 130 | 169 |
| 131 void DataReductionProxyChromeSettings::Shutdown() { | 170 void DataReductionProxyChromeSettings::Shutdown() { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 #elif defined(OS_OPENBSD) | 230 #elif defined(OS_OPENBSD) |
| 192 return data_reduction_proxy::Client::CHROME_OPENBSD; | 231 return data_reduction_proxy::Client::CHROME_OPENBSD; |
| 193 #elif defined(OS_SOLARIS) | 232 #elif defined(OS_SOLARIS) |
| 194 return data_reduction_proxy::Client::CHROME_SOLARIS; | 233 return data_reduction_proxy::Client::CHROME_SOLARIS; |
| 195 #elif defined(OS_QNX) | 234 #elif defined(OS_QNX) |
| 196 return data_reduction_proxy::Client::CHROME_QNX; | 235 return data_reduction_proxy::Client::CHROME_QNX; |
| 197 #else | 236 #else |
| 198 return data_reduction_proxy::Client::UNKNOWN; | 237 return data_reduction_proxy::Client::UNKNOWN; |
| 199 #endif | 238 #endif |
| 200 } | 239 } |
| OLD | NEW |