| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 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 | 14 * its contributors may be used to endorse or promote products derived |
| 15 * from this software without specific prior written permission. | 15 * from this software without specific prior written permission. |
| 16 * | 16 * |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 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 | 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 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 | 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 #ifndef DatabaseTask_h | |
| 29 #define DatabaseTask_h | |
| 30 | 28 |
| 31 #include "heap/Handle.h" | 29 #ifndef TaskSynchronizer_h |
| 32 #include "modules/webdatabase/DatabaseBackend.h" | 30 #define TaskSynchronizer_h |
| 33 #include "modules/webdatabase/DatabaseBasicTypes.h" | 31 |
| 34 #include "modules/webdatabase/DatabaseError.h" | 32 #include "wtf/Noncopyable.h" |
| 35 #include "modules/webdatabase/SQLTransactionBackend.h" | |
| 36 #include "platform/Task.h" | |
| 37 #include "wtf/OwnPtr.h" | |
| 38 #include "wtf/PassOwnPtr.h" | |
| 39 #include "wtf/PassRefPtr.h" | |
| 40 #include "wtf/RefPtr.h" | |
| 41 #include "wtf/Threading.h" | 33 #include "wtf/Threading.h" |
| 42 #include "wtf/Vector.h" | 34 #include "wtf/ThreadingPrimitives.h" |
| 43 #include "wtf/text/WTFString.h" | |
| 44 | 35 |
| 45 namespace WebCore { | 36 namespace WebCore { |
| 46 | 37 |
| 47 // Can be used to wait until DatabaseTask is completed. | 38 // TaskSynchronizer can be used to wait for task completion. |
| 48 // Has to be passed into DatabaseTask::create to be associated with the task. | 39 class TaskSynchronizer { |
| 49 class DatabaseTaskSynchronizer { | 40 WTF_MAKE_NONCOPYABLE(TaskSynchronizer); |
| 50 WTF_MAKE_NONCOPYABLE(DatabaseTaskSynchronizer); | |
| 51 public: | 41 public: |
| 52 DatabaseTaskSynchronizer(); | 42 TaskSynchronizer(); |
| 53 | 43 |
| 54 // Called from main thread to wait until task is completed. | 44 // Called from a thread that waits for the task completion. |
| 55 void waitForTaskCompletion(); | 45 void waitForTaskCompletion(); |
| 56 | 46 |
| 57 // Called by the task. | 47 // Called from a thread that executes the task. |
| 58 void taskCompleted(); | 48 void taskCompleted(); |
| 59 | 49 |
| 60 #ifndef NDEBUG | 50 #ifndef NDEBUG |
| 61 bool hasCheckedForTermination() const { return m_hasCheckedForTermination; } | 51 bool hasCheckedForTermination() const { return m_hasCheckedForTermination; } |
| 62 void setHasCheckedForTermination() { m_hasCheckedForTermination = true; } | 52 void setHasCheckedForTermination() { m_hasCheckedForTermination = true; } |
| 63 #endif | 53 #endif |
| 64 | 54 |
| 65 private: | 55 private: |
| 66 bool m_taskCompleted; | 56 bool m_taskCompleted; |
| 67 Mutex m_synchronousMutex; | 57 Mutex m_synchronousMutex; |
| 68 ThreadCondition m_synchronousCondition; | 58 ThreadCondition m_synchronousCondition; |
| 69 #ifndef NDEBUG | 59 #ifndef NDEBUG |
| 70 bool m_hasCheckedForTermination; | 60 bool m_hasCheckedForTermination; |
| 71 #endif | 61 #endif |
| 72 }; | 62 }; |
| 73 | 63 |
| 74 class DatabaseTask : public blink::WebThread::Task { | 64 } |
| 75 WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED; | |
| 76 public: | |
| 77 virtual ~DatabaseTask(); | |
| 78 | 65 |
| 79 virtual void run() OVERRIDE FINAL; | 66 #endif // TaskSynchronizer_h |
| 80 | |
| 81 DatabaseBackend* database() const { return m_database.get(); } | |
| 82 #ifndef NDEBUG | |
| 83 bool hasSynchronizer() const { return m_synchronizer; } | |
| 84 bool hasCheckedForTermination() const { return m_synchronizer->hasCheckedFor
Termination(); } | |
| 85 #endif | |
| 86 | |
| 87 protected: | |
| 88 DatabaseTask(DatabaseBackend*, DatabaseTaskSynchronizer*); | |
| 89 | |
| 90 private: | |
| 91 virtual void doPerformTask() = 0; | |
| 92 virtual void taskCancelled() { } | |
| 93 | |
| 94 RefPtrWillBeCrossThreadPersistent<DatabaseBackend> m_database; | |
| 95 DatabaseTaskSynchronizer* m_synchronizer; | |
| 96 | |
| 97 #if !LOG_DISABLED | |
| 98 virtual const char* debugTaskName() const = 0; | |
| 99 bool m_complete; | |
| 100 #endif | |
| 101 }; | |
| 102 | |
| 103 class DatabaseBackend::DatabaseOpenTask FINAL : public DatabaseTask { | |
| 104 public: | |
| 105 static PassOwnPtr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVers
ionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseError& error,
String& errorMessage, bool& success) | |
| 106 { | |
| 107 return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchr
onizer, error, errorMessage, success)); | |
| 108 } | |
| 109 | |
| 110 private: | |
| 111 DatabaseOpenTask(DatabaseBackend*, bool setVersionInNewDatabase, DatabaseTas
kSynchronizer*, DatabaseError&, String& errorMessage, bool& success); | |
| 112 | |
| 113 virtual void doPerformTask() OVERRIDE; | |
| 114 #if !LOG_DISABLED | |
| 115 virtual const char* debugTaskName() const OVERRIDE; | |
| 116 #endif | |
| 117 | |
| 118 bool m_setVersionInNewDatabase; | |
| 119 DatabaseError& m_error; | |
| 120 String& m_errorMessage; | |
| 121 bool& m_success; | |
| 122 }; | |
| 123 | |
| 124 class DatabaseBackend::DatabaseCloseTask FINAL : public DatabaseTask { | |
| 125 public: | |
| 126 static PassOwnPtr<DatabaseCloseTask> create(DatabaseBackend* db, DatabaseTas
kSynchronizer* synchronizer) | |
| 127 { | |
| 128 return adoptPtr(new DatabaseCloseTask(db, synchronizer)); | |
| 129 } | |
| 130 | |
| 131 private: | |
| 132 DatabaseCloseTask(DatabaseBackend*, DatabaseTaskSynchronizer*); | |
| 133 | |
| 134 virtual void doPerformTask() OVERRIDE; | |
| 135 #if !LOG_DISABLED | |
| 136 virtual const char* debugTaskName() const OVERRIDE; | |
| 137 #endif | |
| 138 }; | |
| 139 | |
| 140 class DatabaseBackend::DatabaseTransactionTask FINAL : public DatabaseTask { | |
| 141 public: | |
| 142 virtual ~DatabaseTransactionTask(); | |
| 143 | |
| 144 // Transaction task is never synchronous, so no 'synchronizer' parameter. | |
| 145 static PassOwnPtr<DatabaseTransactionTask> create(PassRefPtr<SQLTransactionB
ackend> transaction) | |
| 146 { | |
| 147 return adoptPtr(new DatabaseTransactionTask(transaction)); | |
| 148 } | |
| 149 | |
| 150 SQLTransactionBackend* transaction() const { return m_transaction.get(); } | |
| 151 | |
| 152 private: | |
| 153 explicit DatabaseTransactionTask(PassRefPtr<SQLTransactionBackend>); | |
| 154 | |
| 155 virtual void doPerformTask() OVERRIDE; | |
| 156 virtual void taskCancelled() OVERRIDE; | |
| 157 #if !LOG_DISABLED | |
| 158 virtual const char* debugTaskName() const OVERRIDE; | |
| 159 #endif | |
| 160 | |
| 161 RefPtr<SQLTransactionBackend> m_transaction; | |
| 162 }; | |
| 163 | |
| 164 class DatabaseBackend::DatabaseTableNamesTask FINAL : public DatabaseTask { | |
| 165 public: | |
| 166 static PassOwnPtr<DatabaseTableNamesTask> create(DatabaseBackend* db, Databa
seTaskSynchronizer* synchronizer, Vector<String>& names) | |
| 167 { | |
| 168 return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names)); | |
| 169 } | |
| 170 | |
| 171 private: | |
| 172 DatabaseTableNamesTask(DatabaseBackend*, DatabaseTaskSynchronizer*, Vector<S
tring>& names); | |
| 173 | |
| 174 virtual void doPerformTask() OVERRIDE; | |
| 175 #if !LOG_DISABLED | |
| 176 virtual const char* debugTaskName() const OVERRIDE; | |
| 177 #endif | |
| 178 | |
| 179 Vector<String>& m_tableNames; | |
| 180 }; | |
| 181 | |
| 182 } // namespace WebCore | |
| 183 | |
| 184 #endif // DatabaseTask_h | |
| OLD | NEW |