#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/modules/storage/cached_storage_area.h"
#include <inttypes.h>
#include <algorithm>
#include "base/functional/callback_helpers.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/trace_event/memory_dump_manager.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/platform/scheduler/public/main_thread.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/blink/renderer/platform/wtf/text/string_buffer.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "third_party/blink/renderer/platform/wtf/text/unicode.h"
#include "third_party/blink/renderer/platform/wtf/text/utf8.h"
namespace blink {
namespace {
enum class StorageFormat : uint8_t { … };
String PackSource(const KURL& page_url, const String& storage_area_id) { … }
void UnpackSource(const String& source,
KURL* page_url,
String* storage_area_id) { … }
base::OnceCallback<void(bool)> MakeSuccessCallback(
CachedStorageArea::Source* source) { … }
}
unsigned CachedStorageArea::GetLength() { … }
String CachedStorageArea::GetKey(unsigned index) { … }
String CachedStorageArea::GetItem(const String& key) { … }
bool CachedStorageArea::SetItem(const String& key,
const String& value,
Source* source) { … }
void CachedStorageArea::EnqueueCheckpointMicrotask(Source* source) { … }
void CachedStorageArea::NotifyCheckpoint() { … }
void CachedStorageArea::RemoveItem(const String& key, Source* source) { … }
void CachedStorageArea::Clear(Source* source) { … }
String CachedStorageArea::RegisterSource(Source* source) { … }
CachedStorageArea::CachedStorageArea(
AreaType type,
const BlinkStorageKey& storage_key,
LocalDOMWindow* local_dom_window,
StorageNamespace* storage_namespace,
bool is_session_storage_for_prerendering,
mojo::PendingRemote<mojom::blink::StorageArea> storage_area)
: … { … }
CachedStorageArea::~CachedStorageArea() { … }
LocalDOMWindow* CachedStorageArea::GetBestCurrentDOMWindow() { … }
void CachedStorageArea::BindStorageArea(
mojo::PendingRemote<mojom::blink::StorageArea> new_area,
LocalDOMWindow* local_dom_window) { … }
void CachedStorageArea::ResetConnection(
mojo::PendingRemote<mojom::blink::StorageArea> new_area) { … }
void CachedStorageArea::KeyChanged(
const Vector<uint8_t>& key,
const Vector<uint8_t>& new_value,
const std::optional<Vector<uint8_t>>& old_value,
const String& source) { … }
void CachedStorageArea::KeyChangeFailed(const Vector<uint8_t>& key,
const String& source) { … }
void CachedStorageArea::KeyDeleted(
const Vector<uint8_t>& key,
const std::optional<Vector<uint8_t>>& old_value,
const String& source) { … }
void CachedStorageArea::AllDeleted(bool was_nonempty, const String& source) { … }
void CachedStorageArea::ShouldSendOldValueOnMutations(bool value) { … }
bool CachedStorageArea::OnMemoryDump(
const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) { … }
void CachedStorageArea::EnqueuePendingMutation(const String& key,
const String& new_value,
const String& old_value,
const String& source) { … }
std::unique_ptr<CachedStorageArea::PendingMutation>
CachedStorageArea::PopPendingMutation(const String& source) { … }
void CachedStorageArea::MaybeApplyNonLocalMutationForKey(
const String& key,
const String& new_value) { … }
void CachedStorageArea::EnsureLoaded() { … }
CachedStorageArea::FormatOption CachedStorageArea::GetKeyFormat() const { … }
CachedStorageArea::FormatOption CachedStorageArea::GetValueFormat() const { … }
bool CachedStorageArea::IsSessionStorage() const { … }
void CachedStorageArea::EnqueueStorageEvent(const String& key,
const String& old_value,
const String& new_value,
const String& url,
const String& storage_area_id) { … }
String CachedStorageArea::Uint8VectorToString(const Vector<uint8_t>& input,
FormatOption format_option) { … }
Vector<uint8_t> CachedStorageArea::StringToUint8Vector(
const String& input,
FormatOption format_option) { … }
void CachedStorageArea::EvictCachedData() { … }
}