SessionTracker.cpp [plain text]
#include "config.h"
#include "SessionTracker.h"
#include "NetworkSession.h"
#include <WebCore/NetworkStorageSession.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/RunLoop.h>
using namespace WebCore;
namespace WebKit {
static String& identifierBase()
{
ASSERT(RunLoop::isMain());
static NeverDestroyed<String> base;
return base;
}
const String& SessionTracker::getIdentifierBase()
{
return identifierBase();
}
void SessionTracker::setIdentifierBase(const String& identifier)
{
ASSERT(RunLoop::isMain());
identifierBase() = identifier;
}
#if USE(NETWORK_SESSION)
static HashMap<PAL::SessionID, RefPtr<NetworkSession>>& staticSessionMap()
{
ASSERT(RunLoop::isMain());
static NeverDestroyed<HashMap<PAL::SessionID, RefPtr<NetworkSession>>> map;
return map;
}
NetworkSession* SessionTracker::networkSession(PAL::SessionID sessionID)
{
return staticSessionMap().get(sessionID);
}
void SessionTracker::setSession(PAL::SessionID sessionID, Ref<NetworkSession>&& session)
{
staticSessionMap().set(sessionID, WTFMove(session));
}
#endif
void SessionTracker::destroySession(PAL::SessionID sessionID)
{
ASSERT(RunLoop::isMain());
#if USE(NETWORK_SESSION)
auto session = staticSessionMap().take(sessionID);
if (session)
session->invalidateAndCancel();
#endif
NetworkStorageSession::destroySession(sessionID);
}
}