Skip to content

Commit

Permalink
Make auction wins and losses network requests report to devtools netw…
Browse files Browse the repository at this point in the history
…ork panel.

Change-Id: Iba3bf534efd2f72cfac0f4acce014d4bc1f91800
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4903636
Commit-Queue: Youssef Bourouphael <ybourouphael@google.com>
Reviewed-by: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1216937}
  • Loading branch information
HabibiYou authored and Chromium LUCI CQ committed Oct 30, 2023
1 parent f56649d commit 047a93e
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 73 deletions.
4 changes: 3 additions & 1 deletion content/browser/interest_group/ad_auction_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,9 @@ void AdAuctionServiceImpl::OnAuctionComplete(
blink::FencedFrame::RedactedFencedFrameConfig config =
current_fenced_frame_urls_map.AssignFencedFrameURLAndInterestGroupInfo(
urn_uuid, requested_ad_size, *ad_descriptor,
std::move(ad_auction_data), reporter->OnNavigateToWinningAdCallback(),
std::move(ad_auction_data),
reporter->OnNavigateToWinningAdCallback(
GetFrame()->GetFrameTreeNodeId()),
ad_component_descriptors, reporter->fenced_frame_reporter());
std::move(callback).Run(/*aborted_by_script=*/false, std::move(config));

Expand Down
9 changes: 5 additions & 4 deletions content/browser/interest_group/auction_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "content/browser/interest_group/auction_nonce_manager.h"
#include "content/browser/interest_group/interest_group_auction_reporter.h"
#include "content/browser/interest_group/interest_group_manager_impl.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "content/services/auction_worklet/public/mojom/private_aggregation_request.mojom.h"
Expand Down Expand Up @@ -432,7 +433,8 @@ void AuctionRunner::FailAuction(
auction_.GetKAnonKeysToJoin());
interest_group_manager_->EnqueueReports(
InterestGroupManagerImpl::ReportType::kDebugLoss,
std::move(debug_loss_report_urls), frame_origin_,
std::move(debug_loss_report_urls),
FrameTreeNode::kFrameTreeNodeInvalidId, frame_origin_,
*client_security_state_, url_loader_factory_);

InterestGroupAuctionReporter::OnFledgePrivateAggregationRequests(
Expand Down Expand Up @@ -511,9 +513,8 @@ void AuctionRunner::StartAuction() {
// Wait for promise with server response to resolve.
return;
}
auction_.StartLoadInterestGroupsPhase(
base::BindOnce(&AuctionRunner::OnLoadInterestGroupsComplete,
base::Unretained(this)));
auction_.StartLoadInterestGroupsPhase(base::BindOnce(
&AuctionRunner::OnLoadInterestGroupsComplete, base::Unretained(this)));
}

void AuctionRunner::OnLoadInterestGroupsComplete(bool success) {
Expand Down
4 changes: 3 additions & 1 deletion content/browser/interest_group/auction_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,9 @@ class AuctionRunnerTest : public RenderViewHostTestHarness,
reporter_->Start(base::BindOnce(&AuctionRunnerTest::OnReportingComplete,
base::Unretained(this)));
// Invoke callback immediately, so as not to block reporter completion.
reporter_->OnNavigateToWinningAdCallback().Run();
reporter_
->OnNavigateToWinningAdCallback(FrameTreeNode::kFrameTreeNodeInvalidId)
.Run();
}

void OnReportingComplete() {
Expand Down
7 changes: 6 additions & 1 deletion content/browser/interest_group/auction_worklet_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ GetAuctionWorkletPermissionsPolicyState(RenderFrameHostImpl* auction_runner_rfh,

const size_t AuctionWorkletManager::kBatchSize;

int AuctionWorkletManager::GetFrameTreeNodeID() {
return delegate_->GetFrame()->frame_tree_node()->frame_tree_node_id();
}

class AuctionWorkletManager::WorkletOwner
: public base::RefCounted<AuctionWorkletManager::WorkletOwner> {
public:
Expand Down Expand Up @@ -115,8 +119,9 @@ class AuctionWorkletManager::WorkletOwner
}

SubresourceUrlAuthorizations* subresource_url_authorizations() {
if (!url_loader_factory_proxy_)
if (!url_loader_factory_proxy_) {
return nullptr;
}
return &url_loader_factory_proxy_->subresource_url_authorizations();
}

Expand Down
2 changes: 2 additions & 0 deletions content/browser/interest_group/auction_worklet_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class CONTENT_EXPORT AuctionWorkletManager {
base::OnceCallback<void(FatalErrorType fatal_error_type,
const std::vector<std::string>& errors)>;

int GetFrameTreeNodeID();

// Delegate class to allow dependency injection in tests. Note that passed in
// URLLoaderFactories can crash and be restarted, so passing in raw pointers
// would be problematic.
Expand Down
19 changes: 11 additions & 8 deletions content/browser/interest_group/interest_group_auction_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ void InterestGroupAuctionReporter::InitializeFromServerResponse(
}

base::RepeatingClosure
InterestGroupAuctionReporter::OnNavigateToWinningAdCallback() {
InterestGroupAuctionReporter::OnNavigateToWinningAdCallback(
int frame_tree_node_id) {
return base::BindRepeating(
&InterestGroupAuctionReporter::OnNavigateToWinningAd,
weak_ptr_factory_.GetWeakPtr());
weak_ptr_factory_.GetWeakPtr(), frame_tree_node_id);
}

void InterestGroupAuctionReporter::OnFledgePrivateAggregationRequests(
Expand Down Expand Up @@ -905,7 +906,8 @@ void InterestGroupAuctionReporter::OnReportingComplete(
MaybeInvokeCallback();
}

void InterestGroupAuctionReporter::OnNavigateToWinningAd() {
void InterestGroupAuctionReporter::OnNavigateToWinningAd(
int frame_tree_node_id) {
if (navigated_to_winning_ad_) {
return;
}
Expand All @@ -919,12 +921,12 @@ void InterestGroupAuctionReporter::OnNavigateToWinningAd() {
// reports are sent over the network in FIFO order.
interest_group_manager_->EnqueueReports(
InterestGroupManagerImpl::ReportType::kDebugWin,
std::move(debug_win_report_urls_), frame_origin_, *client_security_state_,
url_loader_factory_);
std::move(debug_win_report_urls_), frame_tree_node_id, frame_origin_,
*client_security_state_, url_loader_factory_);
debug_win_report_urls_.clear();
interest_group_manager_->EnqueueReports(
InterestGroupManagerImpl::ReportType::kDebugLoss,
std::move(debug_loss_report_urls_), frame_origin_,
std::move(debug_loss_report_urls_), frame_tree_node_id, frame_origin_,
*client_security_state_, url_loader_factory_);
debug_loss_report_urls_.clear();

Expand Down Expand Up @@ -981,10 +983,11 @@ void InterestGroupAuctionReporter::SendPendingReportsIfNavigated() {
if (!navigated_to_winning_ad_) {
return;
}
int frame_tree_node_id = auction_worklet_manager_->GetFrameTreeNodeID();
interest_group_manager_->EnqueueReports(
InterestGroupManagerImpl::ReportType::kSendReportTo,
std::move(pending_report_urls_), frame_origin_, *client_security_state_,
url_loader_factory_);
std::move(pending_report_urls_), frame_tree_node_id, frame_origin_,
*client_security_state_, url_loader_factory_);
pending_report_urls_.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "content/browser/interest_group/interest_group_storage.h"
#include "content/browser/interest_group/subresource_url_authorizations.h"
#include "content/browser/private_aggregation/private_aggregation_manager.h"
#include "content/browser/renderer_host/frame_tree_node.h"
#include "content/common/content_export.h"
#include "content/services/auction_worklet/public/mojom/bidder_worklet.mojom.h"
#include "content/services/auction_worklet/public/mojom/private_aggregation_request.mojom.h"
Expand Down Expand Up @@ -266,7 +267,7 @@ class CONTENT_EXPORT InterestGroupAuctionReporter {
// navigated to the winning ad. May be invoked multiple times, safe to invoke
// after destruction. `this` will not invoke the callback passed to Start()
// until the callback this method returns has been invoked at least once.
base::RepeatingClosure OnNavigateToWinningAdCallback();
base::RepeatingClosure OnNavigateToWinningAdCallback(int frame_tree_node_id);

const std::vector<std::string>& errors() const { return errors_; }

Expand Down Expand Up @@ -401,7 +402,7 @@ class CONTENT_EXPORT InterestGroupAuctionReporter {
// Invoked when the winning ad has been navigated to. If
// `navigated_to_winning_ad_` is false, sets it to true and invokes
// MaybeInvokeCallback(). Otherwise, does nothing.
void OnNavigateToWinningAd();
void OnNavigateToWinningAd(int frame_tree_node_id);

// Invokes callback passed in to Start() if both OnReportingComplete() and
// OnNavigateToWinningAd() have been invoked.
Expand Down

0 comments on commit 047a93e

Please sign in to comment.