Skip to content

Commit

Permalink
FLEDGE worklet requestAdBeacon implementation
Browse files Browse the repository at this point in the history
This CL implements the FLEDGE worklet side changes for the Fenced Frame
events reporting design. The worklet changes add a `requestAdBeacon`
function to allow generateBid and scoreAd to pass in metadata that will
be attached to the resulting urn:uuid if that bid and seller win the
auction.

The reporting explainer can be found here:
https://github.com/WICG/turtledove/blob/main/Fenced_Frames_Ads_Reporting.md

and the implementation design is here:
https://docs.google.com/document/d/1cpz0ulw363AKRcQIbWEItPA4iGb05WZZqf2c57AZ-eo/edit?usp=sharing

Change-Id: Ideb05e438c1fa58b126c8d486b3022ac5c4cb15d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3553503
Reviewed-by: Maks Orlovich <morlovich@chromium.org>
Reviewed-by: Will Harris <wfh@chromium.org>
Commit-Queue: Russ Hamilton <behamilton@google.com>
Cr-Commit-Position: refs/heads/main@{#989951}
  • Loading branch information
brusshamilton authored and Chromium LUCI CQ committed Apr 7, 2022
1 parent bf725cb commit a570af2
Show file tree
Hide file tree
Showing 16 changed files with 1,000 additions and 66 deletions.
13 changes: 6 additions & 7 deletions content/browser/interest_group/ad_auction_service_impl.cc
Expand Up @@ -460,6 +460,7 @@ void AdAuctionServiceImpl::OnAuctionComplete(
std::vector<GURL> report_urls,
std::vector<GURL> debug_loss_report_urls,
std::vector<GURL> debug_win_report_urls,
ReportingMetadata ad_beacon_map,
std::vector<std::string> errors) {
// Delete the AuctionRunner. Since all arguments are passed by value, they're
// all safe to used after this has been done.
Expand Down Expand Up @@ -487,13 +488,11 @@ void AdAuctionServiceImpl::OnAuctionComplete(
return;
}
DCHECK(winning_group_id); // Should always be present with a render_url
render_url =
GetFrame()
->GetPage()
.fenced_frame_urls_map()
.AddFencedFrameURLWithInterestGroupInfo(
*render_url, {winning_group_id->owner, winning_group_id->name},
ad_component_urls);
FencedFrameURLMapping& fenced_frame_urls_map =
GetFrame()->GetPage().fenced_frame_urls_map();
render_url = fenced_frame_urls_map.AddFencedFrameURLWithInterestGroupInfo(
*render_url, {winning_group_id->owner, winning_group_id->name},
ad_component_urls, ad_beacon_map);
DCHECK(render_url->is_valid());

std::move(callback).Run(render_url);
Expand Down
2 changes: 2 additions & 0 deletions content/browser/interest_group/ad_auction_service_impl.h
Expand Up @@ -9,6 +9,7 @@
#include <set>

#include "base/containers/unique_ptr_adapters.h"
#include "content/browser/fenced_frame/fenced_frame_url_mapping.h"
#include "content/browser/interest_group/auction_runner.h"
#include "content/browser/interest_group/auction_worklet_manager.h"
#include "content/common/content_export.h"
Expand Down Expand Up @@ -99,6 +100,7 @@ class CONTENT_EXPORT AdAuctionServiceImpl final
std::vector<GURL> report_urls,
std::vector<GURL> debug_loss_report_urls,
std::vector<GURL> debug_win_report_urls,
ReportingMetadata ad_beacon_map,
std::vector<std::string> errors);

InterestGroupManagerImpl& GetInterestGroupManager() const;
Expand Down
47 changes: 38 additions & 9 deletions content/browser/interest_group/auction_runner.cc
Expand Up @@ -44,6 +44,7 @@ namespace content {

namespace {

using blink::mojom::ReportingDestination;
constexpr base::TimeDelta kMaxTimeout = base::Milliseconds(500);

// For group freshness metrics.
Expand Down Expand Up @@ -1065,6 +1066,7 @@ void AuctionRunner::Auction::ReportSellerResult(
void AuctionRunner::Auction::OnReportSellerResultComplete(
const absl::optional<std::string>& signals_for_winner,
const absl::optional<GURL>& seller_report_url,
const base::flat_map<std::string, GURL>& seller_ad_beacon_map,
const std::vector<std::string>& errors) {
// There should be no other report URLs at this point.
DCHECK(report_urls_.empty());
Expand All @@ -1075,6 +1077,10 @@ void AuctionRunner::Auction::OnReportSellerResultComplete(
// an error if it crashes at this point, failing the auction unnecessarily.
seller_worklet_handle_.reset();

if (!seller_ad_beacon_map.empty())
ad_beacon_map_.metadata[ReportingDestination::kSeller] =
seller_ad_beacon_map;

if (seller_report_url) {
if (!IsUrlValid(*seller_report_url)) {
mojo::ReportBadMessage("Invalid seller report URL");
Expand Down Expand Up @@ -1140,6 +1146,7 @@ void AuctionRunner::Auction::ReportBidWin(

void AuctionRunner::Auction::OnReportBidWinComplete(
const absl::optional<GURL>& bidder_report_url,
const base::flat_map<std::string, GURL>& bidder_ad_beacon_map,
const std::vector<std::string>& errors) {
// There should be at most one other report URL at this point.
DCHECK_LE(report_urls_.size(), 1u);
Expand All @@ -1148,6 +1155,10 @@ void AuctionRunner::Auction::OnReportBidWinComplete(
// fatal error notification.
top_bid_->bid->bid_state->worklet_handle.reset();

if (!bidder_ad_beacon_map.empty())
ad_beacon_map_.metadata[ReportingDestination::kBuyer] =
bidder_ad_beacon_map;

if (bidder_report_url) {
if (!IsUrlValid(*bidder_report_url)) {
mojo::ReportBadMessage("Invalid bidder report URL");
Expand Down Expand Up @@ -1178,7 +1189,8 @@ void AuctionRunner::Auction::OnWinningComponentSellerWorkletFatalError(
// An error while reloading the worklet to call ReportResult() does not
// currently fail the auction.
OnReportSellerResultComplete(/*signals_for_winner=*/absl::nullopt,
/*seller_report_url=*/absl::nullopt, errors);
/*seller_report_url=*/absl::nullopt,
/*seller_ad_beacon_map=*/{}, errors);
}
}

Expand All @@ -1197,12 +1209,28 @@ void AuctionRunner::Auction::OnWinningBidderWorkletFatalError(
} else {
// An error while reloading the worklet to call ReportWin() does not
// currently fail the auction.
OnReportBidWinComplete(/*bidder_report_url=*/absl::nullopt, errors);
OnReportBidWinComplete(/*bidder_report_url=*/absl::nullopt,
/*bidder_ad_beacon_map=*/{}, errors);
}
}

void AuctionRunner::Auction::OnComponentAuctionReportingPhaseComplete(
bool success) {
// Copy ad beacon registry.
DCHECK(top_bid_->bid->auction);
if (top_bid_->bid->auction->ad_beacon_map_.metadata.count(
ReportingDestination::kSeller) > 0) {
ad_beacon_map_.metadata[ReportingDestination::kComponentSeller] =
top_bid_->bid->auction->ad_beacon_map_
.metadata[ReportingDestination::kSeller];
}
if (top_bid_->bid->auction->ad_beacon_map_.metadata.count(
ReportingDestination::kBuyer) > 0) {
ad_beacon_map_.metadata[ReportingDestination::kBuyer] =
top_bid_->bid->auction->ad_beacon_map_
.metadata[ReportingDestination::kBuyer];
}

// Inherit the success or error from the nested auction.
OnReportingPhaseComplete(*top_bid_->bid->auction->final_auction_result_);
}
Expand Down Expand Up @@ -1290,12 +1318,13 @@ void AuctionRunner::FailAuction() {

UpdateInterestGroupsPostAuction();

std::move(callback_).Run(
this, /*render_url=*/absl::nullopt,
/*winning_group_key=*/absl::nullopt,
/*ad_component_urls=*/{},
/*report_urls=*/{}, std::move(debug_loss_report_urls),
std::move(debug_win_report_urls), auction_.TakeErrors());
std::move(callback_).Run(this, /*render_url=*/absl::nullopt,
/*winning_group_key=*/absl::nullopt,
/*ad_component_urls=*/{},
/*report_urls=*/{},
std::move(debug_loss_report_urls),
std::move(debug_win_report_urls),
/*ad_beacon_map=*/{}, auction_.TakeErrors());
}

AuctionRunner::AuctionRunner(
Expand Down Expand Up @@ -1463,7 +1492,7 @@ void AuctionRunner::OnReportingPhaseComplete(bool success) {
this, std::move(winning_group_key), auction_.top_bid()->bid->render_url,
auction_.top_bid()->bid->ad_components, auction_.TakeReportUrls(),
std::move(debug_loss_report_urls), std::move(debug_win_report_urls),
auction_.TakeErrors());
auction_.TakeAdBeaconMap(), auction_.TakeErrors());
}

void AuctionRunner::UpdateInterestGroupsPostAuction() {
Expand Down
21 changes: 19 additions & 2 deletions content/browser/interest_group/auction_runner.h
Expand Up @@ -12,10 +12,12 @@
#include <vector>

#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "content/browser/fenced_frame/fenced_frame_url_mapping.h"
#include "content/browser/interest_group/auction_worklet_manager.h"
#include "content/browser/interest_group/interest_group_storage.h"
#include "content/common/content_export.h"
Expand Down Expand Up @@ -51,6 +53,7 @@ class CONTENT_EXPORT AuctionRunner {
url::Origin owner;
std::string name;
};

// Invoked when a FLEDGE auction is complete.
//
// `winning_group_id` owner and name of the winning interest group (if any).
Expand Down Expand Up @@ -80,6 +83,7 @@ class CONTENT_EXPORT AuctionRunner {
std::vector<GURL> report_urls,
std::vector<GURL> debug_loss_report_urls,
std::vector<GURL> debug_win_report_urls,
ReportingMetadata ad_beacon_map,
std::vector<std::string> errors)>;

// Returns true if `origin` is allowed to use the interest group API. Will be
Expand Down Expand Up @@ -404,6 +408,10 @@ class CONTENT_EXPORT AuctionRunner {
void TakeDebugReportUrls(std::vector<GURL>& debug_win_report_urls,
std::vector<GURL>& debug_loss_report_urls);

// Retrieves the ad beacon map. May only be called once, since it takes
// ownership of the stored ad beacon map.
ReportingMetadata TakeAdBeaconMap() { return std::move(ad_beacon_map_); }

// Retrieves any reporting URLs returned by ReportWin() and ReportResult()
// methods. May only be called after an auction has completed successfully.
// May only be called once, since it takes ownership of stored reporting
Expand Down Expand Up @@ -580,11 +588,14 @@ class CONTENT_EXPORT AuctionRunner {
void OnReportSellerResultComplete(
const absl::optional<std::string>& signals_for_winner,
const absl::optional<GURL>& seller_report_url,
const base::flat_map<std::string, GURL>& seller_ad_beacon_map,
const std::vector<std::string>& error_msgs);
void LoadBidderWorkletToReportBidWin(const std::string& signals_for_winner);
void ReportBidWin(const std::string& signals_for_winner);
void OnReportBidWinComplete(const absl::optional<GURL>& bidder_report_url,
const std::vector<std::string>& error_msgs);
void OnReportBidWinComplete(
const absl::optional<GURL>& bidder_report_url,
const base::flat_map<std::string, GURL>& bidder_ad_beacon_map,
const std::vector<std::string>& error_msgs);

// Called when the component SellerWorklet with the bidder that won an
// auction has an out-of-band fatal error during the ReportResult() call.
Expand Down Expand Up @@ -733,6 +744,12 @@ class CONTENT_EXPORT AuctionRunner {
// All errors reported by worklets thus far.
std::vector<std::string> errors_;

// Ad Beacon URL mapping generated from reportResult() or reportWin() from
// this auction and its components. Destination is relative to this auction.
// Returned to the caller for it to deal with, so the Auction itself can be
// deleted at the end of the auction.
ReportingMetadata ad_beacon_map_;

// This is set to true if the scoring phase ran and was able to score all
// bids that were made (of which there may have been none). This is used to
// gate accessors that should return nothing if the entire auction failed
Expand Down

0 comments on commit a570af2

Please sign in to comment.