| Index: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc
|
| diff --git a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc
|
| index 61a26f2cfd7dcf2cc39ef58da66b5ce04fbda096..2443a1fceed9790a43245e134f29683dd0962b6e 100644
|
| --- a/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc
|
| +++ b/components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc
|
| @@ -3,6 +3,8 @@
|
| // found in the LICENSE file.
|
|
|
| #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h"
|
| +
|
| +#include "base/callback.h"
|
| #include "net/proxy/proxy_retry_info.h"
|
| #include "net/proxy/proxy_server.h"
|
| #include "net/proxy/proxy_service.h"
|
| @@ -23,7 +25,8 @@ DataReductionProxyUsageStats::DataReductionProxyUsageStats(
|
| ui_thread_proxy_(ui_thread_proxy),
|
| io_thread_proxy_(io_thread_proxy),
|
| eligible_num_requests_through_proxy_(0),
|
| - actual_num_requests_through_proxy_(0) {
|
| + actual_num_requests_through_proxy_(0),
|
| + unavailable_(false) {
|
| NetworkChangeNotifier::AddNetworkChangeObserver(this);
|
| };
|
|
|
| @@ -40,40 +43,20 @@ void DataReductionProxyUsageStats::OnUrlRequestCompleted(
|
| bool was_received_via_proxy =
|
| data_reduction_proxy_params_->WasDataReductionProxyUsed(
|
| request, NULL);
|
| - ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
|
| - &DataReductionProxyUsageStats::IncRequestCountsOnUiThread,
|
| - base::Unretained(this), was_received_via_proxy));
|
| + IncrementRequestCounts(was_received_via_proxy);
|
| }
|
| }
|
| }
|
|
|
| -/**
|
| - * Determines if the data reduction proxy is currently unreachable. We keep
|
| - * track of count of requests which go through data reduction proxy as well as
|
| - * count of requests which are eligible to go through the proxy. If and only if
|
| - * no requests go through proxy and some requests were eligible, we conclude
|
| - * that the proxy is unreachable.
|
| - *
|
| - * Returns true if the data reduction proxy is unreachable.
|
| - */
|
| -bool DataReductionProxyUsageStats::isDataReductionProxyUnreachable() {
|
| - DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
|
| -
|
| - return eligible_num_requests_through_proxy_ > 0 &&
|
| - actual_num_requests_through_proxy_ == 0;
|
| -}
|
| -
|
| void DataReductionProxyUsageStats::OnNetworkChanged(
|
| NetworkChangeNotifier::ConnectionType type) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
|
| - &DataReductionProxyUsageStats::ClearRequestCountsOnUiThread,
|
| - base::Unretained(this)));
|
| + ClearRequestCounts();
|
| }
|
|
|
| -void DataReductionProxyUsageStats::IncRequestCountsOnUiThread(
|
| +void DataReductionProxyUsageStats::IncrementRequestCounts(
|
| bool was_received_via_proxy) {
|
| - DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
|
| + DCHECK(io_thread_proxy_->BelongsToCurrentThread());
|
| if (was_received_via_proxy) {
|
| actual_num_requests_through_proxy_++;
|
| }
|
| @@ -83,14 +66,36 @@ void DataReductionProxyUsageStats::IncRequestCountsOnUiThread(
|
| // gets blocked, we reset the counts occasionally.
|
| if (eligible_num_requests_through_proxy_ > 50
|
| && actual_num_requests_through_proxy_ > 0) {
|
| - ClearRequestCountsOnUiThread();
|
| + ClearRequestCounts();
|
| + } else {
|
| + MaybeNotifyUnavailability();
|
| }
|
| }
|
|
|
| -void DataReductionProxyUsageStats::ClearRequestCountsOnUiThread() {
|
| - DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
|
| +void DataReductionProxyUsageStats::ClearRequestCounts() {
|
| + DCHECK(io_thread_proxy_->BelongsToCurrentThread());
|
| eligible_num_requests_through_proxy_ = 0;
|
| actual_num_requests_through_proxy_ = 0;
|
| + MaybeNotifyUnavailability();
|
| +}
|
| +
|
| +void DataReductionProxyUsageStats::MaybeNotifyUnavailability() {
|
| + bool prev_unavailable = unavailable_;
|
| + unavailable_ = (eligible_num_requests_through_proxy_ > 0 &&
|
| + actual_num_requests_through_proxy_ == 0);
|
| + if (prev_unavailable != unavailable_) {
|
| + ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
|
| + &DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread,
|
| + base::Unretained(this),
|
| + unavailable_));
|
| + }
|
| +}
|
| +
|
| +void DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread(
|
| + bool unavailable) {
|
| + DCHECK(ui_thread_proxy_->BelongsToCurrentThread());
|
| + if (!unavailable_callback_.is_null())
|
| + unavailable_callback_.Run(unavailable);
|
| }
|
|
|
| } // namespace data_reduction_proxy
|
|
|