SessionTracker.cpp [plain text]
#include "config.h"
#include "SessionTracker.h"
#include <wtf/NeverDestroyed.h>
#include <wtf/RunLoop.h>
using namespace WebCore;
namespace WebKit {
static HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>& staticSessionMap()
{
ASSERT(RunLoop::isMain());
static NeverDestroyed<HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>> map;
return map.get();
}
static HashMap<const NetworkStorageSession*, SessionID>& storageSessionToID()
{
ASSERT(RunLoop::isMain());
static NeverDestroyed<HashMap<const NetworkStorageSession*, SessionID>> map;
return map.get();
}
static String& identifierBase()
{
ASSERT(RunLoop::isMain());
static NeverDestroyed<String> base;
return base;
}
const HashMap<SessionID, std::unique_ptr<NetworkStorageSession>>& SessionTracker::sessionMap()
{
return staticSessionMap();
}
const String& SessionTracker::getIdentifierBase()
{
return identifierBase();
}
NetworkStorageSession* SessionTracker::session(SessionID sessionID)
{
if (sessionID == SessionID::defaultSessionID())
return &NetworkStorageSession::defaultStorageSession();
return staticSessionMap().get(sessionID);
}
SessionID SessionTracker::sessionID(const NetworkStorageSession& session)
{
if (&session == &NetworkStorageSession::defaultStorageSession())
return SessionID::defaultSessionID();
return storageSessionToID().get(&session);
}
void SessionTracker::setSession(SessionID sessionID, std::unique_ptr<NetworkStorageSession> session)
{
ASSERT(sessionID != SessionID::defaultSessionID());
storageSessionToID().set(session.get(), sessionID);
staticSessionMap().set(sessionID, WTF::move(session));
}
void SessionTracker::destroySession(SessionID sessionID)
{
ASSERT(RunLoop::isMain());
if (staticSessionMap().contains(sessionID)) {
storageSessionToID().remove(session(sessionID));
staticSessionMap().remove(sessionID);
}
}
void SessionTracker::setIdentifierBase(const String& identifier)
{
ASSERT(RunLoop::isMain());
identifierBase() = identifier;
}
}