Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: third_party/WebKit/Source/modules/webdatabase/Database.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "modules/webdatabase/SQLTransactionErrorCallback.h" 48 #include "modules/webdatabase/SQLTransactionErrorCallback.h"
49 #include "modules/webdatabase/sqlite/SQLiteStatement.h" 49 #include "modules/webdatabase/sqlite/SQLiteStatement.h"
50 #include "modules/webdatabase/sqlite/SQLiteTransaction.h" 50 #include "modules/webdatabase/sqlite/SQLiteTransaction.h"
51 #include "platform/Logging.h" 51 #include "platform/Logging.h"
52 #include "platform/heap/SafePoint.h" 52 #include "platform/heap/SafePoint.h"
53 #include "public/platform/Platform.h" 53 #include "public/platform/Platform.h"
54 #include "public/platform/WebDatabaseObserver.h" 54 #include "public/platform/WebDatabaseObserver.h"
55 #include "public/platform/WebSecurityOrigin.h" 55 #include "public/platform/WebSecurityOrigin.h"
56 #include "wtf/Atomics.h" 56 #include "wtf/Atomics.h"
57 #include "wtf/CurrentTime.h" 57 #include "wtf/CurrentTime.h"
58 #include <memory>
59 58
60 // Registering "opened" databases with the DatabaseTracker 59 // Registering "opened" databases with the DatabaseTracker
61 // ======================================================= 60 // =======================================================
62 // The DatabaseTracker maintains a list of databases that have been 61 // The DatabaseTracker maintains a list of databases that have been
63 // "opened" so that the client can call interrupt or delete on every database 62 // "opened" so that the client can call interrupt or delete on every database
64 // associated with a DatabaseContext. 63 // associated with a DatabaseContext.
65 // 64 //
66 // We will only call DatabaseTracker::addOpenDatabase() to add the database 65 // We will only call DatabaseTracker::addOpenDatabase() to add the database
67 // to the tracker as opened when we've succeeded in opening the database, 66 // to the tracker as opened when we've succeeded in opening the database,
68 // and will set m_opened to true. Similarly, we only call 67 // and will set m_opened to true. Similarly, we only call
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 258 }
260 259
261 bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError& error, String& errorMessage) 260 bool Database::openAndVerifyVersion(bool setVersionInNewDatabase, DatabaseError& error, String& errorMessage)
262 { 261 {
263 TaskSynchronizer synchronizer; 262 TaskSynchronizer synchronizer;
264 if (!getDatabaseContext()->databaseThreadAvailable()) 263 if (!getDatabaseContext()->databaseThreadAvailable())
265 return false; 264 return false;
266 265
267 DatabaseTracker::tracker().prepareToOpenDatabase(this); 266 DatabaseTracker::tracker().prepareToOpenDatabase(this);
268 bool success = false; 267 bool success = false;
269 std::unique_ptr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setV ersionInNewDatabase, &synchronizer, error, errorMessage, success); 268 OwnPtr<DatabaseOpenTask> task = DatabaseOpenTask::create(this, setVersionInN ewDatabase, &synchronizer, error, errorMessage, success);
270 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task)); 269 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task));
271 synchronizer.waitForTaskCompletion(); 270 synchronizer.waitForTaskCompletion();
272 271
273 return success; 272 return success;
274 } 273 }
275 274
276 void Database::close() 275 void Database::close()
277 { 276 {
278 ASSERT(getDatabaseContext()->databaseThread()); 277 ASSERT(getDatabaseContext()->databaseThread());
279 ASSERT(getDatabaseContext()->databaseThread()->isDatabaseThread()); 278 ASSERT(getDatabaseContext()->databaseThread()->isDatabaseThread());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 324
326 void Database::scheduleTransaction() 325 void Database::scheduleTransaction()
327 { 326 {
328 ASSERT(!m_transactionInProgressMutex.tryLock()); // Locked by caller. 327 ASSERT(!m_transactionInProgressMutex.tryLock()); // Locked by caller.
329 SQLTransactionBackend* transaction = nullptr; 328 SQLTransactionBackend* transaction = nullptr;
330 329
331 if (m_isTransactionQueueEnabled && !m_transactionQueue.isEmpty()) 330 if (m_isTransactionQueueEnabled && !m_transactionQueue.isEmpty())
332 transaction = m_transactionQueue.takeFirst(); 331 transaction = m_transactionQueue.takeFirst();
333 332
334 if (transaction && getDatabaseContext()->databaseThreadAvailable()) { 333 if (transaction && getDatabaseContext()->databaseThreadAvailable()) {
335 std::unique_ptr<DatabaseTransactionTask> task = DatabaseTransactionTask: :create(transaction); 334 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(t ransaction);
336 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for transacti on %p\n", task.get(), task->transaction()); 335 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for transacti on %p\n", task.get(), task->transaction());
337 m_transactionInProgress = true; 336 m_transactionInProgress = true;
338 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task)); 337 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task));
339 } else { 338 } else {
340 m_transactionInProgress = false; 339 m_transactionInProgress = false;
341 } 340 }
342 } 341 }
343 342
344 void Database::scheduleTransactionStep(SQLTransactionBackend* transaction) 343 void Database::scheduleTransactionStep(SQLTransactionBackend* transaction)
345 { 344 {
346 if (!getDatabaseContext()->databaseThreadAvailable()) 345 if (!getDatabaseContext()->databaseThreadAvailable())
347 return; 346 return;
348 347
349 std::unique_ptr<DatabaseTransactionTask> task = DatabaseTransactionTask::cre ate(transaction); 348 OwnPtr<DatabaseTransactionTask> task = DatabaseTransactionTask::create(trans action);
350 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for the transacti on step\n", task.get()); 349 WTF_LOG(StorageAPI, "Scheduling DatabaseTransactionTask %p for the transacti on step\n", task.get());
351 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task)); 350 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task));
352 } 351 }
353 352
354 SQLTransactionClient* Database::transactionClient() const 353 SQLTransactionClient* Database::transactionClient() const
355 { 354 {
356 return getDatabaseContext()->databaseThread()->transactionClient(); 355 return getDatabaseContext()->databaseThread()->transactionClient();
357 } 356 }
358 357
359 SQLTransactionCoordinator* Database::transactionCoordinator() const 358 SQLTransactionCoordinator* Database::transactionCoordinator() const
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 802 }
804 803
805 void Database::readTransaction( 804 void Database::readTransaction(
806 SQLTransactionCallback* callback, 805 SQLTransactionCallback* callback,
807 SQLTransactionErrorCallback* errorCallback, 806 SQLTransactionErrorCallback* errorCallback,
808 VoidCallback* successCallback) 807 VoidCallback* successCallback)
809 { 808 {
810 runTransaction(callback, errorCallback, successCallback, true); 809 runTransaction(callback, errorCallback, successCallback, true);
811 } 810 }
812 811
813 static void callTransactionErrorCallback(SQLTransactionErrorCallback* callback, std::unique_ptr<SQLErrorData> errorData) 812 static void callTransactionErrorCallback(SQLTransactionErrorCallback* callback, PassOwnPtr<SQLErrorData> errorData)
814 { 813 {
815 callback->handleEvent(SQLError::create(*errorData)); 814 callback->handleEvent(SQLError::create(*errorData));
816 } 815 }
817 816
818 void Database::runTransaction( 817 void Database::runTransaction(
819 SQLTransactionCallback* callback, 818 SQLTransactionCallback* callback,
820 SQLTransactionErrorCallback* errorCallback, 819 SQLTransactionErrorCallback* errorCallback,
821 VoidCallback* successCallback, 820 VoidCallback* successCallback,
822 bool readOnly, 821 bool readOnly,
823 const ChangeVersionData* changeVersionData) 822 const ChangeVersionData* changeVersionData)
824 { 823 {
825 ASSERT(getExecutionContext()->isContextThread()); 824 ASSERT(getExecutionContext()->isContextThread());
826 // FIXME: Rather than passing errorCallback to SQLTransaction and then 825 // FIXME: Rather than passing errorCallback to SQLTransaction and then
827 // sometimes firing it ourselves, this code should probably be pushed down 826 // sometimes firing it ourselves, this code should probably be pushed down
828 // into Database so that we only create the SQLTransaction if we're 827 // into Database so that we only create the SQLTransaction if we're
829 // actually going to run it. 828 // actually going to run it.
830 #if ENABLE(ASSERT) 829 #if ENABLE(ASSERT)
831 SQLTransactionErrorCallback* originalErrorCallback = errorCallback; 830 SQLTransactionErrorCallback* originalErrorCallback = errorCallback;
832 #endif 831 #endif
833 SQLTransaction* transaction = SQLTransaction::create(this, callback, success Callback, errorCallback, readOnly); 832 SQLTransaction* transaction = SQLTransaction::create(this, callback, success Callback, errorCallback, readOnly);
834 SQLTransactionBackend* transactionBackend = runTransaction(transaction, read Only, changeVersionData); 833 SQLTransactionBackend* transactionBackend = runTransaction(transaction, read Only, changeVersionData);
835 if (!transactionBackend) { 834 if (!transactionBackend) {
836 SQLTransactionErrorCallback* callback = transaction->releaseErrorCallbac k(); 835 SQLTransactionErrorCallback* callback = transaction->releaseErrorCallbac k();
837 ASSERT(callback == originalErrorCallback); 836 ASSERT(callback == originalErrorCallback);
838 if (callback) { 837 if (callback) {
839 std::unique_ptr<SQLErrorData> error = SQLErrorData::create(SQLError: :UNKNOWN_ERR, "database has been closed"); 838 OwnPtr<SQLErrorData> error = SQLErrorData::create(SQLError::UNKNOWN_ ERR, "database has been closed");
840 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTas k(&callTransactionErrorCallback, callback, passed(std::move(error)))); 839 getExecutionContext()->postTask(BLINK_FROM_HERE, createSameThreadTas k(&callTransactionErrorCallback, callback, passed(std::move(error))));
841 } 840 }
842 } 841 }
843 } 842 }
844 843
845 void Database::scheduleTransactionCallback(SQLTransaction* transaction) 844 void Database::scheduleTransactionCallback(SQLTransaction* transaction)
846 { 845 {
847 // The task is constructed in a database thread, and destructed in the 846 // The task is constructed in a database thread, and destructed in the
848 // context thread. 847 // context thread.
849 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&SQLT ransaction::performPendingCallback, wrapCrossThreadPersistent(transaction))); 848 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&SQLT ransaction::performPendingCallback, wrapCrossThreadPersistent(transaction)));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 Vector<String> Database::tableNames() 880 Vector<String> Database::tableNames()
882 { 881 {
883 // FIXME: Not using isolatedCopy on these strings looks ok since threads 882 // FIXME: Not using isolatedCopy on these strings looks ok since threads
884 // take strict turns in dealing with them. However, if the code changes, 883 // take strict turns in dealing with them. However, if the code changes,
885 // this may not be true anymore. 884 // this may not be true anymore.
886 Vector<String> result; 885 Vector<String> result;
887 TaskSynchronizer synchronizer; 886 TaskSynchronizer synchronizer;
888 if (!getDatabaseContext()->databaseThreadAvailable()) 887 if (!getDatabaseContext()->databaseThreadAvailable())
889 return result; 888 return result;
890 889
891 std::unique_ptr<DatabaseTableNamesTask> task = DatabaseTableNamesTask::creat e(this, &synchronizer, result); 890 OwnPtr<DatabaseTableNamesTask> task = DatabaseTableNamesTask::create(this, & synchronizer, result);
892 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task)); 891 getDatabaseContext()->databaseThread()->scheduleTask(std::move(task));
893 synchronizer.waitForTaskCompletion(); 892 synchronizer.waitForTaskCompletion();
894 893
895 return result; 894 return result;
896 } 895 }
897 896
898 SecurityOrigin* Database::getSecurityOrigin() const 897 SecurityOrigin* Database::getSecurityOrigin() const
899 { 898 {
900 if (getExecutionContext()->isContextThread()) 899 if (getExecutionContext()->isContextThread())
901 return m_contextThreadSecurityOrigin.get(); 900 return m_contextThreadSecurityOrigin.get();
902 if (getDatabaseContext()->databaseThread()->isDatabaseThread()) 901 if (getDatabaseContext()->databaseThread()->isDatabaseThread())
903 return m_databaseThreadSecurityOrigin.get(); 902 return m_databaseThreadSecurityOrigin.get();
904 return 0; 903 return 0;
905 } 904 }
906 905
907 bool Database::opened() 906 bool Database::opened()
908 { 907 {
909 return static_cast<bool>(acquireLoad(&m_opened)); 908 return static_cast<bool>(acquireLoad(&m_opened));
910 } 909 }
911 910
912 } // namespace blink 911 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698