0

[shared storage] Consolidate FLEDGE's shared storage modifier methods

What:
- Consolidate the existing modifier methods into a single
  `SharedStorageUpdate(SharedStorageModifierMethod)` method.
- No behavior change.

Why:
- Enable Batch Updates: This prepares for the upcoming support for the
  JavaScript API, batchUpdate(sequence<SharedStorageModifierMethod>),
  allowing websites to perform multiple modifications in a single
  operation. Explainer: https://github.com/WICG/shared-storage/pull/199
- Improved Maintainability: This simplifies the Mojo interface and
  reduces future maintenance overhead.

Bug: 373899210
Change-Id: I26ad3d9048709dfcda2614d573dcea6d60a971aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5953467
Reviewed-by: Dominic Farolino <dom@chromium.org>
Reviewed-by: Russ Hamilton <behamilton@google.com>
Commit-Queue: Yao Xiao <yaoxia@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1373433}
This commit is contained in:
Yao Xiao
2024-10-24 18:04:30 +00:00
committed by Chromium LUCI CQ
parent b618d46a5e
commit 4cf6811ced
10 changed files with 231 additions and 343 deletions

@@ -55,56 +55,42 @@ void AuctionSharedStorageHost::BindNewReceiver(
.worklet_origin = worklet_origin}); .worklet_origin = worklet_origin});
} }
void AuctionSharedStorageHost::Set( void AuctionSharedStorageHost::SharedStorageUpdate(
const std::u16string& key, blink::mojom::SharedStorageModifierMethodPtr method,
const std::u16string& value,
bool ignore_if_present,
auction_worklet::mojom::AuctionWorkletFunction auction_worklet::mojom::AuctionWorkletFunction
source_auction_worklet_function) { source_auction_worklet_function) {
storage::SharedStorageManager::SetBehavior set_behavior = if (method->is_set_method()) {
ignore_if_present blink::mojom::SharedStorageSetMethodPtr& set_method =
? storage::SharedStorageManager::SetBehavior::kIgnoreIfPresent method->get_set_method();
: storage::SharedStorageManager::SetBehavior::kDefault;
shared_storage_manager_->Set(receiver_set_.current_context().worklet_origin, storage::SharedStorageManager::SetBehavior set_behavior =
key, value, base::DoNothing(), set_behavior); set_method->ignore_if_present
? storage::SharedStorageManager::SetBehavior::kIgnoreIfPresent
: storage::SharedStorageManager::SetBehavior::kDefault;
GetContentClient()->browser()->LogWebFeatureForCurrentPage( shared_storage_manager_->Set(receiver_set_.current_context().worklet_origin,
receiver_set_.current_context().auction_runner_rfh, set_method->key, set_method->value,
ToWebFeature(source_auction_worklet_function)); base::DoNothing(), set_behavior);
} } else if (method->is_append_method()) {
blink::mojom::SharedStorageAppendMethodPtr& append_method =
method->get_append_method();
void AuctionSharedStorageHost::Append( shared_storage_manager_->Append(
const std::u16string& key, receiver_set_.current_context().worklet_origin, append_method->key,
const std::u16string& value, append_method->value, base::DoNothing());
auction_worklet::mojom::AuctionWorkletFunction } else if (method->is_delete_method()) {
source_auction_worklet_function) { blink::mojom::SharedStorageDeleteMethodPtr& delete_method =
shared_storage_manager_->Append( method->get_delete_method();
receiver_set_.current_context().worklet_origin, key, value,
base::DoNothing());
GetContentClient()->browser()->LogWebFeatureForCurrentPage( shared_storage_manager_->Delete(
receiver_set_.current_context().auction_runner_rfh, receiver_set_.current_context().worklet_origin, delete_method->key,
ToWebFeature(source_auction_worklet_function)); base::DoNothing());
} } else {
CHECK(method->is_clear_method());
void AuctionSharedStorageHost::Delete( shared_storage_manager_->Clear(
const std::u16string& key, receiver_set_.current_context().worklet_origin, base::DoNothing());
auction_worklet::mojom::AuctionWorkletFunction }
source_auction_worklet_function) {
shared_storage_manager_->Delete(
receiver_set_.current_context().worklet_origin, key, base::DoNothing());
GetContentClient()->browser()->LogWebFeatureForCurrentPage(
receiver_set_.current_context().auction_runner_rfh,
ToWebFeature(source_auction_worklet_function));
}
void AuctionSharedStorageHost::Clear(
auction_worklet::mojom::AuctionWorkletFunction
source_auction_worklet_function) {
shared_storage_manager_->Clear(receiver_set_.current_context().worklet_origin,
base::DoNothing());
GetContentClient()->browser()->LogWebFeatureForCurrentPage( GetContentClient()->browser()->LogWebFeatureForCurrentPage(
receiver_set_.current_context().auction_runner_rfh, receiver_set_.current_context().auction_runner_rfh,

@@ -9,6 +9,7 @@
#include "content/services/auction_worklet/public/mojom/auction_shared_storage_host.mojom.h" #include "content/services/auction_worklet/public/mojom/auction_shared_storage_host.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h" #include "mojo/public/cpp/bindings/receiver_set.h"
#include "url/origin.h"
namespace storage { namespace storage {
class SharedStorageManager; class SharedStorageManager;
@@ -40,20 +41,9 @@ class CONTENT_EXPORT AuctionSharedStorageHost
receiver); receiver);
// auction_worklet::mojom::AuctionSharedStorageHost: // auction_worklet::mojom::AuctionSharedStorageHost:
void Set(const std::u16string& key, void SharedStorageUpdate(blink::mojom::SharedStorageModifierMethodPtr method,
const std::u16string& value, auction_worklet::mojom::AuctionWorkletFunction
bool ignore_if_present, source_auction_worklet_function) override;
auction_worklet::mojom::AuctionWorkletFunction
source_auction_worklet_function) override;
void Append(const std::u16string& key,
const std::u16string& value,
auction_worklet::mojom::AuctionWorkletFunction
source_auction_worklet_function) override;
void Delete(const std::u16string& key,
auction_worklet::mojom::AuctionWorkletFunction
source_auction_worklet_function) override;
void Clear(auction_worklet::mojom::AuctionWorkletFunction
source_auction_worklet_function) override;
private: private:
struct ReceiverContext; struct ReceiverContext;

@@ -61,6 +61,7 @@
#include "third_party/blink/public/common/interest_group/ad_display_size.h" #include "third_party/blink/public/common/interest_group/ad_display_size.h"
#include "third_party/blink/public/common/interest_group/interest_group.h" #include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h" #include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
#include "third_party/googletest/src/googlemock/include/gmock/gmock-more-matchers.h" #include "third_party/googletest/src/googlemock/include/gmock/gmock-more-matchers.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
@@ -10611,43 +10612,32 @@ TEST_F(BidderWorkletSharedStorageAPIEnabledTest,
// dedicated pipe. // dedicated pipe.
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
using RequestType =
auction_worklet::TestAuctionSharedStorageHost::RequestType;
using Request = auction_worklet::TestAuctionSharedStorageHost::Request; using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
EXPECT_THAT( EXPECT_THAT(
test_shared_storage_host.observed_requests(), test_shared_storage_host.observed_requests(),
testing::ElementsAre( testing::ElementsAre(
Request{.type = RequestType::kSet, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = false, /*ignore_if_present=*/false)),
.source_auction_worklet_function = mojom::AuctionWorkletFunction::kBidderGenerateBid),
mojom::AuctionWorkletFunction::kBidderGenerateBid}, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
Request{.type = RequestType::kSet, blink::mojom::SharedStorageSetMethod::New(
.key = u"a", /*key=*/u"a", /*value=*/u"b",
.value = u"b", /*ignore_if_present=*/true)),
.ignore_if_present = true, mojom::AuctionWorkletFunction::kBidderGenerateBid),
.source_auction_worklet_function = Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
mojom::AuctionWorkletFunction::kBidderGenerateBid}, blink::mojom::SharedStorageAppendMethod::New(
Request{.type = RequestType::kAppend, /*key=*/u"a", /*value=*/u"b")),
.key = u"a", mojom::AuctionWorkletFunction::kBidderGenerateBid),
.value = u"b", Request(
.ignore_if_present = false, blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
.source_auction_worklet_function = blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
mojom::AuctionWorkletFunction::kBidderGenerateBid}, mojom::AuctionWorkletFunction::kBidderGenerateBid),
Request{.type = RequestType::kDelete, Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
.key = u"a", blink::mojom::SharedStorageClearMethod::New()),
.value = std::u16string(), mojom::AuctionWorkletFunction::kBidderGenerateBid)));
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderGenerateBid},
Request{.type = RequestType::kClear,
.key = std::u16string(),
.value = std::u16string(),
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
} }
{ {
@@ -10710,43 +10700,32 @@ TEST_F(BidderWorkletSharedStorageAPIEnabledTest,
// dedicated pipe. // dedicated pipe.
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
using RequestType =
auction_worklet::TestAuctionSharedStorageHost::RequestType;
using Request = auction_worklet::TestAuctionSharedStorageHost::Request; using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
EXPECT_THAT( EXPECT_THAT(
test_shared_storage_host.observed_requests(), test_shared_storage_host.observed_requests(),
testing::ElementsAre( testing::ElementsAre(
Request{.type = RequestType::kSet, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = false, /*ignore_if_present=*/false)),
.source_auction_worklet_function = mojom::AuctionWorkletFunction::kBidderReportWin),
mojom::AuctionWorkletFunction::kBidderReportWin}, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
Request{.type = RequestType::kSet, blink::mojom::SharedStorageSetMethod::New(
.key = u"a", /*key=*/u"a", /*value=*/u"b",
.value = u"b", /*ignore_if_present=*/true)),
.ignore_if_present = true, mojom::AuctionWorkletFunction::kBidderReportWin),
.source_auction_worklet_function = Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
mojom::AuctionWorkletFunction::kBidderReportWin}, blink::mojom::SharedStorageAppendMethod::New(
Request{.type = RequestType::kAppend, /*key=*/u"a", /*value=*/u"b")),
.key = u"a", mojom::AuctionWorkletFunction::kBidderReportWin),
.value = u"b", Request(
.ignore_if_present = false, blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
.source_auction_worklet_function = blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
mojom::AuctionWorkletFunction::kBidderReportWin}, mojom::AuctionWorkletFunction::kBidderReportWin),
Request{.type = RequestType::kDelete, Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
.key = u"a", blink::mojom::SharedStorageClearMethod::New()),
.value = std::u16string(), mojom::AuctionWorkletFunction::kBidderReportWin)));
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderReportWin},
Request{.type = RequestType::kClear,
.key = std::u16string(),
.value = std::u16string(),
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderReportWin}));
} }
{ {
@@ -10851,18 +10830,16 @@ TEST_F(BidderWorkletTwoThreadsSharedStorageAPIEnabledTest,
// handling the GenerateBid has observed the requests. // handling the GenerateBid has observed the requests.
EXPECT_TRUE(test_shared_storage_host1.observed_requests().empty()); EXPECT_TRUE(test_shared_storage_host1.observed_requests().empty());
using RequestType =
auction_worklet::TestAuctionSharedStorageHost::RequestType;
using Request = auction_worklet::TestAuctionSharedStorageHost::Request; using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
EXPECT_THAT(test_shared_storage_host0.observed_requests(), EXPECT_THAT(test_shared_storage_host0.observed_requests(),
testing::ElementsAre(Request{ testing::ElementsAre(Request(
.type = RequestType::kSet, blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = false, /*ignore_if_present=*/false)),
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderGenerateBid})); mojom::AuctionWorkletFunction::kBidderGenerateBid)));
} }
class BidderWorkletPrivateAggregationEnabledTest : public BidderWorkletTest { class BidderWorkletPrivateAggregationEnabledTest : public BidderWorkletTest {

@@ -41,6 +41,7 @@
#include "third_party/blink/public/common/interest_group/interest_group.h" #include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom.h" #include "third_party/blink/public/mojom/aggregation_service/aggregatable_report.mojom.h"
#include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom-forward.h" #include "third_party/blink/public/mojom/private_aggregation/private_aggregation_host.mojom-forward.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
#include "v8/include/v8-context.h" #include "v8/include/v8-context.h"
#include "v8/include/v8-primitive.h" #include "v8/include/v8-primitive.h"
@@ -2134,8 +2135,6 @@ TEST_F(ContextRecyclerTest,
} }
TEST_F(ContextRecyclerTest, SharedStorageMethods) { TEST_F(ContextRecyclerTest, SharedStorageMethods) {
using RequestType =
auction_worklet::TestAuctionSharedStorageHost::RequestType;
using Request = auction_worklet::TestAuctionSharedStorageHost::Request; using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
const std::string kInvalidValue( const std::string kInvalidValue(
@@ -2192,13 +2191,12 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
EXPECT_THAT(error_msgs, ElementsAre()); EXPECT_THAT(error_msgs, ElementsAre());
EXPECT_THAT(test_shared_storage_host.observed_requests(), EXPECT_THAT(test_shared_storage_host.observed_requests(),
ElementsAre(Request{ ElementsAre(Request(
.type = RequestType::kSet, blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = false, /*ignore_if_present=*/false)),
.source_auction_worklet_function = mojom::AuctionWorkletFunction::kBidderGenerateBid)));
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
test_shared_storage_host.ClearObservedRequests(); test_shared_storage_host.ClearObservedRequests();
} }
@@ -2221,13 +2219,12 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
EXPECT_THAT(error_msgs, ElementsAre()); EXPECT_THAT(error_msgs, ElementsAre());
EXPECT_THAT(test_shared_storage_host.observed_requests(), EXPECT_THAT(test_shared_storage_host.observed_requests(),
ElementsAre(Request{ ElementsAre(Request(
.type = RequestType::kSet, blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = true, /*ignore_if_present=*/true)),
.source_auction_worklet_function = mojom::AuctionWorkletFunction::kBidderGenerateBid)));
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
test_shared_storage_host.ClearObservedRequests(); test_shared_storage_host.ClearObservedRequests();
} }
@@ -2245,13 +2242,11 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
EXPECT_THAT(error_msgs, ElementsAre()); EXPECT_THAT(error_msgs, ElementsAre());
EXPECT_THAT(test_shared_storage_host.observed_requests(), EXPECT_THAT(test_shared_storage_host.observed_requests(),
ElementsAre(Request{ ElementsAre(Request(
.type = RequestType::kAppend, blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
.key = u"a", blink::mojom::SharedStorageAppendMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b")),
.ignore_if_present = false, mojom::AuctionWorkletFunction::kBidderGenerateBid)));
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
test_shared_storage_host.ClearObservedRequests(); test_shared_storage_host.ClearObservedRequests();
} }
@@ -2268,13 +2263,11 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
EXPECT_THAT(error_msgs, ElementsAre()); EXPECT_THAT(error_msgs, ElementsAre());
EXPECT_THAT(test_shared_storage_host.observed_requests(), EXPECT_THAT(test_shared_storage_host.observed_requests(),
ElementsAre(Request{ ElementsAre(Request(
.type = RequestType::kDelete, blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
.key = u"a", blink::mojom::SharedStorageDeleteMethod::New(
.value = std::u16string(), /*key=*/u"a")),
.ignore_if_present = false, mojom::AuctionWorkletFunction::kBidderGenerateBid)));
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
test_shared_storage_host.ClearObservedRequests(); test_shared_storage_host.ClearObservedRequests();
} }
@@ -2291,13 +2284,10 @@ TEST_F(ContextRecyclerTest, SharedStorageMethods) {
EXPECT_THAT(error_msgs, ElementsAre()); EXPECT_THAT(error_msgs, ElementsAre());
EXPECT_THAT(test_shared_storage_host.observed_requests(), EXPECT_THAT(test_shared_storage_host.observed_requests(),
ElementsAre(Request{ ElementsAre(Request(
.type = RequestType::kClear, blink::mojom::SharedStorageModifierMethod::NewClearMethod(
.key = std::u16string(), blink::mojom::SharedStorageClearMethod::New()),
.value = std::u16string(), mojom::AuctionWorkletFunction::kBidderGenerateBid)));
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kBidderGenerateBid}));
test_shared_storage_host.ClearObservedRequests(); test_shared_storage_host.ClearObservedRequests();
} }

@@ -13,6 +13,7 @@
#include "base/functional/bind.h" #include "base/functional/bind.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h" #include "base/test/bind.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "content/services/auction_worklet/worklet_test_util.h" #include "content/services/auction_worklet/worklet_test_util.h"

@@ -18,24 +18,7 @@ enum AuctionWorkletFunction {
// storage API (i.e. the setter methods). We intentionally do not return the // storage API (i.e. the setter methods). We intentionally do not return the
// result of these calls to avoid leaking state to the worklet. // result of these calls to avoid leaking state to the worklet.
interface AuctionSharedStorageHost { interface AuctionSharedStorageHost {
// Handle sharedStorage.set(): set `key`s entry to `value`. If // Handle the modifier method `method`.
// `ignore_if_present` is true, the entry is not updated if `key` already SharedStorageUpdate(blink.mojom.SharedStorageModifierMethod method,
// exists. AuctionWorkletFunction source_auction_worklet_function);
Set(blink.mojom.SharedStorageKeyArgument key,
blink.mojom.SharedStorageValueArgument value,
bool ignore_if_present,
AuctionWorkletFunction source_auction_worklet_function);
// Handle sharedStorage.append(): append `value` to the entry for `key`.
// Equivalent to "set" if the `key` is not present.
Append(blink.mojom.SharedStorageKeyArgument key,
blink.mojom.SharedStorageValueArgument value,
AuctionWorkletFunction source_auction_worklet_function);
// Handle sharedStorage.delete(): delete the entry at the given `key`.
Delete(blink.mojom.SharedStorageKeyArgument key,
AuctionWorkletFunction source_auction_worklet_function);
// Handle sharedStorage.clear(): delete all entries.
Clear(AuctionWorkletFunction source_auction_worklet_function);
}; };

@@ -57,6 +57,7 @@
#include "third_party/blink/public/common/interest_group/ad_display_size.h" #include "third_party/blink/public/common/interest_group/ad_display_size.h"
#include "third_party/blink/public/common/interest_group/auction_config.h" #include "third_party/blink/public/common/interest_group/auction_config.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h" #include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
#include "url/origin.h" #include "url/origin.h"
@@ -5976,43 +5977,32 @@ TEST_F(SellerWorkletSharedStorageAPIEnabledTest, SharedStorageWriteInScoreAd) {
// dedicated pipe. // dedicated pipe.
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
using RequestType =
auction_worklet::TestAuctionSharedStorageHost::RequestType;
using Request = auction_worklet::TestAuctionSharedStorageHost::Request; using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
EXPECT_THAT( EXPECT_THAT(
test_shared_storage_host.observed_requests(), test_shared_storage_host.observed_requests(),
testing::ElementsAre( testing::ElementsAre(
Request{.type = RequestType::kSet, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = false, /*ignore_if_present=*/false)),
.source_auction_worklet_function = mojom::AuctionWorkletFunction::kSellerScoreAd),
mojom::AuctionWorkletFunction::kSellerScoreAd}, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
Request{.type = RequestType::kSet, blink::mojom::SharedStorageSetMethod::New(
.key = u"a", /*key=*/u"a", /*value=*/u"b",
.value = u"b", /*ignore_if_present=*/true)),
.ignore_if_present = true, mojom::AuctionWorkletFunction::kSellerScoreAd),
.source_auction_worklet_function = Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
mojom::AuctionWorkletFunction::kSellerScoreAd}, blink::mojom::SharedStorageAppendMethod::New(
Request{.type = RequestType::kAppend, /*key=*/u"a", /*value=*/u"b")),
.key = u"a", mojom::AuctionWorkletFunction::kSellerScoreAd),
.value = u"b", Request(
.ignore_if_present = false, blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
.source_auction_worklet_function = blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
mojom::AuctionWorkletFunction::kSellerScoreAd}, mojom::AuctionWorkletFunction::kSellerScoreAd),
Request{.type = RequestType::kDelete, Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
.key = u"a", blink::mojom::SharedStorageClearMethod::New()),
.value = std::u16string(), mojom::AuctionWorkletFunction::kSellerScoreAd)));
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kSellerScoreAd},
Request{.type = RequestType::kClear,
.key = std::u16string(),
.value = std::u16string(),
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kSellerScoreAd}));
} }
{ {
@@ -6073,43 +6063,32 @@ TEST_F(SellerWorkletSharedStorageAPIEnabledTest,
// dedicated pipe. // dedicated pipe.
task_environment_.RunUntilIdle(); task_environment_.RunUntilIdle();
using RequestType =
auction_worklet::TestAuctionSharedStorageHost::RequestType;
using Request = auction_worklet::TestAuctionSharedStorageHost::Request; using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
EXPECT_THAT( EXPECT_THAT(
test_shared_storage_host.observed_requests(), test_shared_storage_host.observed_requests(),
testing::ElementsAre( testing::ElementsAre(
Request{.type = RequestType::kSet, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = false, /*ignore_if_present=*/false)),
.source_auction_worklet_function = mojom::AuctionWorkletFunction::kSellerReportResult),
mojom::AuctionWorkletFunction::kSellerReportResult}, Request(blink::mojom::SharedStorageModifierMethod::NewSetMethod(
Request{.type = RequestType::kSet, blink::mojom::SharedStorageSetMethod::New(
.key = u"a", /*key=*/u"a", /*value=*/u"b",
.value = u"b", /*ignore_if_present=*/true)),
.ignore_if_present = true, mojom::AuctionWorkletFunction::kSellerReportResult),
.source_auction_worklet_function = Request(blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
mojom::AuctionWorkletFunction::kSellerReportResult}, blink::mojom::SharedStorageAppendMethod::New(
Request{.type = RequestType::kAppend, /*key=*/u"a", /*value=*/u"b")),
.key = u"a", mojom::AuctionWorkletFunction::kSellerReportResult),
.value = u"b", Request(
.ignore_if_present = false, blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
.source_auction_worklet_function = blink::mojom::SharedStorageDeleteMethod::New(/*key=*/u"a")),
mojom::AuctionWorkletFunction::kSellerReportResult}, mojom::AuctionWorkletFunction::kSellerReportResult),
Request{.type = RequestType::kDelete, Request(blink::mojom::SharedStorageModifierMethod::NewClearMethod(
.key = u"a", blink::mojom::SharedStorageClearMethod::New()),
.value = std::u16string(), mojom::AuctionWorkletFunction::kSellerReportResult)));
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kSellerReportResult},
Request{.type = RequestType::kClear,
.key = std::u16string(),
.value = std::u16string(),
.ignore_if_present = false,
.source_auction_worklet_function =
mojom::AuctionWorkletFunction::kSellerReportResult}));
} }
{ {
@@ -6343,18 +6322,15 @@ TEST_F(SellerWorkletTwoThreadsSharedStorageAPIEnabledTest,
// handling the ScoreAd has observed the requests. // handling the ScoreAd has observed the requests.
EXPECT_TRUE(test_shared_storage_host1.observed_requests().empty()); EXPECT_TRUE(test_shared_storage_host1.observed_requests().empty());
using RequestType =
auction_worklet::TestAuctionSharedStorageHost::RequestType;
using Request = auction_worklet::TestAuctionSharedStorageHost::Request; using Request = auction_worklet::TestAuctionSharedStorageHost::Request;
EXPECT_THAT(test_shared_storage_host0.observed_requests(), EXPECT_THAT(test_shared_storage_host0.observed_requests(),
testing::ElementsAre( testing::ElementsAre(Request(
Request{.type = RequestType::kSet, blink::mojom::SharedStorageModifierMethod::NewSetMethod(
.key = u"a", blink::mojom::SharedStorageSetMethod::New(
.value = u"b", /*key=*/u"a", /*value=*/u"b",
.ignore_if_present = false, /*ignore_if_present=*/false)),
.source_auction_worklet_function = mojom::AuctionWorkletFunction::kSellerScoreAd)));
mojom::AuctionWorkletFunction::kSellerScoreAd}));
} }
class SellerWorkletRealTimeTest : public SellerWorkletTest { class SellerWorkletRealTimeTest : public SellerWorkletTest {

@@ -14,6 +14,7 @@
#include "content/services/auction_worklet/webidl_compat.h" #include "content/services/auction_worklet/webidl_compat.h"
#include "gin/converter.h" #include "gin/converter.h"
#include "third_party/blink/public/common/shared_storage/shared_storage_utils.h" #include "third_party/blink/public/common/shared_storage/shared_storage_utils.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
#include "v8/include/v8-exception.h" #include "v8/include/v8-exception.h"
#include "v8/include/v8-external.h" #include "v8/include/v8-external.h"
#include "v8/include/v8-function-callback.h" #include "v8/include/v8-function-callback.h"
@@ -142,9 +143,12 @@ void SharedStorageBindings::Set(
return; return;
} }
bindings->shared_storage_host_->Set( auto method = blink::mojom::SharedStorageModifierMethod::NewSetMethod(
arg0_key, arg1_value, ignore_if_present.value_or(false), blink::mojom::SharedStorageSetMethod::New(
bindings->source_auction_worklet_function_); arg0_key, arg1_value, ignore_if_present.value_or(false)));
bindings->shared_storage_host_->SharedStorageUpdate(
std::move(method), bindings->source_auction_worklet_function_);
} }
// static // static
@@ -187,8 +191,11 @@ void SharedStorageBindings::Append(
return; return;
} }
bindings->shared_storage_host_->Append( auto method = blink::mojom::SharedStorageModifierMethod::NewAppendMethod(
arg0_key, arg1_value, bindings->source_auction_worklet_function_); blink::mojom::SharedStorageAppendMethod::New(arg0_key, arg1_value));
bindings->shared_storage_host_->SharedStorageUpdate(
std::move(method), bindings->source_auction_worklet_function_);
} }
// static // static
@@ -223,8 +230,11 @@ void SharedStorageBindings::Delete(
return; return;
} }
bindings->shared_storage_host_->Delete( auto method = blink::mojom::SharedStorageModifierMethod::NewDeleteMethod(
arg0_key, bindings->source_auction_worklet_function_); blink::mojom::SharedStorageDeleteMethod::New(arg0_key));
bindings->shared_storage_host_->SharedStorageUpdate(
std::move(method), bindings->source_auction_worklet_function_);
} }
// static // static
@@ -241,7 +251,10 @@ void SharedStorageBindings::Clear(
return; return;
} }
bindings->shared_storage_host_->Clear( auto method = blink::mojom::SharedStorageModifierMethod::NewClearMethod(
bindings->source_auction_worklet_function_); blink::mojom::SharedStorageClearMethod::New());
bindings->shared_storage_host_->SharedStorageUpdate(
std::move(method), bindings->source_auction_worklet_function_);
} }
} // namespace auction_worklet } // namespace auction_worklet

@@ -22,6 +22,7 @@
#include "services/network/public/cpp/url_loader_completion_status.h" #include "services/network/public/cpp/url_loader_completion_status.h"
#include "services/network/public/mojom/url_response_head.mojom.h" #include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h" #include "services/network/test/test_url_loader_factory.h"
#include "third_party/blink/public/mojom/shared_storage/shared_storage.mojom.h"
namespace auction_worklet { namespace auction_worklet {
@@ -137,10 +138,34 @@ base::WaitableEvent* WedgeV8Thread(AuctionV8Helper* v8_helper) {
return event_handle; return event_handle;
} }
TestAuctionSharedStorageHost::Request::Request(
blink::mojom::SharedStorageModifierMethodPtr method,
mojom::AuctionWorkletFunction source_auction_worklet_function)
: method(std::move(method)),
source_auction_worklet_function(source_auction_worklet_function) {}
TestAuctionSharedStorageHost::Request::~Request() = default;
TestAuctionSharedStorageHost::Request::Request(const Request& other)
: method(other.method->Clone()),
source_auction_worklet_function(other.source_auction_worklet_function) {}
TestAuctionSharedStorageHost::Request&
TestAuctionSharedStorageHost::Request::operator=(const Request& other) {
if (this != &other) {
method = other.method->Clone();
source_auction_worklet_function = other.source_auction_worklet_function;
}
return *this;
}
TestAuctionSharedStorageHost::Request::Request(Request&& other) = default;
TestAuctionSharedStorageHost::Request&
TestAuctionSharedStorageHost::Request::operator=(Request&& other) = default;
bool TestAuctionSharedStorageHost::Request::operator==( bool TestAuctionSharedStorageHost::Request::operator==(
const Request& rhs) const { const Request& rhs) const {
return type == rhs.type && key == rhs.key && value == rhs.value && return method == rhs.method &&
ignore_if_present == rhs.ignore_if_present &&
source_auction_worklet_function == rhs.source_auction_worklet_function; source_auction_worklet_function == rhs.source_auction_worklet_function;
} }
@@ -148,50 +173,12 @@ TestAuctionSharedStorageHost::TestAuctionSharedStorageHost() = default;
TestAuctionSharedStorageHost::~TestAuctionSharedStorageHost() = default; TestAuctionSharedStorageHost::~TestAuctionSharedStorageHost() = default;
void TestAuctionSharedStorageHost::Set( void TestAuctionSharedStorageHost::SharedStorageUpdate(
const std::u16string& key, blink::mojom::SharedStorageModifierMethodPtr method,
const std::u16string& value, auction_worklet::mojom::AuctionWorkletFunction
bool ignore_if_present, source_auction_worklet_function) {
mojom::AuctionWorkletFunction source_auction_worklet_function) { observed_requests_.emplace_back(
observed_requests_.emplace_back(Request{ Request(std::move(method), source_auction_worklet_function));
.type = RequestType::kSet,
.key = key,
.value = value,
.ignore_if_present = ignore_if_present,
.source_auction_worklet_function = source_auction_worklet_function});
}
void TestAuctionSharedStorageHost::Append(
const std::u16string& key,
const std::u16string& value,
mojom::AuctionWorkletFunction source_auction_worklet_function) {
observed_requests_.emplace_back(Request{
.type = RequestType::kAppend,
.key = key,
.value = value,
.ignore_if_present = false,
.source_auction_worklet_function = source_auction_worklet_function});
}
void TestAuctionSharedStorageHost::Delete(
const std::u16string& key,
mojom::AuctionWorkletFunction source_auction_worklet_function) {
observed_requests_.emplace_back(Request{
.type = RequestType::kDelete,
.key = key,
.value = std::u16string(),
.ignore_if_present = false,
.source_auction_worklet_function = source_auction_worklet_function});
}
void TestAuctionSharedStorageHost::Clear(
mojom::AuctionWorkletFunction source_auction_worklet_function) {
observed_requests_.emplace_back(Request{
.type = RequestType::kClear,
.key = std::u16string(),
.value = std::u16string(),
.ignore_if_present = false,
.source_auction_worklet_function = source_auction_worklet_function});
} }
void TestAuctionSharedStorageHost::ClearObservedRequests() { void TestAuctionSharedStorageHost::ClearObservedRequests() {

@@ -80,18 +80,17 @@ base::WaitableEvent* WedgeV8Thread(AuctionV8Helper* v8_helper);
// Receives shared storage mojom messages. // Receives shared storage mojom messages.
class TestAuctionSharedStorageHost : public mojom::AuctionSharedStorageHost { class TestAuctionSharedStorageHost : public mojom::AuctionSharedStorageHost {
public: public:
enum RequestType {
kSet,
kAppend,
kDelete,
kClear,
};
struct Request { struct Request {
RequestType type; Request(blink::mojom::SharedStorageModifierMethodPtr method,
std::u16string key; mojom::AuctionWorkletFunction source_auction_worklet_function);
std::u16string value; ~Request();
bool ignore_if_present;
Request(const Request& other);
Request& operator=(const Request& other);
Request(Request&& other);
Request& operator=(Request&& other);
blink::mojom::SharedStorageModifierMethodPtr method;
mojom::AuctionWorkletFunction source_auction_worklet_function; mojom::AuctionWorkletFunction source_auction_worklet_function;
bool operator==(const Request& rhs) const; bool operator==(const Request& rhs) const;
@@ -102,23 +101,9 @@ class TestAuctionSharedStorageHost : public mojom::AuctionSharedStorageHost {
~TestAuctionSharedStorageHost() override; ~TestAuctionSharedStorageHost() override;
// mojom::AuctionSharedStorageHost: // mojom::AuctionSharedStorageHost:
void Set( void SharedStorageUpdate(blink::mojom::SharedStorageModifierMethodPtr method,
const std::u16string& key, auction_worklet::mojom::AuctionWorkletFunction
const std::u16string& value, source_auction_worklet_function) override;
bool ignore_if_present,
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
void Append(
const std::u16string& key,
const std::u16string& value,
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
void Delete(
const std::u16string& key,
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
void Clear(
mojom::AuctionWorkletFunction source_auction_worklet_function) override;
const std::vector<Request>& observed_requests() const { const std::vector<Request>& observed_requests() const {
return observed_requests_; return observed_requests_;