chromium/content/services/auction_worklet/auction_worklet_service_impl.cc

// Copyright 2021 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/services/auction_worklet/auction_worklet_service_impl.h"

#include <memory>
#include <string>
#include <utility>

#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
#include "base/synchronization/waitable_event.h"
#include "content/common/features.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/bidder_worklet.h"
#include "content/services/auction_worklet/public/mojom/auction_worklet_service.mojom-forward.h"
#include "content/services/auction_worklet/public/mojom/auction_worklet_service.mojom.h"
#include "content/services/auction_worklet/seller_worklet.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom.h"

namespace auction_worklet {

namespace {

static size_t g_next_seller_worklet_thread_index =;

}  // namespace

// V8HelperHolder exists to make sure we don't end up creating a fresh V8 thread
// every time a new service instance is created. It itself must be accessed from
// a single thread, and should be destroyed before task scheduling is shut down.
//
// It has two modes:
//
// 1) Dedicated process mode, for running as a service. In that case, it only
//    ends up using one V8 thread, as service process isolation will ensure that
//    SellerInstance() and BidderInstance() will not both be called in the same
///   process.  It also makes sure to wait to fully unwind the V8 thread
//    in its destructor, since that must be done before task scheduler shutdown
//    to avoid crashes from V8 GC trying to post tasks.
//
// 2) Shared process mode, for running inside a renderer. In that case, it
//    provides up two V8 threads --- one for seller, one for bidder --- to
//    provide the base level of parallelism one would have with those getting
//    separate processes.
class AuctionWorkletServiceImpl::V8HelperHolder
    : public base::RefCounted<V8HelperHolder> {};

std::vector<AuctionWorkletServiceImpl::V8HelperHolder*>*
    AuctionWorkletServiceImpl::V8HelperHolder::g_bidder_instances =;

std::vector<AuctionWorkletServiceImpl::V8HelperHolder*>*
    AuctionWorkletServiceImpl::V8HelperHolder::g_seller_instances =;

// static
void AuctionWorkletServiceImpl::CreateForRenderer(
    mojo::PendingReceiver<mojom::AuctionWorkletService> receiver) {}

// static
std::unique_ptr<AuctionWorkletServiceImpl>
AuctionWorkletServiceImpl::CreateForService(
    mojo::PendingReceiver<mojom::AuctionWorkletService> receiver) {}

AuctionWorkletServiceImpl::AuctionWorkletServiceImpl(
    ProcessModel process_model,
    mojo::PendingReceiver<mojom::AuctionWorkletService> receiver)
    :{}

AuctionWorkletServiceImpl::~AuctionWorkletServiceImpl() = default;

std::vector<scoped_refptr<AuctionV8Helper>>
AuctionWorkletServiceImpl::AuctionV8HelpersForTesting() {}

void AuctionWorkletServiceImpl::LoadBidderWorklet(
    mojo::PendingReceiver<mojom::BidderWorklet> bidder_worklet_receiver,
    std::vector<mojo::PendingRemote<mojom::AuctionSharedStorageHost>>
        shared_storage_hosts,
    bool pause_for_debugger_on_start,
    mojo::PendingRemote<network::mojom::URLLoaderFactory>
        pending_url_loader_factory,
    mojo::PendingRemote<auction_worklet::mojom::AuctionNetworkEventsHandler>
        auction_network_events_handler,
    const GURL& script_source_url,
    const std::optional<GURL>& wasm_helper_url,
    const std::optional<GURL>& trusted_bidding_signals_url,
    const std::string& trusted_bidding_signals_slot_size_param,
    const url::Origin& top_window_origin,
    mojom::AuctionWorkletPermissionsPolicyStatePtr permissions_policy_state,
    std::optional<uint16_t> experiment_group_id,
    mojom::TrustedSignalsPublicKeyPtr public_key) {}

void AuctionWorkletServiceImpl::LoadSellerWorklet(
    mojo::PendingReceiver<mojom::SellerWorklet> seller_worklet_receiver,
    std::vector<mojo::PendingRemote<mojom::AuctionSharedStorageHost>>
        shared_storage_hosts,
    bool pause_for_debugger_on_start,
    mojo::PendingRemote<network::mojom::URLLoaderFactory>
        pending_url_loader_factory,
    mojo::PendingRemote<auction_worklet::mojom::AuctionNetworkEventsHandler>
        auction_network_events_handler,
    const GURL& decision_logic_url,
    const std::optional<GURL>& trusted_scoring_signals_url,
    const url::Origin& top_window_origin,
    mojom::AuctionWorkletPermissionsPolicyStatePtr permissions_policy_state,
    std::optional<uint16_t> experiment_group_id) {}

size_t AuctionWorkletServiceImpl::GetNextSellerWorkletThreadIndex() {}

void AuctionWorkletServiceImpl::DisconnectSellerWorklet(
    mojo::ReceiverId receiver_id,
    const std::string& reason) {}

void AuctionWorkletServiceImpl::DisconnectBidderWorklet(
    mojo::ReceiverId receiver_id,
    const std::string& reason) {}

}  // namespace auction_worklet