| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc
|
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc
|
| index 7d9c06677493de75f21c90f96e201eebe640bb9a..50796496e8eaf9545c77f6be607a34b2b68b9c99 100644
|
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc
|
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc
|
| @@ -1,16 +1,17 @@
|
| // Copyright 2016 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.h"
|
|
|
| +#include "base/rand_util.h"
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_page_load_timing.h"
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
|
| #include "components/data_reduction_proxy/core/common/data_reduction_proxy_util.h"
|
| #include "components/data_reduction_proxy/proto/client_config.pb.h"
|
| #include "components/data_reduction_proxy/proto/pageload_metrics.pb.h"
|
| #include "net/base/load_flags.h"
|
| #include "net/url_request/url_fetcher.h"
|
| #include "net/url_request/url_request_context_getter.h"
|
| #include "net/url_request/url_request_status.h"
|
| @@ -58,21 +59,22 @@ std::string SerializeData(const DataReductionProxyData& request_data,
|
| std::string serialized_request;
|
| batched_request.SerializeToString(&serialized_request);
|
| return serialized_request;
|
| }
|
|
|
| } // namespace
|
|
|
| DataReductionProxyPingbackClient::DataReductionProxyPingbackClient(
|
| net::URLRequestContextGetter* url_request_context)
|
| : url_request_context_(url_request_context),
|
| - pingback_url_(util::AddApiKeyToUrl(params::GetPingbackURL())) {}
|
| + pingback_url_(util::AddApiKeyToUrl(params::GetPingbackURL())),
|
| + pingback_reporting_fraction_(0.0) {}
|
|
|
| DataReductionProxyPingbackClient::~DataReductionProxyPingbackClient() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| }
|
|
|
| void DataReductionProxyPingbackClient::OnURLFetchComplete(
|
| const net::URLFetcher* source) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(source == current_fetcher_.get());
|
| // TODO(ryansturm): Add UMA to measure failures. crbug.com/616544
|
| @@ -109,16 +111,27 @@ DataReductionProxyPingbackClient::MaybeCreateFetcherForDataAndStart(
|
| fetcher->SetRequestContext(url_request_context_);
|
| // Configure max retries to be at most kMaxRetries times for 5xx errors.
|
| static const int kMaxRetries = 5;
|
| fetcher->SetMaxRetriesOn5xx(kMaxRetries);
|
| fetcher->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries);
|
| fetcher->Start();
|
| return fetcher;
|
| }
|
|
|
| bool DataReductionProxyPingbackClient::ShouldSendPingback() const {
|
| - // TODO(ryansturm): Modulate the frequency of sending a pingback based on a
|
| - // client config parameter. crbug.com/616805
|
| - return params::IsForcePingbackEnabledViaFlags();
|
| + return params::IsForcePingbackEnabledViaFlags() ||
|
| + GenerateRandomFloat() < pingback_reporting_fraction_;
|
| +}
|
| +
|
| +float DataReductionProxyPingbackClient::GenerateRandomFloat() const {
|
| + return static_cast<float>(base::RandDouble());
|
| +}
|
| +
|
| +void DataReductionProxyPingbackClient::SetPingbackReportingFraction(
|
| + float pingback_reporting_fraction) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + DCHECK_LE(0.0f, pingback_reporting_fraction);
|
| + DCHECK_GE(1.0f, pingback_reporting_fraction);
|
| + pingback_reporting_fraction_ = pingback_reporting_fraction;
|
| }
|
|
|
| } // namespace data_reduction_proxy
|
|
|