WebSWOriginStore.cpp [plain text]
#include "config.h"
#if ENABLE(SERVICE_WORKER)
#include "WebSWOriginStore.h"
#include "WebSWClientConnectionMessages.h"
#include "WebSWServerConnection.h"
#include <WebCore/SecurityOrigin.h>
namespace WebKit {
using namespace WebCore;
WebSWOriginStore::WebSWOriginStore()
: m_store(*this)
{
}
void WebSWOriginStore::addToStore(const SecurityOriginData& origin)
{
m_store.scheduleAddition(computeSharedStringHash(origin.toString()));
m_store.flushPendingChanges();
}
void WebSWOriginStore::removeFromStore(const SecurityOriginData& origin)
{
m_store.scheduleRemoval(computeSharedStringHash(origin.toString()));
m_store.flushPendingChanges();
}
void WebSWOriginStore::clearStore()
{
m_store.clear();
}
void WebSWOriginStore::importComplete()
{
m_isImported = true;
for (auto* connection : m_webSWServerConnections)
connection->send(Messages::WebSWClientConnection::SetSWOriginTableIsImported());
}
void WebSWOriginStore::registerSWServerConnection(WebSWServerConnection& connection)
{
m_webSWServerConnections.add(&connection);
if (!m_store.isEmpty())
sendStoreHandle(connection);
if (m_isImported)
connection.send(Messages::WebSWClientConnection::SetSWOriginTableIsImported());
}
void WebSWOriginStore::unregisterSWServerConnection(WebSWServerConnection& connection)
{
m_webSWServerConnections.remove(&connection);
}
void WebSWOriginStore::sendStoreHandle(WebSWServerConnection& connection)
{
SharedMemory::Handle handle;
if (!m_store.createSharedMemoryHandle(handle))
return;
connection.send(Messages::WebSWClientConnection::SetSWOriginTableSharedMemory(handle));
}
void WebSWOriginStore::didInvalidateSharedMemory()
{
for (auto* connection : m_webSWServerConnections)
sendStoreHandle(*connection);
}
}
#endif // ENABLE(SERVICE_WORKER)