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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc

Issue 1363673004: [DRP] Consistently use LoFi for an entire page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final comments Created 5 years, 2 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/core/browser/data_reduction_proxy_request_options.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
index 6a52cdf18446ea1cabf8224b51949a8aadafcf55..b165acad2990bb090d92a7f69eb0054cde629a40 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.cc
@@ -161,25 +161,26 @@ void DataReductionProxyRequestOptions::UpdateVersion() {
}
void DataReductionProxyRequestOptions::MayRegenerateHeaderBasedOnLoFi(
- const net::URLRequest* request) {
+ bool is_using_lofi_mode) {
DCHECK(thread_checker_.CalledOnValidThread());
- if (!data_reduction_proxy_config_)
- return;
-
- bool lofi_now_enabled =
- !(request && request->load_flags() & net::LOAD_BYPASS_CACHE) &&
- data_reduction_proxy_config_->ShouldUseLoFiHeaderForRequests();
+ // The Lo-Fi directive should not be added for users in the Lo-Fi field
+ // trial "Control" group. Check that the user is in a group that should
+ // get "q=low".
+ bool lofi_enabled_via_flag_or_field_trial =
+ params::IsLoFiOnViaFlags() || params::IsIncludedInLoFiEnabledFieldTrial();
// Lo-Fi was not enabled, but now is. Add the header option.
- if (lofi_.empty() && lofi_now_enabled) {
+ if (lofi_.empty() && is_using_lofi_mode &&
+ lofi_enabled_via_flag_or_field_trial) {
lofi_ = "low";
RegenerateRequestHeaderValue();
return;
}
// Lo-Fi was enabled, but no longer is. Remove the header option.
- if (!lofi_.empty() && !lofi_now_enabled) {
+ if (!lofi_.empty() &&
+ (!is_using_lofi_mode || !lofi_enabled_via_flag_or_field_trial)) {
lofi_ = std::string();
RegenerateRequestHeaderValue();
return;
@@ -188,7 +189,7 @@ void DataReductionProxyRequestOptions::MayRegenerateHeaderBasedOnLoFi(
// User was not part of Lo-Fi active control experiment, but now is.
if (std::find(experiments_.begin(), experiments_.end(),
std::string(kLoFiExperimentID)) == experiments_.end() &&
- data_reduction_proxy_config_->IsInLoFiActiveControlExperiment()) {
+ is_using_lofi_mode && params::IsIncludedInLoFiControlFieldTrial()) {
experiments_.push_back(kLoFiExperimentID);
RegenerateRequestHeaderValue();
DCHECK(std::find(experiments_.begin(), experiments_.end(),
@@ -200,7 +201,7 @@ void DataReductionProxyRequestOptions::MayRegenerateHeaderBasedOnLoFi(
auto it = std::find(experiments_.begin(), experiments_.end(),
std::string(kLoFiExperimentID));
if (it != experiments_.end() &&
- !data_reduction_proxy_config_->IsInLoFiActiveControlExperiment()) {
+ (!is_using_lofi_mode || !params::IsIncludedInLoFiControlFieldTrial())) {
experiments_.erase(it);
RegenerateRequestHeaderValue();
DCHECK(std::find(experiments_.begin(), experiments_.end(),
@@ -248,31 +249,34 @@ void DataReductionProxyRequestOptions::RandBytes(void* output,
void DataReductionProxyRequestOptions::MaybeAddRequestHeader(
net::URLRequest* request,
const net::ProxyServer& proxy_server,
- net::HttpRequestHeaders* request_headers) {
+ net::HttpRequestHeaders* request_headers,
+ bool is_using_lofi_mode) {
DCHECK(thread_checker_.CalledOnValidThread());
if (!proxy_server.is_valid())
return;
if (proxy_server.is_direct())
return;
MaybeAddRequestHeaderImpl(request, proxy_server.host_port_pair(), false,
- request_headers);
+ request_headers, is_using_lofi_mode);
}
void DataReductionProxyRequestOptions::MaybeAddProxyTunnelRequestHandler(
const net::HostPortPair& proxy_server,
net::HttpRequestHeaders* request_headers) {
DCHECK(thread_checker_.CalledOnValidThread());
- MaybeAddRequestHeaderImpl(nullptr, proxy_server, true, request_headers);
+ MaybeAddRequestHeaderImpl(nullptr, proxy_server, true, request_headers,
+ false);
}
void DataReductionProxyRequestOptions::SetHeader(
const net::URLRequest* request,
- net::HttpRequestHeaders* headers) {
+ net::HttpRequestHeaders* headers,
+ bool is_using_lofi_mode) {
base::Time now = Now();
// Authorization credentials must be regenerated if they are expired.
if (!use_assigned_credentials_ && (now > credentials_expiration_time_))
UpdateCredentials();
- MayRegenerateHeaderBasedOnLoFi(request);
+ MayRegenerateHeaderBasedOnLoFi(is_using_lofi_mode);
const char kChromeProxyHeader[] = "Chrome-Proxy";
std::string header_value;
if (headers->HasHeader(kChromeProxyHeader)) {
@@ -392,13 +396,14 @@ void DataReductionProxyRequestOptions::MaybeAddRequestHeaderImpl(
const net::URLRequest* request,
const net::HostPortPair& proxy_server,
bool expect_ssl,
- net::HttpRequestHeaders* request_headers) {
+ net::HttpRequestHeaders* request_headers,
+ bool is_using_lofi_mode) {
if (proxy_server.IsEmpty())
return;
if (data_reduction_proxy_config_->IsDataReductionProxy(proxy_server, NULL) &&
data_reduction_proxy_config_->UsingHTTPTunnel(proxy_server) ==
expect_ssl) {
- SetHeader(request, request_headers);
+ SetHeader(request, request_headers, is_using_lofi_mode);
}
}

Powered by Google App Engine
This is Rietveld 408576698