chromium/third_party/blink/public/common/shared_storage/shared_storage_utils.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_SHARED_STORAGE_SHARED_STORAGE_UTILS_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_SHARED_STORAGE_SHARED_STORAGE_UTILS_H_

#include <cstdlib>
#include <string_view>

#include "third_party/blink/public/common/common_export.h"

namespace blink {

static constexpr char kSharedStorageModuleScriptNotLoadedErrorMessage[] =;

static constexpr char kSharedStorageOperationNotFoundErrorMessage[] =;

static constexpr char
    kSharedStorageEmptyOperationDefinitionInstanceErrorMessage[] =;

static constexpr char kSharedStorageCannotDeserializeDataErrorMessage[] =;

static constexpr char kSharedStorageEmptyScriptResultErrorMessage[] =;

static constexpr char kSharedStorageReturnValueToIntErrorMessage[] =;

static constexpr char kSharedStorageReturnValueOutOfRangeErrorMessage[] =;

// Whether or not the worklet ever entered keep-alive, and if so, the reason the
// keep-alive was terminated. Recorded to UMA; always add new values to the end
// and do not reorder or delete values from this list.
enum class SharedStorageWorkletDestroyedStatus {};

// Error type encountered by worklet.
// Recorded to UMA; always add new values to the end and do not reorder or
// delete values from this list. Instead of deleting an obsolete value "kFoo",
// for example, insert "OBSOLETE_" in the value's name after the initial "k" to
// get "kOBSOLETE_foo".
enum class SharedStorageWorkletErrorType {};

// Whether or not there is sufficient budget for the `selectURL()` call, and if
// there is insufficient budget, which of the budgets fell short. Note that
// budgets are checked in the order: site navigation budget, overall pageload
// budget, site pageload budget. Recorded to UMA; always add new values to the
// end and do not reorder or delete values from this list.
enum class SharedStorageSelectUrlBudgetStatus {};

// Whether the length of the urls input parameter (of the
// sharedStorage.runURLSelectionOperation method) is valid.
BLINK_COMMON_EXPORT bool IsValidSharedStorageURLsArrayLength(size_t length);

// Whether the length of a shared storage's key is valid.
BLINK_COMMON_EXPORT bool IsValidSharedStorageKeyStringLength(size_t length);

// Whether the length of shared storage's value is valid.
BLINK_COMMON_EXPORT bool IsValidSharedStorageValueStringLength(size_t length);

// Logs histogram of the calling method and error type for worklet errors.
BLINK_COMMON_EXPORT void LogSharedStorageWorkletError(
    SharedStorageWorkletErrorType error_type);

// Logs histogram of the `selectURL()` budget status.
BLINK_COMMON_EXPORT void LogSharedStorageSelectURLBudgetStatus(
    SharedStorageSelectUrlBudgetStatus budget_status);

// Whether `privateAggregation` should be exposed to `SharedStorageWorklet`
// scope.
BLINK_COMMON_EXPORT bool ShouldDefinePrivateAggregationInSharedStorage();

// Whether the `context_id` is valid UTF-8 and has a valid length.
BLINK_COMMON_EXPORT bool IsValidPrivateAggregationContextId(
    std::string_view context_id);

// Maximum allowed length of the context_id string.
static constexpr int kPrivateAggregationApiContextIdMaxLength =;

// Whether the `filtering_id_max_bytes` has a valid value.
BLINK_COMMON_EXPORT bool IsValidPrivateAggregationFilteringIdMaxBytes(
    size_t filtering_id_max_bytes);

static constexpr size_t kPrivateAggregationApiDefaultFilteringIdMaxBytes =;
static constexpr size_t kPrivateAggregationApiMaxFilteringIdMaxBytes =;

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_PUBLIC_COMMON_SHARED_STORAGE_SHARED_STORAGE_UTILS_H_