Diff
Modified: branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp (119485 => 119486)
--- branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp 2012-06-05 14:50:04 UTC (rev 119485)
+++ branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp 2012-06-05 14:51:00 UTC (rev 119486)
@@ -93,6 +93,14 @@
RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
};
+PassRefPtr<IDBDatabaseBackendImpl> IDBDatabaseBackendImpl::create(const String& name, IDBBackingStore* database, IDBTransactionCoordinator* coordinator, IDBFactoryBackendImpl* factory, const String& uniqueIdentifier)
+{
+ RefPtr<IDBDatabaseBackendImpl> backend = adoptRef(new IDBDatabaseBackendImpl(name, database, coordinator, factory, uniqueIdentifier));
+ if (!backend->openInternal())
+ return 0;
+ return backend.release();
+}
+
IDBDatabaseBackendImpl::IDBDatabaseBackendImpl(const String& name, IDBBackingStore* backingStore, IDBTransactionCoordinator* coordinator, IDBFactoryBackendImpl* factory, const String& uniqueIdentifier)
: m_backingStore(backingStore)
, m_id(InvalidId)
@@ -103,19 +111,17 @@
, m_transactionCoordinator(coordinator)
{
ASSERT(!m_name.isNull());
- openInternal();
}
-void IDBDatabaseBackendImpl::openInternal()
+bool IDBDatabaseBackendImpl::openInternal()
{
bool success = m_backingStore->getIDBDatabaseMetaData(m_name, m_version, m_id);
ASSERT(success == (m_id != InvalidId));
if (success) {
loadObjectStores();
- return;
+ return true;
}
- if (!m_backingStore->createIDBDatabaseMetaData(m_name, m_version, m_id))
- ASSERT_NOT_REACHED(); // FIXME: Need better error handling.
+ return m_backingStore->createIDBDatabaseMetaData(m_name, m_version, m_id);
}
IDBDatabaseBackendImpl::~IDBDatabaseBackendImpl()
@@ -325,9 +331,10 @@
if (!m_pendingDeleteCalls.isEmpty() || m_runningVersionChangeTransaction || !m_pendingSetVersionCalls.isEmpty())
m_pendingOpenCalls.append(PendingOpenCall::create(callbacks));
else {
- if (m_id == InvalidId)
- openInternal();
- callbacks->onSuccess(this);
+ if (m_id == InvalidId && !openInternal())
+ callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
+ else
+ callbacks->onSuccess(this);
}
}
Modified: branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h (119485 => 119486)
--- branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h 2012-06-05 14:50:04 UTC (rev 119485)
+++ branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h 2012-06-05 14:51:00 UTC (rev 119486)
@@ -45,10 +45,7 @@
class IDBDatabaseBackendImpl : public IDBDatabaseBackendInterface {
public:
- static PassRefPtr<IDBDatabaseBackendImpl> create(const String& name, IDBBackingStore* database, IDBTransactionCoordinator* coordinator, IDBFactoryBackendImpl* factory, const String& uniqueIdentifier)
- {
- return adoptRef(new IDBDatabaseBackendImpl(name, database, coordinator, factory, uniqueIdentifier));
- }
+ static PassRefPtr<IDBDatabaseBackendImpl> create(const String& name, IDBBackingStore* database, IDBTransactionCoordinator*, IDBFactoryBackendImpl*, const String& uniqueIdentifier);
virtual ~IDBDatabaseBackendImpl();
PassRefPtr<IDBBackingStore> backingStore() const;
@@ -79,7 +76,7 @@
private:
IDBDatabaseBackendImpl(const String& name, IDBBackingStore* database, IDBTransactionCoordinator*, IDBFactoryBackendImpl*, const String& uniqueIdentifier);
- void openInternal();
+ bool openInternal();
void loadObjectStores();
void processPendingCalls();
Modified: branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBFactoryBackendImpl.cpp (119485 => 119486)
--- branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBFactoryBackendImpl.cpp 2012-06-05 14:50:04 UTC (rev 119485)
+++ branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBFactoryBackendImpl.cpp 2012-06-05 14:51:00 UTC (rev 119486)
@@ -129,8 +129,11 @@
}
RefPtr<IDBDatabaseBackendImpl> databaseBackend = IDBDatabaseBackendImpl::create(name, backingStore.get(), m_transactionCoordinator.get(), this, uniqueIdentifier);
- m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
- databaseBackend->deleteDatabase(callbacks);
+ if (databaseBackend) {
+ m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
+ databaseBackend->deleteDatabase(callbacks);
+ } else
+ callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
}
PassRefPtr<IDBBackingStore> IDBFactoryBackendImpl::openBackingStore(PassRefPtr<SecurityOrigin> securityOrigin, const String& dataDirectory)
@@ -177,8 +180,11 @@
}
RefPtr<IDBDatabaseBackendImpl> databaseBackend = IDBDatabaseBackendImpl::create(name, backingStore.get(), m_transactionCoordinator.get(), this, uniqueIdentifier);
- callbacks->onSuccess(RefPtr<IDBDatabaseBackendInterface>(databaseBackend.get()).release());
- m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
+ if (databaseBackend) {
+ callbacks->onSuccess(RefPtr<IDBDatabaseBackendInterface>(databaseBackend.get()).release());
+ m_databaseBackendMap.set(uniqueIdentifier, databaseBackend.get());
+ } else
+ callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error."));
}
} // namespace WebCore
Modified: branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBFactoryBackendImpl.h (119485 => 119486)
--- branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBFactoryBackendImpl.h 2012-06-05 14:50:04 UTC (rev 119485)
+++ branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBFactoryBackendImpl.h 2012-06-05 14:51:00 UTC (rev 119486)
@@ -51,9 +51,9 @@
virtual ~IDBFactoryBackendImpl();
// Notifications from weak pointers.
- void removeIDBDatabaseBackend(const String& uniqueIdentifier);
+ virtual void removeIDBDatabaseBackend(const String& uniqueIdentifier);
void addIDBBackingStore(const String& fileIdentifier, IDBBackingStore*);
- void removeIDBBackingStore(const String& fileIdentifier);
+ virtual void removeIDBBackingStore(const String& fileIdentifier);
virtual void getDatabaseNames(PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir);
@@ -61,9 +61,11 @@
virtual void openFromWorker(const String& name, IDBCallbacks*, PassRefPtr<SecurityOrigin>, WorkerContext*, const String& dataDir);
virtual void deleteDatabase(const String& name, PassRefPtr<IDBCallbacks>, PassRefPtr<SecurityOrigin>, Frame*, const String& dataDir);
+protected:
+ IDBFactoryBackendImpl();
+ virtual PassRefPtr<IDBBackingStore> openBackingStore(PassRefPtr<SecurityOrigin>, const String& dataDir);
+
private:
- IDBFactoryBackendImpl();
- PassRefPtr<IDBBackingStore> openBackingStore(PassRefPtr<SecurityOrigin>, const String& dataDir);
void openInternal(const String& name, IDBCallbacks*, PassRefPtr<SecurityOrigin>, const String& dataDir);
typedef HashMap<String, IDBDatabaseBackendImpl*> IDBDatabaseBackendMap;
Modified: branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.h (119485 => 119486)
--- branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.h 2012-06-05 14:50:04 UTC (rev 119485)
+++ branches/chromium/1132/Source/WebCore/Modules/indexeddb/IDBLevelDBBackingStore.h 2012-06-05 14:51:00 UTC (rev 119486)
@@ -80,9 +80,10 @@
static bool backingStoreExists(SecurityOrigin*, const String& name, const String& pathBase);
-private:
+protected:
IDBLevelDBBackingStore(const String& identifier, IDBFactoryBackendImpl*, PassOwnPtr<LevelDBDatabase>);
+private:
String m_identifier;
RefPtr<IDBFactoryBackendImpl> m_factory;
OwnPtr<LevelDBDatabase> m_db;
Modified: branches/chromium/1132/Source/WebKit/chromium/WebKit.gypi (119485 => 119486)
--- branches/chromium/1132/Source/WebKit/chromium/WebKit.gypi 2012-06-05 14:50:04 UTC (rev 119485)
+++ branches/chromium/1132/Source/WebKit/chromium/WebKit.gypi 2012-06-05 14:51:00 UTC (rev 119486)
@@ -104,7 +104,9 @@
'tests/FrameTestHelpers.cpp',
'tests/FrameTestHelpers.h',
'tests/GraphicsLayerChromiumTest.cpp',
+ 'tests/IDBAbortOnCorruptTest.cpp',
'tests/IDBBindingUtilitiesTest.cpp',
+ 'tests/IDBFakeBackingStore.h',
'tests/IDBKeyPathTest.cpp',
'tests/IDBLevelDBCodingTest.cpp',
'tests/ImageLayerChromiumTest.cpp',
Copied: branches/chromium/1132/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp (from rev 117978, trunk/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp) (0 => 119486)
--- branches/chromium/1132/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp (rev 0)
+++ branches/chromium/1132/Source/WebKit/chromium/tests/IDBAbortOnCorruptTest.cpp 2012-06-05 14:51:00 UTC (rev 119486)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2012 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.
+ *
+ * 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 "IDBFactoryBackendImpl.h"
+#include "IDBFakeBackingStore.h"
+#include "SecurityOrigin.h"
+#include <gtest/gtest.h>
+#include <wtf/Vector.h>
+
+#if ENABLE(INDEXED_DATABASE)
+
+using namespace WebCore;
+
+namespace {
+
+class MockIDBCallbacks : public IDBCallbacks {
+public:
+ MockIDBCallbacks() : m_wasErrorCalled(false) { }
+
+ virtual ~MockIDBCallbacks()
+ {
+ EXPECT_TRUE(m_wasErrorCalled);
+ }
+ virtual void onError(PassRefPtr<IDBDatabaseError>)
+ {
+ m_wasErrorCalled = true;
+ }
+ virtual void onSuccess(PassRefPtr<DOMStringList>) { }
+ virtual void onSuccess(PassRefPtr<IDBCursorBackendInterface>) { }
+ virtual void onSuccess(PassRefPtr<IDBDatabaseBackendInterface>)
+ {
+ EXPECT_TRUE(false);
+ }
+ virtual void onSuccess(PassRefPtr<IDBKey>) { }
+ virtual void onSuccess(PassRefPtr<IDBTransactionBackendInterface>) { }
+ virtual void onSuccess(PassRefPtr<SerializedScriptValue>) { }
+ virtual void onSuccessWithContinuation() { }
+ virtual void onSuccessWithPrefetch(const Vector<RefPtr<IDBKey> >&, const Vector<RefPtr<IDBKey> >&, const Vector<RefPtr<SerializedScriptValue> >&) { }
+ virtual void onBlocked() { }
+private:
+ bool m_wasErrorCalled;
+};
+
+class FailingBackingStore : public IDBFakeBackingStore {
+public:
+ virtual ~FailingBackingStore() { }
+ static PassRefPtr<IDBBackingStore> open()
+ {
+ return adoptRef(new FailingBackingStore);
+ }
+ virtual bool createIDBDatabaseMetaData(const String&, const String&, int64_t&)
+ {
+ return false;
+ }
+};
+
+class FailingIDBFactoryBackendImpl : public IDBFactoryBackendImpl {
+public:
+ virtual ~FailingIDBFactoryBackendImpl() { }
+ static PassRefPtr<FailingIDBFactoryBackendImpl> create()
+ {
+ return adoptRef(new FailingIDBFactoryBackendImpl);
+ }
+ virtual void removeIDBDatabaseBackend(const WTF::String &) { }
+
+protected:
+ virtual PassRefPtr<IDBBackingStore> openBackingStore(PassRefPtr<SecurityOrigin> prpOrigin, const String& dataDir)
+ {
+ return FailingBackingStore::open();
+ }
+};
+
+TEST(IDBAbortTest, TheTest)
+{
+ RefPtr<IDBFactoryBackendImpl> factory = FailingIDBFactoryBackendImpl::create();
+ const String& name = "db name";
+ MockIDBCallbacks callbacks;
+ RefPtr<SecurityOrigin> origin = SecurityOrigin::create("http", "localhost", 81);
+ factory->open(name, &callbacks, origin, 0 /*Frame*/, String() /*path*/);
+}
+
+} // namespace
+
+#endif // ENABLE(INDEXED_DATABASE)
Copied: branches/chromium/1132/Source/WebKit/chromium/tests/IDBFakeBackingStore.h (from rev 117978, trunk/Source/WebKit/chromium/tests/IDBFakeBackingStore.h) (0 => 119486)
--- branches/chromium/1132/Source/WebKit/chromium/tests/IDBFakeBackingStore.h (rev 0)
+++ branches/chromium/1132/Source/WebKit/chromium/tests/IDBFakeBackingStore.h 2012-06-05 14:51:00 UTC (rev 119486)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2012 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.
+ *
+ * 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.
+ */
+
+#ifndef IDBFakeBackingStore_h
+#define IDBFakeBackingStore_h
+
+#include "IDBBackingStore.h"
+
+namespace WebCore {
+
+class IDBFakeBackingStore : public IDBBackingStore {
+public:
+ virtual void getDatabaseNames(Vector<String>& foundNames) OVERRIDE { }
+ virtual bool getIDBDatabaseMetaData(const String& name, String& foundVersion, int64_t& foundId) OVERRIDE { return false; }
+ virtual bool createIDBDatabaseMetaData(const String& name, const String& version, int64_t& rowId) OVERRIDE { return true; }
+ virtual bool updateIDBDatabaseMetaData(int64_t rowId, const String& version) OVERRIDE { return false; }
+ virtual bool deleteDatabase(const String& name) OVERRIDE { return false; }
+
+ virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags) OVERRIDE { }
+ virtual bool createObjectStore(int64_t databaseId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement, int64_t& assignedObjectStoreId) OVERRIDE { return false; }
+ virtual void deleteObjectStore(int64_t databaseId, int64_t objectStoreId) OVERRIDE { }
+
+ virtual PassRefPtr<ObjectStoreRecordIdentifier> createInvalidRecordIdentifier() OVERRIDE { return PassRefPtr<ObjectStoreRecordIdentifier>(); }
+
+ virtual String getObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, const IDBKey&) OVERRIDE { return String(); }
+ virtual bool putObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, const IDBKey&, const String& value, ObjectStoreRecordIdentifier*) OVERRIDE { return false; }
+ virtual void clearObjectStore(int64_t databaseId, int64_t objectStoreId) OVERRIDE { }
+ virtual void deleteObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, const ObjectStoreRecordIdentifier*) OVERRIDE { }
+ virtual int64_t nextAutoIncrementNumber(int64_t databaseId, int64_t objectStoreId) OVERRIDE { return 0.0; }
+ virtual bool keyExistsInObjectStore(int64_t databaseId, int64_t objectStoreId, const IDBKey&, ObjectStoreRecordIdentifier* foundRecordIdentifier) OVERRIDE { return false; }
+
+ virtual bool forEachObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, ObjectStoreRecordCallback&) OVERRIDE { return false; }
+
+ virtual void getIndexes(int64_t databaseId, int64_t objectStoreId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<IDBKeyPath>& foundKeyPaths, Vector<bool>& foundUniqueFlags, Vector<bool>& foundMultiEntryFlags) OVERRIDE { }
+ virtual bool createIndex(int64_t databaseId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool isUnique, bool isMultiEntry, int64_t& indexId) OVERRIDE { return false; }
+ virtual void deleteIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId) OVERRIDE { }
+ virtual bool putIndexDataForRecord(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&, const ObjectStoreRecordIdentifier*) OVERRIDE { return false; }
+ virtual bool deleteIndexDataForRecord(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const ObjectStoreRecordIdentifier*) OVERRIDE { return false; }
+ virtual String getObjectViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&) OVERRIDE { return String(); }
+ virtual PassRefPtr<IDBKey> getPrimaryKeyViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&) OVERRIDE { return PassRefPtr<IDBKey>(); }
+ virtual bool keyExistsInIndex(int64_t databaseid, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey) OVERRIDE { return false; }
+
+ virtual PassRefPtr<Cursor> openObjectStoreCursor(int64_t databaseId, int64_t objectStoreId, const IDBKeyRange*, IDBCursor::Direction) OVERRIDE { return PassRefPtr<Cursor>(); }
+ virtual PassRefPtr<Cursor> openIndexKeyCursor(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange*, IDBCursor::Direction) OVERRIDE { return PassRefPtr<Cursor>(); }
+ virtual PassRefPtr<Cursor> openIndexCursor(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange*, IDBCursor::Direction) OVERRIDE { return PassRefPtr<Cursor>(); }
+
+ virtual PassRefPtr<Transaction> createTransaction() OVERRIDE { return PassRefPtr<Transaction>(); }
+};
+
+} // namespace WebCore
+
+#endif // IDBFakeBackingStore_h