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

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

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

Powered by Google App Engine
This is Rietveld 408576698