Changeset 60508 in webkit
- Timestamp:
- Jun 1, 2010 2:39:11 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r60503 r60508 1 2010-06-01 Dumitru Daniliuc <dumi@chromium.org> 2 3 Reviewed by Adam Barth. 4 5 Clean up the DB classes in preparation for a bigger refactoring. 6 https://bugs.webkit.org/show_bug.cgi?id=39041 7 8 * storage/ChangeVersionWrapper.cpp: 9 * storage/ChangeVersionWrapper.h: 10 * storage/Database.cpp: 11 (WebCore::Database::Database): 12 (WebCore::Database::lastActionChangedDatabase): 13 (WebCore::Database::lastActionWasInsert): 14 (WebCore::Database::inProgressTransactionCompleted): 15 (WebCore::Database::securityOrigin): 16 * storage/Database.h: 17 (WebCore::Database::sqliteDatabase): 18 (WebCore::Database::databaseDebugName): 19 * storage/DatabaseTask.cpp: 20 (WebCore::DatabaseTransactionTask::doPerformTask): 21 * storage/DatabaseTask.h: 22 * storage/SQLStatement.cpp: 23 (WebCore::SQLStatement::execute): 24 * storage/SQLStatement.h: 25 * storage/SQLTransaction.cpp: 26 (WebCore::SQLTransaction::SQLTransaction): 27 (WebCore::SQLTransaction::openTransactionAndPreflight): 28 (WebCore::SQLTransaction::runStatements): 29 (WebCore::SQLTransaction::runCurrentStatement): 30 (WebCore::SQLTransaction::postflightAndCommit): 31 (WebCore::SQLTransaction::cleanupAfterSuccessCallback): 32 (WebCore::SQLTransaction::cleanupAfterTransactionErrorCallback): 33 * storage/SQLTransaction.h: 34 1 35 2010-06-01 Rob Buis <rwlbuis@gmail.com> 2 36 -
trunk/WebCore/storage/ChangeVersionWrapper.cpp
r49160 r60508 31 31 #if ENABLE(DATABASE) 32 32 #include "Database.h" 33 #include "SQLError.h" 34 #include <wtf/PassRefPtr.h> 35 #include <wtf/RefPtr.h> 33 36 34 37 namespace WebCore { -
trunk/WebCore/storage/ChangeVersionWrapper.h
r43283 r60508 33 33 #include "PlatformString.h" 34 34 #include "SQLTransaction.h" 35 #include <wtf/Forward.h> 35 36 36 37 namespace WebCore { 38 39 class SQLError; 37 40 38 41 class ChangeVersionWrapper : public SQLTransactionWrapper { -
trunk/WebCore/storage/Database.cpp
r58366 r60508 30 30 #include "Database.h" 31 31 32 #include <wtf/StdLibExtras.h>33 34 32 #if ENABLE(DATABASE) 35 33 #include "ChangeVersionWrapper.h" … … 41 39 #include "Document.h" 42 40 #include "ExceptionCode.h" 43 #include "Frame.h"44 41 #include "InspectorController.h" 45 42 #include "Logging.h" 46 43 #include "NotImplemented.h" 47 44 #include "Page.h" 48 #include "OriginQuotaManager.h" 49 #include "ScriptController.h" 50 #include "SQLiteDatabase.h" 51 #include "SQLiteFileSystem.h" 52 #include "SQLiteStatement.h" 53 #include "SQLResultSet.h" 45 #include "SQLTransactionCallback.h" 54 46 #include "SQLTransactionClient.h" 55 47 #include "SQLTransactionCoordinator.h" 56 57 #endif // ENABLE(DATABASE) 48 #include "SQLTransactionErrorCallback.h" 49 #include "SQLiteStatement.h" 50 #include "ScriptController.h" 51 #include "ScriptExecutionContext.h" 52 #include "SecurityOrigin.h" 53 #include "StringHash.h" 54 #include "VoidCallback.h" 55 #include <wtf/OwnPtr.h> 56 #include <wtf/PassOwnPtr.h> 57 #include <wtf/PassRefPtr.h> 58 #include <wtf/RefPtr.h> 59 #include <wtf/StdLibExtras.h> 58 60 59 61 #if USE(JSC) … … 71 73 return name; 72 74 } 73 74 #if ENABLE(DATABASE)75 75 76 76 static bool isDatabaseAvailable = true; … … 214 214 { 215 215 ASSERT(m_scriptExecutionContext.get()); 216 m_ mainThreadSecurityOrigin = m_scriptExecutionContext->securityOrigin();217 m_databaseThreadSecurityOrigin = m_ mainThreadSecurityOrigin->threadsafeCopy();216 m_contextThreadSecurityOrigin = m_scriptExecutionContext->securityOrigin(); 217 m_databaseThreadSecurityOrigin = m_contextThreadSecurityOrigin->threadsafeCopy(); 218 218 if (m_name.isNull()) 219 219 m_name = ""; … … 490 490 ASSERT(m_databaseAuthorizer); 491 491 m_databaseAuthorizer->setReadOnly(); 492 } 493 494 bool Database::lastActionChangedDatabase() 495 { 496 ASSERT(m_databaseAuthorizer); 497 return m_databaseAuthorizer->lastActionChangedDatabase(); 498 } 499 500 bool Database::lastActionWasInsert() 501 { 502 ASSERT(m_databaseAuthorizer); 503 return m_databaseAuthorizer->lastActionWasInsert(); 492 504 } 493 505 … … 644 656 } 645 657 658 void Database::inProgressTransactionCompleted() 659 { 660 MutexLocker locker(m_transactionInProgressMutex); 661 m_transactionInProgress = false; 662 scheduleTransaction(); 663 } 664 646 665 void Database::scheduleTransaction() 647 666 { … … 781 800 SecurityOrigin* Database::securityOrigin() const 782 801 { 783 if ( scriptExecutionContext()->isContextThread())784 return m_ mainThreadSecurityOrigin.get();802 if (m_scriptExecutionContext->isContextThread()) 803 return m_contextThreadSecurityOrigin.get(); 785 804 if (currentThread() == m_scriptExecutionContext->databaseThread()->getThreadID()) 786 805 return m_databaseThreadSecurityOrigin.get(); … … 819 838 } 820 839 840 } // namespace WebCore 841 821 842 #endif // ENABLE(DATABASE) 822 823 } // namespace WebCore -
trunk/WebCore/storage/Database.h
r58437 r60508 32 32 #if ENABLE(DATABASE) 33 33 #include "PlatformString.h" 34 #include "SQLiteDatabase.h" 35 #ifndef NDEBUG 34 36 #include "SecurityOrigin.h" 35 #include "SQLiteDatabase.h"36 #include "SQLTransaction.h"37 #include "StringHash.h"38 #include "Timer.h"39 #include "VoidCallback.h"40 41 #include <wtf/Forward.h>42 #include <wtf/HashSet.h>43 #include <wtf/PassRefPtr.h>44 #include <wtf/RefPtr.h>45 #include <wtf/Deque.h>46 #else47 #include "PlatformString.h"48 37 #endif 49 38 50 #if ENABLE(DATABASE) 39 #include <wtf/Deque.h> 40 #include <wtf/Forward.h> 41 51 42 namespace WebCore { 52 43 … … 55 46 class DatabaseThread; 56 47 class ScriptExecutionContext; 57 class SQLResultSet; 48 class SecurityOrigin; 49 class SQLTransaction; 58 50 class SQLTransactionCallback; 59 51 class SQLTransactionClient; 60 52 class SQLTransactionCoordinator; 61 53 class SQLTransactionErrorCallback; 62 class SQLValue;54 class VoidCallback; 63 55 64 56 typedef int ExceptionCode; 65 57 66 58 class Database : public ThreadSafeShared<Database> { 67 friend class DatabaseTransactionTask;68 friend class SQLStatement;69 friend class SQLTransaction;70 59 public: 71 60 static void setIsAvailable(bool); … … 75 64 76 65 // Direct support for the DOM API 77 static PassRefPtr<Database> openDatabase(ScriptExecutionContext* context, const String& name, 78 const String& expectedVersion, const String& displayName, 79 unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, 80 ExceptionCode&); 66 static PassRefPtr<Database> openDatabase(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName, 67 unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&); 81 68 String version() const; 82 void changeVersion(const String& oldVersion, const String& newVersion, 83 PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback, 84 PassRefPtr<VoidCallback> successCallback); 85 void transaction(PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback, 69 void changeVersion(const String& oldVersion, const String& newVersion, PassRefPtr<SQLTransactionCallback>, 70 PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback); 71 void transaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, 86 72 PassRefPtr<VoidCallback> successCallback, bool readOnly); 87 73 … … 92 78 void enableAuthorizer(); 93 79 void setAuthorizerReadOnly(); 80 bool lastActionChangedDatabase(); 81 bool lastActionWasInsert(); 94 82 95 83 Vector<String> tableNames(); … … 97 85 ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext.get(); } 98 86 SecurityOrigin* securityOrigin() const; 87 SQLiteDatabase& sqliteDatabase() { return m_sqliteDatabase; } 99 88 String stringIdentifier() const; 100 89 String displayName() const; … … 128 117 bool performOpenAndVerify(ExceptionCode&); 129 118 119 void inProgressTransactionCompleted(); 120 void scheduleTransactionCallback(SQLTransaction*); 121 void scheduleTransactionStep(SQLTransaction*, bool immediately = false); 122 130 123 Vector<String> performGetTableNames(); 131 124 void performCreationCallback(); … … 137 130 138 131 private: 139 Database(ScriptExecutionContext* context, const String& name, 140 const String& expectedVersion, const String& displayName, 141 unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback); 132 Database(ScriptExecutionContext*, const String& name, const String& expectedVersion, 133 const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback>); 142 134 143 135 bool openAndVerifyVersion(ExceptionCode&); 144 136 145 137 void scheduleTransaction(); 146 void scheduleTransactionCallback(SQLTransaction*);147 void scheduleTransactionStep(SQLTransaction* transaction, bool immediately = false);148 138 149 139 Deque<RefPtr<SQLTransaction> > m_transactionQueue; … … 155 145 156 146 RefPtr<ScriptExecutionContext> m_scriptExecutionContext; 157 RefPtr<SecurityOrigin> m_ mainThreadSecurityOrigin;147 RefPtr<SecurityOrigin> m_contextThreadSecurityOrigin; 158 148 RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin; 159 149 String m_name; … … 178 168 179 169 #ifndef NDEBUG 180 String databaseDebugName() const { return m_ mainThreadSecurityOrigin->toString() + "::" + m_name; }170 String databaseDebugName() const { return m_contextThreadSecurityOrigin->toString() + "::" + m_name; } 181 171 #endif 182 172 }; … … 184 174 } // namespace WebCore 185 175 186 #else187 188 namespace WebCore {189 class Database : public ThreadSafeShared<Database> {190 public:191 static const String& databaseInfoTableName();192 };193 } // namespace WebCore194 195 176 #endif // ENABLE(DATABASE) 196 177 -
trunk/WebCore/storage/DatabaseTask.cpp
r57034 r60508 144 144 void DatabaseTransactionTask::doPerformTask() 145 145 { 146 if (m_transaction->performNextStep()) { 147 // The transaction is complete, we can move on to the next one. 148 MutexLocker locker(m_transaction->database()->m_transactionInProgressMutex); 149 m_transaction->database()->scheduleTransaction(); 150 } 146 if (m_transaction->performNextStep()) 147 m_transaction->database()->inProgressTransactionCompleted(); 151 148 } 152 149 -
trunk/WebCore/storage/DatabaseTask.h
r57034 r60508 33 33 #include "ExceptionCode.h" 34 34 #include "PlatformString.h" 35 #include "SQLTransaction.h" 35 36 #include <wtf/OwnPtr.h> 36 37 #include <wtf/PassOwnPtr.h> … … 40 41 41 42 namespace WebCore { 42 43 class DatabaseTask;44 class DatabaseThread;45 class SQLValue;46 class SQLCallback;47 class SQLTransaction;48 class VersionChangeCallback;49 43 50 44 // Can be used to wait until DatabaseTask is completed. -
trunk/WebCore/storage/SQLStatement.cpp
r58801 r60508 32 32 33 33 #include "Database.h" 34 #include "DatabaseAuthorizer.h"35 34 #include "Logging.h" 36 35 #include "SQLError.h" 37 36 #include "SQLiteDatabase.h" 38 37 #include "SQLiteStatement.h" 39 #include "SQLResultSet.h"40 38 #include "SQLStatementCallback.h" 41 39 #include "SQLStatementErrorCallback.h" … … 74 72 db->setAuthorizerReadOnly(); 75 73 76 SQLiteDatabase* database = &db-> m_sqliteDatabase;74 SQLiteDatabase* database = &db->sqliteDatabase(); 77 75 78 76 SQLiteStatement statement(*database, m_statement); … … 131 129 } else if (result == SQLResultDone) { 132 130 // Didn't find anything, or was an insert 133 if (db-> m_databaseAuthorizer->lastActionWasInsert())131 if (db->lastActionWasInsert()) 134 132 resultSet->setInsertId(database->lastInsertRowID()); 135 133 } else if (result == SQLResultFull) { -
trunk/WebCore/storage/SQLStatement.h
r47808 r60508 32 32 33 33 #include "PlatformString.h" 34 35 #include "SQLError.h"36 34 #include "SQLResultSet.h" 37 #include "SQLStatementCallback.h"38 #include "SQLStatementErrorCallback.h"39 35 #include "SQLValue.h" 40 41 #include <wtf/PassRefPtr.h> 42 #include <wtf/RefPtr.h> 43 #include <wtf/Threading.h> 36 #include <wtf/Forward.h> 44 37 #include <wtf/Vector.h> 45 38 … … 47 40 48 41 class Database; 42 class SQLError; 43 class SQLStatementCallback; 44 class SQLStatementErrorCallback; 49 45 class SQLTransaction; 50 class String;51 46 52 47 class SQLStatement : public ThreadSafeShared<SQLStatement> { … … 67 62 SQLError* sqlError() const { return m_error.get(); } 68 63 private: 69 SQLStatement(const String& statement, const Vector<SQLValue>& arguments, PassRefPtr<SQLStatementCallback> callback, PassRefPtr<SQLStatementErrorCallback> errorCallback, bool readOnly);64 SQLStatement(const String& statement, const Vector<SQLValue>& arguments, PassRefPtr<SQLStatementCallback>, PassRefPtr<SQLStatementErrorCallback>, bool readOnly); 70 65 71 66 void setFailureDueToQuota(); -
trunk/WebCore/storage/SQLTransaction.cpp
r59267 r60508 32 32 #if ENABLE(DATABASE) 33 33 34 #include "ChromeClient.h"35 34 #include "Database.h" 36 #include "DatabaseAuthorizer.h"37 #include "DatabaseDetails.h"38 35 #include "DatabaseThread.h" 39 36 #include "ExceptionCode.h" 40 37 #include "Logging.h" 41 #include "Page.h"42 38 #include "PlatformString.h" 43 39 #include "ScriptExecutionContext.h" 44 #include "Settings.h"45 40 #include "SQLError.h" 46 41 #include "SQLiteTransaction.h" 47 #include "SQLResultSet.h"48 42 #include "SQLStatement.h" 49 43 #include "SQLStatementCallback.h" 50 44 #include "SQLStatementErrorCallback.h" 45 #include "SQLTransactionCallback.h" 51 46 #include "SQLTransactionClient.h" 52 47 #include "SQLTransactionCoordinator.h" 48 #include "SQLTransactionErrorCallback.h" 53 49 #include "SQLValue.h" 50 #include "VoidCallback.h" 51 #include <wtf/OwnPtr.h> 52 #include <wtf/PassRefPtr.h> 53 #include <wtf/RefPtr.h> 54 54 55 55 // There's no way of knowing exactly how much more space will be required when a statement hits the quota limit. … … 66 66 } 67 67 68 SQLTransaction::SQLTransaction(Database* db, PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback, PassRefPtr<VoidCallback> successCallback,69 PassRefPtr< SQLTransactionWrapper> wrapper, bool readOnly)68 SQLTransaction::SQLTransaction(Database* db, PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCallback> errorCallback, 69 PassRefPtr<VoidCallback> successCallback, PassRefPtr<SQLTransactionWrapper> wrapper, bool readOnly) 70 70 : m_nextStep(&SQLTransaction::acquireLock) 71 71 , m_executeSqlAllowed(false) … … 235 235 void SQLTransaction::openTransactionAndPreflight() 236 236 { 237 ASSERT(!m_database-> m_sqliteDatabase.transactionInProgress());237 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); 238 238 ASSERT(m_lockAcquired); 239 239 … … 249 249 // Set the maximum usage for this transaction if this transactions is not read-only 250 250 if (!m_readOnly) 251 m_database-> m_sqliteDatabase.setMaximumSize(m_database->maximumSize());251 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); 252 252 253 253 ASSERT(!m_sqliteTransaction); 254 m_sqliteTransaction.set(new SQLiteTransaction(m_database-> m_sqliteDatabase, m_readOnly));255 256 m_database-> m_databaseAuthorizer->disable();254 m_sqliteTransaction.set(new SQLiteTransaction(m_database->sqliteDatabase(), m_readOnly)); 255 256 m_database->disableAuthorizer(); 257 257 m_sqliteTransaction->begin(); 258 m_database-> m_databaseAuthorizer->enable();258 m_database->enableAuthorizer(); 259 259 260 260 // Transaction Steps 1+2 - Open a transaction to the database, jumping to the error callback if that fails 261 261 if (!m_sqliteTransaction->inProgress()) { 262 ASSERT(!m_database-> m_sqliteDatabase.transactionInProgress());262 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); 263 263 m_sqliteTransaction.clear(); 264 264 m_transactionError = SQLError::create(0, "unable to open a transaction to the database"); … … 269 269 // Transaction Steps 3 - Peform preflight steps, jumping to the error callback if they fail 270 270 if (m_wrapper && !m_wrapper->performPreflight(this)) { 271 ASSERT(!m_database-> m_sqliteDatabase.transactionInProgress());271 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); 272 272 m_sqliteTransaction.clear(); 273 273 m_transactionError = m_wrapper->sqlError(); … … 327 327 // the quota, which can happen only in a read-write transaction. Therefore, there 328 328 // is no need to check here if the transaction is read-write. 329 m_database-> m_sqliteDatabase.setMaximumSize(m_database->maximumSize());329 m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); 330 330 } else { 331 331 // If the current statement has already been run, failed due to quota constraints, and we're not retrying it, … … 364 364 return false; 365 365 366 m_database-> m_databaseAuthorizer->reset();366 m_database->resetAuthorizer(); 367 367 368 368 if (m_currentStatement->execute(m_database.get())) { 369 if (m_database-> m_databaseAuthorizer->lastActionChangedDatabase()) {369 if (m_database->lastActionChangedDatabase()) { 370 370 // Flag this transaction as having changed the database for later delegate notification 371 371 m_modifiedDatabase = true; … … 456 456 ASSERT(m_sqliteTransaction); 457 457 458 m_database-> m_databaseAuthorizer->disable();458 m_database->disableAuthorizer(); 459 459 m_sqliteTransaction->commit(); 460 m_database-> m_databaseAuthorizer->enable();460 m_database->enableAuthorizer(); 461 461 462 462 // If the commit failed, the transaction will still be marked as "in progress" … … 510 510 // There is no next step 511 511 LOG(StorageAPI, "Transaction %p is complete\n", this); 512 ASSERT(!m_database-> m_sqliteDatabase.transactionInProgress());512 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); 513 513 m_sqliteTransaction.clear(); 514 514 m_nextStep = 0; … … 560 560 ASSERT(m_lockAcquired); 561 561 562 m_database-> m_databaseAuthorizer->disable();562 m_database->disableAuthorizer(); 563 563 if (m_sqliteTransaction) { 564 564 // Transaction Step 12 - Rollback the transaction. 565 565 m_sqliteTransaction->rollback(); 566 566 567 ASSERT(!m_database-> m_sqliteDatabase.transactionInProgress());567 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); 568 568 m_sqliteTransaction.clear(); 569 569 } 570 m_database-> m_databaseAuthorizer->enable();570 m_database->enableAuthorizer(); 571 571 572 572 // Transaction Step 12 - Any still-pending statements in the transaction are discarded. … … 578 578 // Transaction is complete! There is no next step 579 579 LOG(StorageAPI, "Transaction %p is complete with an error\n", this); 580 ASSERT(!m_database-> m_sqliteDatabase.transactionInProgress());580 ASSERT(!m_database->sqliteDatabase().transactionInProgress()); 581 581 m_nextStep = 0; 582 582 -
trunk/WebCore/storage/SQLTransaction.h
r54162 r60508 33 33 #include <wtf/Threading.h> 34 34 35 #include "SQLiteTransaction.h"36 35 #include "SQLStatement.h" 37 #include "SQLTransactionCallback.h"38 #include "SQLTransactionErrorCallback.h"39 36 #include <wtf/Deque.h> 40 37 #include <wtf/Forward.h> 41 #include <wtf/OwnPtr.h>42 #include <wtf/RefPtr.h>43 38 #include <wtf/Vector.h> 44 39 … … 49 44 class Database; 50 45 class SQLError; 46 class SQLiteTransaction; 51 47 class SQLStatementCallback; 52 48 class SQLStatementErrorCallback; 53 49 class SQLTransaction; 50 class SQLTransactionCallback; 51 class SQLTransactionErrorCallback; 54 52 class SQLValue; 55 53 class String; … … 73 71 74 72 void executeSQL(const String& sqlStatement, const Vector<SQLValue>& arguments, 75 PassRefPtr<SQLStatementCallback> callback, PassRefPtr<SQLStatementErrorCallback> callbackError, ExceptionCode& e);73 PassRefPtr<SQLStatementCallback>, PassRefPtr<SQLStatementErrorCallback>, ExceptionCode&); 76 74 77 75 void lockAcquired();
Note: See TracChangeset
for help on using the changeset viewer.