Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.cc

Issue 568893002: Trigger data reduction proxy unreachable message via on proxy fall back. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed bengr's comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 b24094763c503b3a30ef59cf9ebad7ba84a9127a..02a07332e6314d4c2e41d1d23e9f24a3be15d482 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
@@ -28,6 +28,10 @@ namespace data_reduction_proxy {
namespace {
+const int UNAVAILABLE_THRESHOLD_NUM_PROXY_NET_ERRORS = 0;
bengr 2014/09/19 21:28:12 Use chromium C++ style here and below: kUnavailabl
Not at Google. Contact bengr 2014/09/22 21:46:58 Done.
+const int UNAVAILABLE_THRESHOLD_NUM_SUCCESSFUL_REQUESTS = 0;
+const int RESET_THRESHOLD_NUM_SUCCESSFUL_REQUESTS = 3;
+
// Records a net error code that resulted in bypassing the data reduction
// proxy (|is_primary| is true) or the data reduction proxy fallback.
void RecordDataReductionProxyBypassOnNetworkError(
@@ -79,9 +83,11 @@ DataReductionProxyUsageStats::DataReductionProxyUsageStats(
last_bypass_type_(BYPASS_EVENT_TYPE_MAX),
triggering_request_(true),
ui_thread_proxy_(ui_thread_proxy),
- eligible_num_requests_through_proxy_(0),
- actual_num_requests_through_proxy_(0),
+ num_successful_requests_through_proxy_(0),
+ num_proxy_net_errors_(0),
unavailable_(false) {
+ DCHECK(params);
+
NetworkChangeNotifier::AddNetworkChangeObserver(this);
};
@@ -93,12 +99,18 @@ void DataReductionProxyUsageStats::OnUrlRequestCompleted(
const net::URLRequest* request, bool started) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (request->status().status() == net::URLRequestStatus::SUCCESS) {
- if (data_reduction_proxy_params_->IsDataReductionProxyEligible(request)) {
- bool was_received_via_proxy =
- data_reduction_proxy_params_->WasDataReductionProxyUsed(
- request, NULL);
- IncrementRequestCounts(was_received_via_proxy);
+ if (request->status().status() == net::URLRequestStatus::SUCCESS &&
+ data_reduction_proxy_params_->WasDataReductionProxyUsed(request, NULL)) {
+ num_successful_requests_through_proxy_++;
+
+ // To account for the case when the proxy is blocked for a little while
+ // and then works fine, we reset the counts when they exceed thresholds.
+ if (num_proxy_net_errors_ > UNAVAILABLE_THRESHOLD_NUM_PROXY_NET_ERRORS &&
+ num_successful_requests_through_proxy_ >
+ RESET_THRESHOLD_NUM_SUCCESSFUL_REQUESTS) {
+ ClearRequestCounts();
+ } else {
+ MaybeNotifyUnavailability();
}
}
}
@@ -109,35 +121,19 @@ void DataReductionProxyUsageStats::OnNetworkChanged(
ClearRequestCounts();
}
-void DataReductionProxyUsageStats::IncrementRequestCounts(
- bool was_received_via_proxy) {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (was_received_via_proxy) {
- actual_num_requests_through_proxy_++;
- }
- eligible_num_requests_through_proxy_++;
-
- // To account for the case when the proxy works for a little while and then
- // gets blocked, we reset the counts occasionally.
- if (eligible_num_requests_through_proxy_ > 50
- && actual_num_requests_through_proxy_ > 0) {
- ClearRequestCounts();
- } else {
- MaybeNotifyUnavailability();
- }
-}
-
void DataReductionProxyUsageStats::ClearRequestCounts() {
DCHECK(thread_checker_.CalledOnValidThread());
- eligible_num_requests_through_proxy_ = 0;
- actual_num_requests_through_proxy_ = 0;
+ num_successful_requests_through_proxy_ = 0;
+ num_proxy_net_errors_ = 0;
MaybeNotifyUnavailability();
}
void DataReductionProxyUsageStats::MaybeNotifyUnavailability() {
bool prev_unavailable = unavailable_;
- unavailable_ = (eligible_num_requests_through_proxy_ > 0 &&
- actual_num_requests_through_proxy_ == 0);
+ unavailable_ =
+ (num_proxy_net_errors_ > UNAVAILABLE_THRESHOLD_NUM_PROXY_NET_ERRORS &&
+ num_successful_requests_through_proxy_ <=
+ UNAVAILABLE_THRESHOLD_NUM_SUCCESSFUL_REQUESTS);
if (prev_unavailable != unavailable_) {
ui_thread_proxy_->PostTask(FROM_HERE, base::Bind(
&DataReductionProxyUsageStats::NotifyUnavailabilityOnUIThread,
@@ -235,15 +231,19 @@ void DataReductionProxyUsageStats::RecordBypassedBytesHistograms(
}
}
-void DataReductionProxyUsageStats::RecordBypassEventHistograms(
+void DataReductionProxyUsageStats::OnProxyFallback(
const net::ProxyServer& bypassed_proxy,
- int net_error) const {
+ int net_error) {
DataReductionProxyTypeInfo data_reduction_proxy_info;
if (bypassed_proxy.is_valid() && !bypassed_proxy.is_direct() &&
data_reduction_proxy_params_->IsDataReductionProxy(
bypassed_proxy.host_port_pair(), &data_reduction_proxy_info)) {
if (data_reduction_proxy_info.is_ssl)
return;
+
+ num_proxy_net_errors_++;
+ MaybeNotifyUnavailability();
+
if (!data_reduction_proxy_info.is_fallback) {
RecordDataReductionProxyBypassInfo(
true, false, bypassed_proxy, BYPASS_EVENT_TYPE_NETWORK_ERROR);

Powered by Google App Engine
This is Rietveld 408576698