| 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 | |
| 29 #ifndef DatabaseTask_h | 28 #ifndef DatabaseTask_h |
| 30 #define DatabaseTask_h | 29 #define DatabaseTask_h |
| 31 | 30 |
| 32 #include "heap/Handle.h" | 31 #include "heap/Handle.h" |
| 33 #include "modules/webdatabase/DatabaseBackend.h" | 32 #include "modules/webdatabase/DatabaseBackend.h" |
| 34 #include "modules/webdatabase/DatabaseBasicTypes.h" | 33 #include "modules/webdatabase/DatabaseBasicTypes.h" |
| 35 #include "modules/webdatabase/DatabaseError.h" | 34 #include "modules/webdatabase/DatabaseError.h" |
| 36 #include "modules/webdatabase/SQLTransactionBackend.h" | 35 #include "modules/webdatabase/SQLTransactionBackend.h" |
| 37 #include "platform/Task.h" | 36 #include "platform/Task.h" |
| 38 #include "platform/TaskSynchronizer.h" | |
| 39 #include "wtf/OwnPtr.h" | 37 #include "wtf/OwnPtr.h" |
| 40 #include "wtf/PassOwnPtr.h" | 38 #include "wtf/PassOwnPtr.h" |
| 41 #include "wtf/PassRefPtr.h" | 39 #include "wtf/PassRefPtr.h" |
| 42 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 43 #include "wtf/Threading.h" | 41 #include "wtf/Threading.h" |
| 44 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
| 45 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.h" |
| 46 | 44 |
| 47 namespace WebCore { | 45 namespace WebCore { |
| 48 | 46 |
| 47 // Can be used to wait until DatabaseTask is completed. |
| 48 // Has to be passed into DatabaseTask::create to be associated with the task. |
| 49 class DatabaseTaskSynchronizer { |
| 50 WTF_MAKE_NONCOPYABLE(DatabaseTaskSynchronizer); |
| 51 public: |
| 52 DatabaseTaskSynchronizer(); |
| 53 |
| 54 // Called from main thread to wait until task is completed. |
| 55 void waitForTaskCompletion(); |
| 56 |
| 57 // Called by the task. |
| 58 void taskCompleted(); |
| 59 |
| 60 #ifndef NDEBUG |
| 61 bool hasCheckedForTermination() const { return m_hasCheckedForTermination; } |
| 62 void setHasCheckedForTermination() { m_hasCheckedForTermination = true; } |
| 63 #endif |
| 64 |
| 65 private: |
| 66 bool m_taskCompleted; |
| 67 Mutex m_synchronousMutex; |
| 68 ThreadCondition m_synchronousCondition; |
| 69 #ifndef NDEBUG |
| 70 bool m_hasCheckedForTermination; |
| 71 #endif |
| 72 }; |
| 73 |
| 49 class DatabaseTask : public blink::WebThread::Task { | 74 class DatabaseTask : public blink::WebThread::Task { |
| 50 WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED; | 75 WTF_MAKE_NONCOPYABLE(DatabaseTask); WTF_MAKE_FAST_ALLOCATED; |
| 51 public: | 76 public: |
| 52 virtual ~DatabaseTask(); | 77 virtual ~DatabaseTask(); |
| 53 | 78 |
| 54 virtual void run() OVERRIDE FINAL; | 79 virtual void run() OVERRIDE FINAL; |
| 55 | 80 |
| 56 DatabaseBackend* database() const { return m_database.get(); } | 81 DatabaseBackend* database() const { return m_database.get(); } |
| 57 #ifndef NDEBUG | 82 #ifndef NDEBUG |
| 58 bool hasSynchronizer() const { return m_synchronizer; } | 83 bool hasSynchronizer() const { return m_synchronizer; } |
| 59 bool hasCheckedForTermination() const { return m_synchronizer->hasCheckedFor
Termination(); } | 84 bool hasCheckedForTermination() const { return m_synchronizer->hasCheckedFor
Termination(); } |
| 60 #endif | 85 #endif |
| 61 | 86 |
| 62 protected: | 87 protected: |
| 63 DatabaseTask(DatabaseBackend*, TaskSynchronizer*); | 88 DatabaseTask(DatabaseBackend*, DatabaseTaskSynchronizer*); |
| 64 | 89 |
| 65 private: | 90 private: |
| 66 virtual void doPerformTask() = 0; | 91 virtual void doPerformTask() = 0; |
| 67 virtual void taskCancelled() { } | 92 virtual void taskCancelled() { } |
| 68 | 93 |
| 69 RefPtrWillBeCrossThreadPersistent<DatabaseBackend> m_database; | 94 RefPtrWillBeCrossThreadPersistent<DatabaseBackend> m_database; |
| 70 TaskSynchronizer* m_synchronizer; | 95 DatabaseTaskSynchronizer* m_synchronizer; |
| 71 | 96 |
| 72 #if !LOG_DISABLED | 97 #if !LOG_DISABLED |
| 73 virtual const char* debugTaskName() const = 0; | 98 virtual const char* debugTaskName() const = 0; |
| 74 bool m_complete; | 99 bool m_complete; |
| 75 #endif | 100 #endif |
| 76 }; | 101 }; |
| 77 | 102 |
| 78 class DatabaseBackend::DatabaseOpenTask FINAL : public DatabaseTask { | 103 class DatabaseBackend::DatabaseOpenTask FINAL : public DatabaseTask { |
| 79 public: | 104 public: |
| 80 static PassOwnPtr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVers
ionInNewDatabase, TaskSynchronizer* synchronizer, DatabaseError& error, String&
errorMessage, bool& success) | 105 static PassOwnPtr<DatabaseOpenTask> create(DatabaseBackend* db, bool setVers
ionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseError& error,
String& errorMessage, bool& success) |
| 81 { | 106 { |
| 82 return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchr
onizer, error, errorMessage, success)); | 107 return adoptPtr(new DatabaseOpenTask(db, setVersionInNewDatabase, synchr
onizer, error, errorMessage, success)); |
| 83 } | 108 } |
| 84 | 109 |
| 85 private: | 110 private: |
| 86 DatabaseOpenTask(DatabaseBackend*, bool setVersionInNewDatabase, TaskSynchro
nizer*, DatabaseError&, String& errorMessage, bool& success); | 111 DatabaseOpenTask(DatabaseBackend*, bool setVersionInNewDatabase, DatabaseTas
kSynchronizer*, DatabaseError&, String& errorMessage, bool& success); |
| 87 | 112 |
| 88 virtual void doPerformTask() OVERRIDE; | 113 virtual void doPerformTask() OVERRIDE; |
| 89 #if !LOG_DISABLED | 114 #if !LOG_DISABLED |
| 90 virtual const char* debugTaskName() const OVERRIDE; | 115 virtual const char* debugTaskName() const OVERRIDE; |
| 91 #endif | 116 #endif |
| 92 | 117 |
| 93 bool m_setVersionInNewDatabase; | 118 bool m_setVersionInNewDatabase; |
| 94 DatabaseError& m_error; | 119 DatabaseError& m_error; |
| 95 String& m_errorMessage; | 120 String& m_errorMessage; |
| 96 bool& m_success; | 121 bool& m_success; |
| 97 }; | 122 }; |
| 98 | 123 |
| 99 class DatabaseBackend::DatabaseCloseTask FINAL : public DatabaseTask { | 124 class DatabaseBackend::DatabaseCloseTask FINAL : public DatabaseTask { |
| 100 public: | 125 public: |
| 101 static PassOwnPtr<DatabaseCloseTask> create(DatabaseBackend* db, TaskSynchro
nizer* synchronizer) | 126 static PassOwnPtr<DatabaseCloseTask> create(DatabaseBackend* db, DatabaseTas
kSynchronizer* synchronizer) |
| 102 { | 127 { |
| 103 return adoptPtr(new DatabaseCloseTask(db, synchronizer)); | 128 return adoptPtr(new DatabaseCloseTask(db, synchronizer)); |
| 104 } | 129 } |
| 105 | 130 |
| 106 private: | 131 private: |
| 107 DatabaseCloseTask(DatabaseBackend*, TaskSynchronizer*); | 132 DatabaseCloseTask(DatabaseBackend*, DatabaseTaskSynchronizer*); |
| 108 | 133 |
| 109 virtual void doPerformTask() OVERRIDE; | 134 virtual void doPerformTask() OVERRIDE; |
| 110 #if !LOG_DISABLED | 135 #if !LOG_DISABLED |
| 111 virtual const char* debugTaskName() const OVERRIDE; | 136 virtual const char* debugTaskName() const OVERRIDE; |
| 112 #endif | 137 #endif |
| 113 }; | 138 }; |
| 114 | 139 |
| 115 class DatabaseBackend::DatabaseTransactionTask FINAL : public DatabaseTask { | 140 class DatabaseBackend::DatabaseTransactionTask FINAL : public DatabaseTask { |
| 116 public: | 141 public: |
| 117 virtual ~DatabaseTransactionTask(); | 142 virtual ~DatabaseTransactionTask(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 131 virtual void taskCancelled() OVERRIDE; | 156 virtual void taskCancelled() OVERRIDE; |
| 132 #if !LOG_DISABLED | 157 #if !LOG_DISABLED |
| 133 virtual const char* debugTaskName() const OVERRIDE; | 158 virtual const char* debugTaskName() const OVERRIDE; |
| 134 #endif | 159 #endif |
| 135 | 160 |
| 136 RefPtrWillBeCrossThreadPersistent<SQLTransactionBackend> m_transaction; | 161 RefPtrWillBeCrossThreadPersistent<SQLTransactionBackend> m_transaction; |
| 137 }; | 162 }; |
| 138 | 163 |
| 139 class DatabaseBackend::DatabaseTableNamesTask FINAL : public DatabaseTask { | 164 class DatabaseBackend::DatabaseTableNamesTask FINAL : public DatabaseTask { |
| 140 public: | 165 public: |
| 141 static PassOwnPtr<DatabaseTableNamesTask> create(DatabaseBackend* db, TaskSy
nchronizer* synchronizer, Vector<String>& names) | 166 static PassOwnPtr<DatabaseTableNamesTask> create(DatabaseBackend* db, Databa
seTaskSynchronizer* synchronizer, Vector<String>& names) |
| 142 { | 167 { |
| 143 return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names)); | 168 return adoptPtr(new DatabaseTableNamesTask(db, synchronizer, names)); |
| 144 } | 169 } |
| 145 | 170 |
| 146 private: | 171 private: |
| 147 DatabaseTableNamesTask(DatabaseBackend*, TaskSynchronizer*, Vector<String>&
names); | 172 DatabaseTableNamesTask(DatabaseBackend*, DatabaseTaskSynchronizer*, Vector<S
tring>& names); |
| 148 | 173 |
| 149 virtual void doPerformTask() OVERRIDE; | 174 virtual void doPerformTask() OVERRIDE; |
| 150 #if !LOG_DISABLED | 175 #if !LOG_DISABLED |
| 151 virtual const char* debugTaskName() const OVERRIDE; | 176 virtual const char* debugTaskName() const OVERRIDE; |
| 152 #endif | 177 #endif |
| 153 | 178 |
| 154 Vector<String>& m_tableNames; | 179 Vector<String>& m_tableNames; |
| 155 }; | 180 }; |
| 156 | 181 |
| 157 } // namespace WebCore | 182 } // namespace WebCore |
| 158 | 183 |
| 159 #endif // DatabaseTask_h | 184 #endif // DatabaseTask_h |
| OLD | NEW |