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 ProxyServer; | 19 class ProxyServer; |
20 class HttpResponseHeaders; | |
20 } | 21 } |
21 | 22 |
22 namespace data_reduction_proxy { | 23 namespace data_reduction_proxy { |
23 | 24 |
24 class DataReductionProxyUsageStats | 25 class DataReductionProxyUsageStats |
25 : public net::NetworkChangeNotifier::NetworkChangeObserver { | 26 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
26 public: | 27 public: |
27 // Records a data reduction proxy bypass event as a "BlockType" if | 28 // 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 | 29 // |bypass_all| is true and as a "BypassType" otherwise. Records the event as |
29 // "Primary" if |is_primary| is true and "Fallback" otherwise. | 30 // "Primary" if |is_primary| is true and "Fallback" otherwise. |
30 static void RecordDataReductionProxyBypassInfo( | 31 static void RecordDataReductionProxyBypassInfo( |
31 bool is_primary, | 32 bool is_primary, |
32 bool bypass_all, | 33 bool bypass_all, |
33 const net::ProxyServer& proxy_server, | 34 const net::ProxyServer& proxy_server, |
34 DataReductionProxyBypassType bypass_type); | 35 DataReductionProxyBypassType bypass_type); |
35 | 36 |
37 // For the given response |headers| that are expected to include the data | |
38 // reduction proxy via header, records response code UMA if the data reduction | |
39 // proxy via header is not present. | |
40 static void DetectAndRecordMissingViaHeaderResponseCode( | |
41 bool is_primary, const net::HttpResponseHeaders* headers); | |
42 | |
36 // MessageLoopProxy instance is owned by io_thread. |params| outlives | 43 // MessageLoopProxy instance is owned by io_thread. |params| outlives |
37 // this class instance. | 44 // this class instance. |
38 DataReductionProxyUsageStats(DataReductionProxyParams* params, | 45 DataReductionProxyUsageStats(DataReductionProxyParams* params, |
39 base::MessageLoopProxy* ui_thread_proxy); | 46 base::MessageLoopProxy* ui_thread_proxy); |
40 virtual ~DataReductionProxyUsageStats(); | 47 virtual ~DataReductionProxyUsageStats(); |
41 | 48 |
42 // Sets the callback to be called on the UI thread when the unavailability | 49 // Sets the callback to be called on the UI thread when the unavailability |
43 // status has changed. | 50 // status has changed. |
44 void set_unavailable_callback( | 51 void set_unavailable_callback( |
45 const base::Callback<void(bool)>& unavailable_callback) { | 52 const base::Callback<void(bool)>& unavailable_callback) { |
46 unavailable_callback_ = unavailable_callback; | 53 unavailable_callback_ = unavailable_callback; |
47 } | 54 } |
48 | 55 |
49 // Callback intended to be called from |ChromeNetworkDelegate| when a | 56 // Callback intended to be called from |ChromeNetworkDelegate| when a |
50 // request completes. This method is used to gather usage stats. | 57 // request completes. This method is used to gather usage stats. |
51 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); | 58 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); |
52 | 59 |
53 // Records the last bypass reason to |bypass_type_| and sets | 60 // Records the last bypass reason to |bypass_type_| and sets |
54 // |triggering_request_| to true. A triggering request is the first request to | 61 // |triggering_request_| to true. A triggering request is the first request to |
55 // cause the current bypass. | 62 // cause the current bypass. |
56 void SetBypassType(DataReductionProxyBypassType type); | 63 void SetBypassType(DataReductionProxyBypassType type); |
57 | 64 |
65 // Record all the data reduction proxy bytes-related histograms for the | |
bengr
2014/09/19 21:42:56
"Records"
sclittle
2014/09/19 22:38:11
Done.
| |
66 // completed URLRequest |request|. | |
67 void RecordBytesHistograms( | |
68 net::URLRequest& request, | |
69 const BooleanPrefMember& data_reduction_proxy_enabled, | |
70 const net::ProxyConfig& data_reduction_proxy_config); | |
bengr
2014/09/19 21:42:56
Forward declare ProxyConfig
sclittle
2014/09/19 22:38:11
Done.
| |
71 | |
58 // Given |data_reduction_proxy_enabled|, a |request|, and the | 72 // Given |data_reduction_proxy_enabled|, a |request|, and the |
59 // |data_reduction_proxy_config| records the number of bypassed bytes for that | 73 // |data_reduction_proxy_config| records the number of bypassed bytes for that |
60 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| | 74 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| |
61 // tells us the state of the kDataReductionProxyEnabled preference. | 75 // tells us the state of the kDataReductionProxyEnabled preference. |
76 // This method is publicly visible for testing purposes; use the method | |
77 // RecordBytesHistograms instead of calling this method directly. | |
bengr
2014/09/19 21:42:56
What test uses it? Can't you friend the test or ma
sclittle
2014/09/19 22:38:11
This particular method isn't actually yet used by
| |
62 void RecordBypassedBytesHistograms( | 78 void RecordBypassedBytesHistograms( |
63 net::URLRequest& request, | 79 net::URLRequest& request, |
64 const BooleanPrefMember& data_reduction_proxy_enabled, | 80 const BooleanPrefMember& data_reduction_proxy_enabled, |
65 const net::ProxyConfig& data_reduction_proxy_config); | 81 const net::ProxyConfig& data_reduction_proxy_config); |
66 | 82 |
67 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy, | 83 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy, |
68 int net_error) const; | 84 int net_error) const; |
69 | 85 |
86 // Records UMA of the number of response bytes of responses that are expected | |
87 // to have the data reduction proxy via header, but where the data reduction | |
88 // proxy via header is not present. | |
89 // This method is publicly visible for testing purposes; use the method | |
90 // RecordBytesHistograms instead of calling this method directly. | |
91 void RecordMissingViaHeaderBytes(net::URLRequest& request); | |
92 | |
70 private: | 93 private: |
71 enum BypassedBytesType { | 94 enum BypassedBytesType { |
72 NOT_BYPASSED = 0, /* Not bypassed. */ | 95 NOT_BYPASSED = 0, /* Not bypassed. */ |
73 SSL, /* Bypass due to SSL. */ | 96 SSL, /* Bypass due to SSL. */ |
74 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ | 97 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ |
75 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ | 98 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ |
76 AUDIO_VIDEO, /* Audio/Video bypass. */ | 99 AUDIO_VIDEO, /* Audio/Video bypass. */ |
77 TRIGGERING_REQUEST, /* Triggering request bypass. */ | 100 TRIGGERING_REQUEST, /* Triggering request bypass. */ |
78 NETWORK_ERROR, /* Network error. */ | 101 NETWORK_ERROR, /* Network error. */ |
79 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ | 102 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 | 154 |
132 // Called when the unavailability status has changed. Runs on the UI thread. | 155 // Called when the unavailability status has changed. Runs on the UI thread. |
133 base::Callback<void(bool)> unavailable_callback_; | 156 base::Callback<void(bool)> unavailable_callback_; |
134 | 157 |
135 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); | 158 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); |
136 }; | 159 }; |
137 | 160 |
138 } // namespace data_reduction_proxy | 161 } // namespace data_reduction_proxy |
139 | 162 |
140 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ | 163 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ |
OLD | NEW |