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

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: remove log statement and fix ResponseInfo::DeepCopy 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..efc33daffdef93a6f052901fc146009e15314fe2 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,7 @@
#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_params.h"
#include "net/base/load_flags.h"
#include "net/http/http_response_headers.h"
#include "net/proxy/proxy_info.h"
@@ -90,6 +91,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 +195,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,19 +259,38 @@ 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);
+ // Some requests, such as pings, don't go through
+ // RenderFrameImpl::WillSendRequest and get 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);
+ if (params::IsLoFiSlowConnectionsOnlyViaFlags() ||
+ data_reduction_proxy_config_->IsIncludedInLoFiEnabledFieldTrial()) {
+ RecordAutoLoFiRequestHeaderStateChange(
+ previous_state_lofi_on_, request->lofi_state() == net::LOFI_ON);
+ }
+ }
+
+ if (request && (request->load_flags() & net::LOAD_MAIN_FRAME) != 0) {
+ previous_state_lofi_on_ = request->lofi_state() == net::LOFI_ON;
+
if (data_reduction_proxy_io_data_) {
+ // TODO(megjablon): Need to switch to per page.
data_reduction_proxy_io_data_->SetLoFiModeActiveOnMainFrame(
- data_reduction_proxy_config_->ShouldUseLoFiHeaderForRequests());
+ request->lofi_state() == net::LOFI_ON);
}
}
@@ -254,13 +357,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