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 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_ |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/prefs/pref_member.h" | 10 #include "base/prefs/pref_member.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/base/network_change_notifier.h" | 15 #include "net/base/network_change_notifier.h" |
16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 class HttpResponseHeaders; | |
20 class ProxyConfig; | |
19 class ProxyServer; | 21 class ProxyServer; |
20 } | 22 } |
21 | 23 |
22 namespace data_reduction_proxy { | 24 namespace data_reduction_proxy { |
23 | 25 |
24 class DataReductionProxyUsageStats | 26 class DataReductionProxyUsageStats |
25 : public net::NetworkChangeNotifier::NetworkChangeObserver { | 27 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
26 public: | 28 public: |
27 // Records a data reduction proxy bypass event as a "BlockType" if | 29 // Records a data reduction proxy bypass event as a "BlockType" if |
28 // |bypass_all| is true and as a "BypassType" otherwise. Records the event as | 30 // |bypass_all| is true and as a "BypassType" otherwise. Records the event as |
29 // "Primary" if |is_primary| is true and "Fallback" otherwise. | 31 // "Primary" if |is_primary| is true and "Fallback" otherwise. |
30 static void RecordDataReductionProxyBypassInfo( | 32 static void RecordDataReductionProxyBypassInfo( |
31 bool is_primary, | 33 bool is_primary, |
32 bool bypass_all, | 34 bool bypass_all, |
33 const net::ProxyServer& proxy_server, | 35 const net::ProxyServer& proxy_server, |
34 DataReductionProxyBypassType bypass_type); | 36 DataReductionProxyBypassType bypass_type); |
35 | 37 |
38 // For the given response |headers| that are expected to include the data | |
39 // reduction proxy via header, records response code UMA if the data reduction | |
40 // proxy via header is not present. | |
41 static void DetectAndRecordMissingViaHeaderResponseCode( | |
42 bool is_primary, const net::HttpResponseHeaders* headers); | |
Alexei Svitkine (slow)
2014/09/23 15:12:13
Nit: 1 param per line if first one is wrapped.
sclittle
2014/09/23 18:13:41
Done.
| |
43 | |
36 // MessageLoopProxy instance is owned by io_thread. |params| outlives | 44 // MessageLoopProxy instance is owned by io_thread. |params| outlives |
37 // this class instance. | 45 // this class instance. |
38 DataReductionProxyUsageStats(DataReductionProxyParams* params, | 46 DataReductionProxyUsageStats(DataReductionProxyParams* params, |
39 base::MessageLoopProxy* ui_thread_proxy); | 47 base::MessageLoopProxy* ui_thread_proxy); |
40 virtual ~DataReductionProxyUsageStats(); | 48 virtual ~DataReductionProxyUsageStats(); |
41 | 49 |
42 // Sets the callback to be called on the UI thread when the unavailability | 50 // Sets the callback to be called on the UI thread when the unavailability |
43 // status has changed. | 51 // status has changed. |
44 void set_unavailable_callback( | 52 void set_unavailable_callback( |
45 const base::Callback<void(bool)>& unavailable_callback) { | 53 const base::Callback<void(bool)>& unavailable_callback) { |
46 unavailable_callback_ = unavailable_callback; | 54 unavailable_callback_ = unavailable_callback; |
47 } | 55 } |
48 | 56 |
49 // Callback intended to be called from |ChromeNetworkDelegate| when a | 57 // Callback intended to be called from |ChromeNetworkDelegate| when a |
50 // request completes. This method is used to gather usage stats. | 58 // request completes. This method is used to gather usage stats. |
51 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); | 59 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); |
52 | 60 |
53 // Records the last bypass reason to |bypass_type_| and sets | 61 // Records the last bypass reason to |bypass_type_| and sets |
54 // |triggering_request_| to true. A triggering request is the first request to | 62 // |triggering_request_| to true. A triggering request is the first request to |
55 // cause the current bypass. | 63 // cause the current bypass. |
56 void SetBypassType(DataReductionProxyBypassType type); | 64 void SetBypassType(DataReductionProxyBypassType type); |
57 | 65 |
58 // Given |data_reduction_proxy_enabled|, a |request|, and the | 66 // Records all the data reduction proxy bytes-related histograms for the |
59 // |data_reduction_proxy_config| records the number of bypassed bytes for that | 67 // completed URLRequest |request|. |
60 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| | 68 void RecordBytesHistograms( |
61 // tells us the state of the kDataReductionProxyEnabled preference. | 69 net::URLRequest* request, |
62 void RecordBypassedBytesHistograms( | |
63 net::URLRequest& request, | |
64 const BooleanPrefMember& data_reduction_proxy_enabled, | 70 const BooleanPrefMember& data_reduction_proxy_enabled, |
65 const net::ProxyConfig& data_reduction_proxy_config); | 71 const net::ProxyConfig& data_reduction_proxy_config); |
66 | 72 |
67 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy, | 73 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy, |
68 int net_error) const; | 74 int net_error) const; |
69 | 75 |
70 private: | 76 private: |
77 friend class DataReductionProxyUsageStatsTest; | |
78 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyUsageStatsTest, | |
79 RecordMissingViaHeaderBytes); | |
80 | |
71 enum BypassedBytesType { | 81 enum BypassedBytesType { |
72 NOT_BYPASSED = 0, /* Not bypassed. */ | 82 NOT_BYPASSED = 0, /* Not bypassed. */ |
73 SSL, /* Bypass due to SSL. */ | 83 SSL, /* Bypass due to SSL. */ |
74 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ | 84 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ |
75 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ | 85 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ |
76 AUDIO_VIDEO, /* Audio/Video bypass. */ | 86 AUDIO_VIDEO, /* Audio/Video bypass. */ |
77 TRIGGERING_REQUEST, /* Triggering request bypass. */ | 87 TRIGGERING_REQUEST, /* Triggering request bypass. */ |
78 NETWORK_ERROR, /* Network error. */ | 88 NETWORK_ERROR, /* Network error. */ |
79 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ | 89 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ |
80 }; | 90 }; |
81 | 91 |
92 // Given |data_reduction_proxy_enabled|, a |request|, and the | |
93 // |data_reduction_proxy_config| records the number of bypassed bytes for that | |
94 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| | |
95 // tells us the state of the kDataReductionProxyEnabled preference. | |
96 void RecordBypassedBytesHistograms( | |
97 net::URLRequest* request, | |
98 const BooleanPrefMember& data_reduction_proxy_enabled, | |
99 const net::ProxyConfig& data_reduction_proxy_config); | |
100 | |
101 // Records UMA of the number of response bytes of responses that are expected | |
102 // to have the data reduction proxy via header, but where the data reduction | |
103 // proxy via header is not present. | |
104 void RecordMissingViaHeaderBytes(net::URLRequest* request); | |
105 | |
82 // NetworkChangeNotifier::NetworkChangeObserver: | 106 // NetworkChangeNotifier::NetworkChangeObserver: |
83 virtual void OnNetworkChanged( | 107 virtual void OnNetworkChanged( |
84 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 108 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
85 | 109 |
86 // Counts requests that went through the data reduction proxy and counts | 110 // Counts requests that went through the data reduction proxy and counts |
87 // requests that were eligible to go through the proxy. | 111 // requests that were eligible to go through the proxy. |
88 void IncrementRequestCounts(bool actual); | 112 void IncrementRequestCounts(bool actual); |
89 void ClearRequestCounts(); | 113 void ClearRequestCounts(); |
90 | 114 |
91 // Checks if the availability status of the data reduction proxy has changed, | 115 // Checks if the availability status of the data reduction proxy has changed, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 | 155 |
132 // Called when the unavailability status has changed. Runs on the UI thread. | 156 // Called when the unavailability status has changed. Runs on the UI thread. |
133 base::Callback<void(bool)> unavailable_callback_; | 157 base::Callback<void(bool)> unavailable_callback_; |
134 | 158 |
135 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); | 159 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); |
136 }; | 160 }; |
137 | 161 |
138 } // namespace data_reduction_proxy | 162 } // namespace data_reduction_proxy |
139 | 163 |
140 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ | 164 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ |
OLD | NEW |