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/net/pref_proxy_config_tracker_impl.h" | 5 #include "chrome/browser/net/pref_proxy_config_tracker_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram_macros.h" | |
8 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 14 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 #include "components/pref_registry/pref_registry_syncable.h" | 16 #include "components/pref_registry/pref_registry_syncable.h" |
16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
19 #include "net/proxy/proxy_list.h" | 20 #include "net/proxy/proxy_list.h" |
20 #include "net/proxy/proxy_server.h" | 21 #include "net/proxy/proxy_server.h" |
21 | 22 |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Determine if |proxy| is of the form "*.googlezip.net". | 27 // Determine if |proxy| is of the form "*.googlezip.net". |
27 bool IsGooglezipDataReductionProxy(const net::ProxyServer& proxy) { | 28 bool IsGooglezipDataReductionProxy(const net::ProxyServer& proxy) { |
28 return proxy.is_valid() && !proxy.is_direct() && | 29 return proxy.is_valid() && !proxy.is_direct() && |
29 EndsWith(proxy.host_port_pair().host(), ".googlezip.net", true); | 30 EndsWith(proxy.host_port_pair().host(), ".googlezip.net", true); |
30 } | 31 } |
31 | 32 |
32 // Removes any Data Reduction Proxies like *.googlezip.net from |proxy_list|. | 33 // Removes any Data Reduction Proxies like *.googlezip.net from |proxy_list|. |
33 void RemoveGooglezipDataReductionProxiesFromList(net::ProxyList* proxy_list) { | 34 // Returns true if any proxies were removed from |proxy_list|, false otherwise. |
34 if (proxy_list->IsEmpty()) | 35 bool RemoveGooglezipDataReductionProxiesFromList(net::ProxyList* proxy_list) { |
35 return; | |
36 | |
37 bool found_googlezip_proxy = false; | 36 bool found_googlezip_proxy = false; |
38 for (const net::ProxyServer& proxy : proxy_list->GetAll()) { | 37 for (const net::ProxyServer& proxy : proxy_list->GetAll()) { |
39 if (IsGooglezipDataReductionProxy(proxy)) { | 38 if (IsGooglezipDataReductionProxy(proxy)) { |
40 found_googlezip_proxy = true; | 39 found_googlezip_proxy = true; |
41 break; | 40 break; |
42 } | 41 } |
43 } | 42 } |
44 if (!found_googlezip_proxy) | 43 if (!found_googlezip_proxy) |
45 return; | 44 return false; |
46 | 45 |
47 net::ProxyList replacement_list; | 46 net::ProxyList replacement_list; |
48 for (const net::ProxyServer& proxy : proxy_list->GetAll()) { | 47 for (const net::ProxyServer& proxy : proxy_list->GetAll()) { |
49 if (!IsGooglezipDataReductionProxy(proxy)) | 48 if (!IsGooglezipDataReductionProxy(proxy)) |
50 replacement_list.AddProxyServer(proxy); | 49 replacement_list.AddProxyServer(proxy); |
51 } | 50 } |
52 | 51 |
53 if (replacement_list.IsEmpty()) | 52 if (replacement_list.IsEmpty()) |
54 replacement_list.AddProxyServer(net::ProxyServer::Direct()); | 53 replacement_list.AddProxyServer(net::ProxyServer::Direct()); |
55 *proxy_list = replacement_list; | 54 *proxy_list = replacement_list; |
55 return true; | |
56 } | |
57 | |
58 void RecordGooglezipProxyRemovalResultHistogram( | |
59 PrefProxyConfigTrackerImpl::GooglezipProxyRemovalResult result) { | |
60 UMA_HISTOGRAM_ENUMERATION( | |
61 "Net.PrefProxyConfig.GooglezipProxyRemovalResult", result, | |
62 PrefProxyConfigTrackerImpl::GOOGLEZIP_PROXY_REMOVAL_RESULT_MAX); | |
56 } | 63 } |
57 | 64 |
58 // Remove any Data Reduction Proxies like *.googlezip.net from |proxy_rules|. | 65 // Remove any Data Reduction Proxies like *.googlezip.net from |proxy_rules|. |
59 // This is to prevent a Data Reduction Proxy from being activated in an | 66 // This is to prevent a Data Reduction Proxy from being activated in an |
60 // unsupported way, such as from a proxy pref, which could cause Chrome to use | 67 // unsupported way, such as from a proxy pref, which could cause Chrome to use |
61 // the Data Reduction Proxy without adding any of the necessary authentication | 68 // the Data Reduction Proxy without adding any of the necessary authentication |
62 // headers or applying the Data Reduction Proxy bypass logic. See | 69 // headers or applying the Data Reduction Proxy bypass logic. See |
63 // http://crbug.com/476610. | 70 // http://crbug.com/476610. |
64 // TODO(sclittle): Add UMA to record how often this method is called, and how | 71 // TODO(sclittle): This method should be removed once the UMA indicates that |
65 // often it actually removes a *.googlezip.net proxy. This method should be | 72 // *.googlezip.net proxies are no longer present in the |proxy_rules|. |
eroman
2015/05/14 22:20:15
Is there a separate strategy to actually remove th
sclittle
2015/05/15 02:29:42
The strategy to remove the bad pref actually alrea
| |
66 // removed once it stops actually finding and removing *.googlezip.net proxies | |
67 // from the proxy rules. | |
68 void RemoveGooglezipDataReductionProxies( | 73 void RemoveGooglezipDataReductionProxies( |
69 net::ProxyConfig::ProxyRules* proxy_rules) { | 74 net::ProxyConfig::ProxyRules* proxy_rules) { |
70 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->fallback_proxies); | 75 // Remove any *.googlezip.net proxies from any of the proxy lists in |
71 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->proxies_for_ftp); | 76 // |proxy_rules|. Bitwise ORs are used instead of logical ORs in order to |
72 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->proxies_for_http); | 77 // avoid short-circuit evaluation. |
73 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->proxies_for_https); | 78 if (RemoveGooglezipDataReductionProxiesFromList( |
eroman
2015/05/14 22:20:15
I don't like this. How about
bool removed = false
sclittle
2015/05/15 02:29:42
Done. Changed to report total number of proxies re
| |
74 RemoveGooglezipDataReductionProxiesFromList(&proxy_rules->single_proxies); | 79 &proxy_rules->fallback_proxies) | |
80 RemoveGooglezipDataReductionProxiesFromList( | |
81 &proxy_rules->proxies_for_ftp) | | |
82 RemoveGooglezipDataReductionProxiesFromList( | |
83 &proxy_rules->proxies_for_http) | | |
84 RemoveGooglezipDataReductionProxiesFromList( | |
85 &proxy_rules->proxies_for_https) | | |
86 RemoveGooglezipDataReductionProxiesFromList( | |
87 &proxy_rules->single_proxies)) { | |
88 RecordGooglezipProxyRemovalResultHistogram( | |
89 PrefProxyConfigTrackerImpl:: | |
90 GOOGLEZIP_PROXY_REMOVAL_RESULT_FOUND_AND_REMOVED); | |
91 } else { | |
92 RecordGooglezipProxyRemovalResultHistogram( | |
eroman
2015/05/14 22:20:15
style: I don't like having two calls to RecordGoog
sclittle
2015/05/15 02:29:42
Now that it's reporting total number of proxies re
| |
93 PrefProxyConfigTrackerImpl::GOOGLEZIP_PROXY_REMOVAL_RESULT_NOT_FOUND); | |
94 } | |
75 } | 95 } |
76 | 96 |
77 } // namespace | 97 } // namespace |
78 | 98 |
79 //============================= ChromeProxyConfigService ======================= | 99 //============================= ChromeProxyConfigService ======================= |
80 | 100 |
81 ChromeProxyConfigService::ChromeProxyConfigService( | 101 ChromeProxyConfigService::ChromeProxyConfigService( |
82 net::ProxyConfigService* base_service) | 102 net::ProxyConfigService* base_service) |
83 : base_service_(base_service), | 103 : base_service_(base_service), |
84 pref_config_state_(ProxyPrefs::CONFIG_UNSET), | 104 pref_config_state_(ProxyPrefs::CONFIG_UNSET), |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 (config_state_ != ProxyPrefs::CONFIG_UNSET && | 435 (config_state_ != ProxyPrefs::CONFIG_UNSET && |
416 !pref_config_.Equals(new_config))) { | 436 !pref_config_.Equals(new_config))) { |
417 config_state_ = config_state; | 437 config_state_ = config_state; |
418 if (config_state_ != ProxyPrefs::CONFIG_UNSET) | 438 if (config_state_ != ProxyPrefs::CONFIG_UNSET) |
419 pref_config_ = new_config; | 439 pref_config_ = new_config; |
420 update_pending_ = true; | 440 update_pending_ = true; |
421 } | 441 } |
422 if (update_pending_) | 442 if (update_pending_) |
423 OnProxyConfigChanged(config_state, new_config); | 443 OnProxyConfigChanged(config_state, new_config); |
424 } | 444 } |
OLD | NEW |