ladybird/Libraries/LibWeb/StorageAPI/StorageShelf.h
Aliaksandr Kalenik f53559cb55 LibWeb: Change Storage{Bottle,Bucket,Shelf} to be GC-allocated
In upcoming changes StorageBottle will own pointers to GC-allocated
objects, so it needs to be a GC-allocated object itself to avoid
introducing more GC roots.
2025-06-12 17:04:35 +02:00

39 lines
1.1 KiB
C++

/*
* Copyright (c) 2024-2025, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/String.h>
#include <LibGC/Ptr.h>
#include <LibWeb/StorageAPI/StorageBottle.h>
#include <LibWeb/StorageAPI/StorageType.h>
namespace Web::StorageAPI {
// https://storage.spec.whatwg.org/#storage-shelf
// A storage shelf exists for each storage key within a storage shed. It holds a bucket map, which is a map of strings to storage buckets.
using BucketMap = OrderedHashMap<String, GC::Ref<StorageBucket>>;
class StorageShelf : public GC::Cell {
GC_CELL(StorageShelf, GC::Cell);
GC_DECLARE_ALLOCATOR(StorageShelf);
public:
static GC::Ref<StorageShelf> create(GC::Heap& heap, StorageType type) { return heap.allocate<StorageShelf>(type); }
BucketMap& bucket_map() { return m_bucket_map; }
BucketMap const& bucket_map() const { return m_bucket_map; }
virtual void visit_edges(GC::Cell::Visitor& visitor) override;
private:
explicit StorageShelf(StorageType);
BucketMap m_bucket_map;
};
}