Commit b8d38118 authored by Tsuyoshi Horo's avatar Tsuyoshi Horo Committed by Commit Bot

Set the throttling_profile_id of the signed exchange certificate requests.

This CL copies the throttling_profile_id of the original signed exchange request
to the certificate request, so that we can throttles the certificate requests
using DevTools.

The throttling_profile_id is copied in this flow.
  Navigation case:
    NavigationURLLoaderImpl::URLLoaderRequestController
    => SignedExchangeRequestHandler
    => SignedExchangeLoader
    => SignedExchangeCertFetcherFactory::Create()
    => SignedExchangeCertFetcherFactoryImpl
    => SignedExchangeCertFetcher::CreateAndStart()
    => SignedExchangeCertFetcher
    => network::ResourceRequest

  Prefetch case:
    PrefetchURLLoader::PrefetchURLLoader()
    => SignedExchangePrefetchHandler
    => SignedExchangeLoader
    => ... same as navigation case...

Bug: 849966
Change-Id: I443af86ca6a465a68e9f4c804d4cd9a9bac12227
Reviewed-on: https://chromium-review.googlesource.com/1088343Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568388}
parent 802dba4f
......@@ -402,7 +402,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
GetURLLoaderOptions(request_info->is_main_frame),
request_info->frame_tree_node_id,
request_info->devtools_navigation_token,
request_info->report_raw_headers,
request_info->devtools_frame_token, request_info->report_raw_headers,
request_info->begin_params->load_flags,
base::MakeRefCounted<
SignedExchangeURLLoaderFactoryForNonNetworkService>(
......@@ -615,7 +615,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
GetURLLoaderOptions(request_info->is_main_frame),
request_info->frame_tree_node_id,
request_info->devtools_navigation_token,
request_info->report_raw_headers,
request_info->devtools_frame_token, request_info->report_raw_headers,
request_info->begin_params->load_flags,
default_url_loader_factory_getter_->GetNetworkFactory(),
base::BindRepeating(
......
......@@ -30,6 +30,7 @@ PrefetchURLLoader::PrefetchURLLoader(
url_(resource_request.url),
report_raw_headers_(resource_request.report_raw_headers),
load_flags_(resource_request.load_flags),
throttling_profile_id_(resource_request.throttling_profile_id),
network_loader_factory_(std::move(network_loader_factory)),
client_binding_(this),
forwarding_client_(std::move(client)),
......@@ -96,10 +97,10 @@ void PrefetchURLLoader::OnReceiveResponse(
signed_exchange_prefetch_handler_ =
std::make_unique<SignedExchangePrefetchHandler>(
frame_tree_node_id_getter_, report_raw_headers_, load_flags_,
response, std::move(loader_), client_binding_.Unbind(),
network_loader_factory_, request_initiator_, url_,
url_loader_throttles_getter_, resource_context_,
request_context_getter_, this);
throttling_profile_id_, response, std::move(loader_),
client_binding_.Unbind(), network_loader_factory_,
request_initiator_, url_, url_loader_throttles_getter_,
resource_context_, request_context_getter_, this);
return;
}
forwarding_client_->OnReceiveResponse(response);
......
......@@ -9,6 +9,8 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/unguessable_token.h"
#include "content/common/content_export.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/system/data_pipe_drainer.h"
......@@ -94,6 +96,7 @@ class CONTENT_EXPORT PrefetchURLLoader : public network::mojom::URLLoader,
const GURL url_;
const bool report_raw_headers_;
const int load_flags_;
const base::Optional<base::UnguessableToken> throttling_profile_id_;
scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory_;
......
......@@ -72,14 +72,15 @@ SignedExchangeCertFetcher::CreateAndStart(
bool force_fetch,
SignedExchangeVersion version,
CertificateCallback callback,
SignedExchangeDevToolsProxy* devtools_proxy) {
SignedExchangeDevToolsProxy* devtools_proxy,
const base::Optional<base::UnguessableToken>& throttling_profile_id) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("loading"),
"SignedExchangeCertFetcher::CreateAndStart");
std::unique_ptr<SignedExchangeCertFetcher> cert_fetcher(
new SignedExchangeCertFetcher(
std::move(shared_url_loader_factory), std::move(throttles), cert_url,
std::move(request_initiator), force_fetch, version,
std::move(callback), devtools_proxy));
std::move(callback), devtools_proxy, throttling_profile_id));
cert_fetcher->Start();
return cert_fetcher;
}
......@@ -92,7 +93,8 @@ SignedExchangeCertFetcher::SignedExchangeCertFetcher(
bool force_fetch,
SignedExchangeVersion version,
CertificateCallback callback,
SignedExchangeDevToolsProxy* devtools_proxy)
SignedExchangeDevToolsProxy* devtools_proxy,
const base::Optional<base::UnguessableToken>& throttling_profile_id)
: shared_url_loader_factory_(std::move(shared_url_loader_factory)),
throttles_(std::move(throttles)),
resource_request_(std::make_unique<network::ResourceRequest>()),
......@@ -117,6 +119,7 @@ SignedExchangeCertFetcher::SignedExchangeCertFetcher(
cert_request_id_ = base::UnguessableToken::Create();
resource_request_->enable_load_timing = true;
}
resource_request_->throttling_profile_id = throttling_profile_id;
}
SignedExchangeCertFetcher::~SignedExchangeCertFetcher() = default;
......
......@@ -54,7 +54,8 @@ class CONTENT_EXPORT SignedExchangeCertFetcher
bool force_fetch,
SignedExchangeVersion version,
CertificateCallback callback,
SignedExchangeDevToolsProxy* devtools_proxy);
SignedExchangeDevToolsProxy* devtools_proxy,
const base::Optional<base::UnguessableToken>& throttling_profile_id);
~SignedExchangeCertFetcher() override;
......@@ -76,7 +77,8 @@ class CONTENT_EXPORT SignedExchangeCertFetcher
bool force_fetch,
SignedExchangeVersion version,
CertificateCallback callback,
SignedExchangeDevToolsProxy* devtools_proxy);
SignedExchangeDevToolsProxy* devtools_proxy,
const base::Optional<base::UnguessableToken>& throttling_profile_id);
void Start();
void Abort();
void OnHandleReady(MojoResult result);
......
......@@ -4,6 +4,7 @@
#include "content/browser/web_package/signed_exchange_cert_fetcher_factory.h"
#include "base/unguessable_token.h"
#include "content/public/common/url_loader_throttle.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
......@@ -17,10 +18,12 @@ class SignedExchangeCertFetcherFactoryImpl
SignedExchangeCertFetcherFactoryImpl(
url::Origin request_initiator,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
URLLoaderThrottlesGetter url_loader_throttles_getter)
URLLoaderThrottlesGetter url_loader_throttles_getter,
const base::Optional<base::UnguessableToken>& throttling_profile_id)
: request_initiator_(std::move(request_initiator)),
url_loader_factory_(std::move(url_loader_factory)),
url_loader_throttles_getter_(std::move(url_loader_throttles_getter)) {}
url_loader_throttles_getter_(std::move(url_loader_throttles_getter)),
throttling_profile_id_(throttling_profile_id) {}
std::unique_ptr<SignedExchangeCertFetcher> CreateFetcherAndStart(
const GURL& cert_url,
......@@ -33,6 +36,7 @@ class SignedExchangeCertFetcherFactoryImpl
url::Origin request_initiator_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
URLLoaderThrottlesGetter url_loader_throttles_getter_;
const base::Optional<base::UnguessableToken> throttling_profile_id_;
};
std::unique_ptr<SignedExchangeCertFetcher>
......@@ -49,7 +53,7 @@ SignedExchangeCertFetcherFactoryImpl::CreateFetcherAndStart(
return SignedExchangeCertFetcher::CreateAndStart(
std::move(url_loader_factory_), std::move(throttles), cert_url,
std::move(request_initiator_), force_fetch, version, std::move(callback),
devtools_proxy);
devtools_proxy, throttling_profile_id_);
}
// static
......@@ -57,10 +61,11 @@ std::unique_ptr<SignedExchangeCertFetcherFactory>
SignedExchangeCertFetcherFactory::Create(
url::Origin request_initiator,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
URLLoaderThrottlesGetter url_loader_throttles_getter) {
URLLoaderThrottlesGetter url_loader_throttles_getter,
const base::Optional<base::UnguessableToken>& throttling_profile_id) {
return std::make_unique<SignedExchangeCertFetcherFactoryImpl>(
std::move(request_initiator), std::move(url_loader_factory),
std::move(url_loader_throttles_getter));
std::move(url_loader_throttles_getter), throttling_profile_id);
}
} // namespace content
......@@ -9,6 +9,8 @@
#include <vector>
#include "base/callback_forward.h"
#include "base/optional.h"
#include "base/unguessable_token.h"
#include "content/browser/web_package/signed_exchange_cert_fetcher.h"
#include "content/common/content_export.h"
#include "url/origin.h"
......@@ -41,7 +43,8 @@ class CONTENT_EXPORT SignedExchangeCertFetcherFactory {
static std::unique_ptr<SignedExchangeCertFetcherFactory> Create(
url::Origin request_initiator,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
URLLoaderThrottlesGetter url_loader_throttles_getter);
URLLoaderThrottlesGetter url_loader_throttles_getter,
const base::Optional<base::UnguessableToken>& throttling_profile_id);
};
} // namespace content
......
......@@ -212,7 +212,8 @@ class SignedExchangeCertFetcherTest : public testing::Test {
&mock_loader_factory_),
std::move(throttles_), url, request_initiator_, force_fetch,
SignedExchangeVersion::kB1, std::move(callback),
nullptr /* devtools_proxy */);
nullptr /* devtools_proxy */,
base::nullopt /* throttling_profile_id */);
}
void CallOnReceiveResponse() {
......
......@@ -87,6 +87,7 @@ SignedExchangeLoader::SignedExchangeLoader(
url::Origin request_initiator,
uint32_t url_loader_options,
int load_flags,
const base::Optional<base::UnguessableToken>& throttling_profile_id,
std::unique_ptr<SignedExchangeDevToolsProxy> devtools_proxy,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
URLLoaderThrottlesGetter url_loader_throttles_getter,
......@@ -99,6 +100,7 @@ SignedExchangeLoader::SignedExchangeLoader(
request_initiator_(request_initiator),
url_loader_options_(url_loader_options),
load_flags_(load_flags),
throttling_profile_id_(throttling_profile_id),
devtools_proxy_(std::move(devtools_proxy)),
url_loader_factory_(std::move(url_loader_factory)),
url_loader_throttles_getter_(std::move(url_loader_throttles_getter)),
......@@ -211,7 +213,7 @@ void SignedExchangeLoader::OnStartLoadingResponseBody(
mojo::ScopedDataPipeConsumerHandle body) {
auto cert_fetcher_factory = SignedExchangeCertFetcherFactory::Create(
std::move(request_initiator_), std::move(url_loader_factory_),
std::move(url_loader_throttles_getter_));
std::move(url_loader_throttles_getter_), throttling_profile_id_);
if (g_signed_exchange_factory_for_testing_) {
signed_exchange_handler_ = g_signed_exchange_factory_for_testing_->Create(
......
......@@ -53,6 +53,7 @@ class SignedExchangeLoader final : public network::mojom::URLLoaderClient,
url::Origin request_initiator,
uint32_t url_loader_options,
int load_flags,
const base::Optional<base::UnguessableToken>& throttling_profile_id,
std::unique_ptr<SignedExchangeDevToolsProxy> devtools_proxy,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
URLLoaderThrottlesGetter url_loader_throttles_getter,
......@@ -136,6 +137,7 @@ class SignedExchangeLoader final : public network::mojom::URLLoaderClient,
url::Origin request_initiator_;
const uint32_t url_loader_options_;
const int load_flags_;
const base::Optional<base::UnguessableToken> throttling_profile_id_;
std::unique_ptr<SignedExchangeDevToolsProxy> devtools_proxy_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
URLLoaderThrottlesGetter url_loader_throttles_getter_;
......
......@@ -22,6 +22,7 @@ SignedExchangePrefetchHandler::SignedExchangePrefetchHandler(
base::RepeatingCallback<int(void)> frame_tree_node_id_getter,
bool report_raw_headers,
int load_flags,
const base::Optional<base::UnguessableToken>& throttling_profile_id,
const network::ResourceResponseHead& response,
network::mojom::URLLoaderPtr network_loader,
network::mojom::URLLoaderClientRequest network_client_request,
......@@ -50,7 +51,7 @@ SignedExchangePrefetchHandler::SignedExchangePrefetchHandler(
signed_exchange_loader_ = std::make_unique<SignedExchangeLoader>(
outer_request_url, response, std::move(client), std::move(endpoints),
std::move(request_initiator), network::mojom::kURLLoadOptionNone,
load_flags,
load_flags, throttling_profile_id,
std::make_unique<SignedExchangeDevToolsProxy>(
outer_request_url, response, std::move(frame_tree_node_id_getter),
base::nullopt /* devtools_navigation_token */, report_raw_headers),
......
......@@ -7,6 +7,8 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/optional.h"
#include "base/unguessable_token.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "services/network/public/mojom/url_loader.mojom.h"
......@@ -39,6 +41,7 @@ class SignedExchangePrefetchHandler final
base::RepeatingCallback<int(void)> frame_tree_node_id_getter,
bool report_raw_headers,
int load_flags,
const base::Optional<base::UnguessableToken>& throttling_profile_id,
const network::ResourceResponseHead& response,
network::mojom::URLLoaderPtr network_loader,
network::mojom::URLLoaderClientRequest network_client_request,
......
......@@ -35,6 +35,7 @@ SignedExchangeRequestHandler::SignedExchangeRequestHandler(
uint32_t url_loader_options,
int frame_tree_node_id,
const base::UnguessableToken& devtools_navigation_token,
const base::Optional<base::UnguessableToken>& throttling_profile_id,
bool report_raw_headers,
int load_flags,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
......@@ -45,6 +46,7 @@ SignedExchangeRequestHandler::SignedExchangeRequestHandler(
url_loader_options_(url_loader_options),
frame_tree_node_id_(frame_tree_node_id),
devtools_navigation_token_(devtools_navigation_token),
throttling_profile_id_(throttling_profile_id),
report_raw_headers_(report_raw_headers),
load_flags_(load_flags),
url_loader_factory_(url_loader_factory),
......@@ -93,6 +95,7 @@ bool SignedExchangeRequestHandler::MaybeCreateLoaderForResponse(
signed_exchange_loader_ = std::make_unique<SignedExchangeLoader>(
url_, response, std::move(client), url_loader->Unbind(),
std::move(request_initiator_), url_loader_options_, load_flags_,
throttling_profile_id_,
std::make_unique<SignedExchangeDevToolsProxy>(
url_, response,
base::BindRepeating([](int id) { return id; }, frame_tree_node_id_),
......
......@@ -6,6 +6,7 @@
#define CONTENT_BROWSER_WEB_PACKAGE_SIGNED_EXCHANGE_REQUEST_HANDLER_H_
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/unguessable_token.h"
#include "content/browser/loader/navigation_loader_interceptor.h"
#include "content/public/common/resource_type.h"
......@@ -37,6 +38,7 @@ class SignedExchangeRequestHandler final : public NavigationLoaderInterceptor {
uint32_t url_loader_options,
int frame_tree_node_id,
const base::UnguessableToken& devtools_navigation_token,
const base::Optional<base::UnguessableToken>& throttling_profile_id,
bool report_raw_headers,
int load_flags,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
......@@ -68,6 +70,7 @@ class SignedExchangeRequestHandler final : public NavigationLoaderInterceptor {
const uint32_t url_loader_options_;
const int frame_tree_node_id_;
base::Optional<const base::UnguessableToken> devtools_navigation_token_;
const base::Optional<base::UnguessableToken> throttling_profile_id_;
const bool report_raw_headers_;
const int load_flags_;
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory_;
......
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