Index: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h |
diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h |
index 4e3dbfe6fb891ae0120428180c030a49cb0db12a..4fe9c5ee2ee71b16859fb0680a8fe2d07a6fb2b9 100644 |
--- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h |
+++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h |
@@ -5,6 +5,7 @@ |
#ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS_H_ |
#define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS_H_ |
+#include "base/callback.h" |
#include "base/message_loop/message_loop_proxy.h" |
#include "base/prefs/pref_member.h" |
#include "base/threading/thread_checker.h" |
@@ -19,21 +20,23 @@ namespace data_reduction_proxy { |
class DataReductionProxyUsageStats |
: public net::NetworkChangeNotifier::NetworkChangeObserver { |
public: |
- // MessageLoopProxy instances are owned by io_thread. |params| outlives |
+ // MessageLoopProxy instance is owned by io_thread. |params| outlives |
// this class instance. |
DataReductionProxyUsageStats(DataReductionProxyParams* params, |
- base::MessageLoopProxy* ui_thread_proxy, |
- base::MessageLoopProxy* io_thread_proxy); |
+ base::MessageLoopProxy* ui_thread_proxy); |
virtual ~DataReductionProxyUsageStats(); |
+ // Sets the callback to be called on the UI thread when the unavailability |
+ // status has changed. |
+ void set_unavailable_callback( |
+ const base::Callback<void(bool)>& unavailable_callback) { |
+ unavailable_callback_ = unavailable_callback; |
+ } |
+ |
// Callback intended to be called from |ChromeNetworkDelegate| when a |
// request completes. This method is used to gather usage stats. |
void OnUrlRequestCompleted(const net::URLRequest* request, bool started); |
- // Determines whether the data reduction proxy is unreachable. |
- // Returns true if data reduction proxy is unreachable. |
- bool isDataReductionProxyUnreachable(); |
- |
// Records the last bypass reason to |bypass_type_| and sets |
// |triggering_request_| to true. A triggering request is the first request to |
// cause the current bypass. |
@@ -58,6 +61,23 @@ class DataReductionProxyUsageStats |
BYPASSED_BYTES_TYPE_MAX /* This must always be last.*/ |
}; |
+ // NetworkChangeNotifier::NetworkChangeObserver: |
+ virtual void OnNetworkChanged( |
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
+ |
+ // Counts requests that went through the data reduction proxy and counts |
+ // requests that were eligible to go through the proxy. |
+ void IncrementRequestCounts(bool actual); |
+ void ClearRequestCounts(); |
+ |
+ // Checks if the availability status of the data reduction proxy has changed, |
+ // and notifies the UIThread via NotifyUnavailabilityOnUIThread if so. The |
+ // data reduction proxy is considered unavailable if and only if no requests |
+ // went through the proxy but some eligible requests were service by other |
+ // routes. |
+ void MaybeNotifyUnavailability(); |
+ void NotifyUnavailabilityOnUIThread(bool unavailable); |
+ |
DataReductionProxyParams* data_reduction_proxy_params_; |
// The last reason for bypass as determined by |
// MaybeBypassProxyAndPrepareToRetry |
@@ -65,7 +85,6 @@ class DataReductionProxyUsageStats |
// True if the last request triggered the current bypass. |
bool triggering_request_; |
base::MessageLoopProxy* ui_thread_proxy_; |
- base::MessageLoopProxy* io_thread_proxy_; |
// The following 2 fields are used to determine if data reduction proxy is |
// unreachable. We keep a count of requests which should go through |
@@ -78,15 +97,12 @@ class DataReductionProxyUsageStats |
// Explicit bypasses are not part of this count. This is the desired behavior |
// since otherwise both counts would be identical. |
unsigned long eligible_num_requests_through_proxy_; |
- // Count of successfull requests through data reduction proxy. |
- unsigned long actual_num_requests_through_proxy_; |
- // NetworkChangeNotifier::NetworkChangeObserver: |
- virtual void OnNetworkChanged( |
- net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
+ // Count of successful requests through data reduction proxy. |
+ unsigned long actual_num_requests_through_proxy_; |
- void IncRequestCountsOnUiThread(bool actual); |
- void ClearRequestCountsOnUiThread(); |
+ // Whether or not the data reduction proxy is unavailable. |
+ bool unavailable_; |
base::ThreadChecker thread_checker_; |
@@ -95,6 +111,9 @@ class DataReductionProxyUsageStats |
BypassedBytesType bypassed_bytes_type, |
int64 content_length); |
+ // Called when the unavailability status has changed. Runs on the UI thread. |
+ base::Callback<void(bool)> unavailable_callback_; |
+ |
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); |
}; |