#ifndef DatabaseBackendBase_h
#define DatabaseBackendBase_h
#include "heap/Handle.h"
#include "modules/webdatabase/sqlite/SQLiteDatabase.h"
#include "modules/webdatabase/DatabaseBasicTypes.h"
#include "modules/webdatabase/DatabaseError.h"
#include "wtf/Forward.h"
#include "wtf/RefPtr.h"
#include "wtf/ThreadSafeRefCounted.h"
#include "wtf/text/WTFString.h"
#if !LOG_DISABLED || !ERROR_DISABLED
#include "platform/weborigin/SecurityOrigin.h"
#endif
namespace WebCore {
class DatabaseAuthorizer;
class DatabaseContext;
class DatabaseBase;
class ExecutionContext;
class SecurityOrigin;
class DatabaseBackendBase : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<DatabaseBackendBase> {
public:
virtual ~DatabaseBackendBase();
virtual void trace(Visitor*);
virtual String version() const;
bool opened() const { return m_opened; }
bool isNew() const { return m_new; }
bool isSyncDatabase() const { return m_isSyncDatabase; }
virtual SecurityOrigin* securityOrigin() const;
virtual String stringIdentifier() const;
virtual String displayName() const;
virtual unsigned long estimatedSize() const;
virtual String fileName() const;
SQLiteDatabase& sqliteDatabase() { return m_sqliteDatabase; }
unsigned long long maximumSize() const;
void incrementalVacuumIfNeeded();
void interrupt();
bool isInterrupted();
void disableAuthorizer();
void enableAuthorizer();
void setAuthorizerPermissions(int permissions);
bool lastActionChangedDatabase();
bool lastActionWasInsert();
void resetDeletes();
bool hadDeletes();
void resetAuthorizer();
virtual void closeImmediately() = 0;
DatabaseContext* databaseContext() const { return m_databaseContext.get(); }
ExecutionContext* executionContext() const;
void setFrontend(DatabaseBase* frontend) { m_frontend = frontend; }
protected:
friend class ChangeVersionWrapper;
friend class SQLStatementBackend;
friend class SQLStatementSync;
friend class SQLTransactionBackend;
friend class SQLTransactionBackendSync;
DatabaseBackendBase(DatabaseContext*, const String& name, const String& expectedVersion,
const String& displayName, unsigned long estimatedSize, DatabaseType);
void closeDatabase();
virtual bool openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError&, String& errorMessage) = 0;
virtual bool performOpenAndVerify(bool shouldSetVersionInNewDatabase, DatabaseError&, String& errorMessage);
bool getVersionFromDatabase(String& version, bool shouldCacheVersion = true);
bool setVersionInDatabase(const String& version, bool shouldCacheVersion = true);
void setExpectedVersion(const String&);
const String& expectedVersion() const { return m_expectedVersion; }
String getCachedVersion()const;
void setCachedVersion(const String&);
bool getActualVersionForTransaction(String& version);
void reportOpenDatabaseResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode);
void reportChangeVersionResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode);
void reportStartTransactionResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode);
void reportCommitTransactionResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode);
void reportExecuteStatementResult(int errorSite, int webSqlErrorCode, int sqliteErrorCode);
void reportVacuumDatabaseResult(int sqliteErrorCode);
void logErrorMessage(const String&);
static const char* databaseInfoTableName();
RefPtr<SecurityOrigin> m_contextThreadSecurityOrigin;
RefPtrWillBeMember<DatabaseContext> m_databaseContext;
String m_name;
String m_expectedVersion;
String m_displayName;
unsigned long m_estimatedSize;
String m_filename;
DatabaseBase* m_frontend;
#if !LOG_DISABLED || !ERROR_DISABLED
String databaseDebugName() const { return m_contextThreadSecurityOrigin->toString() + "::" + m_name; }
#endif
private:
DatabaseGuid m_guid;
bool m_opened;
bool m_new;
const bool m_isSyncDatabase;
SQLiteDatabase m_sqliteDatabase;
RefPtrWillBeMember<DatabaseAuthorizer> m_databaseAuthorizer;
friend class DatabaseServer;
};
}
#endif