#ifndef DatabaseManager_h
#define DatabaseManager_h
#include "heap/Handle.h"
#include "modules/webdatabase/DatabaseBasicTypes.h"
#include "modules/webdatabase/DatabaseError.h"
#include "wtf/Assertions.h"
#include "wtf/HashMap.h"
#include "wtf/PassRefPtr.h"
#include "wtf/ThreadingPrimitives.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
class AbstractDatabaseServer;
class Database;
class DatabaseBackendBase;
class DatabaseCallback;
class DatabaseContext;
class DatabaseSync;
class TaskSynchronizer;
class ExceptionState;
class SecurityOrigin;
class ExecutionContext;
typedef int ExceptionCode;
class DatabaseManager {
WTF_MAKE_NONCOPYABLE(DatabaseManager); WTF_MAKE_FAST_ALLOCATED;
public:
static DatabaseManager& manager();
void registerDatabaseContext(DatabaseContext*);
void unregisterDatabaseContext(DatabaseContext*);
#if !ASSERT_DISABLED
void didConstructDatabaseContext();
void didDestructDatabaseContext();
#else
void didConstructDatabaseContext() { }
void didDestructDatabaseContext() { }
#endif
static void throwExceptionForDatabaseError(DatabaseError, const String& errorMessage, ExceptionState&);
PassRefPtrWillBeRawPtr<Database> openDatabase(ExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassOwnPtr<DatabaseCallback>, DatabaseError&, String& errorMessage);
PassRefPtrWillBeRawPtr<DatabaseSync> openDatabaseSync(ExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, unsigned long estimatedSize, PassOwnPtr<DatabaseCallback>, DatabaseError&, String& errorMessage);
String fullPathForDatabase(SecurityOrigin*, const String& name, bool createIfDoesNotExist = true);
void closeDatabasesImmediately(const String& originIdentifier, const String& name);
void interruptAllDatabasesForContext(DatabaseContext*);
private:
DatabaseManager();
~DatabaseManager();
DatabaseContext* databaseContextFor(ExecutionContext*);
DatabaseContext* existingDatabaseContextFor(ExecutionContext*);
PassRefPtrWillBeRawPtr<DatabaseBackendBase> openDatabaseBackend(ExecutionContext*,
DatabaseType, const String& name, const String& expectedVersion, const String& displayName,
unsigned long estimatedSize, bool setVersionInNewDatabase, DatabaseError&, String& errorMessage);
static void logErrorMessage(ExecutionContext*, const String& message);
AbstractDatabaseServer* m_server;
#if ENABLE(OILPAN)
typedef HashMap<ExecutionContext*, OwnPtr<Persistent<DatabaseContext> > > ContextMap;
#else
typedef HashMap<ExecutionContext*, RefPtr<DatabaseContext> > ContextMap;
#endif
ContextMap m_contextMap;
#if !ASSERT_DISABLED
int m_databaseContextRegisteredCount;
int m_databaseContextInstanceCount;
#endif
Mutex m_contextMapLock;
};
}
#endif