diff options
Diffstat (limited to 'WebCore/storage')
41 files changed, 677 insertions, 295 deletions
diff --git a/WebCore/storage/AbstractDatabase.cpp b/WebCore/storage/AbstractDatabase.cpp index ca9a1b5..bcc5d06 100644 --- a/WebCore/storage/AbstractDatabase.cpp +++ b/WebCore/storage/AbstractDatabase.cpp @@ -32,7 +32,6 @@ #if ENABLE(DATABASE) #include "DatabaseAuthorizer.h" #include "DatabaseTracker.h" -#include "ExceptionCode.h" #include "Logging.h" #include "SQLiteStatement.h" #include "ScriptExecutionContext.h" @@ -462,6 +461,19 @@ void AbstractDatabase::resetAuthorizer() m_databaseAuthorizer->reset(); } +unsigned long long AbstractDatabase::maximumSize() const +{ + return DatabaseTracker::tracker().getMaxSizeForDatabase(this); +} + +void AbstractDatabase::incrementalVacuumIfNeeded() +{ + int64_t freeSpaceSize = m_sqliteDatabase.freeSpaceSize(); + int64_t totalSize = m_sqliteDatabase.totalSize(); + if (totalSize <= 10 * freeSpaceSize) + m_sqliteDatabase.runIncrementalVacuumCommand(); +} + } // namespace WebCore #endif // ENABLE(DATABASE) diff --git a/WebCore/storage/AbstractDatabase.h b/WebCore/storage/AbstractDatabase.h index d38a819..e302909 100644 --- a/WebCore/storage/AbstractDatabase.h +++ b/WebCore/storage/AbstractDatabase.h @@ -31,6 +31,7 @@ #if ENABLE(DATABASE) +#include "ExceptionCode.h" #include "PlatformString.h" #include "SQLiteDatabase.h" #include <wtf/Forward.h> @@ -45,8 +46,6 @@ class DatabaseAuthorizer; class ScriptExecutionContext; class SecurityOrigin; -typedef int ExceptionCode; - class AbstractDatabase : public ThreadSafeShared<AbstractDatabase> { public: static bool isAvailable(); @@ -65,6 +64,10 @@ public: virtual String displayName() const; virtual unsigned long estimatedSize() const; virtual String fileName() const; + SQLiteDatabase& sqliteDatabase() { return m_sqliteDatabase; } + + unsigned long long maximumSize() const; + void incrementalVacuumIfNeeded(); // FIXME: move all version-related methods to a DatabaseVersionTracker class bool versionMatchesExpected() const; @@ -103,8 +106,6 @@ protected: unsigned long m_estimatedSize; String m_filename; - SQLiteDatabase m_sqliteDatabase; - #ifndef NDEBUG String databaseDebugName() const { return m_contextThreadSecurityOrigin->toString() + "::" + m_name; } #endif @@ -116,6 +117,8 @@ private: bool m_opened; bool m_new; + SQLiteDatabase m_sqliteDatabase; + RefPtr<DatabaseAuthorizer> m_databaseAuthorizer; }; diff --git a/WebCore/storage/ChangeVersionWrapper.cpp b/WebCore/storage/ChangeVersionWrapper.cpp index 66ca63f..17be716 100644 --- a/WebCore/storage/ChangeVersionWrapper.cpp +++ b/WebCore/storage/ChangeVersionWrapper.cpp @@ -50,13 +50,13 @@ bool ChangeVersionWrapper::performPreflight(SQLTransaction* transaction) if (!transaction->database()->getVersionFromDatabase(actualVersion)) { LOG_ERROR("Unable to retrieve actual current version from database"); - m_sqlError = SQLError::create(0, "unable to verify current version of database"); + m_sqlError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to verify current version of database"); return false; } if (actualVersion != m_oldVersion) { LOG_ERROR("Old version doesn't match actual version"); - m_sqlError = SQLError::create(2, "current version of the database and `oldVersion` argument do not match"); + m_sqlError = SQLError::create(SQLError::VERSION_ERR, "current version of the database and `oldVersion` argument do not match"); return false; } @@ -69,7 +69,7 @@ bool ChangeVersionWrapper::performPostflight(SQLTransaction* transaction) if (!transaction->database()->setVersionInDatabase(m_newVersion)) { LOG_ERROR("Unable to set new version in database"); - m_sqlError = SQLError::create(0, "unable to set new version in database"); + m_sqlError = SQLError::create(SQLError::UNKNOWN_ERR, "unable to set new version in database"); return false; } diff --git a/WebCore/storage/Database.cpp b/WebCore/storage/Database.cpp index 30087ee..69f5036 100644 --- a/WebCore/storage/Database.cpp +++ b/WebCore/storage/Database.cpp @@ -36,7 +36,6 @@ #include "DatabaseThread.h" #include "DatabaseTracker.h" #include "Document.h" -#include "ExceptionCode.h" #include "InspectorController.h" #include "Logging.h" #include "NotImplemented.h" @@ -141,25 +140,37 @@ Database::Database(ScriptExecutionContext* context, const String& name, const St class DerefContextTask : public ScriptExecutionContext::Task { public: - static PassOwnPtr<DerefContextTask> create() + static PassOwnPtr<DerefContextTask> create(PassRefPtr<ScriptExecutionContext> context) { - return new DerefContextTask(); + return new DerefContextTask(context); } virtual void performTask(ScriptExecutionContext* context) { - context->deref(); + ASSERT_UNUSED(context, context == m_context); + m_context.clear(); } virtual bool isCleanupTask() const { return true; } + +private: + DerefContextTask(PassRefPtr<ScriptExecutionContext> context) + : m_context(context) + { + } + + RefPtr<ScriptExecutionContext> m_context; }; Database::~Database() { // The reference to the ScriptExecutionContext needs to be cleared on the JavaScript thread. If we're on that thread already, we can just let the RefPtr's destruction do the dereffing. if (!m_scriptExecutionContext->isContextThread()) { - m_scriptExecutionContext->postTask(DerefContextTask::create()); - m_scriptExecutionContext.release().releaseRef(); + // Grab a pointer to the script execution here because we're releasing it when we pass it to + // DerefContextTask::create. + ScriptExecutionContext* scriptExecutionContext = m_scriptExecutionContext.get(); + + scriptExecutionContext->postTask(DerefContextTask::create(m_scriptExecutionContext.release())); } } @@ -336,7 +347,7 @@ Vector<String> Database::performGetTableNames() { disableAuthorizer(); - SQLiteStatement statement(m_sqliteDatabase, "SELECT name FROM sqlite_master WHERE type='table';"); + SQLiteStatement statement(sqliteDatabase(), "SELECT name FROM sqlite_master WHERE type='table';"); if (statement.prepare() != SQLResultOk) { LOG_ERROR("Unable to retrieve list of tables for database %s", databaseDebugName().ascii().data()); enableAuthorizer(); @@ -397,14 +408,6 @@ SecurityOrigin* Database::securityOrigin() const return 0; } -void Database::incrementalVacuumIfNeeded() -{ - int64_t freeSpaceSize = m_sqliteDatabase.freeSpaceSize(); - int64_t totalSize = m_sqliteDatabase.totalSize(); - if (totalSize <= 10 * freeSpaceSize) - m_sqliteDatabase.runIncrementalVacuumCommand(); -} - } // namespace WebCore #endif // ENABLE(DATABASE) diff --git a/WebCore/storage/Database.h b/WebCore/storage/Database.h index 22ef55e..e8482a7 100644 --- a/WebCore/storage/Database.h +++ b/WebCore/storage/Database.h @@ -31,8 +31,8 @@ #if ENABLE(DATABASE) #include "AbstractDatabase.h" +#include "ExceptionCode.h" #include "PlatformString.h" -#include "SQLiteDatabase.h" #include <wtf/Deque.h> #include <wtf/Forward.h> @@ -66,7 +66,6 @@ public: Vector<String> tableNames(); virtual SecurityOrigin* securityOrigin() const; - SQLiteDatabase& sqliteDatabase() { return m_sqliteDatabase; } virtual void markAsDeletedAndClose(); bool deleted() const { return m_deleted; } @@ -83,8 +82,6 @@ public: SQLTransactionClient* transactionClient() const; SQLTransactionCoordinator* transactionCoordinator() const; - void incrementalVacuumIfNeeded(); - private: class DatabaseOpenTask; class DatabaseCloseTask; diff --git a/WebCore/storage/DatabaseAuthorizer.cpp b/WebCore/storage/DatabaseAuthorizer.cpp index d155d6c..17abebd 100644 --- a/WebCore/storage/DatabaseAuthorizer.cpp +++ b/WebCore/storage/DatabaseAuthorizer.cpp @@ -290,7 +290,7 @@ int DatabaseAuthorizer::createVTable(const String& tableName, const String& modu return SQLAuthDeny; // Allow only the FTS3 extension - if (moduleName != "fts3") + if (!equalIgnoringCase(moduleName, "fts3")) return SQLAuthDeny; m_lastActionChangedDatabase = true; @@ -303,7 +303,7 @@ int DatabaseAuthorizer::dropVTable(const String& tableName, const String& module return SQLAuthDeny; // Allow only the FTS3 extension - if (moduleName != "fts3") + if (!equalIgnoringCase(moduleName, "fts3")) return SQLAuthDeny; return updateDeletesBasedOnTableName(tableName); diff --git a/WebCore/storage/DatabaseCallback.h b/WebCore/storage/DatabaseCallback.h index dfdc038..9ece2a3 100644 --- a/WebCore/storage/DatabaseCallback.h +++ b/WebCore/storage/DatabaseCallback.h @@ -33,7 +33,7 @@ #if ENABLE(DATABASE) -#include <wtf/Threading.h> +#include <wtf/ThreadSafeShared.h> namespace WebCore { diff --git a/WebCore/storage/DatabaseSync.cpp b/WebCore/storage/DatabaseSync.cpp index 8de9680..f64c27f 100644 --- a/WebCore/storage/DatabaseSync.cpp +++ b/WebCore/storage/DatabaseSync.cpp @@ -2,28 +2,30 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions are + * met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" @@ -32,8 +34,9 @@ #if ENABLE(DATABASE) #include "DatabaseCallback.h" #include "DatabaseTracker.h" -#include "ExceptionCode.h" #include "Logging.h" +#include "SQLException.h" +#include "SQLTransactionSync.h" #include "SQLTransactionSyncCallback.h" #include "ScriptExecutionContext.h" #include "SecurityOrigin.h" @@ -87,14 +90,56 @@ DatabaseSync::~DatabaseSync() } } -void DatabaseSync::changeVersion(const String&, const String&, PassRefPtr<SQLTransactionSyncCallback>, ExceptionCode&) +void DatabaseSync::changeVersion(const String& oldVersion, const String& newVersion, PassRefPtr<SQLTransactionSyncCallback> changeVersionCallback, ExceptionCode& ec) { ASSERT(m_scriptExecutionContext->isContextThread()); + + if (sqliteDatabase().transactionInProgress()) { + ec = SQLException::DATABASE_ERR; + return; + } + + RefPtr<SQLTransactionSync> transaction = SQLTransactionSync::create(this, changeVersionCallback, false); + if ((ec = transaction->begin())) + return; + + String actualVersion; + if (!getVersionFromDatabase(actualVersion)) { + ec = SQLException::UNKNOWN_ERR; + return; + } + + if (actualVersion != oldVersion) { + ec = SQLException::VERSION_ERR; + return; + } + + if ((ec = transaction->execute())) + return; + + if (!setVersionInDatabase(newVersion)) { + ec = SQLException::UNKNOWN_ERR; + return; + } + + if ((ec = transaction->commit())) + return; + + setExpectedVersion(newVersion); } -void DatabaseSync::transaction(PassRefPtr<SQLTransactionSyncCallback>, bool, ExceptionCode&) +void DatabaseSync::transaction(PassRefPtr<SQLTransactionSyncCallback> callback, bool readOnly, ExceptionCode& ec) { ASSERT(m_scriptExecutionContext->isContextThread()); + + if (sqliteDatabase().transactionInProgress()) { + ec = SQLException::DATABASE_ERR; + return; + } + + RefPtr<SQLTransactionSync> transaction = SQLTransactionSync::create(this, callback, readOnly); + if ((ec = transaction->begin()) || (ec = transaction->execute()) || (ec = transaction->commit())) + transaction->rollback(); } void DatabaseSync::markAsDeletedAndClose() diff --git a/WebCore/storage/DatabaseSync.h b/WebCore/storage/DatabaseSync.h index 96b4f7d..2019f85 100644 --- a/WebCore/storage/DatabaseSync.h +++ b/WebCore/storage/DatabaseSync.h @@ -2,28 +2,30 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions are + * met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef DatabaseSync_h @@ -31,6 +33,7 @@ #if ENABLE(DATABASE) #include "AbstractDatabase.h" +#include "ExceptionCode.h" #include "PlatformString.h" #include <wtf/Forward.h> #ifndef NDEBUG @@ -40,6 +43,7 @@ namespace WebCore { class DatabaseCallback; +class SQLTransactionSync; class SQLTransactionSyncCallback; class ScriptExecutionContext; class SecurityOrigin; diff --git a/WebCore/storage/DatabaseSync.idl b/WebCore/storage/DatabaseSync.idl index 29b87a7..30adf38 100644 --- a/WebCore/storage/DatabaseSync.idl +++ b/WebCore/storage/DatabaseSync.idl @@ -2,28 +2,30 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions are + * met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ module storage { diff --git a/WebCore/storage/DatabaseTracker.cpp b/WebCore/storage/DatabaseTracker.cpp index 8d23a4f..de38ec3 100644 --- a/WebCore/storage/DatabaseTracker.cpp +++ b/WebCore/storage/DatabaseTracker.cpp @@ -221,7 +221,6 @@ bool DatabaseTracker::hasEntryForDatabase(SecurityOrigin* origin, const String& unsigned long long DatabaseTracker::getMaxSizeForDatabase(const AbstractDatabase* database) { - ASSERT(currentThread() == database->scriptExecutionContext()->databaseThread()->getThreadID()); // The maximum size for a database is the full quota for its origin, minus the current usage within the origin, // plus the current usage of the given database MutexLocker lockDatabase(m_databaseGuard); diff --git a/WebCore/storage/IDBAny.h b/WebCore/storage/IDBAny.h index ff2d6b9..77bba7c 100644 --- a/WebCore/storage/IDBAny.h +++ b/WebCore/storage/IDBAny.h @@ -44,6 +44,13 @@ class SerializedScriptValue; class IDBAny : public RefCounted<IDBAny> { public: static PassRefPtr<IDBAny> create(); + template<typename T> + static PassRefPtr<IDBAny> create(T* idbObject) + { + RefPtr<IDBAny> any = IDBAny::create(); + any->set(idbObject); + return any.release(); + } ~IDBAny(); enum Type { diff --git a/WebCore/storage/IDBDatabaseRequest.cpp b/WebCore/storage/IDBDatabaseRequest.cpp index 3168d06..fce2671 100644 --- a/WebCore/storage/IDBDatabaseRequest.cpp +++ b/WebCore/storage/IDBDatabaseRequest.cpp @@ -39,10 +39,8 @@ namespace WebCore { IDBDatabaseRequest::IDBDatabaseRequest(PassRefPtr<IDBDatabase> database) : m_database(database) { - m_this = IDBAny::create(); // We pass a reference to this object before it can be adopted. relaxAdoptionRequirement(); - m_this->set(this); } IDBDatabaseRequest::~IDBDatabaseRequest() @@ -51,7 +49,7 @@ IDBDatabaseRequest::~IDBDatabaseRequest() PassRefPtr<IDBRequest> IDBDatabaseRequest::createObjectStore(ScriptExecutionContext* context, const String& name, const String& keyPath, bool autoIncrement) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_database->createObjectStore(name, keyPath, autoIncrement, request); return request; } @@ -65,7 +63,7 @@ PassRefPtr<IDBObjectStoreRequest> IDBDatabaseRequest::objectStore(const String& PassRefPtr<IDBRequest> IDBDatabaseRequest::removeObjectStore(ScriptExecutionContext* context, const String& name) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_database->removeObjectStore(name, request); return request; } diff --git a/WebCore/storage/IDBDatabaseRequest.h b/WebCore/storage/IDBDatabaseRequest.h index 23b1ecc..fd19882 100644 --- a/WebCore/storage/IDBDatabaseRequest.h +++ b/WebCore/storage/IDBDatabaseRequest.h @@ -63,7 +63,6 @@ private: IDBDatabaseRequest(PassRefPtr<IDBDatabase>); RefPtr<IDBDatabase> m_database; - RefPtr<IDBAny> m_this; }; } // namespace WebCore diff --git a/WebCore/storage/IDBKeyRange.cpp b/WebCore/storage/IDBKeyRange.cpp index 34c11fe..9f22fc8 100644 --- a/WebCore/storage/IDBKeyRange.cpp +++ b/WebCore/storage/IDBKeyRange.cpp @@ -34,12 +34,10 @@ namespace WebCore { IDBKeyRange::IDBKeyRange(PassRefPtr<SerializedScriptValue> left, PassRefPtr<SerializedScriptValue> right, unsigned short flags) - : m_left(IDBAny::create()) - , m_right(IDBAny::create()) + : m_left(left) + , m_right(right) , m_flags(flags) { - m_left->set(left); - m_right->set(right); } } // namespace WebCore diff --git a/WebCore/storage/IDBKeyRange.h b/WebCore/storage/IDBKeyRange.h index 4c5efe2..52239e4 100644 --- a/WebCore/storage/IDBKeyRange.h +++ b/WebCore/storage/IDBKeyRange.h @@ -53,15 +53,15 @@ public: ~IDBKeyRange() { } - PassRefPtr<IDBAny> left() const { return m_left; } - PassRefPtr<IDBAny> right() const { return m_right; } + PassRefPtr<IDBAny> left() const { return IDBAny::create(m_left.get()); } + PassRefPtr<IDBAny> right() const { return IDBAny::create(m_right.get()); } unsigned short flags() const { return m_flags; } private: IDBKeyRange(PassRefPtr<SerializedScriptValue> left, PassRefPtr<SerializedScriptValue> right, unsigned short flags); - RefPtr<IDBAny> m_left; - RefPtr<IDBAny> m_right; + RefPtr<SerializedScriptValue> m_left; + RefPtr<SerializedScriptValue> m_right; unsigned short m_flags; }; diff --git a/WebCore/storage/IDBObjectStoreRequest.cpp b/WebCore/storage/IDBObjectStoreRequest.cpp index fdd498b..3e095c1 100644 --- a/WebCore/storage/IDBObjectStoreRequest.cpp +++ b/WebCore/storage/IDBObjectStoreRequest.cpp @@ -40,10 +40,8 @@ namespace WebCore { IDBObjectStoreRequest::IDBObjectStoreRequest(PassRefPtr<IDBObjectStore> idbObjectStore) : m_objectStore(idbObjectStore) { - m_this = IDBAny::create(); // We pass a reference to this object before it can be adopted. relaxAdoptionRequirement(); - m_this->set(this); } String IDBObjectStoreRequest::name() const @@ -63,35 +61,35 @@ PassRefPtr<DOMStringList> IDBObjectStoreRequest::indexNames() const PassRefPtr<IDBRequest> IDBObjectStoreRequest::get(ScriptExecutionContext* context, PassRefPtr<IDBKey> key) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_objectStore->get(key, request); return request; } PassRefPtr<IDBRequest> IDBObjectStoreRequest::add(ScriptExecutionContext* context, PassRefPtr<SerializedScriptValue> value, PassRefPtr<IDBKey> key) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_objectStore->put(value, key, true, request); return request; } PassRefPtr<IDBRequest> IDBObjectStoreRequest::put(ScriptExecutionContext* context, PassRefPtr<SerializedScriptValue> value, PassRefPtr<IDBKey> key) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_objectStore->put(value, key, false, request); return request; } PassRefPtr<IDBRequest> IDBObjectStoreRequest::remove(ScriptExecutionContext* context, PassRefPtr<IDBKey> key) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_objectStore->remove(key, request); return request; } PassRefPtr<IDBRequest> IDBObjectStoreRequest::createIndex(ScriptExecutionContext* context, const String& name, const String& keyPath, bool unique) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_objectStore->createIndex(name, keyPath, unique, request); return request; } @@ -105,7 +103,7 @@ PassRefPtr<IDBIndexRequest> IDBObjectStoreRequest::index(const String& name) PassRefPtr<IDBRequest> IDBObjectStoreRequest::removeIndex(ScriptExecutionContext* context, const String& name) { - RefPtr<IDBRequest> request = IDBRequest::create(context, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this)); m_objectStore->removeIndex(name, request); return request; } diff --git a/WebCore/storage/IDBObjectStoreRequest.h b/WebCore/storage/IDBObjectStoreRequest.h index af752f5..86f64d6 100644 --- a/WebCore/storage/IDBObjectStoreRequest.h +++ b/WebCore/storage/IDBObjectStoreRequest.h @@ -68,7 +68,6 @@ private: IDBObjectStoreRequest(PassRefPtr<IDBObjectStore>); RefPtr<IDBObjectStore> m_objectStore; - RefPtr<IDBAny> m_this; }; } // namespace WebCore diff --git a/WebCore/storage/IndexedDatabaseRequest.cpp b/WebCore/storage/IndexedDatabaseRequest.cpp index a25fb2b..45ae1bd 100644 --- a/WebCore/storage/IndexedDatabaseRequest.cpp +++ b/WebCore/storage/IndexedDatabaseRequest.cpp @@ -44,10 +44,8 @@ namespace WebCore { IndexedDatabaseRequest::IndexedDatabaseRequest(IndexedDatabase* indexedDatabase) : m_indexedDatabase(indexedDatabase) { - m_this = IDBAny::create(); // We pass a reference to this object before it can be adopted. relaxAdoptionRequirement(); - m_this->set(this); } IndexedDatabaseRequest::~IndexedDatabaseRequest() @@ -65,7 +63,7 @@ PassRefPtr<IDBRequest> IndexedDatabaseRequest::open(ScriptExecutionContext* cont if (!document->frame()) return 0; - RefPtr<IDBRequest> request = IDBRequest::create(document, m_this); + RefPtr<IDBRequest> request = IDBRequest::create(document, IDBAny::create(this)); m_indexedDatabase->open(name, description, request, document->securityOrigin(), document->frame()); return request; } diff --git a/WebCore/storage/IndexedDatabaseRequest.h b/WebCore/storage/IndexedDatabaseRequest.h index 9802380..f505d9d 100644 --- a/WebCore/storage/IndexedDatabaseRequest.h +++ b/WebCore/storage/IndexedDatabaseRequest.h @@ -64,7 +64,6 @@ private: IndexedDatabaseRequest(IndexedDatabase*); RefPtr<IndexedDatabase> m_indexedDatabase; - RefPtr<IDBAny> m_this; }; } // namespace WebCore diff --git a/WebCore/storage/SQLError.h b/WebCore/storage/SQLError.h index efbe4ec..496145a 100644 --- a/WebCore/storage/SQLError.h +++ b/WebCore/storage/SQLError.h @@ -32,7 +32,7 @@ #if ENABLE(DATABASE) #include "PlatformString.h" -#include <wtf/Threading.h> +#include <wtf/ThreadSafeShared.h> namespace WebCore { diff --git a/WebCore/storage/SQLException.idl b/WebCore/storage/SQLException.idl index 9830142..cbbc311 100644 --- a/WebCore/storage/SQLException.idl +++ b/WebCore/storage/SQLException.idl @@ -32,7 +32,8 @@ module storage { interface [ Conditional=DATABASE, - NoStaticTables + NoStaticTables, + DontCheckEnums ] SQLException { readonly attribute unsigned long code; readonly attribute DOMString message; diff --git a/WebCore/storage/SQLResultSet.cpp b/WebCore/storage/SQLResultSet.cpp index 19c66c7..7482628 100644 --- a/WebCore/storage/SQLResultSet.cpp +++ b/WebCore/storage/SQLResultSet.cpp @@ -31,9 +31,6 @@ #if ENABLE(DATABASE) -#include "ExceptionCode.h" -#include "SQLValue.h" - namespace WebCore { static unsigned const MaxErrorCode = 2; diff --git a/WebCore/storage/SQLResultSet.h b/WebCore/storage/SQLResultSet.h index 5a0ff78..268472f 100644 --- a/WebCore/storage/SQLResultSet.h +++ b/WebCore/storage/SQLResultSet.h @@ -31,13 +31,12 @@ #if ENABLE(DATABASE) +#include "ExceptionCode.h" #include "SQLResultSetRowList.h" -#include <wtf/Threading.h> +#include <wtf/ThreadSafeShared.h> namespace WebCore { -typedef int ExceptionCode; - class SQLResultSet : public ThreadSafeShared<SQLResultSet> { public: static PassRefPtr<SQLResultSet> create() { return adoptRef(new SQLResultSet); } diff --git a/WebCore/storage/SQLStatementCallback.h b/WebCore/storage/SQLStatementCallback.h index 68e7cb8..4bb2e06 100644 --- a/WebCore/storage/SQLStatementCallback.h +++ b/WebCore/storage/SQLStatementCallback.h @@ -30,7 +30,7 @@ #if ENABLE(DATABASE) -#include <wtf/Threading.h> +#include <wtf/ThreadSafeShared.h> namespace WebCore { diff --git a/WebCore/storage/SQLStatementErrorCallback.h b/WebCore/storage/SQLStatementErrorCallback.h index 8db98be..7c45afd 100644 --- a/WebCore/storage/SQLStatementErrorCallback.h +++ b/WebCore/storage/SQLStatementErrorCallback.h @@ -31,7 +31,7 @@ #if ENABLE(DATABASE) -#include <wtf/Threading.h> +#include <wtf/ThreadSafeShared.h> namespace WebCore { diff --git a/WebCore/storage/SQLStatementSync.cpp b/WebCore/storage/SQLStatementSync.cpp new file mode 100644 index 0000000..7be3f50 --- /dev/null +++ b/WebCore/storage/SQLStatementSync.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "SQLStatementSync.h" + +#if ENABLE(DATABASE) + +#include "DatabaseSync.h" +#include "SQLException.h" +#include "SQLResultSet.h" +#include "SQLValue.h" +#include "SQLiteDatabase.h" +#include "SQLiteStatement.h" +#include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> + +namespace WebCore { + +SQLStatementSync::SQLStatementSync(const String& statement, const Vector<SQLValue>& arguments, bool readOnly) + : m_statement(statement) + , m_arguments(arguments) + , m_readOnly(readOnly) +{ + ASSERT(!m_statement.isEmpty()); +} + +PassRefPtr<SQLResultSet> SQLStatementSync::execute(DatabaseSync* db, ExceptionCode& ec) +{ + if (m_readOnly) + db->setAuthorizerReadOnly(); + + SQLiteDatabase* database = &db->sqliteDatabase(); + + SQLiteStatement statement(*database, m_statement); + int result = statement.prepare(); + if (result != SQLResultOk) { + ec = SQLException::SYNTAX_ERR; + return 0; + } + + if (statement.bindParameterCount() != m_arguments.size()) { + ec = SQLException::SYNTAX_ERR; + return 0; + } + + for (unsigned i = 0; i < m_arguments.size(); ++i) { + result = statement.bindValue(i + 1, m_arguments[i]); + if (result == SQLResultFull) { + ec = SQLException::QUOTA_ERR; + return 0; + } + + if (result != SQLResultOk) { + ec = SQLException::DATABASE_ERR; + return 0; + } + } + + RefPtr<SQLResultSet> resultSet = SQLResultSet::create(); + + // Step so we can fetch the column names. + result = statement.step(); + if (result == SQLResultRow) { + int columnCount = statement.columnCount(); + SQLResultSetRowList* rows = resultSet->rows(); + + for (int i = 0; i < columnCount; i++) + rows->addColumn(statement.getColumnName(i)); + + do { + for (int i = 0; i < columnCount; i++) + rows->addResult(statement.getColumnValue(i)); + + result = statement.step(); + } while (result == SQLResultRow); + + if (result != SQLResultDone) { + ec = SQLException::DATABASE_ERR; + return 0; + } + } else if (result == SQLResultDone) { + // Didn't find anything, or was an insert. + if (db->lastActionWasInsert()) + resultSet->setInsertId(database->lastInsertRowID()); + } else if (result == SQLResultFull) { + // Quota error, the delegate will be asked for more space and this statement might be re-run. + ec = SQLException::QUOTA_ERR; + return 0; + } else { + ec = SQLException::DATABASE_ERR; + return 0; + } + + resultSet->setRowsAffected(database->lastChanges()); + return resultSet.release(); +} + +} // namespace WebCore + +#endif // ENABLE(DATABASE) diff --git a/WebCore/storage/SQLStatementSync.h b/WebCore/storage/SQLStatementSync.h new file mode 100644 index 0000000..dc0394c --- /dev/null +++ b/WebCore/storage/SQLStatementSync.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SQLStatementSync_h +#define SQLStatementSync_h + +#if ENABLE(DATABASE) + +#include "ExceptionCode.h" +#include "PlatformString.h" +#include "SQLValue.h" +#include <wtf/Forward.h> +#include <wtf/Vector.h> + +namespace WebCore { + +class DatabaseSync; +class SQLResultSet; + +class SQLStatementSync { +public: + SQLStatementSync(const String& statement, const Vector<SQLValue>& arguments, bool readOnly); + + PassRefPtr<SQLResultSet> execute(DatabaseSync*, ExceptionCode&); + +private: + String m_statement; + Vector<SQLValue> m_arguments; + bool m_readOnly; +}; + +} // namespace WebCore + +#endif // ENABLE(DATABASE) + +#endif // SQLStatementSync_h diff --git a/WebCore/storage/SQLTransaction.cpp b/WebCore/storage/SQLTransaction.cpp index 960427b..decdf24 100644 --- a/WebCore/storage/SQLTransaction.cpp +++ b/WebCore/storage/SQLTransaction.cpp @@ -33,7 +33,6 @@ #include "Database.h" #include "DatabaseThread.h" -#include "ExceptionCode.h" #include "Logging.h" #include "PlatformString.h" #include "ScriptExecutionContext.h" @@ -370,7 +369,7 @@ bool SQLTransaction::runCurrentStatement() // Flag this transaction as having changed the database for later delegate notification m_modifiedDatabase = true; // Also dirty the size of this database file for calculating quota usage - m_database->transactionClient()->didExecuteStatement(this); + m_database->transactionClient()->didExecuteStatement(database()); } if (m_currentStatement->hasStatementCallback()) { @@ -432,7 +431,7 @@ void SQLTransaction::deliverQuotaIncreaseCallback() ASSERT(m_currentStatement); ASSERT(!m_shouldRetryCurrentStatement); - m_shouldRetryCurrentStatement = m_database->transactionClient()->didExceedQuota(this); + m_shouldRetryCurrentStatement = m_database->transactionClient()->didExceedQuota(database()); m_nextStep = &SQLTransaction::runStatements; LOG(StorageAPI, "Scheduling runStatements for transaction %p\n", this); @@ -472,7 +471,7 @@ void SQLTransaction::postflightAndCommit() // The commit was successful. If the transaction modified this database, notify the delegates. if (m_modifiedDatabase) - m_database->transactionClient()->didCommitTransaction(this); + m_database->transactionClient()->didCommitWriteTransaction(database()); // Now release our unneeded callbacks, to break reference cycles. m_callback = 0; diff --git a/WebCore/storage/SQLTransaction.h b/WebCore/storage/SQLTransaction.h index 3cef036..5c62ca2 100644 --- a/WebCore/storage/SQLTransaction.h +++ b/WebCore/storage/SQLTransaction.h @@ -30,17 +30,15 @@ #if ENABLE(DATABASE) -#include <wtf/Threading.h> - +#include "ExceptionCode.h" #include "SQLStatement.h" #include <wtf/Deque.h> #include <wtf/Forward.h> +#include <wtf/ThreadSafeShared.h> #include <wtf/Vector.h> namespace WebCore { -typedef int ExceptionCode; - class Database; class SQLError; class SQLiteTransaction; diff --git a/WebCore/storage/SQLTransactionCallback.h b/WebCore/storage/SQLTransactionCallback.h index 048410f..73123ee 100644 --- a/WebCore/storage/SQLTransactionCallback.h +++ b/WebCore/storage/SQLTransactionCallback.h @@ -31,7 +31,7 @@ #if ENABLE(DATABASE) -#include <wtf/Threading.h> +#include <wtf/ThreadSafeShared.h> namespace WebCore { diff --git a/WebCore/storage/SQLTransactionClient.cpp b/WebCore/storage/SQLTransactionClient.cpp index 32c8e07..6b95606 100644 --- a/WebCore/storage/SQLTransactionClient.cpp +++ b/WebCore/storage/SQLTransactionClient.cpp @@ -33,36 +33,27 @@ #if ENABLE(DATABASE) -#include "Chrome.h" -#include "ChromeClient.h" -#include "Database.h" -#include "DatabaseThread.h" +#include "AbstractDatabase.h" #include "DatabaseTracker.h" -#include "Document.h" -#include "Page.h" -#include "SQLTransaction.h" +#include "ScriptExecutionContext.h" +#include "SecurityOrigin.h" namespace WebCore { -void SQLTransactionClient::didCommitTransaction(SQLTransaction* transaction) +void SQLTransactionClient::didCommitWriteTransaction(AbstractDatabase* database) { - ASSERT(currentThread() == transaction->database()->scriptExecutionContext()->databaseThread()->getThreadID()); - Database* database = transaction->database(); DatabaseTracker::tracker().scheduleNotifyDatabaseChanged( database->securityOrigin(), database->stringIdentifier()); } -void SQLTransactionClient::didExecuteStatement(SQLTransaction* transaction) +void SQLTransactionClient::didExecuteStatement(AbstractDatabase* database) { - ASSERT(currentThread() == transaction->database()->scriptExecutionContext()->databaseThread()->getThreadID()); - DatabaseTracker::tracker().databaseChanged(transaction->database()); + DatabaseTracker::tracker().databaseChanged(database); } -bool SQLTransactionClient::didExceedQuota(SQLTransaction* transaction) +bool SQLTransactionClient::didExceedQuota(AbstractDatabase* database) { - ASSERT(transaction->database()->scriptExecutionContext()->isContextThread()); - Database* database = transaction->database(); - + ASSERT(database->scriptExecutionContext()->isContextThread()); unsigned long long currentQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin()); database->scriptExecutionContext()->databaseExceededQuota(database->stringIdentifier()); unsigned long long newQuota = DatabaseTracker::tracker().quotaForOrigin(database->securityOrigin()); diff --git a/WebCore/storage/SQLTransactionClient.h b/WebCore/storage/SQLTransactionClient.h index 801647b..fed0657 100644 --- a/WebCore/storage/SQLTransactionClient.h +++ b/WebCore/storage/SQLTransactionClient.h @@ -37,16 +37,17 @@ namespace WebCore { - class SQLTransaction; - - // A client to the SQLTransaction class. Allows SQLTransaction to notify interested - // parties that certain things have happened in a transaction. - class SQLTransactionClient : public Noncopyable { - public: - void didCommitTransaction(SQLTransaction*); - void didExecuteStatement(SQLTransaction*); - bool didExceedQuota(SQLTransaction*); - }; +class AbstractDatabase; + +// A client to the SQLTransaction class. Allows SQLTransaction to notify interested +// parties that certain things have happened in a transaction. +class SQLTransactionClient : public Noncopyable { +public: + void didCommitWriteTransaction(AbstractDatabase*); + void didExecuteStatement(AbstractDatabase*); + bool didExceedQuota(AbstractDatabase*); +}; + } #endif // ENABLE(DATABASE) diff --git a/WebCore/storage/SQLTransactionErrorCallback.h b/WebCore/storage/SQLTransactionErrorCallback.h index 2fe2cb3..71580eb 100644 --- a/WebCore/storage/SQLTransactionErrorCallback.h +++ b/WebCore/storage/SQLTransactionErrorCallback.h @@ -31,7 +31,7 @@ #if ENABLE(DATABASE) -#include <wtf/Threading.h> +#include <wtf/ThreadSafeShared.h> namespace WebCore { diff --git a/WebCore/storage/SQLTransactionSync.cpp b/WebCore/storage/SQLTransactionSync.cpp index 5e7c879..af98f8f 100644 --- a/WebCore/storage/SQLTransactionSync.cpp +++ b/WebCore/storage/SQLTransactionSync.cpp @@ -2,28 +2,30 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions are + * met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" @@ -32,11 +34,14 @@ #if ENABLE(DATABASE) #include "DatabaseSync.h" -#include "ExceptionCode.h" #include "PlatformString.h" +#include "SQLException.h" #include "SQLResultSet.h" +#include "SQLStatementSync.h" +#include "SQLTransactionClient.h" #include "SQLTransactionSyncCallback.h" #include "SQLValue.h" +#include "SQLiteTransaction.h" #include "ScriptExecutionContext.h" #include <wtf/PassRefPtr.h> #include <wtf/RefPtr.h> @@ -52,22 +57,150 @@ SQLTransactionSync::SQLTransactionSync(DatabaseSync* db, PassRefPtr<SQLTransacti : m_database(db) , m_callback(callback) , m_readOnly(readOnly) + , m_modifiedDatabase(false) + , m_transactionClient(new SQLTransactionClient()) { ASSERT(m_database->scriptExecutionContext()->isContextThread()); - ASSERT(callback); } SQLTransactionSync::~SQLTransactionSync() { ASSERT(m_database->scriptExecutionContext()->isContextThread()); + if (m_sqliteTransaction && m_sqliteTransaction->inProgress()) + rollback(); } -PassRefPtr<SQLResultSet> SQLTransactionSync::executeSQL(const String&, const Vector<SQLValue>&, ExceptionCode&) +PassRefPtr<SQLResultSet> SQLTransactionSync::executeSQL(const String& sqlStatement, const Vector<SQLValue>& arguments, ExceptionCode& ec) { ASSERT(m_database->scriptExecutionContext()->isContextThread()); + if (!m_database->opened()) { + ec = SQLException::UNKNOWN_ERR; + return 0; + } + + if (!m_database->versionMatchesExpected()) { + ec = SQLException::VERSION_ERR; + return 0; + } + + if (sqlStatement.isEmpty()) + return 0; + + bool readOnlyMode = m_readOnly || m_database->scriptExecutionContext()->isDatabaseReadOnly(); + SQLStatementSync statement(sqlStatement, arguments, readOnlyMode); + + m_database->resetAuthorizer(); + bool retryStatement = true; + RefPtr<SQLResultSet> resultSet; + while (retryStatement) { + retryStatement = false; + resultSet = statement.execute(m_database.get(), ec); + if (!resultSet) { + if (m_sqliteTransaction->wasRolledBackBySqlite()) + return 0; + + if (ec == SQLException::QUOTA_ERR) { + if (m_transactionClient->didExceedQuota(database())) { + ec = 0; + retryStatement = true; + } else + return 0; + } + } + } + + if (m_database->lastActionChangedDatabase()) { + m_modifiedDatabase = true; + m_transactionClient->didExecuteStatement(database()); + } + + return resultSet.release(); +} + +ExceptionCode SQLTransactionSync::begin() +{ + ASSERT(m_database->scriptExecutionContext()->isContextThread()); + if (!m_database->opened()) + return SQLException::UNKNOWN_ERR; + + ASSERT(!m_database->sqliteDatabase().transactionInProgress()); + + // Set the maximum usage for this transaction if this transactions is not read-only. + if (!m_readOnly) + m_database->sqliteDatabase().setMaximumSize(m_database->maximumSize()); + + ASSERT(!m_sqliteTransaction); + m_sqliteTransaction.set(new SQLiteTransaction(m_database->sqliteDatabase(), m_readOnly)); + + m_database->resetDeletes(); + m_database->disableAuthorizer(); + m_sqliteTransaction->begin(); + m_database->enableAuthorizer(); + + // Check if begin() succeeded. + if (!m_sqliteTransaction->inProgress()) { + ASSERT(!m_database->sqliteDatabase().transactionInProgress()); + m_sqliteTransaction.clear(); + return SQLException::DATABASE_ERR; + } + + return 0; +} + +ExceptionCode SQLTransactionSync::execute() +{ + ASSERT(m_database->scriptExecutionContext()->isContextThread()); + if (!m_database->opened() || !m_callback || !m_callback->handleEvent(m_database->scriptExecutionContext(), this)) { + m_callback = 0; + return SQLException::UNKNOWN_ERR; + } + + m_callback = 0; + return 0; +} + +ExceptionCode SQLTransactionSync::commit() +{ + ASSERT(m_database->scriptExecutionContext()->isContextThread()); + if (!m_database->opened()) + return SQLException::UNKNOWN_ERR; + + ASSERT(m_sqliteTransaction); + + m_database->disableAuthorizer(); + m_sqliteTransaction->commit(); + m_database->enableAuthorizer(); + + // If the commit failed, the transaction will still be marked as "in progress" + if (m_sqliteTransaction->inProgress()) + return SQLException::DATABASE_ERR; + + m_sqliteTransaction.clear(); + + // Vacuum the database if anything was deleted. + if (m_database->hadDeletes()) + m_database->incrementalVacuumIfNeeded(); + + // The commit was successful. If the transaction modified this database, notify the delegates. + if (m_modifiedDatabase) + m_transactionClient->didCommitWriteTransaction(database()); + return 0; } +void SQLTransactionSync::rollback() +{ + ASSERT(m_database->scriptExecutionContext()->isContextThread()); + m_database->disableAuthorizer(); + if (m_sqliteTransaction) { + m_sqliteTransaction->rollback(); + m_sqliteTransaction.clear(); + } + m_database->enableAuthorizer(); + + ASSERT(!m_database->sqliteDatabase().transactionInProgress()); +} + } // namespace WebCore #endif // ENABLE(DATABASE) diff --git a/WebCore/storage/SQLTransactionSync.h b/WebCore/storage/SQLTransactionSync.h index 7c03927..025215b 100644 --- a/WebCore/storage/SQLTransactionSync.h +++ b/WebCore/storage/SQLTransactionSync.h @@ -2,46 +2,50 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions are + * met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #ifndef SQLTransactionSync_h #define SQLTransactionSync_h #if ENABLE(DATABASE) +#include "ExceptionCode.h" #include <wtf/Forward.h> #include <wtf/RefCounted.h> #include <wtf/Vector.h> namespace WebCore { -typedef int ExceptionCode; - class DatabaseSync; class SQLResultSet; +class SQLTransactionClient; class SQLTransactionSyncCallback; class SQLValue; +class SQLiteTransaction; class String; // Instances of this class should be created and used only on the worker's context thread. @@ -56,12 +60,21 @@ public: DatabaseSync* database() { return m_database.get(); } bool isReadOnly() const { return m_readOnly; } + ExceptionCode begin(); + ExceptionCode execute(); + ExceptionCode commit(); + void rollback(); + private: SQLTransactionSync(DatabaseSync*, PassRefPtr<SQLTransactionSyncCallback>, bool readOnly); RefPtr<DatabaseSync> m_database; RefPtr<SQLTransactionSyncCallback> m_callback; bool m_readOnly; + + bool m_modifiedDatabase; + OwnPtr<SQLTransactionClient> m_transactionClient; + OwnPtr<SQLiteTransaction> m_sqliteTransaction; }; } // namespace WebCore diff --git a/WebCore/storage/SQLTransactionSync.idl b/WebCore/storage/SQLTransactionSync.idl index a4002b1..003a21d 100644 --- a/WebCore/storage/SQLTransactionSync.idl +++ b/WebCore/storage/SQLTransactionSync.idl @@ -2,28 +2,30 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions are + * met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ module storage { diff --git a/WebCore/storage/SQLTransactionSyncCallback.h b/WebCore/storage/SQLTransactionSyncCallback.h index eba82b0..557db86 100644 --- a/WebCore/storage/SQLTransactionSyncCallback.h +++ b/WebCore/storage/SQLTransactionSyncCallback.h @@ -2,28 +2,30 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - *Transaction - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * modification, are permitted provided that the following conditions are + * met: * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef SQLTransactionSyncCallback_h @@ -32,7 +34,6 @@ #if ENABLE(DATABASE) #include <wtf/RefCounted.h> -#include <wtf/Threading.h> namespace WebCore { diff --git a/WebCore/storage/SQLTransactionSyncCallback.idl b/WebCore/storage/SQLTransactionSyncCallback.idl index 1bff22b..b0fffca 100644 --- a/WebCore/storage/SQLTransactionSyncCallback.idl +++ b/WebCore/storage/SQLTransactionSyncCallback.idl @@ -2,28 +2,30 @@ * Copyright (C) 2010 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * modification, are permitted provided that the following conditions are + * met: * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ module storage { diff --git a/WebCore/storage/chromium/DatabaseTrackerChromium.cpp b/WebCore/storage/chromium/DatabaseTrackerChromium.cpp index 13c65cc..7d9c4de 100644 --- a/WebCore/storage/chromium/DatabaseTrackerChromium.cpp +++ b/WebCore/storage/chromium/DatabaseTrackerChromium.cpp @@ -33,16 +33,13 @@ #include "AbstractDatabase.h" #include "DatabaseObserver.h" -#include "DatabaseThread.h" #include "QuotaTracker.h" +#include "PlatformString.h" #include "ScriptExecutionContext.h" #include "SecurityOrigin.h" #include "SecurityOriginHash.h" #include "SQLiteFileSystem.h" -#include <wtf/HashSet.h> -#include <wtf/MainThread.h> #include <wtf/StdLibExtras.h> -#include <wtf/text/CString.h> namespace WebCore { @@ -167,7 +164,6 @@ void DatabaseTracker::getOpenDatabases(SecurityOrigin* origin, const String& nam unsigned long long DatabaseTracker::getMaxSizeForDatabase(const AbstractDatabase* database) { - ASSERT(currentThread() == database->scriptExecutionContext()->databaseThread()->getThreadID()); unsigned long long spaceAvailable = 0; unsigned long long databaseSize = 0; QuotaTracker::instance().getDatabaseSizeAndSpaceAvailableToOrigin( diff --git a/WebCore/storage/chromium/SQLTransactionClientChromium.cpp b/WebCore/storage/chromium/SQLTransactionClientChromium.cpp index a10ca3e..22d95e6 100644 --- a/WebCore/storage/chromium/SQLTransactionClientChromium.cpp +++ b/WebCore/storage/chromium/SQLTransactionClientChromium.cpp @@ -31,18 +31,15 @@ #include "config.h" #include "SQLTransactionClient.h" -#include "Database.h" +#include "AbstractDatabase.h" #include "DatabaseObserver.h" -#include "DatabaseThread.h" -#include "Document.h" -#include "SQLTransaction.h" -#include <wtf/MainThread.h> +#include "ScriptExecutionContext.h" namespace WebCore { class NotifyDatabaseChangedTask : public ScriptExecutionContext::Task { public: - static PassOwnPtr<NotifyDatabaseChangedTask> create(Database *database) + static PassOwnPtr<NotifyDatabaseChangedTask> create(AbstractDatabase *database) { return new NotifyDatabaseChangedTask(database); } @@ -53,34 +50,35 @@ public: } private: - NotifyDatabaseChangedTask(PassRefPtr<Database> database) + NotifyDatabaseChangedTask(PassRefPtr<AbstractDatabase> database) : m_database(database) { } - RefPtr<Database> m_database; + RefPtr<AbstractDatabase> m_database; }; -void SQLTransactionClient::didCommitTransaction(SQLTransaction* transaction) +void SQLTransactionClient::didCommitWriteTransaction(AbstractDatabase* database) { - ASSERT(currentThread() == transaction->database()->scriptExecutionContext()->databaseThread()->getThreadID()); - if (!transaction->isReadOnly()) { - transaction->database()->scriptExecutionContext()->postTask(NotifyDatabaseChangedTask::create(transaction->database())); + if (!database->scriptExecutionContext()->isContextThread()) { + database->scriptExecutionContext()->postTask(NotifyDatabaseChangedTask::create(database)); + return; } + + WebCore::DatabaseObserver::databaseModified(database); } -void SQLTransactionClient::didExecuteStatement(SQLTransaction* transaction) +void SQLTransactionClient::didExecuteStatement(AbstractDatabase* database) { // This method is called after executing every statement that changes the DB. // Chromium doesn't need to do anything at that point. - ASSERT(currentThread() == transaction->database()->scriptExecutionContext()->databaseThread()->getThreadID()); } -bool SQLTransactionClient::didExceedQuota(SQLTransaction* transaction) +bool SQLTransactionClient::didExceedQuota(AbstractDatabase* database) { // Chromium does not allow users to manually change the quota for an origin (for now, at least). // Don't do anything. - ASSERT(transaction->database()->scriptExecutionContext()->isContextThread()); + ASSERT(database->scriptExecutionContext()->isContextThread()); return false; } |