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

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: test fixes Created 5 years, 4 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..1bc30b7558f0d0fba3657d8c43501f7381515ada 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
@@ -90,6 +90,87 @@ void RecordContentLengthHistograms(bool lofi_low_header_added,
received_content_length);
}
+// Values of change in the state of Auto Lo-Fi request headers.
bengr 2015/08/25 00:00:01 Auto Lo-Fi request header state changes.
megjablon 2015/08/25 20:29:46 Done.
+// Possible Lo-Fi headers are: empty (""), low ("low").
bengr 2015/08/25 00:00:01 Please make sure you grabbed the current version o
megjablon 2015/08/25 20:29:46 Done.
+// 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
+};
+
+// 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) {
+ 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 +193,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_);
@@ -175,20 +257,34 @@ void DataReductionProxyNetworkDelegate::OnBeforeSendProxyHeadersInternal(
net::HttpRequestHeaders* headers) {
DCHECK(data_reduction_proxy_config_);
- // 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());
- }
+ // Some requests, such as pings, don't go through will send request and get
bengr 2015/08/25 00:00:01 Name the method instead of "will send request".
megjablon 2015/08/25 20:29:46 Done.
+ // the LoFi state since they outlive the parent document. Set LoFi off on
+ // these requests.
+ if (request && request->lofi_state() == net::LOFI_DEFAULT &&
+ (request->load_flags() & net::LOAD_MAIN_FRAME) == 0) {
+ request->set_lofi_state(net::LOFI_OFF);
+ }
+
+ if (request && request->lofi_state() == net::LOFI_DEFAULT) {
+ request->set_lofi_state(
+ data_reduction_proxy_config_->ShouldTurnOnLoFiOnMainFrameRequest(
+ network_quality_estimator)
+ ? net::LOFI_ON
+ : net::LOFI_OFF);
+ RecordAutoLoFiRequestHeaderStateChange(
+ previous_state_lofi_on_, request->lofi_state() == net::LOFI_ON);
+ previous_state_lofi_on_ = request->lofi_state() == net::LOFI_ON;
+ }
+
+ if (request && (request->load_flags() & net::LOAD_MAIN_FRAME) != 0 &&
+ data_reduction_proxy_io_data_) {
+ // TODO(megjablon): Need to switch to per page.
+ data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame(
+ request->lofi_state() == net::LOFI_ON);
}
if (data_reduction_proxy_request_options_) {
@@ -254,13 +350,11 @@ 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(),
+ request->lofi_state() == net::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