• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007, 2008, 2013 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 
29 #ifndef DatabaseTask_h
30 #define DatabaseTask_h
31 
32 #include "modules/webdatabase/Database.h"
33 #include "modules/webdatabase/DatabaseBasicTypes.h"
34 #include "modules/webdatabase/DatabaseError.h"
35 #include "modules/webdatabase/SQLTransactionBackend.h"
36 #include "platform/Task.h"
37 #include "platform/TaskSynchronizer.h"
38 #include "platform/heap/Handle.h"
39 #include "wtf/OwnPtr.h"
40 #include "wtf/PassOwnPtr.h"
41 #include "wtf/PassRefPtr.h"
42 #include "wtf/RefPtr.h"
43 #include "wtf/Threading.h"
44 #include "wtf/Vector.h"
45 #include "wtf/text/WTFString.h"
46 
47 namespace blink {
48 
49 class DatabaseTask : public WebThread::Task {
50     WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED;
51 public:
52     virtual ~DatabaseTask();
53 
54     virtual void run() OVERRIDE FINAL;
55 
database()56     Database* database() const { return m_database.get(); }
57 #if ENABLE(ASSERT)
hasSynchronizer()58     bool hasSynchronizer() const { return m_synchronizer; }
59 #endif
60 
61 protected:
62     DatabaseTask(Database*, TaskSynchronizer*);
63 
64 private:
65     virtual void doPerformTask() = 0;
taskCancelled()66     virtual void taskCancelled() { }
67 
68     RefPtrWillBeCrossThreadPersistent<Database> m_database;
69     TaskSynchronizer* m_synchronizer;
70 
71 #if !LOG_DISABLED
72     virtual const char* debugTaskName() const = 0;
73     bool m_complete;
74 #endif
75 };
76 
77 class Database::DatabaseOpenTask FINAL : public DatabaseTask {
78 public:
create(Database * db,bool setVersionInNewDatabase,TaskSynchronizer * synchronizer,DatabaseError & error,String & errorMessage,bool & success)79     static PassOwnPtr<DatabaseOpenTask> create(Database* db, bool setVersionInNewDatabase, TaskSynchronizer* synchronizer, DatabaseError& error, String& errorMessage, bool& success)
80     {
81         return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchronizer, error, errorMessage, success));
82     }
83 
84 private:
85     DatabaseOpenTask(Database*, bool setVersionInNewDatabase, TaskSynchronizer*, DatabaseError&, String& errorMessage, bool& success);
86 
87     virtual void doPerformTask() OVERRIDE;
88 #if !LOG_DISABLED
89     virtual const char* debugTaskName() const OVERRIDE;
90 #endif
91 
92     bool m_setVersionInNewDatabase;
93     DatabaseError& m_error;
94     String& m_errorMessage;
95     bool& m_success;
96 };
97 
98 class Database::DatabaseCloseTask FINAL : public DatabaseTask {
99 public:
create(Database * db,TaskSynchronizer * synchronizer)100     static PassOwnPtr<DatabaseCloseTask> create(Database* db, TaskSynchronizer* synchronizer)
101     {
102         return adoptPtr(new DatabaseCloseTask(db, synchronizer));
103     }
104 
105 private:
106     DatabaseCloseTask(Database*, TaskSynchronizer*);
107 
108     virtual void doPerformTask() OVERRIDE;
109 #if !LOG_DISABLED
110     virtual const char* debugTaskName() const OVERRIDE;
111 #endif
112 };
113 
114 class Database::DatabaseTransactionTask FINAL : public DatabaseTask {
115 public:
116     virtual ~DatabaseTransactionTask();
117 
118     // Transaction task is never synchronous, so no 'synchronizer' parameter.
create(PassRefPtrWillBeRawPtr<SQLTransactionBackend> transaction)119     static PassOwnPtr<DatabaseTransactionTask> create(PassRefPtrWillBeRawPtr<SQLTransactionBackend> transaction)
120     {
121         return adoptPtr(new DatabaseTransactionTask(transaction));
122     }
123 
transaction()124     SQLTransactionBackend* transaction() const { return m_transaction.get(); }
125 
126 private:
127     explicit DatabaseTransactionTask(PassRefPtrWillBeRawPtr<SQLTransactionBackend>);
128 
129     virtual void doPerformTask() OVERRIDE;
130     virtual void taskCancelled() OVERRIDE;
131 #if !LOG_DISABLED
132     virtual const char* debugTaskName() const OVERRIDE;
133 #endif
134 
135     RefPtrWillBeCrossThreadPersistent<SQLTransactionBackend> m_transaction;
136 };
137 
138 class Database::DatabaseTableNamesTask FINAL : public DatabaseTask {
139 public:
create(Database * db,TaskSynchronizer * synchronizer,Vector<String> & names)140     static PassOwnPtr<DatabaseTableNamesTask> create(Database* db, TaskSynchronizer* synchronizer, Vector<String>& names)
141     {
142         return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names));
143     }
144 
145 private:
146     DatabaseTableNamesTask(Database*, TaskSynchronizer*, Vector<String>& names);
147 
148     virtual void doPerformTask() OVERRIDE;
149 #if !LOG_DISABLED
150     virtual const char* debugTaskName() const OVERRIDE;
151 #endif
152 
153     Vector<String>& m_tableNames;
154 };
155 
156 } // namespace blink
157 
158 #endif // DatabaseTask_h
159