#pragma once
#include "Connection.h"
#include "StorageAreaIdentifier.h"
#include "StorageAreaImplIdentifier.h"
#include <WebCore/SecurityOriginData.h>
#include <wtf/Forward.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
class StorageMap;
}
namespace WebKit {
class LocalStorageDatabase;
class LocalStorageNamespace;
class StorageArea : public CanMakeWeakPtr<StorageArea> {
WTF_MAKE_NONCOPYABLE(StorageArea);
WTF_MAKE_FAST_ALLOCATED;
public:
using Identifier = StorageAreaIdentifier;
StorageArea(LocalStorageNamespace*, const WebCore::SecurityOriginData&, unsigned quotaInBytes, Ref<WorkQueue>&&);
~StorageArea();
const WebCore::SecurityOriginData& securityOrigin() const { return m_securityOrigin; }
Identifier identifier() { return m_identifier; }
void addListener(IPC::Connection::UniqueID);
void removeListener(IPC::Connection::UniqueID);
bool hasListener(IPC::Connection::UniqueID connectionID) const;
std::unique_ptr<StorageArea> clone() const;
void setItem(IPC::Connection::UniqueID sourceConnection, StorageAreaImplIdentifier, const String& key, const String& value, const String& urlString, bool& quotaException);
void removeItem(IPC::Connection::UniqueID sourceConnection, StorageAreaImplIdentifier, const String& key, const String& urlString);
void clear(IPC::Connection::UniqueID sourceConnection, StorageAreaImplIdentifier, const String& urlString);
const HashMap<String, String>& items() const;
void clear();
bool isEphemeral() const { return !m_localStorageNamespace; }
void openDatabaseAndImportItemsIfNeeded() const;
void syncToDatabase();
void close();
private:
void dispatchEvents(IPC::Connection::UniqueID sourceConnection, StorageAreaImplIdentifier, const String& key, const String& oldValue, const String& newValue, const String& urlString) const;
WeakPtr<LocalStorageNamespace> m_localStorageNamespace;
mutable RefPtr<LocalStorageDatabase> m_localStorageDatabase;
mutable bool m_didImportItemsFromDatabase { false };
WebCore::SecurityOriginData m_securityOrigin;
unsigned m_quotaInBytes { 0 };
RefPtr<WebCore::StorageMap> m_storageMap;
HashSet<IPC::Connection::UniqueID> m_eventListeners;
Identifier m_identifier;
Ref<WorkQueue> m_queue;
};
}