chromium/third_party/blink/renderer/platform/heap/cross_thread_handle_internal.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_RENDERER_PLATFORM_HEAP_CROSS_THREAD_HANDLE_INTERNAL_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_CROSS_THREAD_HANDLE_INTERNAL_H_

#include "base/functional/bind.h"
#include "base/threading/platform_thread.h"
#include "third_party/blink/renderer/platform/heap/heap_buildflags.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier.h"
#include "v8/include/cppgc/cross-thread-persistent.h"
#include "v8/include/cppgc/source-location.h"

// Required to optimize away locations for builds that do not need them to avoid
// binary size blowup.
// Same as in `platform/heap/persistent.h`. Avoiding the include to avoid
// exposing other types that are harder to use in concurrent contexts.
#if BUILDFLAG(VERBOSE_PERSISTENT)
#define CROSS_THREAD_HANDLE_LOCATION_FROM_HERE
#else  // !BUILDFLAG(VERBOSE_PERSISTENT)
#define CROSS_THREAD_HANDLE_LOCATION_FROM_HERE
#endif  // !BUILDFLAG(VERBOSE_PERSISTENT)

namespace blink {

template <typename T, typename WeaknessPolicy>
class BasicUnwrappingCrossThreadHandle;

// A source location that is used for tracking creation of
// `CrossThreadHandle` and `CrossThreadWeakHandle` in debugging
// configurations.
CrossThreadHandleLocation;

namespace internal {

struct StrongCrossThreadHandleWeaknessPolicy {};

struct WeakCrossThreadHandleWeaknessPolicy {};

template <typename T, typename WeaknessPolicy>
class BasicCrossThreadHandle {};

template <typename T, typename WeaknessPolicy>
class BasicUnwrappingCrossThreadHandle final
    : public BasicCrossThreadHandle<T, WeaknessPolicy> {};

}  // namespace internal
}  // namespace blink

namespace WTF {

CrossThreadCopier<blink::internal::BasicCrossThreadHandle<T, WeaknessPolicy>>;

CrossThreadCopier<blink::internal::BasicUnwrappingCrossThreadHandle<T, WeaknessPolicy>>;

}  // namespace WTF

namespace base {

IsWeakReceiver<blink::internal::BasicUnwrappingCrossThreadHandle<T, blink::internal::WeakCrossThreadHandleWeaknessPolicy>>;

BindUnwrapTraits<blink::internal::BasicUnwrappingCrossThreadHandle<T, WeaknessPolicy>>;

MaybeValidTraits<blink::internal::BasicCrossThreadHandle<T, WeaknessPolicy>>;

MaybeValidTraits<blink::internal::BasicUnwrappingCrossThreadHandle<T, WeaknessPolicy>>;

}  // namespace base

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_HEAP_CROSS_THREAD_HANDLE_INTERNAL_H_