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

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

Issue 602503002: 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: Remove DCHECKs from tests Created 6 years, 3 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( 47 DataReductionProxyUsageStats(
39 DataReductionProxyParams* params, 48 DataReductionProxyParams* params,
40 const scoped_refptr<base::MessageLoopProxy>& ui_thread_proxy); 49 const scoped_refptr<base::MessageLoopProxy>& ui_thread_proxy);
41 virtual ~DataReductionProxyUsageStats(); 50 virtual ~DataReductionProxyUsageStats();
42 51
43 // Sets the callback to be called on the UI thread when the unavailability 52 // Sets the callback to be called on the UI thread when the unavailability
44 // status has changed. 53 // status has changed.
45 void set_unavailable_callback( 54 void set_unavailable_callback(
46 const base::Callback<void(bool)>& unavailable_callback) { 55 const base::Callback<void(bool)>& unavailable_callback) {
47 unavailable_callback_ = unavailable_callback; 56 unavailable_callback_ = unavailable_callback;
48 } 57 }
49 58
50 // Callback intended to be called from |ChromeNetworkDelegate| when a 59 // Callback intended to be called from |ChromeNetworkDelegate| when a
51 // request completes. This method is used to gather usage stats. 60 // request completes. This method is used to gather usage stats.
52 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); 61 void OnUrlRequestCompleted(const net::URLRequest* request, bool started);
53 62
54 // Records the last bypass reason to |bypass_type_| and sets 63 // Records the last bypass reason to |bypass_type_| and sets
55 // |triggering_request_| to true. A triggering request is the first request to 64 // |triggering_request_| to true. A triggering request is the first request to
56 // cause the current bypass. 65 // cause the current bypass.
57 void SetBypassType(DataReductionProxyBypassType type); 66 void SetBypassType(DataReductionProxyBypassType type);
58 67
59 // Given |data_reduction_proxy_enabled|, a |request|, and the 68 // Records all the data reduction proxy bytes-related histograms for the
60 // |data_reduction_proxy_config| records the number of bypassed bytes for that 69 // completed URLRequest |request|.
61 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| 70 void RecordBytesHistograms(
62 // tells us the state of the kDataReductionProxyEnabled preference. 71 net::URLRequest* request,
63 void RecordBypassedBytesHistograms(
64 net::URLRequest& request,
65 const BooleanPrefMember& data_reduction_proxy_enabled, 72 const BooleanPrefMember& data_reduction_proxy_enabled,
66 const net::ProxyConfig& data_reduction_proxy_config); 73 const net::ProxyConfig& data_reduction_proxy_config);
67 74
68 // Called by |ChromeNetworkDelegate| when a proxy is put into the bad proxy 75 // Called by |ChromeNetworkDelegate| when a proxy is put into the bad proxy
69 // list. Used to track when the data reduction proxy falls back. 76 // list. Used to track when the data reduction proxy falls back.
70 void OnProxyFallback(const net::ProxyServer& bypassed_proxy, 77 void OnProxyFallback(const net::ProxyServer& bypassed_proxy,
71 int net_error); 78 int net_error);
72 79
73 private: 80 private:
81 friend class DataReductionProxyUsageStatsTest;
82 FRIEND_TEST_ALL_PREFIXES(DataReductionProxyUsageStatsTest,
83 RecordMissingViaHeaderBytes);
84
74 enum BypassedBytesType { 85 enum BypassedBytesType {
75 NOT_BYPASSED = 0, /* Not bypassed. */ 86 NOT_BYPASSED = 0, /* Not bypassed. */
76 SSL, /* Bypass due to SSL. */ 87 SSL, /* Bypass due to SSL. */
77 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ 88 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */
78 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ 89 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */
79 AUDIO_VIDEO, /* Audio/Video bypass. */ 90 AUDIO_VIDEO, /* Audio/Video bypass. */
80 TRIGGERING_REQUEST, /* Triggering request bypass. */ 91 TRIGGERING_REQUEST, /* Triggering request bypass. */
81 NETWORK_ERROR, /* Network error. */ 92 NETWORK_ERROR, /* Network error. */
82 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ 93 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/
83 }; 94 };
84 95
96 // Given |data_reduction_proxy_enabled|, a |request|, and the
97 // |data_reduction_proxy_config| records the number of bypassed bytes for that
98 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled|
99 // tells us the state of the kDataReductionProxyEnabled preference.
100 void RecordBypassedBytesHistograms(
101 net::URLRequest* request,
102 const BooleanPrefMember& data_reduction_proxy_enabled,
103 const net::ProxyConfig& data_reduction_proxy_config);
104
105 // Records UMA of the number of response bytes of responses that are expected
106 // to have the data reduction proxy via header, but where the data reduction
107 // proxy via header is not present.
108 void RecordMissingViaHeaderBytes(net::URLRequest* request);
109
85 // NetworkChangeNotifier::NetworkChangeObserver: 110 // NetworkChangeNotifier::NetworkChangeObserver:
86 virtual void OnNetworkChanged( 111 virtual void OnNetworkChanged(
87 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; 112 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
88 113
89 // Called when request counts change. Resets counts if they exceed thresholds, 114 // Called when request counts change. Resets counts if they exceed thresholds,
90 // and calls MaybeNotifyUnavailability otherwise. 115 // and calls MaybeNotifyUnavailability otherwise.
91 void OnRequestCountChanged(); 116 void OnRequestCountChanged();
92 117
93 // Clears request counts unconditionally. 118 // Clears request counts unconditionally.
94 void ClearRequestCounts(); 119 void ClearRequestCounts();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 159
135 // Called when the unavailability status has changed. Runs on the UI thread. 160 // Called when the unavailability status has changed. Runs on the UI thread.
136 base::Callback<void(bool)> unavailable_callback_; 161 base::Callback<void(bool)> unavailable_callback_;
137 162
138 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); 163 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats);
139 }; 164 };
140 165
141 } // namespace data_reduction_proxy 166 } // namespace data_reduction_proxy
142 167
143 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ 168 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698