| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_USAGE_
STATS_H_ | |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_USAGE_
STATS_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/prefs/pref_member.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/threading/thread_checker.h" | |
| 12 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | |
| 13 #include "net/base/host_port_pair.h" | |
| 14 #include "net/base/network_change_notifier.h" | |
| 15 #include "net/url_request/url_request.h" | |
| 16 | |
| 17 namespace net { | |
| 18 class HttpResponseHeaders; | |
| 19 class ProxyConfig; | |
| 20 class ProxyServer; | |
| 21 } | |
| 22 | |
| 23 namespace data_reduction_proxy { | |
| 24 | |
| 25 class DataReductionProxyConfig; | |
| 26 | |
| 27 // TODO(bengr): Rename as DataReductionProxyBypassStats. | |
| 28 class DataReductionProxyUsageStats | |
| 29 : public net::NetworkChangeNotifier::NetworkChangeObserver { | |
| 30 public: | |
| 31 typedef base::Callback<void(bool /* unreachable */)> UnreachableCallback; | |
| 32 | |
| 33 // Records a data reduction proxy bypass event as a "BlockType" if | |
| 34 // |bypass_all| is true and as a "BypassType" otherwise. Records the event as | |
| 35 // "Primary" if |is_primary| is true and "Fallback" otherwise. | |
| 36 static void RecordDataReductionProxyBypassInfo( | |
| 37 bool is_primary, | |
| 38 bool bypass_all, | |
| 39 const net::ProxyServer& proxy_server, | |
| 40 DataReductionProxyBypassType bypass_type); | |
| 41 | |
| 42 // For the given response |headers| that are expected to include the data | |
| 43 // reduction proxy via header, records response code UMA if the data reduction | |
| 44 // proxy via header is not present. | |
| 45 static void DetectAndRecordMissingViaHeaderResponseCode( | |
| 46 bool is_primary, | |
| 47 const net::HttpResponseHeaders* headers); | |
| 48 | |
| 49 // |params| outlives this class instance. |unreachable_callback| provides a | |
| 50 // hook to inform the user that the Data Reduction Proxy is unreachable, which | |
| 51 // occurs on the UI thread, hence the |ui_task_runner|. | |
| 52 // |config| must not be null. | |
| 53 DataReductionProxyUsageStats( | |
| 54 DataReductionProxyConfig* config, | |
| 55 UnreachableCallback unreachable_callback, | |
| 56 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner); | |
| 57 | |
| 58 ~DataReductionProxyUsageStats() override; | |
| 59 | |
| 60 // Callback intended to be called from |DataReductionProxyNetworkDelegate| | |
| 61 // when a request completes. This method is used to gather usage stats. | |
| 62 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); | |
| 63 | |
| 64 // Records the last bypass reason to |bypass_type_| and sets | |
| 65 // |triggering_request_| to true. A triggering request is the first request to | |
| 66 // cause the current bypass. | |
| 67 void SetBypassType(DataReductionProxyBypassType type); | |
| 68 | |
| 69 // Visible for testing. | |
| 70 DataReductionProxyBypassType GetBypassType() const; | |
| 71 | |
| 72 // Records all the data reduction proxy bytes-related histograms for the | |
| 73 // completed URLRequest |request|. | |
| 74 void RecordBytesHistograms( | |
| 75 const net::URLRequest& request, | |
| 76 const BooleanPrefMember& data_reduction_proxy_enabled, | |
| 77 const net::ProxyConfig& data_reduction_proxy_config); | |
| 78 | |
| 79 // Called by |ChromeNetworkDelegate| when a proxy is put into the bad proxy | |
| 80 // list. Used to track when the data reduction proxy falls back. | |
| 81 void OnProxyFallback(const net::ProxyServer& bypassed_proxy, | |
| 82 int net_error); | |
| 83 | |
| 84 // Called by |ChromeNetworkDelegate| when an HTTP connect has been called. | |
| 85 // Used to track proxy connection failures. | |
| 86 void OnConnectComplete(const net::HostPortPair& proxy_server, | |
| 87 int net_error); | |
| 88 | |
| 89 private: | |
| 90 friend class DataReductionProxyUsageStatsTest; | |
| 91 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyUsageStatsTest, | |
| 92 RecordMissingViaHeaderBytes); | |
| 93 | |
| 94 enum BypassedBytesType { | |
| 95 NOT_BYPASSED = 0, /* Not bypassed. */ | |
| 96 SSL, /* Bypass due to SSL. */ | |
| 97 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ | |
| 98 PROXY_OVERRIDDEN, /* Bypass due to a proxy taking precedence. */ | |
| 99 AUDIO_VIDEO, /* Audio/Video bypass. */ | |
| 100 TRIGGERING_REQUEST, /* Triggering request bypass. */ | |
| 101 NETWORK_ERROR, /* Network error. */ | |
| 102 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ | |
| 103 }; | |
| 104 | |
| 105 // Given |data_reduction_proxy_enabled|, a |request|, and the | |
| 106 // |data_reduction_proxy_config| records the number of bypassed bytes for that | |
| 107 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| | |
| 108 // tells us the state of the kDataReductionProxyEnabled preference. | |
| 109 void RecordBypassedBytesHistograms( | |
| 110 const net::URLRequest& request, | |
| 111 const BooleanPrefMember& data_reduction_proxy_enabled, | |
| 112 const net::ProxyConfig& data_reduction_proxy_config); | |
| 113 | |
| 114 // Records UMA of the number of response bytes of responses that are expected | |
| 115 // to have the data reduction proxy via header, but where the data reduction | |
| 116 // proxy via header is not present. | |
| 117 void RecordMissingViaHeaderBytes(const net::URLRequest& request); | |
| 118 | |
| 119 // NetworkChangeNotifier::NetworkChangeObserver: | |
| 120 void OnNetworkChanged( | |
| 121 net::NetworkChangeNotifier::ConnectionType type) override; | |
| 122 | |
| 123 // Clears request counts unconditionally. | |
| 124 void ClearRequestCounts(); | |
| 125 | |
| 126 // Checks if the availability status of the data reduction proxy has changed, | |
| 127 // and notifies the UIThread via NotifyUnavailabilityOnUIThread if so. The | |
| 128 // data reduction proxy is considered unavailable if and only if no requests | |
| 129 // went through the proxy but some eligible requests were service by other | |
| 130 // routes. | |
| 131 void NotifyUnavailabilityIfChanged(); | |
| 132 void NotifyUnavailabilityOnUIThread(bool unavailable); | |
| 133 | |
| 134 void RecordBypassedBytes( | |
| 135 DataReductionProxyBypassType bypass_type, | |
| 136 BypassedBytesType bypassed_bytes_type, | |
| 137 int64 content_length); | |
| 138 | |
| 139 DataReductionProxyConfig* data_reduction_proxy_config_; | |
| 140 | |
| 141 UnreachableCallback unreachable_callback_; | |
| 142 | |
| 143 // The last reason for bypass as determined by | |
| 144 // MaybeBypassProxyAndPrepareToRetry | |
| 145 DataReductionProxyBypassType last_bypass_type_; | |
| 146 // True if the last request triggered the current bypass. | |
| 147 bool triggering_request_; | |
| 148 const scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | |
| 149 | |
| 150 // The following 2 fields are used to determine if data reduction proxy is | |
| 151 // unreachable. We keep a count of requests which should go through | |
| 152 // data request proxy, as well as those which actually do. The proxy is | |
| 153 // unreachable if no successful requests are made through it despite a | |
| 154 // non-zero number of requests being eligible. | |
| 155 | |
| 156 // Count of successful requests through the data reduction proxy. | |
| 157 unsigned long successful_requests_through_proxy_count_; | |
| 158 | |
| 159 // Count of network errors encountered when connecting to a data reduction | |
| 160 // proxy. | |
| 161 unsigned long proxy_net_errors_count_; | |
| 162 | |
| 163 // Whether or not the data reduction proxy is unavailable. | |
| 164 bool unavailable_; | |
| 165 | |
| 166 base::ThreadChecker thread_checker_; | |
| 167 | |
| 168 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); | |
| 169 }; | |
| 170 | |
| 171 } // namespace data_reduction_proxy | |
| 172 | |
| 173 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_USA
GE_STATS_H_ | |
| OLD | NEW |