summaryrefslogtreecommitdiff
path: root/Source/WebCore/Modules/webdatabase/Database.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/Modules/webdatabase/Database.h')
-rw-r--r--Source/WebCore/Modules/webdatabase/Database.h161
1 files changed, 119 insertions, 42 deletions
diff --git a/Source/WebCore/Modules/webdatabase/Database.h b/Source/WebCore/Modules/webdatabase/Database.h
index 068468acb..348d6ae2f 100644
--- a/Source/WebCore/Modules/webdatabase/Database.h
+++ b/Source/WebCore/Modules/webdatabase/Database.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2008, 2013, 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -10,7 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -26,80 +26,157 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef Database_h
-#define Database_h
+#pragma once
-#if ENABLE(SQL_DATABASE)
-
-#include "DatabaseBackend.h"
-#include "DatabaseBase.h"
-#include "DatabaseBasicTypes.h"
-#include "DatabaseError.h"
-#include <wtf/text/WTFString.h>
+#include "ExceptionOr.h"
+#include "SQLiteDatabase.h"
+#include <wtf/Deque.h>
+#include <wtf/Lock.h>
namespace WebCore {
-class ChangeVersionData;
class DatabaseCallback;
class DatabaseContext;
+class DatabaseDetails;
+class DatabaseThread;
+class ScriptExecutionContext;
class SecurityOrigin;
class SQLTransaction;
class SQLTransactionBackend;
class SQLTransactionCallback;
+class SQLTransactionCoordinator;
class SQLTransactionErrorCallback;
+class SQLTransactionWrapper;
class VoidCallback;
+struct SecurityOriginData;
+
+using DatabaseGUID = int;
-class Database : public DatabaseBase, public DatabaseBackend {
+class Database : public ThreadSafeRefCounted<Database> {
public:
- virtual ~Database();
+ ~Database();
+
+ ExceptionOr<void> openAndVerifyVersion(bool setVersionInNewDatabase);
+ void close();
+
+ void interrupt();
+
+ bool opened() const { return m_opened; }
+ bool isNew() const { return m_new; }
+
+ unsigned long long maximumSize();
+
+ void scheduleTransactionStep(SQLTransaction&);
+ void inProgressTransactionCompleted();
+
+ bool hasPendingTransaction();
+
+ bool hasPendingCreationEvent() const { return m_hasPendingCreationEvent; }
+ void setHasPendingCreationEvent(bool value) { m_hasPendingCreationEvent = value; }
+
+ void didCommitWriteTransaction();
+ bool didExceedQuota();
+
+ SQLTransactionCoordinator* transactionCoordinator();
// Direct support for the DOM API
- virtual String version() const;
- void changeVersion(const String& oldVersion, const String& newVersion, PassRefPtr<SQLTransactionCallback>,
- PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback);
- void transaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback);
- void readTransaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback);
+ String version() const;
+ void changeVersion(const String& oldVersion, const String& newVersion, RefPtr<SQLTransactionCallback>&&, RefPtr<SQLTransactionErrorCallback>&&, RefPtr<VoidCallback>&& successCallback);
+ void transaction(RefPtr<SQLTransactionCallback>&&, RefPtr<SQLTransactionErrorCallback>&&, RefPtr<VoidCallback>&& successCallback);
+ void readTransaction(RefPtr<SQLTransactionCallback>&&, RefPtr<SQLTransactionErrorCallback>&&, RefPtr<VoidCallback>&& successCallback);
// Internal engine support
- static Database* from(DatabaseBackend*);
- DatabaseContext* databaseContext() const { return m_databaseContext.get(); }
+ String stringIdentifier() const;
+ String displayName() const;
+ unsigned estimatedSize() const;
+ String fileName() const;
+ DatabaseDetails details() const;
+ SQLiteDatabase& sqliteDatabase() { return m_sqliteDatabase; }
+
+ void disableAuthorizer();
+ void enableAuthorizer();
+ void setAuthorizerPermissions(int);
+ bool lastActionChangedDatabase();
+ bool lastActionWasInsert();
+ void resetDeletes();
+ bool hadDeletes();
+ void resetAuthorizer();
+
+ DatabaseContext& databaseContext() { return m_databaseContext; }
+ DatabaseThread& databaseThread();
+ ScriptExecutionContext& scriptExecutionContext() { return m_scriptExecutionContext; }
+ void logErrorMessage(const String& message);
Vector<String> tableNames();
- virtual SecurityOrigin* securityOrigin() const;
+ SecurityOriginData securityOrigin();
- virtual void markAsDeletedAndClose();
+ void markAsDeletedAndClose();
bool deleted() const { return m_deleted; }
- virtual void closeImmediately();
-
void scheduleTransactionCallback(SQLTransaction*);
+ void incrementalVacuumIfNeeded();
+
+ // Called from DatabaseTask
+ ExceptionOr<void> performOpenAndVerify(bool shouldSetVersionInNewDatabase);
+ Vector<String> performGetTableNames();
+
+ // Called from DatabaseTask and DatabaseThread
+ void performClose();
+
private:
- Database(PassRefPtr<DatabaseBackendContext>, const String& name,
- const String& expectedVersion, const String& displayName, unsigned long estimatedSize);
- PassRefPtr<DatabaseBackend> backend();
- static PassRefPtr<Database> create(ScriptExecutionContext*, PassRefPtr<DatabaseBackendBase>);
+ Database(DatabaseContext&, const String& name, const String& expectedVersion, const String& displayName, unsigned estimatedSize);
- void runTransaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>,
- PassRefPtr<VoidCallback> successCallback, bool readOnly, const ChangeVersionData* = 0);
+ void closeDatabase();
- Vector<String> performGetTableNames();
+ 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 scheduleTransaction();
+
+ void runTransaction(RefPtr<SQLTransactionCallback>&&, RefPtr<SQLTransactionErrorCallback>&&, RefPtr<VoidCallback>&& successCallback, RefPtr<SQLTransactionWrapper>&&, bool readOnly);
+
+#if !LOG_DISABLED || !ERROR_DISABLED
+ String databaseDebugName() const;
+#endif
+
+ Ref<ScriptExecutionContext> m_scriptExecutionContext;
+ Ref<SecurityOrigin> m_contextThreadSecurityOrigin;
+ Ref<SecurityOrigin> m_databaseThreadSecurityOrigin;
+ Ref<DatabaseContext> m_databaseContext;
- RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin;
- RefPtr<DatabaseContext> m_databaseContext;
+ bool m_deleted { false };
+ bool m_hasPendingCreationEvent { false };
- bool m_deleted;
+ String m_name;
+ String m_expectedVersion;
+ String m_displayName;
+ unsigned m_estimatedSize;
+ String m_filename;
+ DatabaseGUID m_guid;
+ bool m_opened { false };
+ bool m_new { false };
+
+ SQLiteDatabase m_sqliteDatabase;
+
+ Ref<DatabaseAuthorizer> m_databaseAuthorizer;
+
+ Deque<Ref<SQLTransaction>> m_transactionQueue;
+ Lock m_transactionInProgressMutex;
+ bool m_transactionInProgress { false };
+ bool m_isTransactionQueueEnabled { true };
+
+ friend class ChangeVersionWrapper;
friend class DatabaseManager;
- friend class DatabaseServer; // FIXME: remove this when the backend has been split out.
- friend class DatabaseBackend; // FIXME: remove this when the backend has been split out.
- friend class SQLStatement;
friend class SQLTransaction;
+ friend class SQLTransactionBackend;
};
} // namespace WebCore
-
-#endif // ENABLE(SQL_DATABASE)
-
-#endif // Database_h