summaryrefslogtreecommitdiffstats
path: root/WebCore/storage/DatabaseTask.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/storage/DatabaseTask.h')
-rw-r--r--WebCore/storage/DatabaseTask.h79
1 files changed, 51 insertions, 28 deletions
diff --git a/WebCore/storage/DatabaseTask.h b/WebCore/storage/DatabaseTask.h
index 4aef892..97a23c7 100644
--- a/WebCore/storage/DatabaseTask.h
+++ b/WebCore/storage/DatabaseTask.h
@@ -32,6 +32,7 @@
#include "ExceptionCode.h"
#include "PlatformString.h"
#include <wtf/OwnPtr.h>
+#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/Threading.h>
#include <wtf/Vector.h>
@@ -39,13 +40,33 @@
namespace WebCore {
class Database;
+class DatabaseTask;
class DatabaseThread;
class SQLValue;
class SQLCallback;
class SQLTransaction;
class VersionChangeCallback;
-class DatabaseTask : public ThreadSafeShared<DatabaseTask> {
+// Can be used to wait until DatabaseTask is completed.
+// Has to be passed into DatabaseTask::create to be associated with the task.
+class DatabaseTaskSynchronizer : public Noncopyable {
+ friend class DatabaseTask;
+public:
+ DatabaseTaskSynchronizer();
+
+ // Called from main thread to wait until task is completed.
+ void waitForTaskCompletion();
+
+private:
+ // Called by the task.
+ void taskCompleted();
+
+ bool m_taskCompleted;
+ Mutex m_synchronousMutex;
+ ThreadCondition m_synchronousCondition;
+};
+
+class DatabaseTask : public Noncopyable {
friend class Database;
public:
virtual ~DatabaseTask();
@@ -53,53 +74,50 @@ public:
void performTask();
Database* database() const { return m_database; }
- bool isComplete() const { return m_complete; }
protected:
- DatabaseTask(Database*);
+ DatabaseTask(Database*, DatabaseTaskSynchronizer*);
private:
virtual void doPerformTask() = 0;
-#ifndef NDEBUG
- virtual const char* debugTaskName() const = 0;
-#endif
-
- void lockForSynchronousScheduling();
- void waitForSynchronousCompletion();
Database* m_database;
+ DatabaseTaskSynchronizer* m_synchronizer;
- bool m_complete;
-
- OwnPtr<Mutex> m_synchronousMutex;
- OwnPtr<ThreadCondition> m_synchronousCondition;
+#ifndef NDEBUG
+ virtual const char* debugTaskName() const = 0;
+ bool m_complete;
+#endif
};
class DatabaseOpenTask : public DatabaseTask {
public:
- static PassRefPtr<DatabaseOpenTask> create(Database* db) { return adoptRef(new DatabaseOpenTask(db)); }
-
- ExceptionCode exceptionCode() const { return m_code; }
- bool openSuccessful() const { return m_success; }
+ static PassOwnPtr<DatabaseOpenTask> create(Database* db, DatabaseTaskSynchronizer* synchronizer, ExceptionCode& code, bool& success)
+ {
+ return new DatabaseOpenTask(db, synchronizer, code, success);
+ }
private:
- DatabaseOpenTask(Database*);
+ DatabaseOpenTask(Database*, DatabaseTaskSynchronizer*, ExceptionCode&, bool& success);
virtual void doPerformTask();
#ifndef NDEBUG
virtual const char* debugTaskName() const;
#endif
- ExceptionCode m_code;
- bool m_success;
+ ExceptionCode& m_code;
+ bool& m_success;
};
class DatabaseCloseTask : public DatabaseTask {
public:
- static PassRefPtr<DatabaseCloseTask> create(Database* db) { return adoptRef(new DatabaseCloseTask(db)); }
+ static PassOwnPtr<DatabaseCloseTask> create(Database* db, DatabaseTaskSynchronizer* synchronizer)
+ {
+ return new DatabaseCloseTask(db, synchronizer);
+ }
private:
- DatabaseCloseTask(Database*);
+ DatabaseCloseTask(Database*, DatabaseTaskSynchronizer*);
virtual void doPerformTask();
#ifndef NDEBUG
@@ -109,7 +127,11 @@ private:
class DatabaseTransactionTask : public DatabaseTask {
public:
- static PassRefPtr<DatabaseTransactionTask> create(PassRefPtr<SQLTransaction> transaction) { return adoptRef(new DatabaseTransactionTask(transaction)); }
+ // Transaction task is never synchronous, so no 'synchronizer' parameter.
+ static PassOwnPtr<DatabaseTransactionTask> create(PassRefPtr<SQLTransaction> transaction)
+ {
+ return new DatabaseTransactionTask(transaction);
+ }
SQLTransaction* transaction() const { return m_transaction.get(); }
@@ -127,19 +149,20 @@ private:
class DatabaseTableNamesTask : public DatabaseTask {
public:
- static PassRefPtr<DatabaseTableNamesTask> create(Database* db) { return adoptRef(new DatabaseTableNamesTask(db)); }
-
- Vector<String>& tableNames() { return m_tableNames; }
+ static PassOwnPtr<DatabaseTableNamesTask> create(Database* db, DatabaseTaskSynchronizer* synchronizer, Vector<String>& names)
+ {
+ return new DatabaseTableNamesTask(db, synchronizer, names);
+ }
private:
- DatabaseTableNamesTask(Database*);
+ DatabaseTableNamesTask(Database*, DatabaseTaskSynchronizer*, Vector<String>& names);
virtual void doPerformTask();
#ifndef NDEBUG
virtual const char* debugTaskName() const;
#endif
- Vector<String> m_tableNames;
+ Vector<String>& m_tableNames;
};
} // namespace WebCore