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

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

Issue 1310743003: Consistently use LoFi for an entire page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: using UserData and adressing nasko comments Created 5 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/core/browser/data_reduction_proxy_network_delegate.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
index ff611f7f80a7ba10c00babf0390d47109a4d10a7..61fb183aeb934d1a2d2e374fff62f380389242e0 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate.cc
@@ -16,6 +16,8 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_lofi_helper.h"
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
#include "net/proxy/proxy_info.h"
@@ -90,6 +92,88 @@ void RecordContentLengthHistograms(bool lofi_low_header_added,
received_content_length);
}
+// Following UMA is plotted to measure how frequently Lo-Fi state changes.
+// Too frequent changes are undesirable.
+void RecordAutoLoFiRequestHeaderStateChange(bool previous_header_low,
+ bool current_header_low) {
+ // Auto Lo-Fi request header state changes.
+ // Possible Lo-Fi header directives are empty ("") and low ("q=low").
+ // This enum must remain synchronized with the enum of the same name in
+ // metrics/histograms/histograms.xml.
+ enum AutoLoFiRequestHeaderState {
+ AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_EMPTY = 0,
+ AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_LOW = 1,
+ AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_EMPTY = 2,
+ AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_LOW = 3,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY
+ };
+
+ AutoLoFiRequestHeaderState state;
+ net::NetworkChangeNotifier::ConnectionType connection_type =
+ net::NetworkChangeNotifier::GetConnectionType();
+
+ if (!previous_header_low) {
+ if (current_header_low)
+ state = AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_LOW;
+ else
+ state = AUTO_LOFI_REQUEST_HEADER_STATE_EMPTY_TO_EMPTY;
+ } else {
+ if (current_header_low) {
+ // Low to low in useful in checking how many consecutive page loads
+ // are done with Lo-Fi enabled.
+ state = AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_LOW;
+ } else {
+ state = AUTO_LOFI_REQUEST_HEADER_STATE_LOW_TO_EMPTY;
+ }
+ }
+
+ switch (connection_type) {
+ case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.Unknown", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.Ethernet", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ case net::NetworkChangeNotifier::CONNECTION_WIFI:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.WiFi", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ case net::NetworkChangeNotifier::CONNECTION_2G:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.2G", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ case net::NetworkChangeNotifier::CONNECTION_3G:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.3G", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ case net::NetworkChangeNotifier::CONNECTION_4G:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.4G", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ case net::NetworkChangeNotifier::CONNECTION_NONE:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.None", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ case net::NetworkChangeNotifier::CONNECTION_BLUETOOTH:
+ UMA_HISTOGRAM_ENUMERATION(
+ "DataReductionProxy.AutoLoFiRequestHeaderState.Bluetooth", state,
+ AUTO_LOFI_REQUEST_HEADER_STATE_INDEX_BOUNDARY);
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
} // namespace
namespace data_reduction_proxy {
@@ -112,7 +196,8 @@ DataReductionProxyNetworkDelegate::DataReductionProxyNetworkDelegate(
configurator_(configurator),
experiments_stats_(experiments_stats),
net_log_(net_log),
- event_creator_(event_creator) {
+ event_creator_(event_creator),
+ previous_state_lofi_on_(false) {
DCHECK(data_reduction_proxy_config_);
DCHECK(data_reduction_proxy_request_options_);
DCHECK(configurator_);
@@ -174,26 +259,57 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendProxyHeadersInternal(
const net::ProxyInfo& proxy_info,
net::HttpRequestHeaders* headers) {
DCHECK(data_reduction_proxy_config_);
+ LoFiState lofi_state = LOFI_DEFAULT;
+
+ if (data_reduction_proxy_io_data_ &&
+ data_reduction_proxy_io_data_->lofi_helper() && request) {
+ DataReductionProxyLoFiHelper* lofi_helper =
+ data_reduction_proxy_io_data_->lofi_helper();
+ lofi_state = lofi_helper->lofi_state(request);
+
+ net::NetworkQualityEstimator* network_quality_estimator = nullptr;
+ if (request->context())
+ network_quality_estimator =
+ request->context()->network_quality_estimator();
+
+ // Some requests, such as pings, don't go through
+ // RenderFrameImpl::WillSendRequest and get the LoFi state since they
+ // outlive the parent document. Set Lo-Fi off on these requests.
+ if (lofi_state == LOFI_DEFAULT &&
+ (request->load_flags() & net::LOAD_MAIN_FRAME) == 0) {
+ lofi_state = LOFI_OFF;
+ lofi_helper->set_lofi_state(request, lofi_state);
+ }
+
+ if (lofi_state == LOFI_DEFAULT) {
+ lofi_state =
+ data_reduction_proxy_config_->ShouldTurnOnLoFiOnMainFrameRequest(
+ network_quality_estimator)
+ ? LOFI_ON
+ : LOFI_OFF;
+ lofi_helper->set_lofi_state(request, lofi_state);
+ if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
+ data_reduction_proxy_config_->IsIncludedInLoFiEnabledFieldTrial()) {
+ RecordAutoLoFiRequestHeaderStateChange(previous_state_lofi_on_,
+ lofi_state == LOFI_ON);
+ }
+ }
+
+ if ((request->load_flags() & net::LOAD_MAIN_FRAME) != 0) {
+ if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
+ data_reduction_proxy_config_->IsIncludedInLoFiEnabledFieldTrial()) {
+ previous_state_lofi_on_ = lofi_state == LOFI_ON;
+ }
- // TODO(bengr): Investigate a better approach to update the network
- // quality so that state of Lo-Fi is stored per page.
- net::NetworkQualityEstimator* network_quality_estimator = nullptr;
- if (request && request->context())
- network_quality_estimator = request->context()->network_quality_estimator();
-
- if (request && ((request->load_flags() & net::LOAD_MAIN_FRAME) != 0)) {
- data_reduction_proxy_config_->UpdateLoFiStatusOnMainFrameRequest(
- ((request->load_flags() & net::LOAD_BYPASS_CACHE) != 0),
- network_quality_estimator);
- if (data_reduction_proxy_io_data_) {
- data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame(
- data_reduction_proxy_config_->ShouldUseLoFiHeaderForRequests());
+ // TODO(megjablon): Need to switch to per page.
+ data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame(lofi_state ==
+ LOFI_ON);
}
}
if (data_reduction_proxy_request_options_) {
data_reduction_proxy_request_options_->MaybeAddRequestHeader(
- request, proxy_info.proxy_server(), headers);
+ request, proxy_info.proxy_server(), headers, lofi_state == LOFI_ON);
}
}
@@ -254,13 +370,13 @@ void DataReductionProxyNetworkDelegate::OnCompletedInternal(
DCHECK(data_reduction_proxy_config_);
- // TODO(bengr): Investigate a better approach to record the Lo-Fi
- // histogram. State of Lo-Fi should be stored per page.
RecordContentLengthHistograms(
// |data_reduction_proxy_io_data_| can be NULL for Webview.
data_reduction_proxy_io_data_ &&
data_reduction_proxy_io_data_->IsEnabled() &&
- data_reduction_proxy_config_->ShouldUseLoFiHeaderForRequests(),
+ data_reduction_proxy_io_data_->lofi_helper() &&
+ data_reduction_proxy_io_data_->lofi_helper()->lofi_state(request) ==
+ LOFI_ON,
received_content_length, original_content_length, freshness_lifetime);
experiments_stats_->RecordBytes(request->request_time(), request_type,
received_content_length,

Powered by Google App Engine
This is Rietveld 408576698