#ifndef CONTENT_SERVICES_AUCTION_WORKLET_EXECUTION_MODE_UTIL_H_
#define CONTENT_SERVICES_AUCTION_WORKLET_EXECUTION_MODE_UTIL_H_
#include "base/containers/lru_cache.h"
#include "base/types/optional_ref.h"
#include "content/common/content_export.h"
#include "content/services/auction_worklet/context_recycler.h"
#include "third_party/blink/public/common/interest_group/interest_group.h"
#include "url/origin.h"
namespace auction_worklet {
class CONTENT_EXPORT ExecutionModeHelper {
public:
explicit ExecutionModeHelper(bool is_seller);
~ExecutionModeHelper();
ContextRecycler* TryReuseContext(
const blink::InterestGroup::ExecutionMode execution_mode,
const uint64_t group_by_origin_id,
const bool allow_group_by_origin,
ContextRecycler* context_recycler_for_kanon_rerun,
bool& should_deep_freeze);
void SaveContextForReuse(
const blink::InterestGroup::ExecutionMode execution_mode,
const uint64_t group_by_origin_id,
const bool allow_group_by_origin,
std::unique_ptr<ContextRecycler> context_recycler);
static bool DeepFreezeContext(v8::Local<v8::Context>& context,
scoped_refptr<AuctionV8Helper> v8_helper,
std::vector<std::string>& errors_out);
private:
const bool is_seller_;
base::optional_ref<ContextRecycler> GetContextRecyclerForOriginGroupMode(
const uint64_t group_by_origin_id);
void SetContextRecyclerForOriginGroupMode(
const uint64_t group_by_origin_id,
std::unique_ptr<ContextRecycler> recycler);
base::optional_ref<ContextRecycler> GetFrozenContextRecycler();
void SetFrozenContextRecycler(
std::unique_ptr<ContextRecycler> context_recycler);
std::unique_ptr<ContextRecycler> context_recycler_for_always_reuse_feature_;
std::unique_ptr<ContextRecycler> context_recycler_for_frozen_context_;
base::LRUCache<uint64_t, std::unique_ptr<ContextRecycler>>
context_recyclers_for_origin_group_mode_;
};
std::string_view GetExecutionModeString(
blink::InterestGroup::ExecutionMode execution_mode);
}
#endif