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/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/prefs/pref_member.h" | 10 #include "base/prefs/pref_member.h" |
10 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
12 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
13 #include "net/base/network_change_notifier.h" | 14 #include "net/base/network_change_notifier.h" |
14 #include "net/proxy/proxy_service.h" | 15 #include "net/proxy/proxy_service.h" |
15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
16 | 17 |
17 namespace data_reduction_proxy { | 18 namespace data_reduction_proxy { |
18 | 19 |
19 class DataReductionProxyUsageStats | 20 class DataReductionProxyUsageStats |
20 : public net::NetworkChangeNotifier::NetworkChangeObserver { | 21 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
21 public: | 22 public: |
22 // MessageLoopProxy instances are owned by io_thread. |params| outlives | 23 // MessageLoopProxy instance is owned by io_thread. |params| outlives |
23 // this class instance. | 24 // this class instance. |
24 DataReductionProxyUsageStats(DataReductionProxyParams* params, | 25 DataReductionProxyUsageStats(DataReductionProxyParams* params, |
25 base::MessageLoopProxy* ui_thread_proxy, | 26 base::MessageLoopProxy* ui_thread_proxy); |
26 base::MessageLoopProxy* io_thread_proxy); | |
27 virtual ~DataReductionProxyUsageStats(); | 27 virtual ~DataReductionProxyUsageStats(); |
28 | 28 |
| 29 // Sets the callback to be called on the UI thread when the unavailability |
| 30 // status has changed. |
| 31 void set_unavailable_callback( |
| 32 const base::Callback<void(bool)>& unavailable_callback) { |
| 33 unavailable_callback_ = unavailable_callback; |
| 34 } |
| 35 |
29 // Callback intended to be called from |ChromeNetworkDelegate| when a | 36 // Callback intended to be called from |ChromeNetworkDelegate| when a |
30 // request completes. This method is used to gather usage stats. | 37 // request completes. This method is used to gather usage stats. |
31 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); | 38 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); |
32 | 39 |
33 // Determines whether the data reduction proxy is unreachable. | |
34 // Returns true if data reduction proxy is unreachable. | |
35 bool isDataReductionProxyUnreachable(); | |
36 | |
37 // Records the last bypass reason to |bypass_type_| and sets | 40 // Records the last bypass reason to |bypass_type_| and sets |
38 // |triggering_request_| to true. A triggering request is the first request to | 41 // |triggering_request_| to true. A triggering request is the first request to |
39 // cause the current bypass. | 42 // cause the current bypass. |
40 void SetBypassType(net::ProxyService::DataReductionProxyBypassType type); | 43 void SetBypassType(net::ProxyService::DataReductionProxyBypassType type); |
41 | 44 |
42 // Given the |content_length| and associated |request|, records the | 45 // Given the |content_length| and associated |request|, records the |
43 // number of bypassed bytes for that |request| into UMAs based on bypass type. | 46 // number of bypassed bytes for that |request| into UMAs based on bypass type. |
44 // |data_reduction_proxy_enabled| tells us the state of the | 47 // |data_reduction_proxy_enabled| tells us the state of the |
45 // kDataReductionProxyEnabled preference. | 48 // kDataReductionProxyEnabled preference. |
46 void RecordBypassedBytesHistograms( | 49 void RecordBypassedBytesHistograms( |
47 net::URLRequest& request, | 50 net::URLRequest& request, |
48 const BooleanPrefMember& data_reduction_proxy_enabled); | 51 const BooleanPrefMember& data_reduction_proxy_enabled); |
49 | 52 |
50 private: | 53 private: |
51 enum BypassedBytesType { | 54 enum BypassedBytesType { |
52 NOT_BYPASSED = 0, /* Not bypassed. */ | 55 NOT_BYPASSED = 0, /* Not bypassed. */ |
53 SSL, /* Bypass due to SSL. */ | 56 SSL, /* Bypass due to SSL. */ |
54 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ | 57 LOCAL_BYPASS_RULES, /* Bypass due to client-side bypass rules. */ |
55 AUDIO_VIDEO, /* Audio/Video bypass. */ | 58 AUDIO_VIDEO, /* Audio/Video bypass. */ |
56 TRIGGERING_REQUEST, /* Triggering request bypass. */ | 59 TRIGGERING_REQUEST, /* Triggering request bypass. */ |
57 NETWORK_ERROR, /* Network error. */ | 60 NETWORK_ERROR, /* Network error. */ |
58 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ | 61 BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ |
59 }; | 62 }; |
60 | 63 |
| 64 // NetworkChangeNotifier::NetworkChangeObserver: |
| 65 virtual void OnNetworkChanged( |
| 66 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 67 |
| 68 // Counts requests that went through the data reduction proxy and counts |
| 69 // requests that were eligible to go through the proxy. |
| 70 void IncrementRequestCounts(bool actual); |
| 71 void ClearRequestCounts(); |
| 72 |
| 73 // Checks if the availability status of the data reduction proxy has changed, |
| 74 // and notifies the UIThread via NotifyUnavailabilityOnUIThread if so. The |
| 75 // data reduction proxy is considered unavailable if and only if no requests |
| 76 // went through the proxy but some eligible requests were service by other |
| 77 // routes. |
| 78 void MaybeNotifyUnavailability(); |
| 79 void NotifyUnavailabilityOnUIThread(bool unavailable); |
| 80 |
61 DataReductionProxyParams* data_reduction_proxy_params_; | 81 DataReductionProxyParams* data_reduction_proxy_params_; |
62 // The last reason for bypass as determined by | 82 // The last reason for bypass as determined by |
63 // MaybeBypassProxyAndPrepareToRetry | 83 // MaybeBypassProxyAndPrepareToRetry |
64 net::ProxyService::DataReductionProxyBypassType last_bypass_type_; | 84 net::ProxyService::DataReductionProxyBypassType last_bypass_type_; |
65 // True if the last request triggered the current bypass. | 85 // True if the last request triggered the current bypass. |
66 bool triggering_request_; | 86 bool triggering_request_; |
67 base::MessageLoopProxy* ui_thread_proxy_; | 87 base::MessageLoopProxy* ui_thread_proxy_; |
68 base::MessageLoopProxy* io_thread_proxy_; | |
69 | 88 |
70 // The following 2 fields are used to determine if data reduction proxy is | 89 // The following 2 fields are used to determine if data reduction proxy is |
71 // unreachable. We keep a count of requests which should go through | 90 // unreachable. We keep a count of requests which should go through |
72 // data request proxy, as well as those which actually do. The proxy is | 91 // data request proxy, as well as those which actually do. The proxy is |
73 // unreachable if no successful requests are made through it despite a | 92 // unreachable if no successful requests are made through it despite a |
74 // non-zero number of requests being eligible. | 93 // non-zero number of requests being eligible. |
75 | 94 |
76 // Count of requests which will be tried to be sent through data reduction | 95 // Count of requests which will be tried to be sent through data reduction |
77 // proxy. The count is only based on the config and not the bad proxy list. | 96 // proxy. The count is only based on the config and not the bad proxy list. |
78 // Explicit bypasses are not part of this count. This is the desired behavior | 97 // Explicit bypasses are not part of this count. This is the desired behavior |
79 // since otherwise both counts would be identical. | 98 // since otherwise both counts would be identical. |
80 unsigned long eligible_num_requests_through_proxy_; | 99 unsigned long eligible_num_requests_through_proxy_; |
81 // Count of successfull requests through data reduction proxy. | 100 |
| 101 // Count of successful requests through data reduction proxy. |
82 unsigned long actual_num_requests_through_proxy_; | 102 unsigned long actual_num_requests_through_proxy_; |
83 | 103 |
84 // NetworkChangeNotifier::NetworkChangeObserver: | 104 // Whether or not the data reduction proxy is unavailable. |
85 virtual void OnNetworkChanged( | 105 bool unavailable_; |
86 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
87 | |
88 void IncRequestCountsOnUiThread(bool actual); | |
89 void ClearRequestCountsOnUiThread(); | |
90 | 106 |
91 base::ThreadChecker thread_checker_; | 107 base::ThreadChecker thread_checker_; |
92 | 108 |
93 void RecordBypassedBytes( | 109 void RecordBypassedBytes( |
94 net::ProxyService::DataReductionProxyBypassType bypass_type, | 110 net::ProxyService::DataReductionProxyBypassType bypass_type, |
95 BypassedBytesType bypassed_bytes_type, | 111 BypassedBytesType bypassed_bytes_type, |
96 int64 content_length); | 112 int64 content_length); |
97 | 113 |
| 114 // Called when the unavailability status has changed. Runs on the UI thread. |
| 115 base::Callback<void(bool)> unavailable_callback_; |
| 116 |
98 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); | 117 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); |
99 }; | 118 }; |
100 | 119 |
101 } // namespace data_reduction_proxy | 120 } // namespace data_reduction_proxy |
102 | 121 |
103 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST
ATS_H_ | 122 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST
ATS_H_ |
OLD | NEW |