| 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/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" |
| 13 | 14 |
| 14 namespace data_reduction_proxy { | 15 namespace data_reduction_proxy { |
| 15 | 16 |
| 16 class DataReductionProxyUsageStats | 17 class DataReductionProxyUsageStats |
| 17 : public net::NetworkChangeNotifier::NetworkChangeObserver { | 18 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 18 public: | 19 public: |
| 19 // MessageLoopProxy instances are owned by io_thread. |params| outlives | 20 // MessageLoopProxy instances are owned by io_thread. |params| outlives |
| 20 // this class instance. | 21 // this class instance. |
| 21 DataReductionProxyUsageStats(DataReductionProxyParams* params, | 22 DataReductionProxyUsageStats(DataReductionProxyParams* params, |
| 22 base::MessageLoopProxy* ui_thread_proxy, | 23 base::MessageLoopProxy* ui_thread_proxy, |
| 23 base::MessageLoopProxy* io_thread_proxy); | 24 base::MessageLoopProxy* io_thread_proxy); |
| 24 virtual ~DataReductionProxyUsageStats(); | 25 virtual ~DataReductionProxyUsageStats(); |
| 25 | 26 |
| 26 /** | 27 // Sets the callback to be called on the UI thread when the unavailability |
| 27 * Callback intended to be called from |ChromeNetworkDelegate| when a | 28 // status has changed. |
| 28 * request completes. This method is used to gather usage stats. | 29 void set_unavailable_callback( |
| 29 */ | 30 const base::Callback<void(bool)>& unavailable_callback) { |
| 31 unavailable_callback_ = unavailable_callback; |
| 32 } |
| 33 |
| 34 // Callback intended to be called from |ChromeNetworkDelegate| when a |
| 35 // request completes. This method is used to gather usage stats. |
| 30 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); | 36 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); |
| 31 | 37 |
| 32 /** | 38 private: |
| 33 * Determines whether the data reduction proxy is unreachable. | 39 // NetworkChangeNotifier::NetworkChangeObserver: |
| 34 * Returns true if data reduction proxy is unreachable. | 40 virtual void OnNetworkChanged( |
| 35 */ | 41 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; |
| 36 bool isDataReductionProxyUnreachable(); | |
| 37 | 42 |
| 38 private: | 43 // Counts requests that went through the data reduction proxy and counts |
| 44 // requests that were eligible to go through the proxy. |
| 45 void IncrementRequestCounts(bool actual); |
| 46 void ClearRequestCounts(); |
| 47 |
| 48 // Checks if the availability status of the data reduction proxy has changed, |
| 49 // and notifies the UIThread via NotifyUnavailabilityOnUIThread if so. The |
| 50 // data reduction proxy is considered unavailable if and only if no requests |
| 51 // went through the proxy but some eligible requests were service by other |
| 52 // routes. |
| 53 void MaybeNotifyUnavailability(); |
| 54 void NotifyUnavailabilityOnUIThread(bool unavailable); |
| 55 |
| 39 DataReductionProxyParams* data_reduction_proxy_params_; | 56 DataReductionProxyParams* data_reduction_proxy_params_; |
| 40 base::MessageLoopProxy* ui_thread_proxy_; | 57 base::MessageLoopProxy* ui_thread_proxy_; |
| 41 base::MessageLoopProxy* io_thread_proxy_; | 58 base::MessageLoopProxy* io_thread_proxy_; |
| 42 | 59 |
| 43 // The following 2 fields are used to determine if data reduction proxy is | 60 // 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 | 61 // 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 | 62 // 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 | 63 // unreachable if no successful requests are made through it despite a |
| 47 // non-zero number of requests being eligible. | 64 // non-zero number of requests being eligible. |
| 48 | 65 |
| 49 // Count of requests which will be tried to be sent through data reduction | 66 // 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. | 67 // 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 | 68 // Explicit bypasses are not part of this count. This is the desired behavior |
| 52 // since otherwise both counts would be identical. | 69 // since otherwise both counts would be identical. |
| 53 unsigned long eligible_num_requests_through_proxy_; | 70 unsigned long eligible_num_requests_through_proxy_; |
| 54 // Count of successfull requests through data reduction proxy. | 71 |
| 72 // Count of successful requests through data reduction proxy. |
| 55 unsigned long actual_num_requests_through_proxy_; | 73 unsigned long actual_num_requests_through_proxy_; |
| 56 | 74 |
| 57 // NetworkChangeNotifier::NetworkChangeObserver: | 75 // Whether or not the data reduction proxy is unavailable. |
| 58 virtual void OnNetworkChanged( | 76 bool unavailable_; |
| 59 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE; | |
| 60 | |
| 61 void IncRequestCountsOnUiThread(bool actual); | |
| 62 void ClearRequestCountsOnUiThread(); | |
| 63 | 77 |
| 64 base::ThreadChecker thread_checker_; | 78 base::ThreadChecker thread_checker_; |
| 65 | 79 |
| 80 // Called when the unavailability status has changed. Runs on the UI thread. |
| 81 base::Callback<void(bool)> unavailable_callback_; |
| 82 |
| 66 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); | 83 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); |
| 67 }; | 84 }; |
| 68 | 85 |
| 69 } // namespace data_reduction_proxy | 86 } // namespace data_reduction_proxy |
| 70 | 87 |
| 71 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST
ATS_H_ | 88 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST
ATS_H_ |
| OLD | NEW |