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 6c217b2f5768bdba67c736494cee83e2629dc718..e3d707811fc3afc5124d2973b72d9ca9d4abf620 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/threading/thread_checker.h" |
#include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
@@ -16,29 +17,43 @@ 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(); |
- /** |
- * 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); |
+ // 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; |
+ } |
- /** |
- * Determines whether the data reduction proxy is unreachable. |
- * Returns true if data reduction proxy is unreachable. |
- */ |
- bool isDataReductionProxyUnreachable(); |
+ // 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); |
private: |
+ // 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_; |
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 |
@@ -51,18 +66,18 @@ 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_; |
+ // Called when the unavailability status has changed. Runs on the UI thread. |
+ base::Callback<void(bool)> unavailable_callback_; |
+ |
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); |
}; |