• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef DatabaseTask_h
29 #define DatabaseTask_h
30 
31 #if ENABLE(DATABASE)
32 #include "ExceptionCode.h"
33 #include "PlatformString.h"
34 #include <wtf/OwnPtr.h>
35 #include <wtf/PassRefPtr.h>
36 #include <wtf/Threading.h>
37 #include <wtf/Vector.h>
38 
39 namespace WebCore {
40 
41 class Database;
42 class DatabaseThread;
43 class SQLValue;
44 class SQLCallback;
45 class SQLTransaction;
46 class VersionChangeCallback;
47 
48 class DatabaseTask : public ThreadSafeShared<DatabaseTask> {
49     friend class Database;
50 public:
51     virtual ~DatabaseTask();
52 
53     void performTask();
54 
database()55     Database* database() const { return m_database; }
isComplete()56     bool isComplete() const { return m_complete; }
57 
58 protected:
59     DatabaseTask(Database*);
60 
61 private:
62     virtual void doPerformTask() = 0;
63 #ifndef NDEBUG
64     virtual const char* debugTaskName() const = 0;
65 #endif
66 
67     void lockForSynchronousScheduling();
68     void waitForSynchronousCompletion();
69 
70     Database* m_database;
71 
72     bool m_complete;
73 
74     OwnPtr<Mutex> m_synchronousMutex;
75     OwnPtr<ThreadCondition> m_synchronousCondition;
76 };
77 
78 class DatabaseOpenTask : public DatabaseTask {
79 public:
create(Database * db)80     static PassRefPtr<DatabaseOpenTask> create(Database* db) { return adoptRef(new DatabaseOpenTask(db)); }
81 
exceptionCode()82     ExceptionCode exceptionCode() const { return m_code; }
openSuccessful()83     bool openSuccessful() const { return m_success; }
84 
85 private:
86     DatabaseOpenTask(Database*);
87 
88     virtual void doPerformTask();
89 #ifndef NDEBUG
90     virtual const char* debugTaskName() const;
91 #endif
92 
93     ExceptionCode m_code;
94     bool m_success;
95 };
96 
97 class DatabaseCloseTask : public DatabaseTask {
98 public:
create(Database * db)99     static PassRefPtr<DatabaseCloseTask> create(Database* db) { return adoptRef(new DatabaseCloseTask(db)); }
100 
101 private:
102     DatabaseCloseTask(Database*);
103 
104     virtual void doPerformTask();
105 #ifndef NDEBUG
106     virtual const char* debugTaskName() const;
107 #endif
108 };
109 
110 class DatabaseTransactionTask : public DatabaseTask {
111 public:
create(PassRefPtr<SQLTransaction> transaction)112     static PassRefPtr<DatabaseTransactionTask> create(PassRefPtr<SQLTransaction> transaction) { return adoptRef(new DatabaseTransactionTask(transaction)); }
113 
transaction()114     SQLTransaction* transaction() const { return m_transaction.get(); }
115 
116     virtual ~DatabaseTransactionTask();
117 private:
118     DatabaseTransactionTask(PassRefPtr<SQLTransaction>);
119 
120     virtual void doPerformTask();
121 #ifndef NDEBUG
122     virtual const char* debugTaskName() const;
123 #endif
124 
125     RefPtr<SQLTransaction> m_transaction;
126 };
127 
128 class DatabaseTableNamesTask : public DatabaseTask {
129 public:
create(Database * db)130     static PassRefPtr<DatabaseTableNamesTask> create(Database* db) { return adoptRef(new DatabaseTableNamesTask(db)); }
131 
tableNames()132     Vector<String>& tableNames() { return m_tableNames; }
133 
134 private:
135     DatabaseTableNamesTask(Database*);
136 
137     virtual void doPerformTask();
138 #ifndef NDEBUG
139     virtual const char* debugTaskName() const;
140 #endif
141 
142     Vector<String> m_tableNames;
143 };
144 
145 } // namespace WebCore
146 
147 #endif // ENABLE(DATABASE)
148 #endif // DatabaseTask_h
149