0

Revert "Add initial skeleton of [KeepAliveTrackerThrottle][1]."

This reverts commit 66163a7365.

Reason for revert: Replaced by https://crrev.com/c/6039011

Original change's description:
> Add initial skeleton of [`KeepAliveTrackerThrottle`][1].
>
> This is for observing the lifetime of a subset of fetch keepalive
> requests that match all of the following conditions:
>
> - A network request with keepalive set to true.
> - A network request with URL param "category=<certain value>"[2].
>
> [1]: https://docs.google.com/document/d/1byKFqqKTsVFnj6rSb7ZjHi4LuRi1LNb-vf4maQbmSSQ/edit?resourcekey=0-7GAe1ae8j_55DMcvp3U3IQ&tab=t.0
> [2]: https://docs.google.com/document/d/1FY3AINZW_h2GU81U-XPQz8bKT6wgt0u7Z9GF4o7_Llk/edit?resourcekey=0-lQnRY9BK0iclRRV62LgVDQ&tab=t.0
>
> Bug: 382527001
> Change-Id: I5e488bf3f0c2c35aeb0222550c34f5b0f9c66a8c
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6325517
> Reviewed-by: Nan Lin <linnan@chromium.org>
> Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
> Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
> Commit-Queue: Ming-Ying Chung <mych@chromium.org>
> Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1431911}

Bug: 382527001
Change-Id: If4d1e92ee831bb5e8d30040a196bb5cc76e21d88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6370004
Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org>
Auto-Submit: Ming-Ying Chung <mych@chromium.org>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1435001}
This commit is contained in:
Ming-Ying Chung
2025-03-19 11:58:35 -07:00
committed by Chromium LUCI CQ
parent fe13977980
commit c37e919e99
11 changed files with 7 additions and 380 deletions

@ -1300,8 +1300,6 @@ source_set("browser") {
"loader/file_url_loader_factory.h",
"loader/keep_alive_attribution_request_helper.cc",
"loader/keep_alive_attribution_request_helper.h",
"loader/keep_alive_tracker_throttle.cc",
"loader/keep_alive_tracker_throttle.h",
"loader/keep_alive_url_loader.cc",
"loader/keep_alive_url_loader.h",
"loader/keep_alive_url_loader_service.cc",

@ -107,19 +107,6 @@ void NotifyBackgroundRegistrationOperation(WeakDocumentPtr weak_document_ptr,
} // namespace
// static
bool KeepAliveAttributionRequestHelper::IsAttributionRequest(
const network::ResourceRequest& request) {
if (!request.keepalive) {
return false;
}
std::optional<RegistrationEligibility> registration_eligibility =
attribution_reporting::GetRegistrationEligibility(
request.attribution_reporting_eligibility);
return registration_eligibility.has_value();
}
// static
std::unique_ptr<KeepAliveAttributionRequestHelper>
KeepAliveAttributionRequestHelper::CreateIfNeeded(

@ -17,7 +17,6 @@
#include "content/browser/attribution_reporting/attribution_suitable_context.h"
#include "content/common/content_export.h"
#include "content/public/browser/weak_document_ptr.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/attribution.mojom-forward.h"
#include "url/gurl.h"
@ -43,9 +42,6 @@ class AttributionDataHostManager;
// A helper instance can handle a single request chain.
class CONTENT_EXPORT KeepAliveAttributionRequestHelper {
public:
// Tells if `request` is a fetch keepalive attribution reporting request.
static bool IsAttributionRequest(const network::ResourceRequest& request);
// Creates a `KeepAliveAttributionRequestHelper` instance when the request is
// eligible for attribution.
static std::unique_ptr<KeepAliveAttributionRequestHelper> CreateIfNeeded(

@ -35,7 +35,6 @@
#include "content/test/test_web_contents.h"
#include "net/http/http_response_headers.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/attribution.mojom-shared.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@ -74,10 +73,9 @@ using attribution_reporting::kAttributionReportingRegisterOsTriggerHeader;
using attribution_reporting::kAttributionReportingRegisterSourceHeader;
using attribution_reporting::kAttributionReportingRegisterTriggerHeader;
class KeepAliveAttributionRequestHelperTestBase
: public RenderViewHostTestHarness {
class KeepAliveAttributionRequestHelperTest : public RenderViewHostTestHarness {
public:
KeepAliveAttributionRequestHelperTestBase()
KeepAliveAttributionRequestHelperTest()
: RenderViewHostTestHarness(
base::test::TaskEnvironment::MainThreadType::UI,
base::test::TaskEnvironment::TimeSource::MOCK_TIME),
@ -158,9 +156,6 @@ class KeepAliveAttributionRequestHelperTestBase
data_decoder::test::InProcessDataDecoder in_process_data_decoder_;
};
using KeepAliveAttributionRequestHelperTest =
KeepAliveAttributionRequestHelperTestBase;
TEST_F(KeepAliveAttributionRequestHelperTest, SingleResponse) {
const GURL source_url = GURL("https://secure_source.com");
const GURL reporting_url("https://report.test");
@ -689,74 +684,5 @@ TEST_F(KeepAliveAttributionRequestHelperTest, CreateIfNeeded_MetricRecorded) {
}
}
// A type to support parameterized testing for testing attribution request.
struct IsAttributionRequestTestCase {
std::string test_case;
AttributionReportingEligibility eligibility;
bool expected;
};
class IsNonKeepAliveRequestAttributionRequestTest
: public KeepAliveAttributionRequestHelperTestBase,
public ::testing::WithParamInterface<IsAttributionRequestTestCase> {};
INSTANTIATE_TEST_SUITE_P(
All,
IsNonKeepAliveRequestAttributionRequestTest,
testing::ValuesIn<IsAttributionRequestTestCase>({
{"kEmpty", AttributionReportingEligibility::kEmpty, false},
{"kEventSource", AttributionReportingEligibility::kEventSource, false},
{"kEventSourceOrTrigger",
AttributionReportingEligibility::kEventSourceOrTrigger, false},
{"kNavigationSource",
AttributionReportingEligibility::kNavigationSource, false},
{"kTrigger", AttributionReportingEligibility::kTrigger, false},
}),
[](const testing::TestParamInfo<IsAttributionRequestTestCase>& info) {
return info.param.test_case;
});
TEST_P(IsNonKeepAliveRequestAttributionRequestTest, WithEligibility) {
network::ResourceRequest request;
request.url = GURL("https://report.test");
request.keepalive = false;
request.attribution_reporting_eligibility = GetParam().eligibility;
EXPECT_THAT(KeepAliveAttributionRequestHelper::IsAttributionRequest(request),
testing::Eq(GetParam().expected));
}
class IsKeepAliveRequestAttributionRequestTest
: public KeepAliveAttributionRequestHelperTestBase,
public ::testing::WithParamInterface<IsAttributionRequestTestCase> {};
INSTANTIATE_TEST_SUITE_P(
All,
IsKeepAliveRequestAttributionRequestTest,
testing::ValuesIn<IsAttributionRequestTestCase>({
{"kEmpty", AttributionReportingEligibility::kEmpty, false},
{"kEventSource", AttributionReportingEligibility::kEventSource, true},
{"kEventSourceOrTrigger",
AttributionReportingEligibility::kEventSourceOrTrigger, true},
{"kNavigationSource",
AttributionReportingEligibility::kNavigationSource, true},
{"kTrigger", AttributionReportingEligibility::kTrigger, true},
}),
[](const testing::TestParamInfo<IsAttributionRequestTestCase>& info) {
return info.param.test_case;
});
TEST_P(IsKeepAliveRequestAttributionRequestTest, WithEligibility) {
network::ResourceRequest request;
request.url = GURL("https://report.test");
request.keepalive = true;
request.attribution_reporting_eligibility = GetParam().eligibility;
EXPECT_THAT(KeepAliveAttributionRequestHelper::IsAttributionRequest(request),
testing::Eq(GetParam().expected));
}
} // namespace
} // namespace content

@ -1,94 +0,0 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/loader/keep_alive_tracker_throttle.h"
#include <string>
#include <string_view>
#include "base/memory/ptr_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "content/browser/loader/keep_alive_attribution_request_helper.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "url/origin.h"
namespace content {
namespace {
constexpr char kUrlCategoryParamName[] = "category";
bool HasCategory(const network::ResourceRequest& request) {
std::string category;
return net::GetValueForKeyInQuery(request.url, kUrlCategoryParamName,
&category);
}
} // namespace
// static
std::unique_ptr<KeepAliveTrackerThrottle>
KeepAliveTrackerThrottle::MaybeCreateKeepAliveTrackerThrottle(
const network::ResourceRequest& request) {
if (!request.keepalive) {
return nullptr;
}
if (!base::FeatureList::IsEnabled(blink::features::kBeaconLeakageLogging)) {
return nullptr;
}
RequestType request_type = RequestType::kFetch;
if (KeepAliveAttributionRequestHelper::IsAttributionRequest(request)) {
request_type = RequestType::kAttribution;
}
if (!HasCategory(request)) {
return nullptr;
}
// TODO(crbug.com/382527001 ): Add request filtering by category.
// https://docs.google.com/document/d/1FY3AINZW_h2GU81U-XPQz8bKT6wgt0u7Z9GF4o7_Llk/edit?resourcekey=0-lQnRY9BK0iclRRV62LgVDQ&tab=t.0#heading=h.w60avsax5vmp
return base::WrapUnique(new KeepAliveTrackerThrottle(request_type));
}
KeepAliveTrackerThrottle::KeepAliveTrackerThrottle(RequestType request_type)
: request_type_(request_type) {}
KeepAliveTrackerThrottle::~KeepAliveTrackerThrottle() = default;
void KeepAliveTrackerThrottle::WillStartRequest(
network::ResourceRequest* request,
bool* defer) {
// TODO(crbug.com/382527001): Add UKM logging.
}
void KeepAliveTrackerThrottle::WillProcessResponse(
const GURL& response_url,
network::mojom::URLResponseHead* response_head,
bool* defer) {
// TODO(crbug.com/382527001): Add UKM logging.
}
void KeepAliveTrackerThrottle::WillRedirectRequest(
net::RedirectInfo* redirect_info,
const network::mojom::URLResponseHead& response_head,
bool* defer,
std::vector<std::string>* to_be_removed_request_headers,
net::HttpRequestHeaders* modified_request_headers,
net::HttpRequestHeaders* modified_cors_exempt_request_headers) {
num_redirects_++;
// TODO(crbug.com/382527001): Add UKM logging.
}
void KeepAliveTrackerThrottle::WillOnCompleteWithError(
const network::URLLoaderCompletionStatus& status) {
// TODO(crbug.com/382527001): Add UKM logging.
}
} // namespace content

@ -1,73 +0,0 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_LOADER_KEEP_ALIVE_TRACKER_THROTTLE_H_
#define CONTENT_BROWSER_LOADER_KEEP_ALIVE_TRACKER_THROTTLE_H_
#include "content/common/content_export.h"
#include "services/network/public/cpp/url_loader_completion_status.h"
#include "third_party/blink/public/common/loader/url_loader_throttle.h"
#include "url/gurl.h"
namespace content {
// KeepAliveTrackerThrottle is responsible for recording browser-side metrics
// for an eligible fetch keepalive request.
//
// See
// https://docs.google.com/document/d/1byKFqqKTsVFnj6rSb7ZjHi4LuRi1LNb-vf4maQbmSSQ/edit?resourcekey=0-7GAe1ae8j_55DMcvp3U3IQ&tab=t.0#heading=h.bk553qrz82t0
class CONTENT_EXPORT KeepAliveTrackerThrottle
: public blink::URLLoaderThrottle {
public:
// The type of request to track for in this throttle. Anything beyond the
// ones listed here will not be recorded.
enum class RequestType {
kFetch = 0,
kAttribution = 1,
};
~KeepAliveTrackerThrottle() override;
// Not movable.
KeepAliveTrackerThrottle(const KeepAliveTrackerThrottle&) = delete;
KeepAliveTrackerThrottle& operator=(const KeepAliveTrackerThrottle&) = delete;
// Returns a `KeepAliveTrackerThrottle` instance if `request` is eligible to
// be tracked by this throttle.
static std::unique_ptr<KeepAliveTrackerThrottle>
MaybeCreateKeepAliveTrackerThrottle(const network::ResourceRequest& request);
// `blink::URLLoaderThrottle` overrides:
void WillStartRequest(network::ResourceRequest* request,
bool* defer) override;
void WillProcessResponse(const GURL& response_url,
network::mojom::URLResponseHead* response_head,
bool* defer) override;
void WillRedirectRequest(
net::RedirectInfo* redirect_info,
const network::mojom::URLResponseHead& response_head,
bool* defer,
std::vector<std::string>* to_be_removed_request_headers,
net::HttpRequestHeaders* modified_request_headers,
net::HttpRequestHeaders* modified_cors_exempt_request_headers) override;
void WillOnCompleteWithError(
const network::URLLoaderCompletionStatus& status) override;
// Testing only:
// TODO(crbug.com/382527001): Remove after UKM logging is added.
RequestType GetRequestTypeForTesting() { return request_type_; }
private:
explicit KeepAliveTrackerThrottle(RequestType request_type);
// The type of the fetch keepalive request this throttle is running for.
const RequestType request_type_;
// Records the number of redrects the tracked fetch keepalive request has
// experienced so far.
uint32_t num_redirects_ = 0;
};
} // namespace content
#endif // CONTENT_BROWSER_LOADER_KEEP_ALIVE_TRACKER_THROTTLE_H_

@ -1,92 +0,0 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/loader/keep_alive_tracker_throttle.h"
#include "base/test/scoped_feature_list.h"
#include "net/http/http_response_headers.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/attribution.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
namespace content {
namespace {
using testing::IsNull;
using testing::NotNull;
network::ResourceRequest CreateRequest(
std::string_view url,
network::mojom::AttributionReportingEligibility attribution_eligibility =
network::mojom::AttributionReportingEligibility::kEmpty,
bool keepalive = true) {
network::ResourceRequest request;
request.url = GURL(url);
request.attribution_reporting_eligibility = attribution_eligibility;
request.keepalive = keepalive;
return request;
}
class MaybeCreateKeepAliveTrackerThrottleTest : public testing::Test {
public:
MaybeCreateKeepAliveTrackerThrottleTest() {
scoped_feature_list_.InitWithFeatures(
{blink::features::kBeaconLeakageLogging}, {});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(MaybeCreateKeepAliveTrackerThrottleTest, NonKeepAliveRequest) {
auto request = CreateRequest(
"https://example.com",
network::mojom::AttributionReportingEligibility::kNavigationSource,
/*keepalive=*/false);
EXPECT_THAT(
KeepAliveTrackerThrottle::MaybeCreateKeepAliveTrackerThrottle(request),
IsNull());
}
TEST_F(MaybeCreateKeepAliveTrackerThrottleTest, NonCategoryRequest) {
auto request = CreateRequest(
"https://example.com",
network::mojom::AttributionReportingEligibility::kNavigationSource);
EXPECT_THAT(
KeepAliveTrackerThrottle::MaybeCreateKeepAliveTrackerThrottle(request),
IsNull());
}
TEST_F(MaybeCreateKeepAliveTrackerThrottleTest, IsTargetFetchKeepAliveRequest) {
auto request = CreateRequest("https://example.com?category=123");
auto throttle =
KeepAliveTrackerThrottle::MaybeCreateKeepAliveTrackerThrottle(request);
EXPECT_THAT(throttle, NotNull());
EXPECT_EQ(throttle->GetRequestTypeForTesting(),
KeepAliveTrackerThrottle::RequestType::kFetch);
}
TEST_F(MaybeCreateKeepAliveTrackerThrottleTest,
IsTargetAttributionReportingRequest) {
auto request = CreateRequest(
"https://example.com?category=random",
network::mojom::AttributionReportingEligibility::kNavigationSource);
auto throttle =
KeepAliveTrackerThrottle::MaybeCreateKeepAliveTrackerThrottle(request);
EXPECT_THAT(throttle, NotNull());
EXPECT_EQ(throttle->GetRequestTypeForTesting(),
KeepAliveTrackerThrottle::RequestType::kAttribution);
}
} // namespace
} // namespace content

@ -11,7 +11,6 @@
#include "components/variations/net/variations_url_loader_throttle.h"
#include "content/browser/client_hints/client_hints.h"
#include "content/browser/client_hints/critical_client_hints_throttle.h"
#include "content/browser/loader/keep_alive_tracker_throttle.h"
#include "content/browser/origin_trials/critical_origin_trials_throttle.h"
#include "content/browser/preloading/prerender/prerender_url_loader_throttle.h"
#include "content/browser/reduce_accept_language/reduce_accept_language_throttle.h"
@ -136,7 +135,6 @@ CreateContentBrowserURLLoaderThrottlesForKeepAlive(
BrowserContext* browser_context,
const base::RepeatingCallback<WebContents*()>& wc_getter,
FrameTreeNodeId frame_tree_node_id) {
// Adds content embedder-specific throttles.
std::vector<std::unique_ptr<blink::URLLoaderThrottle>> throttles =
GetContentClient()->browser()->CreateURLLoaderThrottlesForKeepAlive(
request, browser_context, wc_getter, frame_tree_node_id);
@ -146,19 +144,10 @@ CreateContentBrowserURLLoaderThrottlesForKeepAlive(
variations::VariationsURLLoaderThrottle::AppendThrottleIfNeeded(
browser_context->GetVariationsClient(), &throttles);
if (auto throttle = MaybeCreateIdentityUrlLoaderThrottle(base::BindRepeating(
webid::SetIdpSigninStatus, browser_context, frame_tree_node_id));
throttle) {
throttles.emplace_back(std::move(throttle));
}
// Adds content-specific throttle. Unlike throttles added above, the following
// does not have equivalent in renderer side.
if (auto throttle =
KeepAliveTrackerThrottle::MaybeCreateKeepAliveTrackerThrottle(
request);
throttle) {
throttles.emplace_back(std::move(throttle));
auto throttle = MaybeCreateIdentityUrlLoaderThrottle(base::BindRepeating(
webid::SetIdpSigninStatus, browser_context, frame_tree_node_id));
if (throttle) {
throttles.push_back(std::move(throttle));
}
return throttles;

@ -40,11 +40,7 @@ CreateContentBrowserURLLoaderThrottles(
// Wrapper around `ContentBrowserClient::CreateURLLoaderThrottlesForKeepAlive()`
// which inserts additional content specific throttles for handling fetch
// keepalive requests.
// The returned throttles may still be run after request initiator is destroyed.
//
// See the following doc for the full picture:
// https://docs.google.com/document/d/1ZzxMMBvpqn8VZBZKnb7Go8TWjnrGcXuLS_USwVVRUvY/edit?tab=t.0#heading=h.r4lb1vfcmngx
// keepalive requests when their initiator is destroyed.
CONTENT_EXPORT
std::vector<std::unique_ptr<blink::URLLoaderThrottle>>
CreateContentBrowserURLLoaderThrottlesForKeepAlive(

@ -2614,7 +2614,6 @@ test("content_unittests") {
"../browser/loader/cors_origin_pattern_setter_unittest.cc",
"../browser/loader/file_url_loader_factory_unittest.cc",
"../browser/loader/keep_alive_attribution_request_helper_unittest.cc",
"../browser/loader/keep_alive_tracker_throttle_unittest.cc",
"../browser/loader/keep_alive_url_loader_service_unittest.cc",
"../browser/loader/merkle_integrity_source_stream_unittest.cc",
"../browser/loader/navigation_early_hints_manager_unittest.cc",

@ -569,11 +569,6 @@
"default": "test",
},
},
{
// https://docs.google.com/document/d/1FY3AINZW_h2GU81U-XPQz8bKT6wgt0u7Z9GF4o7_Llk/edit?resourcekey=0-lQnRY9BK0iclRRV62LgVDQ
name: "BeaconLeakageLogging",
public: true,
},
{
name: "BidiCaretAffinity",
},