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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
12 #include "base/strings/string_util.h" | |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 15 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
15 #include "chrome/browser/prefs/proxy_prefs.h" | 16 #include "chrome/browser/prefs/proxy_prefs.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h" |
20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" |
21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" | 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" |
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" | 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" |
23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" | 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" |
24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" | 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" |
26 #include "net/base/host_port_pair.h" | |
27 #include "net/proxy/proxy_config.h" | |
28 #include "net/proxy/proxy_list.h" | |
29 #include "net/proxy/proxy_server.h" | |
25 #include "net/url_request/url_request_context_getter.h" | 30 #include "net/url_request/url_request_context_getter.h" |
26 | 31 |
32 namespace { | |
33 | |
34 // Assume that any proxy host ending with this suffix is a Data Reduction Proxy. | |
35 const char kDataReductionProxyHostSuffix[] = ".googlezip.net"; | |
36 | |
37 // Searches |proxy_list| for any Data Reduction Proxies, even if they don't | |
38 // match a currently configured Data Reduction Proxy. | |
39 bool ContainsDataReductionProxy(const net::ProxyList& proxy_list) { | |
40 for (const net::ProxyServer& proxy : proxy_list.GetAll()) { | |
41 if (proxy.is_valid() && !proxy.is_direct() && | |
42 EndsWith(proxy.host_port_pair().host(), kDataReductionProxyHostSuffix, | |
43 true)) { | |
44 return true; | |
45 } | |
46 } | |
47 return false; | |
48 } | |
49 | |
50 // Searches |proxy_rules| for any Data Reduction Proxies, even if they don't | |
51 // match a currently configured Data Reduction Proxy. | |
52 bool ContainsDataReductionProxy( | |
53 const net::ProxyConfig::ProxyRules& proxy_rules) { | |
54 return ContainsDataReductionProxy(proxy_rules.proxies_for_http) || | |
55 ContainsDataReductionProxy(proxy_rules.proxies_for_https); | |
56 } | |
57 | |
58 } // namespace | |
59 | |
27 // The Data Reduction Proxy has been turned into a "best effort" proxy, | 60 // The Data Reduction Proxy has been turned into a "best effort" proxy, |
28 // meaning it is used only if the effective proxy configuration resolves to | 61 // meaning it is used only if the effective proxy configuration resolves to |
29 // DIRECT for a URL. It no longer can be a ProxyConfig in the proxy preference | 62 // DIRECT for a URL. It no longer can be a ProxyConfig in the proxy preference |
30 // hierarchy. This method removes the Data Reduction Proxy configuration from | 63 // hierarchy. This method removes the Data Reduction Proxy configuration from |
31 // prefs, if present. |proxy_pref_name| is the name of the proxy pref. | 64 // prefs, if present. |proxy_pref_name| is the name of the proxy pref. |
32 void DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefs( | 65 void DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefs( |
33 PrefService* prefs) { | 66 PrefService* prefs) { |
34 base::DictionaryValue* dict = | 67 base::DictionaryValue* dict = |
35 (base::DictionaryValue*) prefs->GetUserPrefValue(prefs::kProxy); | 68 (base::DictionaryValue*) prefs->GetUserPrefValue(prefs::kProxy); |
36 if (!dict) | 69 if (!dict) |
(...skipping 14 matching lines...) Expand all Loading... | |
51 prefs->ClearPref(prefs::kProxy); | 84 prefs->ClearPref(prefs::kProxy); |
52 return; | 85 return; |
53 } | 86 } |
54 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) != mode) | 87 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) != mode) |
55 return; | 88 return; |
56 std::string proxy_server; | 89 std::string proxy_server; |
57 if (!dict->GetString("server", &proxy_server)) | 90 if (!dict->GetString("server", &proxy_server)) |
58 return; | 91 return; |
59 net::ProxyConfig::ProxyRules proxy_rules; | 92 net::ProxyConfig::ProxyRules proxy_rules; |
60 proxy_rules.ParseFromString(proxy_server); | 93 proxy_rules.ParseFromString(proxy_server); |
61 if (!Config()->ContainsDataReductionProxy(proxy_rules)) { | 94 // Clear the proxy pref if it matches a currently configured Data Reduction |
95 // Proxy, or if the proxy host ends with ".googlezip.net", in order to ensure | |
96 // that any DRP in the pref is cleared even if the DRP configuration was | |
97 // changed. See http://crbug.com/476610. | |
98 if (!Config()->ContainsDataReductionProxy(proxy_rules) && | |
99 !ContainsDataReductionProxy(proxy_rules)) { | |
bengr
2015/04/28 16:52:27
You might want to rename this method to be clearer
sclittle
2015/04/28 18:27:57
Renamed.
I'd lean toward keeping this here. Confi
| |
62 return; | 100 return; |
63 } | 101 } |
64 prefs->ClearPref(prefs::kProxy); | 102 prefs->ClearPref(prefs::kProxy); |
65 } | 103 } |
66 | 104 |
67 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() | 105 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() |
68 : data_reduction_proxy::DataReductionProxySettings() { | 106 : data_reduction_proxy::DataReductionProxySettings() { |
69 } | 107 } |
70 | 108 |
71 DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() { | 109 DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 #elif defined(OS_OPENBSD) | 172 #elif defined(OS_OPENBSD) |
135 return data_reduction_proxy::Client::CHROME_OPENBSD; | 173 return data_reduction_proxy::Client::CHROME_OPENBSD; |
136 #elif defined(OS_SOLARIS) | 174 #elif defined(OS_SOLARIS) |
137 return data_reduction_proxy::Client::CHROME_SOLARIS; | 175 return data_reduction_proxy::Client::CHROME_SOLARIS; |
138 #elif defined(OS_QNX) | 176 #elif defined(OS_QNX) |
139 return data_reduction_proxy::Client::CHROME_QNX; | 177 return data_reduction_proxy::Client::CHROME_QNX; |
140 #else | 178 #else |
141 return data_reduction_proxy::Client::UNKNOWN; | 179 return data_reduction_proxy::Client::UNKNOWN; |
142 #endif | 180 #endif |
143 } | 181 } |
OLD | NEW |