Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h

Issue 577343002: Adds UMA to measure when the data reduction proxy via header is missing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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,
43 const net::HttpResponseHeaders* headers);
44
36 // MessageLoopProxy instance is owned by io_thread. |params| outlives 45 // MessageLoopProxy instance is owned by io_thread. |params| outlives
37 // this class instance. 46 // this class instance.
38 DataReductionProxyUsageStats(DataReductionProxyParams* params, 47 DataReductionProxyUsageStats(DataReductionProxyParams* params,
39 base::MessageLoopProxy* ui_thread_proxy); 48 base::MessageLoopProxy* ui_thread_proxy);
40 virtual ~DataReductionProxyUsageStats(); 49 virtual ~DataReductionProxyUsageStats();
41 50
42 // Sets the callback to be called on the UI thread when the unavailability 51 // Sets the callback to be called on the UI thread when the unavailability
43 // status has changed. 52 // status has changed.
44 void set_unavailable_callback( 53 void set_unavailable_callback(
45 const base::Callback<void(bool)>& unavailable_callback) { 54 const base::Callback<void(bool)>& unavailable_callback) {
46 unavailable_callback_ = unavailable_callback; 55 unavailable_callback_ = unavailable_callback;
47 } 56 }
48 57
49 // Callback intended to be called from |ChromeNetworkDelegate| when a 58 // Callback intended to be called from |ChromeNetworkDelegate| when a
50 // request completes. This method is used to gather usage stats. 59 // request completes. This method is used to gather usage stats.
51 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); 60 void OnUrlRequestCompleted(const net::URLRequest* request, bool started);
52 61
53 // Records the last bypass reason to |bypass_type_| and sets 62 // Records the last bypass reason to |bypass_type_| and sets
54 // |triggering_request_| to true. A triggering request is the first request to 63 // |triggering_request_| to true. A triggering request is the first request to
55 // cause the current bypass. 64 // cause the current bypass.
56 void SetBypassType(DataReductionProxyBypassType type); 65 void SetBypassType(DataReductionProxyBypassType type);
57 66
58 // Given |data_reduction_proxy_enabled|, a |request|, and the 67 // Records all the data reduction proxy bytes-related histograms for the
59 // |data_reduction_proxy_config| records the number of bypassed bytes for that 68 // completed URLRequest |request|.
60 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| 69 void RecordBytesHistograms(
61 // tells us the state of the kDataReductionProxyEnabled preference. 70 net::URLRequest* request,
62 void RecordBypassedBytesHistograms(
63 net::URLRequest& request,
64 const BooleanPrefMember& data_reduction_proxy_enabled, 71 const BooleanPrefMember& data_reduction_proxy_enabled,
65 const net::ProxyConfig& data_reduction_proxy_config); 72 const net::ProxyConfig& data_reduction_proxy_config);
66 73
67 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy, 74 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy,
68 int net_error) const; 75 int net_error) const;
69 76
70 private: 77 private:
78 friend class DataReductionProxyUsageStatsTest;
79 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyUsageStatsTest,
80 RecordMissingViaHeaderBytes);
81
71 enum BypassedBytesType { 82 enum BypassedBytesType {
72 NOT_BYPASSED = 0, /* Not bypassed. */ 83 NOT_BYPASSED = 0, /* Not bypassed. */
73 SSL, /* Bypass due to SSL. */ 84 SSL, /* Bypass due to SSL. */
74 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ 85 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */
75 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ 86 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */
76 AUDIO_VIDEO, /* Audio/Video bypass. */ 87 AUDIO_VIDEO, /* Audio/Video bypass. */
77 TRIGGERING_REQUEST, /* Triggering request bypass. */ 88 TRIGGERING_REQUEST, /* Triggering request bypass. */
78 NETWORK_ERROR, /* Network error. */ 89 NETWORK_ERROR, /* Network error. */
79 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ 90 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/
80 }; 91 };
81 92
93 // Given |data_reduction_proxy_enabled|, a |request|, and the
94 // |data_reduction_proxy_config| records the number of bypassed bytes for that
95 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled|
96 // tells us the state of the kDataReductionProxyEnabled preference.
97 void RecordBypassedBytesHistograms(
98 net::URLRequest* request,
99 const BooleanPrefMember& data_reduction_proxy_enabled,
100 const net::ProxyConfig& data_reduction_proxy_config);
101
102 // Records UMA of the number of response bytes of responses that are expected
103 // to have the data reduction proxy via header, but where the data reduction
104 // proxy via header is not present.
105 void RecordMissingViaHeaderBytes(net::URLRequest* request);
106
82 // NetworkChangeNotifier::NetworkChangeObserver: 107 // NetworkChangeNotifier::NetworkChangeObserver:
83 virtual void OnNetworkChanged( 108 virtual void OnNetworkChanged(
84 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 109 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
85 110
86 // Counts requests that went through the data reduction proxy and counts 111 // Counts requests that went through the data reduction proxy and counts
87 // requests that were eligible to go through the proxy. 112 // requests that were eligible to go through the proxy.
88 void IncrementRequestCounts(bool actual); 113 void IncrementRequestCounts(bool actual);
89 void ClearRequestCounts(); 114 void ClearRequestCounts();
90 115
91 // Checks if the availability status of the data reduction proxy has changed, 116 // Checks if the availability status of the data reduction proxy has changed,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 156
132 // Called when the unavailability status has changed. Runs on the UI thread. 157 // Called when the unavailability status has changed. Runs on the UI thread.
133 base::Callback<void(bool)> unavailable_callback_; 158 base::Callback<void(bool)> unavailable_callback_;
134 159
135 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); 160 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats);
136 }; 161 };
137 162
138 } // namespace data_reduction_proxy 163 } // namespace data_reduction_proxy
139 164
140 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ 165 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698