#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/bindings/parkable_string.h"
#include <array>
#include <string_view>
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/process/memory.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/trace_event/typed_macros.h"
#include "partition_alloc/oom.h"
#include "partition_alloc/partition_alloc.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/platform/bindings/buildflags.h"
#include "third_party/blink/renderer/platform/bindings/parkable_string_manager.h"
#include "third_party/blink/renderer/platform/crypto.h"
#include "third_party/blink/renderer/platform/disk_data_allocator.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/web_process_memory_dump.h"
#include "third_party/blink/renderer/platform/scheduler/public/post_cross_thread_task.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/scheduler/public/worker_pool.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/allocator/partitions.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_base.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_copier_std.h"
#include "third_party/blink/renderer/platform/wtf/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/sanitizers.h"
#include "third_party/blink/renderer/platform/wtf/thread_specific.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/snappy/src/snappy.h"
#include "third_party/zlib/google/compression_utils.h"
#if BUILDFLAG(HAS_ZSTD_COMPRESSION)
#include "third_party/zstd/src/lib/zstd.h"
#endif
namespace blink {
namespace {
ParkableStringImpl::Age MakeOlder(ParkableStringImpl::Age age) { … }
enum class ParkingAction { … };
void RecordLatencyHistogram(const char* histogram_name,
base::TimeDelta duration) { … }
void RecordThroughputHistogram(const char* histogram_name,
int throughput_mb_s) { … }
void RecordStatistics(size_t size,
base::TimeDelta duration,
ParkingAction action) { … }
void AsanPoisonString(const String& string) { … }
void AsanUnpoisonString(const String& string) { … }
class NullableCharBuffer final { … };
}
struct BackgroundTaskParams final { … };
enum class ParkableStringImpl::State : uint8_t { … };
enum class ParkableStringImpl::Status : uint8_t { … };
ParkableStringImpl::ParkableMetadata::ParkableMetadata(
String string,
std::unique_ptr<SecureDigest> digest)
: … { … }
std::unique_ptr<ParkableStringImpl::SecureDigest>
ParkableStringImpl::HashString(StringImpl* string) { … }
scoped_refptr<ParkableStringImpl> ParkableStringImpl::MakeNonParkable(
scoped_refptr<StringImpl>&& impl) { … }
scoped_refptr<ParkableStringImpl> ParkableStringImpl::MakeParkable(
scoped_refptr<StringImpl>&& impl,
std::unique_ptr<SecureDigest> digest) { … }
ParkableStringImpl::CompressionAlgorithm
ParkableStringImpl::GetCompressionAlgorithm() { … }
ParkableStringImpl::ParkableStringImpl(scoped_refptr<StringImpl>&& impl,
std::unique_ptr<SecureDigest> digest)
: … { … }
ParkableStringImpl::~ParkableStringImpl() { … }
void ParkableStringImpl::Lock() { … }
void ParkableStringImpl::Unlock() { … }
const String& ParkableStringImpl::ToString() { … }
size_t ParkableStringImpl::CharactersSizeInBytes() const { … }
size_t ParkableStringImpl::MemoryFootprintForDump() const { … }
ParkableStringImpl::AgeOrParkResult ParkableStringImpl::MaybeAgeOrParkString() { … }
bool ParkableStringImpl::Park(ParkingMode mode) { … }
bool ParkableStringImpl::ParkInternal(ParkingMode mode) { … }
void ParkableStringImpl::DiscardUncompressedData() { … }
void ParkableStringImpl::DiscardCompressedData() { … }
bool ParkableStringImpl::is_parked_no_lock() const { … }
bool ParkableStringImpl::is_on_disk_no_lock() const { … }
bool ParkableStringImpl::is_compression_failed_no_lock() const { … }
bool ParkableStringImpl::is_parked() const { … }
bool ParkableStringImpl::is_on_disk() const { … }
ParkableStringImpl::Status ParkableStringImpl::CurrentStatus() const { … }
bool ParkableStringImpl::CanParkNow() const { … }
void ParkableStringImpl::Unpark() { … }
String ParkableStringImpl::UnparkInternal() { … }
void ParkableStringImpl::ReleaseAndRemoveIfNeeded() const { … }
void ParkableStringImpl::PostBackgroundCompressionTask() { … }
void ParkableStringImpl::CompressInBackground(
std::unique_ptr<BackgroundTaskParams> params) { … }
void ParkableStringImpl::OnParkingCompleteOnMainThread(
std::unique_ptr<BackgroundTaskParams> params,
std::unique_ptr<Vector<uint8_t>> compressed,
base::TimeDelta parking_thread_time) { … }
void ParkableStringImpl::PostBackgroundWritingTask(
std::unique_ptr<ReservedChunk> reserved_chunk) { … }
void ParkableStringImpl::WriteToDiskInBackground(
std::unique_ptr<BackgroundTaskParams> params,
DiskDataAllocator* data_allocator) { … }
void ParkableStringImpl::OnWritingCompleteOnMainThread(
std::unique_ptr<BackgroundTaskParams> params,
std::unique_ptr<DiskDataMetadata> on_disk_metadata,
base::TimeDelta writing_time) { … }
ParkableString::ParkableString(scoped_refptr<StringImpl>&& impl)
: … { … }
ParkableString::ParkableString(
scoped_refptr<StringImpl>&& impl,
std::unique_ptr<ParkableStringImpl::SecureDigest> digest) { … }
ParkableString::~ParkableString() = default;
void ParkableString::Lock() const { … }
void ParkableString::Unlock() const { … }
void ParkableString::OnMemoryDump(WebProcessMemoryDump* pmd,
const String& name) const { … }
bool ParkableString::Is8Bit() const { … }
const String& ParkableString::ToString() const { … }
size_t ParkableString::CharactersSizeInBytes() const { … }
}