Title: [96322] trunk
Revision
96322
Author
[email protected]
Date
2011-09-29 05:29:13 -0700 (Thu, 29 Sep 2011)

Log Message

IndexedDB: Use LevelDB also for in-memory databases
https://bugs.webkit.org/show_bug.cgi?id=68903

Reviewed by Steve Block.

Source/WebCore:

Add LevelDBDatabase::openInMemory() which uses leveldb::NewMemEnv()
to create in-memory LevelDB databases.

Use this in IDBLeveLDBBackingStore::open() when the caller passes in
an empty file path.
This happens in Chromium's incognito mode, and when running layout
tests.

Fix IDBSQLiteBackingStore::backingStoreExists() so it doesn't create
files when passed in an empty file path, but uses the in-memory mode
instead.

Existing layout tests will all be run in-memory.

* platform/leveldb/LevelDBDatabase.cpp:
(WebCore::LevelDBDatabase::~LevelDBDatabase):
(WebCore::openDB):
(WebCore::LevelDBDatabase::open):
(WebCore::LevelDBDatabase::openInMemory):
* platform/leveldb/LevelDBDatabase.h:
* storage/IDBLevelDBBackingStore.cpp:
(WebCore::IDBLevelDBBackingStore::open):
* storage/IDBSQLiteBackingStore.cpp:
(WebCore::IDBSQLiteBackingStore::backingStoreExists):

Source/WebKit/chromium:

Don't fall back to SQLite or use a temporary dir for in-memory
databases (Incognito and layout tests); LevelDB supports in-memory
databases now.

* public/WebIDBFactory.h:
* src/WebIDBFactoryImpl.cpp:
(WebKit::WebIDBFactoryImpl::getDatabaseNames):
(WebKit::WebIDBFactoryImpl::open):

Tools:

Remove the temporary dir that was necessary before LevelDB supported
in-memory databases.

* DumpRenderTree/chromium/TestShell.cpp:
(TestShell::TestShell):
* DumpRenderTree/chromium/TestShell.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (96321 => 96322)


--- trunk/Source/WebCore/ChangeLog	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebCore/ChangeLog	2011-09-29 12:29:13 UTC (rev 96322)
@@ -1,3 +1,35 @@
+2011-09-29  Hans Wennborg  <[email protected]>
+
+        IndexedDB: Use LevelDB also for in-memory databases
+        https://bugs.webkit.org/show_bug.cgi?id=68903
+
+        Reviewed by Steve Block.
+
+        Add LevelDBDatabase::openInMemory() which uses leveldb::NewMemEnv()
+        to create in-memory LevelDB databases.
+
+        Use this in IDBLeveLDBBackingStore::open() when the caller passes in
+        an empty file path.
+        This happens in Chromium's incognito mode, and when running layout
+        tests.
+
+        Fix IDBSQLiteBackingStore::backingStoreExists() so it doesn't create
+        files when passed in an empty file path, but uses the in-memory mode
+        instead.
+
+        Existing layout tests will all be run in-memory.
+
+        * platform/leveldb/LevelDBDatabase.cpp:
+        (WebCore::LevelDBDatabase::~LevelDBDatabase):
+        (WebCore::openDB):
+        (WebCore::LevelDBDatabase::open):
+        (WebCore::LevelDBDatabase::openInMemory):
+        * platform/leveldb/LevelDBDatabase.h:
+        * storage/IDBLevelDBBackingStore.cpp:
+        (WebCore::IDBLevelDBBackingStore::open):
+        * storage/IDBSQLiteBackingStore.cpp:
+        (WebCore::IDBSQLiteBackingStore::backingStoreExists):
+
 2011-09-29  Ilya Tikhonovsky  <[email protected]>
 
         Web Inspector: speed-up Network panel. Change _staleResources type from array to object.

Modified: trunk/Source/WebCore/platform/leveldb/LevelDBDatabase.cpp (96321 => 96322)


--- trunk/Source/WebCore/platform/leveldb/LevelDBDatabase.cpp	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebCore/platform/leveldb/LevelDBDatabase.cpp	2011-09-29 12:29:13 UTC (rev 96322)
@@ -33,8 +33,10 @@
 #include "LevelDBSlice.h"
 #include "LevelDBWriteBatch.h"
 #include "Logging.h"
+#include <helpers/memenv/memenv.h>
 #include <leveldb/comparator.h>
 #include <leveldb/db.h>
+#include <leveldb/env.h>
 #include <leveldb/slice.h>
 #include <string>
 #include <wtf/PassOwnPtr.h>
@@ -96,18 +98,26 @@
     // m_db's destructor uses m_comparatorAdapter; order of deletion is important.
     m_db.clear();
     m_comparatorAdapter.clear();
+    m_env.clear();
 }
 
+static leveldb::Status openDB(leveldb::Comparator* comparator, leveldb::Env* env, const String& path, leveldb::DB** db)
+{
+    leveldb::Options options;
+    options.comparator = comparator;
+    options.create_if_missing = true;
+    options.paranoid_checks = true;
+    options.env = env;
+
+    return leveldb::DB::Open(options, path.utf8().data(), db);
+}
+
 PassOwnPtr<LevelDBDatabase> LevelDBDatabase::open(const String& fileName, const LevelDBComparator* comparator)
 {
     OwnPtr<ComparatorAdapter> comparatorAdapter = adoptPtr(new ComparatorAdapter(comparator));
 
-    leveldb::Options options;
-    options.comparator = comparatorAdapter.get();
-    options.create_if_missing = true;
-    options.paranoid_checks = true;
     leveldb::DB* db;
-    const leveldb::Status s = leveldb::DB::Open(options, fileName.utf8().data(), &db);
+    const leveldb::Status s = openDB(comparatorAdapter.get(), leveldb::Env::Default(), fileName, &db);
 
     if (!s.ok()) {
         LOG_ERROR("Failed to open LevelDB database from %s: %s", fileName.ascii().data(), s.ToString().c_str());
@@ -122,6 +132,28 @@
     return result.release();
 }
 
+PassOwnPtr<LevelDBDatabase> LevelDBDatabase::openInMemory(const LevelDBComparator* comparator)
+{
+    OwnPtr<ComparatorAdapter> comparatorAdapter = adoptPtr(new ComparatorAdapter(comparator));
+    OwnPtr<leveldb::Env> inMemoryEnv = adoptPtr(leveldb::NewMemEnv(leveldb::Env::Default()));
+
+    leveldb::DB* db;
+    const leveldb::Status s = openDB(comparatorAdapter.get(), inMemoryEnv.get(), String(), &db);
+
+    if (!s.ok()) {
+        LOG_ERROR("Failed to open in-memory LevelDB database: %s", s.ToString().c_str());
+        return nullptr;
+    }
+
+    OwnPtr<LevelDBDatabase> result = adoptPtr(new LevelDBDatabase);
+    result->m_env = inMemoryEnv.release();
+    result->m_db = adoptPtr(db);
+    result->m_comparatorAdapter = comparatorAdapter.release();
+    result->m_comparator = comparator;
+
+    return result.release();
+}
+
 bool LevelDBDatabase::put(const LevelDBSlice& key, const Vector<char>& value)
 {
     leveldb::WriteOptions writeOptions;

Modified: trunk/Source/WebCore/platform/leveldb/LevelDBDatabase.h (96321 => 96322)


--- trunk/Source/WebCore/platform/leveldb/LevelDBDatabase.h	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebCore/platform/leveldb/LevelDBDatabase.h	2011-09-29 12:29:13 UTC (rev 96322)
@@ -36,6 +36,7 @@
 namespace leveldb {
 class Comparator;
 class DB;
+class Env;
 }
 
 namespace WebCore {
@@ -48,6 +49,7 @@
 class LevelDBDatabase {
 public:
     static PassOwnPtr<LevelDBDatabase> open(const String& fileName, const LevelDBComparator*);
+    static PassOwnPtr<LevelDBDatabase> openInMemory(const LevelDBComparator*);
     ~LevelDBDatabase();
 
     bool put(const LevelDBSlice& key, const Vector<char>& value);
@@ -60,9 +62,10 @@
 private:
     LevelDBDatabase();
 
+    OwnPtr<leveldb::Env> m_env;
+    OwnPtr<leveldb::Comparator> m_comparatorAdapter;
     OwnPtr<leveldb::DB> m_db;
     const LevelDBComparator* m_comparator;
-    OwnPtr<leveldb::Comparator> m_comparatorAdapter;
 };
 
 }

Modified: trunk/Source/WebCore/storage/IDBLevelDBBackingStore.cpp (96321 => 96322)


--- trunk/Source/WebCore/storage/IDBLevelDBBackingStore.cpp	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebCore/storage/IDBLevelDBBackingStore.cpp	2011-09-29 12:29:13 UTC (rev 96322)
@@ -136,20 +136,22 @@
 {
     String pathBase = pathBaseArg;
 
-    if (pathBase.isEmpty()) {
-        ASSERT_NOT_REACHED(); // FIXME: We need to handle this case for incognito and DumpRenderTree.
-        return PassRefPtr<IDBBackingStore>();
-    }
+    OwnPtr<LevelDBComparator> comparator = adoptPtr(new Comparator());
+    OwnPtr<LevelDBDatabase> db;
 
-    if (!makeAllDirectories(pathBase)) {
-        LOG_ERROR("Unable to create IndexedDB database path %s", pathBase.utf8().data());
-        return PassRefPtr<IDBBackingStore>();
+    if (pathBase.isEmpty())
+        db = LevelDBDatabase::openInMemory(comparator.get());
+    else {
+        if (!makeAllDirectories(pathBase)) {
+            LOG_ERROR("Unable to create IndexedDB database path %s", pathBase.utf8().data());
+            return PassRefPtr<IDBBackingStore>();
+        }
+        // FIXME: We should eventually use the same LevelDB database for all origins.
+        String path = pathByAppendingComponent(pathBase, securityOrigin->databaseIdentifier() + ".indexeddb.leveldb");
+
+        db = LevelDBDatabase::open(path, comparator.get());
     }
-    // FIXME: We should eventually use the same LevelDB database for all origins.
-    String path = pathByAppendingComponent(pathBase, securityOrigin->databaseIdentifier() + ".indexeddb.leveldb");
 
-    OwnPtr<LevelDBComparator> comparator = adoptPtr(new Comparator());
-    OwnPtr<LevelDBDatabase> db = LevelDBDatabase::open(path, comparator.get());
     if (!db)
         return PassRefPtr<IDBBackingStore>();
 

Modified: trunk/Source/WebCore/storage/IDBSQLiteBackingStore.cpp (96321 => 96322)


--- trunk/Source/WebCore/storage/IDBSQLiteBackingStore.cpp	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebCore/storage/IDBSQLiteBackingStore.cpp	2011-09-29 12:29:13 UTC (rev 96322)
@@ -169,7 +169,7 @@
 {
     RefPtr<IDBSQLiteBackingStore> backingStore(adoptRef(new IDBSQLiteBackingStore(fileIdentifier, factory)));
 
-    String path = ":memory:";
+    String path = ":memory:"; // in-memory SQLite database.
     if (!pathBase.isEmpty()) {
         if (!makeAllDirectories(pathBase)) {
             // FIXME: Is there any other thing we could possibly do to recover at this point? If so, do it rather than just erroring out.
@@ -1012,7 +1012,9 @@
 
 bool IDBSQLiteBackingStore::backingStoreExists(SecurityOrigin* securityOrigin, const String& name, const String& pathBase)
 {
-    String path = pathByAppendingComponent(pathBase, securityOrigin->databaseIdentifier() + ".indexeddb");
+    String path = ":memory:"; // in-memory SQLite database.
+    if (!pathBase.isEmpty())
+        path = pathByAppendingComponent(pathBase, securityOrigin->databaseIdentifier() + ".indexeddb");
     SQLiteDatabase db;
     if (!db.open(path))
         return false;

Modified: trunk/Source/WebKit/chromium/ChangeLog (96321 => 96322)


--- trunk/Source/WebKit/chromium/ChangeLog	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebKit/chromium/ChangeLog	2011-09-29 12:29:13 UTC (rev 96322)
@@ -1,3 +1,19 @@
+2011-09-29  Hans Wennborg  <[email protected]>
+
+        IndexedDB: Use LevelDB also for in-memory databases
+        https://bugs.webkit.org/show_bug.cgi?id=68903
+
+        Reviewed by Steve Block.
+
+        Don't fall back to SQLite or use a temporary dir for in-memory
+        databases (Incognito and layout tests); LevelDB supports in-memory
+        databases now.
+
+        * public/WebIDBFactory.h:
+        * src/WebIDBFactoryImpl.cpp:
+        (WebKit::WebIDBFactoryImpl::getDatabaseNames):
+        (WebKit::WebIDBFactoryImpl::open):
+
 2011-09-28  Fady Samuel  <[email protected]>
 
         [Chromium] Seperate GTK specific Gyp rules from X11 Gyp rules

Modified: trunk/Source/WebKit/chromium/public/WebIDBFactory.h (96321 => 96322)


--- trunk/Source/WebKit/chromium/public/WebIDBFactory.h	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebKit/chromium/public/WebIDBFactory.h	2011-09-29 12:29:13 UTC (rev 96322)
@@ -66,7 +66,6 @@
 
     // Used for DumpRenderTree tests.
     WEBKIT_EXPORT static void setOverrideBackingStoreType(BackingStoreType);
-    WEBKIT_EXPORT static void setTemporaryDatabaseFolder(const WebString& path);
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/chromium/src/WebIDBFactoryImpl.cpp (96321 => 96322)


--- trunk/Source/WebKit/chromium/src/WebIDBFactoryImpl.cpp	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Source/WebKit/chromium/src/WebIDBFactoryImpl.cpp	2011-09-29 12:29:13 UTC (rev 96322)
@@ -45,7 +45,6 @@
 namespace WebKit {
 
 static WebIDBFactory::BackingStoreType overriddenBackingStoreType = WebIDBFactory::DefaultBackingStore;
-static WebString tempDatabaseFolder;
 
 WebIDBFactory* WebIDBFactory::create()
 {
@@ -57,11 +56,6 @@
     overriddenBackingStoreType = type;
 }
 
-void WebIDBFactory::setTemporaryDatabaseFolder(const WebString& path)
-{
-    tempDatabaseFolder = path;
-}
-
 WebIDBFactoryImpl::WebIDBFactoryImpl()
     : m_idbFactoryBackend(IDBFactoryBackendImpl::create())
 {
@@ -83,16 +77,6 @@
     if (backingStoreType == DefaultBackingStore)
         backingStoreType = LevelDBBackingStore;
 
-    if (dataDir.isEmpty() && backingStoreType == LevelDBBackingStore) {
-        if (!tempDatabaseFolder.isEmpty()) {
-            // Layout tests provide a temporary folder.
-            path = tempDatabaseFolder;
-        } else {
-            // For incognito mode, fall back to SQLite.
-            backingStoreType = SQLiteBackingStore;
-        }
-    }
-
     m_idbFactoryBackend->getDatabaseNames(IDBCallbacksProxy::create(adoptPtr(callbacks)), origin, 0, path, maximumSize, static_cast<IDBFactoryBackendInterface::BackingStoreType>(backingStoreType));
 }
 
@@ -109,16 +93,6 @@
     if (backingStoreType == DefaultBackingStore)
         backingStoreType = LevelDBBackingStore;
 
-    if (dataDir.isEmpty() && backingStoreType == LevelDBBackingStore) {
-        if (!tempDatabaseFolder.isEmpty()) {
-            // Layout tests provide a temporary folder.
-            path = tempDatabaseFolder;
-        } else {
-            // For incognito mode, fall back to SQLite.
-            backingStoreType = SQLiteBackingStore;
-        }
-    }
-
     m_idbFactoryBackend->open(name, IDBCallbacksProxy::create(adoptPtr(callbacks)), origin, 0, path, maximumSize, static_cast<IDBFactoryBackendInterface::BackingStoreType>(backingStoreType));
 }
 

Modified: trunk/Tools/ChangeLog (96321 => 96322)


--- trunk/Tools/ChangeLog	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Tools/ChangeLog	2011-09-29 12:29:13 UTC (rev 96322)
@@ -1,3 +1,17 @@
+2011-09-29  Hans Wennborg  <[email protected]>
+
+        IndexedDB: Use LevelDB also for in-memory databases
+        https://bugs.webkit.org/show_bug.cgi?id=68903
+
+        Reviewed by Steve Block.
+
+        Remove the temporary dir that was necessary before LevelDB supported
+        in-memory databases.
+
+        * DumpRenderTree/chromium/TestShell.cpp:
+        (TestShell::TestShell):
+        * DumpRenderTree/chromium/TestShell.h:
+
 2011-09-28  Xianzhu Wang  <[email protected]>
 
         Run TestWebKitAPI on Chromium buildbots

Modified: trunk/Tools/DumpRenderTree/chromium/TestShell.cpp (96321 => 96322)


--- trunk/Tools/DumpRenderTree/chromium/TestShell.cpp	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Tools/DumpRenderTree/chromium/TestShell.cpp	2011-09-29 12:29:13 UTC (rev 96322)
@@ -136,12 +136,6 @@
     // timed-out DRT process was crashed.
     m_timeout = 30 * 1000;
 
-#if ENABLE(INDEXED_DATABASE)
-    m_tempIndexedDBDirectory = adoptPtr(webkit_support::CreateScopedTempDirectory());
-    m_tempIndexedDBDirectory->CreateUniqueTempDir();
-    WebIDBFactory::setTemporaryDatabaseFolder(WebString::fromUTF8(m_tempIndexedDBDirectory->path().c_str()));
-#endif
-
     createMainWindow();
 }
 

Modified: trunk/Tools/DumpRenderTree/chromium/TestShell.h (96321 => 96322)


--- trunk/Tools/DumpRenderTree/chromium/TestShell.h	2011-09-29 11:59:27 UTC (rev 96321)
+++ trunk/Tools/DumpRenderTree/chromium/TestShell.h	2011-09-29 12:29:13 UTC (rev 96322)
@@ -235,9 +235,6 @@
     // Used by the watchdog to know when it's finished.
     HANDLE m_finishedEvent;
 #endif
-
-    // Temporary directory for IndexedDB (LevelDB doesn't support in-memory databases.)
-    OwnPtr<webkit_support::ScopedTempDirectory> m_tempIndexedDBDirectory;
 };
 
 void platformInit(int*, char***);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to