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 |
28 #include "config.h" | 29 #include "config.h" |
29 #include "modules/webdatabase/DatabaseTask.h" | 30 #include "modules/webdatabase/DatabaseTask.h" |
30 | 31 |
31 #include "platform/Logging.h" | 32 #include "platform/Logging.h" |
32 #include "modules/webdatabase/Database.h" | 33 #include "modules/webdatabase/Database.h" |
33 #include "modules/webdatabase/DatabaseContext.h" | 34 #include "modules/webdatabase/DatabaseContext.h" |
34 #include "modules/webdatabase/DatabaseThread.h" | 35 #include "modules/webdatabase/DatabaseThread.h" |
35 | 36 |
36 namespace WebCore { | 37 namespace WebCore { |
37 | 38 |
38 DatabaseTaskSynchronizer::DatabaseTaskSynchronizer() | 39 DatabaseTask::DatabaseTask(DatabaseBackend* database, TaskSynchronizer* synchron
izer) |
39 : m_taskCompleted(false) | |
40 #ifndef NDEBUG | |
41 , m_hasCheckedForTermination(false) | |
42 #endif | |
43 { | |
44 } | |
45 | |
46 void DatabaseTaskSynchronizer::waitForTaskCompletion() | |
47 { | |
48 // Prevent the deadlock between park request by other threads and blocking | |
49 // by m_synchronousCondition. | |
50 ThreadState::SafePointScope scope(ThreadState::HeapPointersOnStack); | |
51 m_synchronousMutex.lock(); | |
52 while (!m_taskCompleted) | |
53 m_synchronousCondition.wait(m_synchronousMutex); | |
54 m_synchronousMutex.unlock(); | |
55 } | |
56 | |
57 void DatabaseTaskSynchronizer::taskCompleted() | |
58 { | |
59 m_synchronousMutex.lock(); | |
60 m_taskCompleted = true; | |
61 m_synchronousCondition.signal(); | |
62 m_synchronousMutex.unlock(); | |
63 } | |
64 | |
65 DatabaseTask::DatabaseTask(DatabaseBackend* database, DatabaseTaskSynchronizer*
synchronizer) | |
66 : m_database(database) | 40 : m_database(database) |
67 , m_synchronizer(synchronizer) | 41 , m_synchronizer(synchronizer) |
68 #if !LOG_DISABLED | 42 #if !LOG_DISABLED |
69 , m_complete(false) | 43 , m_complete(false) |
70 #endif | 44 #endif |
71 { | 45 { |
72 } | 46 } |
73 | 47 |
74 DatabaseTask::~DatabaseTask() | 48 DatabaseTask::~DatabaseTask() |
75 { | 49 { |
(...skipping 26 matching lines...) Expand all Loading... |
102 m_synchronizer->taskCompleted(); | 76 m_synchronizer->taskCompleted(); |
103 | 77 |
104 #if !LOG_DISABLED | 78 #if !LOG_DISABLED |
105 m_complete = true; | 79 m_complete = true; |
106 #endif | 80 #endif |
107 } | 81 } |
108 | 82 |
109 // *** DatabaseOpenTask *** | 83 // *** DatabaseOpenTask *** |
110 // Opens the database file and verifies the version matches the expected version
. | 84 // Opens the database file and verifies the version matches the expected version
. |
111 | 85 |
112 DatabaseBackend::DatabaseOpenTask::DatabaseOpenTask(DatabaseBackend* database, b
ool setVersionInNewDatabase, DatabaseTaskSynchronizer* synchronizer, DatabaseErr
or& error, String& errorMessage, bool& success) | 86 DatabaseBackend::DatabaseOpenTask::DatabaseOpenTask(DatabaseBackend* database, b
ool setVersionInNewDatabase, TaskSynchronizer* synchronizer, DatabaseError& erro
r, String& errorMessage, bool& success) |
113 : DatabaseTask(database, synchronizer) | 87 : DatabaseTask(database, synchronizer) |
114 , m_setVersionInNewDatabase(setVersionInNewDatabase) | 88 , m_setVersionInNewDatabase(setVersionInNewDatabase) |
115 , m_error(error) | 89 , m_error(error) |
116 , m_errorMessage(errorMessage) | 90 , m_errorMessage(errorMessage) |
117 , m_success(success) | 91 , m_success(success) |
118 { | 92 { |
119 ASSERT(synchronizer); // A task with output parameters is supposed to be syn
chronous. | 93 ASSERT(synchronizer); // A task with output parameters is supposed to be syn
chronous. |
120 } | 94 } |
121 | 95 |
122 void DatabaseBackend::DatabaseOpenTask::doPerformTask() | 96 void DatabaseBackend::DatabaseOpenTask::doPerformTask() |
123 { | 97 { |
124 String errorMessage; | 98 String errorMessage; |
125 m_success = database()->performOpenAndVerify(m_setVersionInNewDatabase, m_er
ror, errorMessage); | 99 m_success = database()->performOpenAndVerify(m_setVersionInNewDatabase, m_er
ror, errorMessage); |
126 if (!m_success) | 100 if (!m_success) |
127 m_errorMessage = errorMessage.isolatedCopy(); | 101 m_errorMessage = errorMessage.isolatedCopy(); |
128 } | 102 } |
129 | 103 |
130 #if !LOG_DISABLED | 104 #if !LOG_DISABLED |
131 const char* DatabaseBackend::DatabaseOpenTask::debugTaskName() const | 105 const char* DatabaseBackend::DatabaseOpenTask::debugTaskName() const |
132 { | 106 { |
133 return "DatabaseOpenTask"; | 107 return "DatabaseOpenTask"; |
134 } | 108 } |
135 #endif | 109 #endif |
136 | 110 |
137 // *** DatabaseCloseTask *** | 111 // *** DatabaseCloseTask *** |
138 // Closes the database. | 112 // Closes the database. |
139 | 113 |
140 DatabaseBackend::DatabaseCloseTask::DatabaseCloseTask(DatabaseBackend* database,
DatabaseTaskSynchronizer* synchronizer) | 114 DatabaseBackend::DatabaseCloseTask::DatabaseCloseTask(DatabaseBackend* database,
TaskSynchronizer* synchronizer) |
141 : DatabaseTask(database, synchronizer) | 115 : DatabaseTask(database, synchronizer) |
142 { | 116 { |
143 } | 117 } |
144 | 118 |
145 void DatabaseBackend::DatabaseCloseTask::doPerformTask() | 119 void DatabaseBackend::DatabaseCloseTask::doPerformTask() |
146 { | 120 { |
147 Database::from(database())->close(); | 121 Database::from(database())->close(); |
148 } | 122 } |
149 | 123 |
150 #if !LOG_DISABLED | 124 #if !LOG_DISABLED |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 #if !LOG_DISABLED | 162 #if !LOG_DISABLED |
189 const char* DatabaseBackend::DatabaseTransactionTask::debugTaskName() const | 163 const char* DatabaseBackend::DatabaseTransactionTask::debugTaskName() const |
190 { | 164 { |
191 return "DatabaseTransactionTask"; | 165 return "DatabaseTransactionTask"; |
192 } | 166 } |
193 #endif | 167 #endif |
194 | 168 |
195 // *** DatabaseTableNamesTask *** | 169 // *** DatabaseTableNamesTask *** |
196 // Retrieves a list of all tables in the database - for WebInspector support. | 170 // Retrieves a list of all tables in the database - for WebInspector support. |
197 | 171 |
198 DatabaseBackend::DatabaseTableNamesTask::DatabaseTableNamesTask(DatabaseBackend*
database, DatabaseTaskSynchronizer* synchronizer, Vector<String>& names) | 172 DatabaseBackend::DatabaseTableNamesTask::DatabaseTableNamesTask(DatabaseBackend*
database, TaskSynchronizer* synchronizer, Vector<String>& names) |
199 : DatabaseTask(database, synchronizer) | 173 : DatabaseTask(database, synchronizer) |
200 , m_tableNames(names) | 174 , m_tableNames(names) |
201 { | 175 { |
202 ASSERT(synchronizer); // A task with output parameters is supposed to be syn
chronous. | 176 ASSERT(synchronizer); // A task with output parameters is supposed to be syn
chronous. |
203 } | 177 } |
204 | 178 |
205 void DatabaseBackend::DatabaseTableNamesTask::doPerformTask() | 179 void DatabaseBackend::DatabaseTableNamesTask::doPerformTask() |
206 { | 180 { |
207 m_tableNames = Database::from(database())->performGetTableNames(); | 181 m_tableNames = Database::from(database())->performGetTableNames(); |
208 } | 182 } |
209 | 183 |
210 #if !LOG_DISABLED | 184 #if !LOG_DISABLED |
211 const char* DatabaseBackend::DatabaseTableNamesTask::debugTaskName() const | 185 const char* DatabaseBackend::DatabaseTableNamesTask::debugTaskName() const |
212 { | 186 { |
213 return "DatabaseTableNamesTask"; | 187 return "DatabaseTableNamesTask"; |
214 } | 188 } |
215 #endif | 189 #endif |
216 | 190 |
217 } // namespace WebCore | 191 } // namespace WebCore |
OLD | NEW |