Commit 5ac53354 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

NQE servicification of client hints

Use network quality tracker instead of network quality estimator (NQE)
to obtain network quality when attaching network quality
client hints for main frame resources.

Network quality tracker can provide network service when network
service is enabled as well as when network service is disabled.

Change-Id: Iafa641ecb487bb00aecc0d3f1a18cfcdabba3de8
Bug: 819244
Reviewed-on: https://chromium-review.googlesource.com/1170568Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582296}
parent d46a8230
......@@ -12,9 +12,8 @@
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/client_hints/client_hints.h"
#include "components/content_settings/core/browser/cookie_settings.h"
......@@ -27,6 +26,7 @@
#include "net/http/http_request_headers.h"
#include "net/nqe/effective_connection_type.h"
#include "net/url_request/url_request.h"
#include "services/network/public/cpp/network_quality_tracker.h"
#include "third_party/blink/public/common/client_hints/client_hints.h"
#include "third_party/blink/public/common/device_memory/approximated_device_memory.h"
#include "third_party/blink/public/platform/web_client_hints_type.h"
......@@ -278,16 +278,15 @@ GetAdditionalNavigationRequestClientHintsHeaders(
}
}
UINetworkQualityEstimatorService* estimator =
UINetworkQualityEstimatorServiceFactory::GetForProfile(
Profile::FromBrowserContext(context));
network::NetworkQualityTracker* network_quality_tracker =
g_browser_process->network_quality_tracker();
if (web_client_hints.IsEnabled(blink::mojom::WebClientHintsType::kRtt)) {
additional_headers->SetHeader(
blink::kClientHintsHeaderMapping[static_cast<int>(
blink::mojom::WebClientHintsType::kRtt)],
base::NumberToString(
internal::RoundRtt(url.host(), estimator->GetHttpRTT())));
base::NumberToString(internal::RoundRtt(
url.host(), network_quality_tracker->GetHttpRTT())));
}
if (web_client_hints.IsEnabled(blink::mojom::WebClientHintsType::kDownlink)) {
......@@ -295,7 +294,8 @@ GetAdditionalNavigationRequestClientHintsHeaders(
blink::kClientHintsHeaderMapping[static_cast<int>(
blink::mojom::WebClientHintsType::kDownlink)],
DoubleToSpecCompliantString(internal::RoundKbpsToMbps(
url.host(), estimator->GetDownstreamThroughputKbps())));
url.host(),
network_quality_tracker->GetDownstreamThroughputKbps())));
}
if (web_client_hints.IsEnabled(blink::mojom::WebClientHintsType::kEct)) {
......@@ -305,7 +305,7 @@ GetAdditionalNavigationRequestClientHintsHeaders(
static_cast<size_t>(net::EFFECTIVE_CONNECTION_TYPE_LAST));
int effective_connection_type =
static_cast<int>(estimator->GetEffectiveConnectionType());
static_cast<int>(network_quality_tracker->GetEffectiveConnectionType());
additional_headers->SetHeader(
blink::kClientHintsHeaderMapping[static_cast<int>(
......
......@@ -539,9 +539,13 @@ class ClientHintsBrowserTest : public InProcessBrowserTest,
EXPECT_FALSE(request.headers.find("ect")->second.empty());
// TODO(tbansal): https://crbug.com/819244: When network servicification is
// enabled, the UI thread NQE observers do not receive notifications on
// change in the network quality.
if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
// enabled, the renderer processes do not receive notifications on
// change in the network quality. Hence, the network quality client hints
// are not set to the correct value on subresources.
bool is_main_frame_navigation =
request.GetURL().spec().find(".html") != std::string::npos;
if (!base::FeatureList::IsEnabled(network::features::kNetworkService) ||
is_main_frame_navigation) {
// Effective connection type is forced to 2G using command line in these
// tests. RTT is expected to be 1800 msec but leave some gap to account
// for added noise and randomization.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment