Chromium Code Reviews| 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 ProxyConfig; | |
| 19 class ProxyServer; | 20 class ProxyServer; |
| 21 class HttpResponseHeaders; | |
|
bengr
2014/09/22 19:36:16
Alphabetize forward declarations.
sclittle
2014/09/22 20:54:25
Done.
| |
| 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); | |
| 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 |
| 66 // Records all the data reduction proxy bytes-related histograms for the | |
| 67 // completed URLRequest |request|. | |
| 68 void RecordBytesHistograms( | |
| 69 net::URLRequest& request, | |
|
bengr
2014/09/22 19:36:16
Don't use non-const refs.
sclittle
2014/09/22 20:54:25
Done. I'll change RecordBypassedBytesHistograms as
| |
| 70 const BooleanPrefMember& data_reduction_proxy_enabled, | |
| 71 const net::ProxyConfig& data_reduction_proxy_config); | |
| 72 | |
| 58 // Given |data_reduction_proxy_enabled|, a |request|, and the | 73 // Given |data_reduction_proxy_enabled|, a |request|, and the |
| 59 // |data_reduction_proxy_config| records the number of bypassed bytes for that | 74 // |data_reduction_proxy_config| records the number of bypassed bytes for that |
| 60 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| | 75 // |request| into UMAs based on bypass type. |data_reduction_proxy_enabled| |
| 61 // tells us the state of the kDataReductionProxyEnabled preference. | 76 // tells us the state of the kDataReductionProxyEnabled preference. |
| 77 // This method is publicly visible for testing purposes; use the method | |
| 78 // RecordBytesHistograms instead of calling this method directly. | |
|
bengr
2014/09/22 19:36:16
As discussed, please just friend the tests.
sclittle
2014/09/22 20:54:25
Done.
| |
| 62 void RecordBypassedBytesHistograms( | 79 void RecordBypassedBytesHistograms( |
| 63 net::URLRequest& request, | 80 net::URLRequest& request, |
| 64 const BooleanPrefMember& data_reduction_proxy_enabled, | 81 const BooleanPrefMember& data_reduction_proxy_enabled, |
| 65 const net::ProxyConfig& data_reduction_proxy_config); | 82 const net::ProxyConfig& data_reduction_proxy_config); |
| 66 | 83 |
| 67 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy, | 84 void RecordBypassEventHistograms(const net::ProxyServer& bypassed_proxy, |
| 68 int net_error) const; | 85 int net_error) const; |
| 69 | 86 |
| 87 // Records UMA of the number of response bytes of responses that are expected | |
| 88 // to have the data reduction proxy via header, but where the data reduction | |
| 89 // proxy via header is not present. | |
| 90 // This method is publicly visible for testing purposes; use the method | |
| 91 // RecordBytesHistograms instead of calling this method directly. | |
| 92 void RecordMissingViaHeaderBytes(net::URLRequest& request); | |
|
bengr
2014/09/22 19:36:16
Don't use non-const refs.
sclittle
2014/09/22 20:54:25
Done.
| |
| 93 | |
| 70 private: | 94 private: |
| 71 enum BypassedBytesType { | 95 enum BypassedBytesType { |
| 72 NOT_BYPASSED = 0, /* Not bypassed. */ | 96 NOT_BYPASSED = 0, /* Not bypassed. */ |
| 73 SSL, /* Bypass due to SSL. */ | 97 SSL, /* Bypass due to SSL. */ |
| 74 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ | 98 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ |
| 75 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ | 99 MANAGED_PROXY_CONFIG, /* Bypass due to managed config. */ |
| 76 AUDIO_VIDEO, /* Audio/Video bypass. */ | 100 AUDIO_VIDEO, /* Audio/Video bypass. */ |
| 77 TRIGGERING_REQUEST, /* Triggering request bypass. */ | 101 TRIGGERING_REQUEST, /* Triggering request bypass. */ |
| 78 NETWORK_ERROR, /* Network error. */ | 102 NETWORK_ERROR, /* Network error. */ |
| 79 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ | 103 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ |
| (...skipping 51 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 |