OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "modules/webdatabase/Database.h" | 26 #include "modules/webdatabase/Database.h" |
27 | 27 |
| 28 #include <memory> |
28 #include "core/dom/ExceptionCode.h" | 29 #include "core/dom/ExceptionCode.h" |
29 #include "core/dom/ExecutionContext.h" | 30 #include "core/dom/ExecutionContext.h" |
30 #include "core/dom/ExecutionContextTask.h" | |
31 #include "core/dom/TaskRunnerHelper.h" | 31 #include "core/dom/TaskRunnerHelper.h" |
32 #include "core/html/VoidCallback.h" | 32 #include "core/html/VoidCallback.h" |
33 #include "core/inspector/ConsoleMessage.h" | 33 #include "core/inspector/ConsoleMessage.h" |
34 #include "modules/webdatabase/ChangeVersionData.h" | 34 #include "modules/webdatabase/ChangeVersionData.h" |
35 #include "modules/webdatabase/ChangeVersionWrapper.h" | 35 #include "modules/webdatabase/ChangeVersionWrapper.h" |
36 #include "modules/webdatabase/DatabaseAuthorizer.h" | 36 #include "modules/webdatabase/DatabaseAuthorizer.h" |
37 #include "modules/webdatabase/DatabaseContext.h" | 37 #include "modules/webdatabase/DatabaseContext.h" |
38 #include "modules/webdatabase/DatabaseManager.h" | 38 #include "modules/webdatabase/DatabaseManager.h" |
39 #include "modules/webdatabase/DatabaseTask.h" | 39 #include "modules/webdatabase/DatabaseTask.h" |
40 #include "modules/webdatabase/DatabaseThread.h" | 40 #include "modules/webdatabase/DatabaseThread.h" |
41 #include "modules/webdatabase/DatabaseTracker.h" | 41 #include "modules/webdatabase/DatabaseTracker.h" |
42 #include "modules/webdatabase/SQLError.h" | 42 #include "modules/webdatabase/SQLError.h" |
43 #include "modules/webdatabase/SQLTransaction.h" | 43 #include "modules/webdatabase/SQLTransaction.h" |
44 #include "modules/webdatabase/SQLTransactionBackend.h" | 44 #include "modules/webdatabase/SQLTransactionBackend.h" |
45 #include "modules/webdatabase/SQLTransactionCallback.h" | 45 #include "modules/webdatabase/SQLTransactionCallback.h" |
46 #include "modules/webdatabase/SQLTransactionClient.h" | 46 #include "modules/webdatabase/SQLTransactionClient.h" |
47 #include "modules/webdatabase/SQLTransactionCoordinator.h" | 47 #include "modules/webdatabase/SQLTransactionCoordinator.h" |
48 #include "modules/webdatabase/SQLTransactionErrorCallback.h" | 48 #include "modules/webdatabase/SQLTransactionErrorCallback.h" |
49 #include "modules/webdatabase/StorageLog.h" | 49 #include "modules/webdatabase/StorageLog.h" |
50 #include "modules/webdatabase/sqlite/SQLiteStatement.h" | 50 #include "modules/webdatabase/sqlite/SQLiteStatement.h" |
51 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" | 51 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" |
| 52 #include "platform/CrossThreadFunctional.h" |
52 #include "platform/WaitableEvent.h" | 53 #include "platform/WaitableEvent.h" |
53 #include "platform/heap/SafePoint.h" | 54 #include "platform/heap/SafePoint.h" |
54 #include "public/platform/Platform.h" | 55 #include "public/platform/Platform.h" |
55 #include "public/platform/WebDatabaseObserver.h" | 56 #include "public/platform/WebDatabaseObserver.h" |
56 #include "public/platform/WebSecurityOrigin.h" | 57 #include "public/platform/WebSecurityOrigin.h" |
57 #include "wtf/Atomics.h" | 58 #include "wtf/Atomics.h" |
58 #include "wtf/CurrentTime.h" | 59 #include "wtf/CurrentTime.h" |
59 #include <memory> | |
60 | 60 |
61 // Registering "opened" databases with the DatabaseTracker | 61 // Registering "opened" databases with the DatabaseTracker |
62 // ======================================================= | 62 // ======================================================= |
63 // The DatabaseTracker maintains a list of databases that have been | 63 // The DatabaseTracker maintains a list of databases that have been |
64 // "opened" so that the client can call interrupt or delete on every database | 64 // "opened" so that the client can call interrupt or delete on every database |
65 // associated with a DatabaseContext. | 65 // associated with a DatabaseContext. |
66 // | 66 // |
67 // We will only call DatabaseTracker::addOpenDatabase() to add the database | 67 // We will only call DatabaseTracker::addOpenDatabase() to add the database |
68 // to the tracker as opened when we've succeeded in opening the database, | 68 // to the tracker as opened when we've succeeded in opening the database, |
69 // and will set m_opened to true. Similarly, we only call | 69 // and will set m_opened to true. Similarly, we only call |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 guidCount().add(m_guid); | 241 guidCount().add(m_guid); |
242 } | 242 } |
243 | 243 |
244 m_filename = DatabaseManager::manager().fullPathForDatabase( | 244 m_filename = DatabaseManager::manager().fullPathForDatabase( |
245 getSecurityOrigin(), m_name); | 245 getSecurityOrigin(), m_name); |
246 | 246 |
247 m_databaseThreadSecurityOrigin = | 247 m_databaseThreadSecurityOrigin = |
248 m_contextThreadSecurityOrigin->isolatedCopy(); | 248 m_contextThreadSecurityOrigin->isolatedCopy(); |
249 ASSERT(m_databaseContext->databaseThread()); | 249 ASSERT(m_databaseContext->databaseThread()); |
250 ASSERT(m_databaseContext->isContextThread()); | 250 ASSERT(m_databaseContext->isContextThread()); |
| 251 m_databaseTaskRunner = |
| 252 TaskRunnerHelper::get(TaskType::DatabaseAccess, getExecutionContext()); |
251 } | 253 } |
252 | 254 |
253 Database::~Database() { | 255 Database::~Database() { |
254 // SQLite is "multi-thread safe", but each database handle can only be used | 256 // SQLite is "multi-thread safe", but each database handle can only be used |
255 // on a single thread at a time. | 257 // on a single thread at a time. |
256 // | 258 // |
257 // For Database, we open the SQLite database on the DatabaseThread, and | 259 // For Database, we open the SQLite database on the DatabaseThread, and |
258 // hence we should also close it on that same thread. This means that the | 260 // hence we should also close it on that same thread. This means that the |
259 // SQLite database need to be closed by another mechanism (see | 261 // SQLite database need to be closed by another mechanism (see |
260 // DatabaseContext::stopDatabases()). By the time we get here, the SQLite | 262 // DatabaseContext::stopDatabases()). By the time we get here, the SQLite |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 SQLTransaction* transaction = SQLTransaction::create( | 868 SQLTransaction* transaction = SQLTransaction::create( |
867 this, callback, successCallback, errorCallback, readOnly); | 869 this, callback, successCallback, errorCallback, readOnly); |
868 SQLTransactionBackend* transactionBackend = | 870 SQLTransactionBackend* transactionBackend = |
869 runTransaction(transaction, readOnly, changeVersionData); | 871 runTransaction(transaction, readOnly, changeVersionData); |
870 if (!transactionBackend) { | 872 if (!transactionBackend) { |
871 SQLTransactionErrorCallback* callback = transaction->releaseErrorCallback(); | 873 SQLTransactionErrorCallback* callback = transaction->releaseErrorCallback(); |
872 ASSERT(callback == originalErrorCallback); | 874 ASSERT(callback == originalErrorCallback); |
873 if (callback) { | 875 if (callback) { |
874 std::unique_ptr<SQLErrorData> error = SQLErrorData::create( | 876 std::unique_ptr<SQLErrorData> error = SQLErrorData::create( |
875 SQLError::kUnknownErr, "database has been closed"); | 877 SQLError::kUnknownErr, "database has been closed"); |
876 TaskRunnerHelper::get(TaskType::DatabaseAccess, getExecutionContext()) | 878 getDatabaseTaskRunner()->postTask( |
877 ->postTask(BLINK_FROM_HERE, WTF::bind(&callTransactionErrorCallback, | 879 BLINK_FROM_HERE, |
878 wrapPersistent(callback), | 880 WTF::bind(&callTransactionErrorCallback, wrapPersistent(callback), |
879 WTF::passed(std::move(error)))); | 881 WTF::passed(std::move(error)))); |
880 } | 882 } |
881 } | 883 } |
882 } | 884 } |
883 | 885 |
884 void Database::scheduleTransactionCallback(SQLTransaction* transaction) { | 886 void Database::scheduleTransactionCallback(SQLTransaction* transaction) { |
885 // The task is constructed in a database thread, and destructed in the | 887 // The task is constructed in a database thread, and destructed in the |
886 // context thread. | 888 // context thread. |
887 getExecutionContext()->postTask( | 889 getDatabaseTaskRunner()->postTask( |
888 TaskType::DatabaseAccess, BLINK_FROM_HERE, | 890 BLINK_FROM_HERE, crossThreadBind(&SQLTransaction::performPendingCallback, |
889 createCrossThreadTask(&SQLTransaction::performPendingCallback, | 891 wrapCrossThreadPersistent(transaction))); |
890 wrapCrossThreadPersistent(transaction))); | |
891 } | 892 } |
892 | 893 |
893 Vector<String> Database::performGetTableNames() { | 894 Vector<String> Database::performGetTableNames() { |
894 disableAuthorizer(); | 895 disableAuthorizer(); |
895 | 896 |
896 SQLiteStatement statement( | 897 SQLiteStatement statement( |
897 sqliteDatabase(), "SELECT name FROM sqlite_master WHERE type='table';"); | 898 sqliteDatabase(), "SELECT name FROM sqlite_master WHERE type='table';"); |
898 if (statement.prepare() != SQLResultOk) { | 899 if (statement.prepare() != SQLResultOk) { |
899 DLOG(ERROR) << "Unable to retrieve list of tables for database " | 900 DLOG(ERROR) << "Unable to retrieve list of tables for database " |
900 << databaseDebugName(); | 901 << databaseDebugName(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 return m_contextThreadSecurityOrigin.get(); | 945 return m_contextThreadSecurityOrigin.get(); |
945 if (getDatabaseContext()->databaseThread()->isDatabaseThread()) | 946 if (getDatabaseContext()->databaseThread()->isDatabaseThread()) |
946 return m_databaseThreadSecurityOrigin.get(); | 947 return m_databaseThreadSecurityOrigin.get(); |
947 return nullptr; | 948 return nullptr; |
948 } | 949 } |
949 | 950 |
950 bool Database::opened() { | 951 bool Database::opened() { |
951 return static_cast<bool>(acquireLoad(&m_opened)); | 952 return static_cast<bool>(acquireLoad(&m_opened)); |
952 } | 953 } |
953 | 954 |
| 955 WebTaskRunner* Database::getDatabaseTaskRunner() const { |
| 956 return m_databaseTaskRunner.get(); |
| 957 } |
| 958 |
954 } // namespace blink | 959 } // namespace blink |
OLD | NEW |