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/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/prefs/pref_member.h" | |
| 9 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
| 10 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 11 #include "net/base/host_port_pair.h" | 12 #include "net/base/host_port_pair.h" |
| 12 #include "net/base/network_change_notifier.h" | 13 #include "net/base/network_change_notifier.h" |
| 14 #include "net/proxy/proxy_service.h" | |
| 13 | 15 |
| 14 namespace data_reduction_proxy { | 16 namespace data_reduction_proxy { |
| 15 | 17 |
| 16 class DataReductionProxyUsageStats | 18 class DataReductionProxyUsageStats |
| 17 : public net::NetworkChangeNotifier::NetworkChangeObserver { | 19 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 18 public: | 20 public: |
| 19 // MessageLoopProxy instances are owned by io_thread. |params| outlives | 21 // MessageLoopProxy instances are owned by io_thread. |params| outlives |
| 20 // this class instance. | 22 // this class instance. |
| 21 DataReductionProxyUsageStats(DataReductionProxyParams* params, | 23 DataReductionProxyUsageStats(DataReductionProxyParams* params, |
| 22 base::MessageLoopProxy* ui_thread_proxy, | 24 base::MessageLoopProxy* ui_thread_proxy, |
| 23 base::MessageLoopProxy* io_thread_proxy); | 25 base::MessageLoopProxy* io_thread_proxy); |
| 24 virtual ~DataReductionProxyUsageStats(); | 26 virtual ~DataReductionProxyUsageStats(); |
| 25 | 27 |
| 26 /** | 28 // Callback intended to be called from |ChromeNetworkDelegate| when a |
| 27 * Callback intended to be called from |ChromeNetworkDelegate| when a | 29 // request completes. This method is used to gather usage stats. |
| 28 * request completes. This method is used to gather usage stats. | |
| 29 */ | |
| 30 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); | 30 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); |
| 31 | 31 |
| 32 /** | 32 // Determines whether the data reduction proxy is unreachable. |
| 33 * Determines whether the data reduction proxy is unreachable. | 33 // Returns true if data reduction proxy is unreachable. |
| 34 * Returns true if data reduction proxy is unreachable. | |
| 35 */ | |
| 36 bool isDataReductionProxyUnreachable(); | 34 bool isDataReductionProxyUnreachable(); |
| 37 | 35 |
| 36 // Records the last bypass reason to |bypass_type_| and sets | |
| 37 // |triggering_request_| to true. | |
| 38 void SetBypassType(net::ProxyService::DataReductionProxyBypassType type); | |
| 39 | |
| 40 // Records the number of bypassed bytes for various bypass reasons into their | |
| 41 // respective UMAs. | |
| 42 void RecordBypassedBytesHistograms( | |
| 43 const int64 content_length, | |
|
Alexei Svitkine (slow)
2014/07/15 18:20:08
Nit: No need for const on primitives.
Also, is th
| |
| 44 const net::URLRequest* request, | |
|
Alexei Svitkine (slow)
2014/07/15 18:20:08
If |request| can never be NULL, which seems to be
megjablon
2014/07/16 00:00:59
Done.
| |
| 45 const BooleanPrefMember* data_reduction_proxy_enabled); | |
| 46 | |
| 38 private: | 47 private: |
| 48 enum DataReductionProxyBypassedBytesType { | |
| 49 // Not bypassed. | |
| 50 NOT_BYPASSED = 0, | |
| 51 | |
| 52 // Bypass due to SSL. | |
| 53 SSL, | |
| 54 | |
| 55 // Bypass due to client-side bypass rules. | |
| 56 LOCAL_BYPASS_RULES, | |
| 57 | |
| 58 // Audio/Video bypass. | |
| 59 AUDIO_VIDEO, | |
| 60 | |
| 61 // Triggering request bypass. | |
| 62 TRIGGERING_REQUEST, | |
| 63 | |
| 64 // This must always be last. | |
| 65 BYPASSED_BYTES_TYPE_MAX | |
| 66 }; | |
| 67 | |
| 39 DataReductionProxyParams* data_reduction_proxy_params_; | 68 DataReductionProxyParams* data_reduction_proxy_params_; |
| 69 net::ProxyService::DataReductionProxyBypassType bypass_type_; | |
| 70 bool triggering_request_; | |
| 40 base::MessageLoopProxy* ui_thread_proxy_; | 71 base::MessageLoopProxy* ui_thread_proxy_; |
| 41 base::MessageLoopProxy* io_thread_proxy_; | 72 base::MessageLoopProxy* io_thread_proxy_; |
| 42 | 73 |
| 43 // The following 2 fields are used to determine if data reduction proxy is | 74 // The following 2 fields are used to determine if data reduction proxy is |
| 44 // unreachable. We keep a count of requests which should go through | 75 // unreachable. We keep a count of requests which should go through |
| 45 // data request proxy, as well as those which actually do. The proxy is | 76 // data request proxy, as well as those which actually do. The proxy is |
| 46 // unreachable if no successful requests are made through it despite a | 77 // unreachable if no successful requests are made through it despite a |
| 47 // non-zero number of requests being eligible. | 78 // non-zero number of requests being eligible. |
| 48 | 79 |
| 49 // Count of requests which will be tried to be sent through data reduction | 80 // Count of requests which will be tried to be sent through data reduction |
| 50 // proxy. The count is only based on the config and not the bad proxy list. | 81 // proxy. The count is only based on the config and not the bad proxy list. |
| 51 // Explicit bypasses are not part of this count. This is the desired behavior | 82 // Explicit bypasses are not part of this count. This is the desired behavior |
| 52 // since otherwise both counts would be identical. | 83 // since otherwise both counts would be identical. |
| 53 unsigned long eligible_num_requests_through_proxy_; | 84 unsigned long eligible_num_requests_through_proxy_; |
| 54 // Count of successfull requests through data reduction proxy. | 85 // Count of successfull requests through data reduction proxy. |
| 55 unsigned long actual_num_requests_through_proxy_; | 86 unsigned long actual_num_requests_through_proxy_; |
| 56 | 87 |
| 57 // NetworkChangeNotifier::NetworkChangeObserver: | 88 // NetworkChangeNotifier::NetworkChangeObserver: |
| 58 virtual void OnNetworkChanged( | 89 virtual void OnNetworkChanged( |
| 59 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | 90 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 60 | 91 |
| 61 void IncRequestCountsOnUiThread(bool actual); | 92 void IncRequestCountsOnUiThread(bool actual); |
| 62 void ClearRequestCountsOnUiThread(); | 93 void ClearRequestCountsOnUiThread(); |
| 63 | 94 |
| 64 base::ThreadChecker thread_checker_; | 95 base::ThreadChecker thread_checker_; |
| 65 | 96 |
| 97 void RecordTriggeringRequestBypassedBytes( | |
| 98 net::ProxyService::DataReductionProxyBypassType bypass_type, | |
| 99 int64 content_length); | |
| 100 void RecordNetworkErrorBypassedBytes(const net::URLRequest* request, | |
|
Alexei Svitkine (slow)
2014/07/15 18:20:08
Nit: Pass by const ref?
megjablon
2014/07/16 00:00:59
We moved this logic into RecordBypassedBytes, dele
| |
| 101 int64 content_length); | |
| 102 void RecordBypassedBytes( | |
| 103 net::ProxyService::DataReductionProxyBypassType bypass_type, | |
| 104 DataReductionProxyBypassedBytesType bypassed_bytes_type, | |
| 105 int64 content_length); | |
| 106 | |
| 66 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); | 107 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); |
| 67 }; | 108 }; |
| 68 | 109 |
| 69 } // namespace data_reduction_proxy | 110 } // namespace data_reduction_proxy |
| 70 | 111 |
| 71 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ | 112 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ |
| OLD | NEW |