IDBFactoryBackendImpl.cpp [plain text]
#include "config.h"
#include "IDBFactoryBackendImpl.h"
#include "DOMStringList.h"
#include "IDBDatabaseBackendImpl.h"
#include "IDBDatabaseException.h"
#include "IDBLevelDBBackingStore.h"
#include "IDBSQLiteBackingStore.h"
#include "IDBTransactionCoordinator.h"
#include "SecurityOrigin.h"
#include <wtf/Threading.h>
#include <wtf/UnusedParam.h>
#if ENABLE(INDEXED_DATABASE)
namespace WebCore {
IDBFactoryBackendImpl::IDBFactoryBackendImpl()
: m_transactionCoordinator(IDBTransactionCoordinator::create())
{
}
IDBFactoryBackendImpl::~IDBFactoryBackendImpl()
{
}
void IDBFactoryBackendImpl::removeIDBDatabaseBackend(const String& uniqueIdentifier)
{
ASSERT(m_databaseBackendMap.contains(uniqueIdentifier));
m_databaseBackendMap.remove(uniqueIdentifier);
}
void IDBFactoryBackendImpl::addIDBBackingStore(const String& uniqueIdentifier, IDBBackingStore* backingStore)
{
ASSERT(!m_backingStoreMap.contains(uniqueIdentifier));
m_backingStoreMap.set(uniqueIdentifier, backingStore);
}
void IDBFactoryBackendImpl::removeIDBBackingStore(const String& uniqueIdentifier)
{
ASSERT(m_backingStoreMap.contains(uniqueIdentifier));
m_backingStoreMap.remove(uniqueIdentifier);
}
void IDBFactoryBackendImpl::open(const String& name, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<SecurityOrigin> securityOrigin, Frame*, const String& dataDir, int64_t maximumSize, BackingStoreType backingStoreType)
{
String fileIdentifier = securityOrigin->databaseIdentifier();
String uniqueIdentifier = fileIdentifier + "@" + name;
IDBDatabaseBackendMap::iterator it = m_databaseBackendMap.find(uniqueIdentifier);
if (it != m_databaseBackendMap.end()) {
callbacks->onSuccess(it->second);
return;
}
RefPtr<IDBBackingStore> backingStore;
IDBBackingStoreMap::iterator it2 = m_backingStoreMap.find(fileIdentifier);
if (it2 != m_backingStoreMap.end())
backingStore = it2->second;
else {
if (backingStoreType == DefaultBackingStore)
backingStore = IDBSQLiteBackingStore::open(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
#if ENABLE(LEVELDB)
else if (backingStoreType == LevelDBBackingStore)
backingStore = IDBLevelDBBackingStore::open(securityOrigin.get(), dataDir, maximumSize, fileIdentifier, this);
#endif
if (!backingStore) {
callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
return;
}
}
RefPtr<IDBDatabaseBackendImpl> databaseBackend = IDBDatabaseBackendImpl::create(name, backingStore.get(), m_transactionCoordinator.get(), this, uniqueIdentifier);
callbacks->onSuccess(databaseBackend.get());
m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
}
}
#endif // ENABLE(INDEXED_DATABASE)