<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[195090] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/195090">195090</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2016-01-14 21:40:39 -0800 (Thu, 14 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Modern IDB: Support opening and deleting SQLite databases on disk.
https://bugs.webkit.org/show_bug.cgi?id=153084

Reviewed by Alex Christensen, Sam Weinig and Andy Estes (oh my!).

Source/WebCore:

No new tests (Infrastructure, no testable change in behavior).

* Modules/indexeddb/IDBDatabaseIdentifier.cpp:
(WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot):
* Modules/indexeddb/IDBDatabaseIdentifier.h:

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::create):
(WebCore::IDBServer::IDBServer::IDBServer):
(WebCore::IDBServer::IDBServer::createBackingStore):
* Modules/indexeddb/server/IDBServer.h:

* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::SQLiteIDBBackingStore):
(WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo):
(WebCore::IDBServer::SQLiteIDBBackingStore::deleteBackingStore):
* Modules/indexeddb/server/SQLiteIDBBackingStore.h:

* Modules/indexeddb/shared/InProcessIDBServer.cpp:
(WebCore::InProcessIDBServer::create):
(WebCore::InProcessIDBServer::InProcessIDBServer):
* Modules/indexeddb/shared/InProcessIDBServer.h:

Source/WebKit:

* Storage/WebDatabaseProvider.cpp:
(WebDatabaseProvider::idbConnectionToServerForSession):
* Storage/WebDatabaseProvider.h:

* WebKit.xcodeproj/project.pbxproj:

Source/WebKit/mac:

* Storage/WebDatabaseProvider.mm: Copied from Source/WebKit/Storage/WebDatabaseProvider.cpp.
(WebDatabaseProvider::indexedDatabaseDirectoryPath):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBDatabaseIdentifiercpp">trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbIDBDatabaseIdentifierh">trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBServercpp">trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverIDBServerh">trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh">trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServercpp">trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServerh">trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitStorageWebDatabaseProvidercpp">trunk/Source/WebKit/Storage/WebDatabaseProvider.cpp</a></li>
<li><a href="#trunkSourceWebKitStorageWebDatabaseProviderh">trunk/Source/WebKit/Storage/WebDatabaseProvider.h</a></li>
<li><a href="#trunkSourceWebKitWebKitxcodeprojprojectpbxproj">trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitmacStorageWebDatabaseProvidermm">trunk/Source/WebKit/mac/Storage/WebDatabaseProvider.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/ChangeLog        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2016-01-14  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Support opening and deleting SQLite databases on disk.
+        https://bugs.webkit.org/show_bug.cgi?id=153084
+
+        Reviewed by Alex Christensen, Sam Weinig and Andy Estes (oh my!).
+
+        No new tests (Infrastructure, no testable change in behavior).
+
+        * Modules/indexeddb/IDBDatabaseIdentifier.cpp:
+        (WebCore::IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot):
+        * Modules/indexeddb/IDBDatabaseIdentifier.h:
+
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::create):
+        (WebCore::IDBServer::IDBServer::IDBServer):
+        (WebCore::IDBServer::IDBServer::createBackingStore):
+        * Modules/indexeddb/server/IDBServer.h:
+
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::SQLiteIDBBackingStore):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::getOrEstablishDatabaseInfo):
+        (WebCore::IDBServer::SQLiteIDBBackingStore::deleteBackingStore):
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.h:
+
+        * Modules/indexeddb/shared/InProcessIDBServer.cpp:
+        (WebCore::InProcessIDBServer::create):
+        (WebCore::InProcessIDBServer::InProcessIDBServer):
+        * Modules/indexeddb/shared/InProcessIDBServer.h:
+
</ins><span class="cx"> 2016-01-14  Myles C. Maxfield  &lt;mmaxfield@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Mixing Content Blocking of fonts and display:none rules causes battery drain
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBDatabaseIdentifiercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.cpp        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -28,6 +28,8 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> 
</span><ins>+#include &quot;FileSystem.h&quot;
+#include &quot;SecurityOrigin.h&quot;
</ins><span class="cx"> #include &lt;wtf/Ref.h&gt;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="lines">@@ -55,6 +57,17 @@
</span><span class="cx">     return identifier;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String IDBDatabaseIdentifier::databaseDirectoryRelativeToRoot(const String&amp; rootDirectory) const
+{
+    String mainFrameDirectory = pathByAppendingComponent(rootDirectory, m_mainFrameOrigin.securityOrigin()-&gt;databaseIdentifier());
+
+    // If the opening origin and main frame origins are the same, there is no partitioning.
+    if (m_openingOrigin == m_mainFrameOrigin)
+        return mainFrameDirectory;
+
+    return pathByAppendingComponent(mainFrameDirectory, m_openingOrigin.securityOrigin()-&gt;databaseIdentifier());
+}
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx"> String IDBDatabaseIdentifier::debugString() const
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbIDBDatabaseIdentifierh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseIdentifier.h        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -92,6 +92,8 @@
</span><span class="cx"> 
</span><span class="cx">     const String&amp; databaseName() const { return m_databaseName; }
</span><span class="cx"> 
</span><ins>+    String databaseDirectoryRelativeToRoot(const String&amp; rootDirectory) const;
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx">     String debugString() const;
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #include &quot;IDBResultData.h&quot;
</span><span class="cx"> #include &quot;Logging.h&quot;
</span><span class="cx"> #include &quot;MemoryIDBBackingStore.h&quot;
</span><ins>+#include &quot;SQLiteIDBBackingStore.h&quot;
</ins><span class="cx"> #include &lt;wtf/Locker.h&gt;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -43,12 +44,26 @@
</span><span class="cx">     return adoptRef(*new IDBServer());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Ref&lt;IDBServer&gt; IDBServer::create(const String&amp; databaseDirectoryPath)
+{
+    return adoptRef(*new IDBServer(databaseDirectoryPath));
+}
+
</ins><span class="cx"> IDBServer::IDBServer()
</span><span class="cx"> {
</span><span class="cx">     Locker&lt;Lock&gt; locker(m_databaseThreadCreationLock);
</span><span class="cx">     m_threadID = createThread(IDBServer::databaseThreadEntry, this, &quot;IndexedDatabase Server&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+IDBServer::IDBServer(const String&amp; databaseDirectoryPath)
+    : m_databaseDirectoryPath(databaseDirectoryPath)
+{
+    LOG(IndexedDB, &quot;IDBServer created at path %s&quot;, databaseDirectoryPath.utf8().data());
+
+    Locker&lt;Lock&gt; locker(m_databaseThreadCreationLock);
+    m_threadID = createThread(IDBServer::databaseThreadEntry, this, &quot;IndexedDatabase Server&quot;);
+}
+
</ins><span class="cx"> void IDBServer::registerConnection(IDBConnectionToClient&amp; connection)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!m_connectionMap.contains(connection.identifier()));
</span><span class="lines">@@ -102,9 +117,7 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!isMainThread());
</span><span class="cx"> 
</span><del>-    // FIXME: For now we only have the in-memory backing store, which we'll continue to use for private browsing.
-    // Once it's time for persistent backing stores this is where we'll calculate the correct path on disk
-    // and create it.
</del><ins>+    // FIXME: Once the SQLite backing store is functional, conditionally make either a Memory or SQLite backing store.
</ins><span class="cx"> 
</span><span class="cx">     return MemoryIDBBackingStore::create(identifier);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverIDBServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx"> class IDBServer : public RefCounted&lt;IDBServer&gt; {
</span><span class="cx"> public:
</span><span class="cx">     static Ref&lt;IDBServer&gt; create();
</span><ins>+    static Ref&lt;IDBServer&gt; create(const String&amp; databaseDirectoryPath);
</ins><span class="cx"> 
</span><span class="cx">     void registerConnection(IDBConnectionToClient&amp;);
</span><span class="cx">     void unregisterConnection(IDBConnectionToClient&amp;);
</span><span class="lines">@@ -92,6 +93,7 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     IDBServer();
</span><ins>+    IDBServer(const String&amp; databaseDirectoryPath);
</ins><span class="cx"> 
</span><span class="cx">     UniqueIDBDatabase&amp; getOrCreateUniqueIDBDatabase(const IDBDatabaseIdentifier&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -112,6 +114,8 @@
</span><span class="cx"> 
</span><span class="cx">     HashMap&lt;uint64_t, UniqueIDBDatabaseConnection*&gt; m_databaseConnections;
</span><span class="cx">     HashMap&lt;IDBResourceIdentifier, UniqueIDBDatabaseTransaction*&gt; m_transactions;
</span><ins>+
+    String m_databaseDirectoryPath;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace IDBServer
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStorecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -28,26 +28,54 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx"> 
</span><ins>+#include &quot;FileSystem.h&quot;
</ins><span class="cx"> #include &quot;IDBDatabaseException.h&quot;
</span><del>-#include &quot;NotImplemented.h&quot;
</del><ins>+#include &quot;IDBKeyData.h&quot;
+#include &quot;Logging.h&quot;
+#include &quot;SQLiteDatabase.h&quot;
+#include &quot;SQLiteFileSystem.h&quot;
+#include &lt;wtf/NeverDestroyed.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> namespace IDBServer {
</span><span class="cx"> 
</span><del>-SQLiteIDBBackingStore::SQLiteIDBBackingStore(const IDBDatabaseIdentifier&amp; identifier)
</del><ins>+SQLiteIDBBackingStore::SQLiteIDBBackingStore(const IDBDatabaseIdentifier&amp; identifier, const String&amp; databaseRootDirectory)
</ins><span class="cx">     : m_identifier(identifier)
</span><span class="cx"> {
</span><ins>+    m_absoluteDatabaseDirectory = identifier.databaseDirectoryRelativeToRoot(databaseRootDirectory);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SQLiteIDBBackingStore::~SQLiteIDBBackingStore()
</span><span class="cx"> {
</span><ins>+    if (m_sqliteDB)
+        m_sqliteDB-&gt;close();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> const IDBDatabaseInfo&amp; SQLiteIDBBackingStore::getOrEstablishDatabaseInfo()
</span><span class="cx"> {
</span><del>-    if (!m_databaseInfo)
-        m_databaseInfo = std::make_unique&lt;IDBDatabaseInfo&gt;(m_identifier.databaseName(), 0);
</del><ins>+    LOG(IndexedDB, &quot;SQLiteIDBBackingStore::getOrEstablishDatabaseInfo - database %s&quot;, m_identifier.databaseName().utf8().data());
</ins><span class="cx"> 
</span><ins>+    if (m_databaseInfo)
+        return *m_databaseInfo;
+
+    m_databaseInfo = std::make_unique&lt;IDBDatabaseInfo&gt;(m_identifier.databaseName(), 0);
+
+    makeAllDirectories(m_absoluteDatabaseDirectory);
+
+    String dbFilename = pathByAppendingComponent(m_absoluteDatabaseDirectory, &quot;IndexedDB.sqlite3&quot;);
+
+    m_sqliteDB = std::make_unique&lt;SQLiteDatabase&gt;();
+    if (!m_sqliteDB-&gt;open(dbFilename)) {
+        LOG_ERROR(&quot;Failed to open SQLite database at path '%s'&quot;, dbFilename.utf8().data());
+        m_sqliteDB = nullptr;
+    }
+
+    if (!m_sqliteDB)
+        return *m_databaseInfo;
+
+    // FIXME: Support populating new SQLite files and pulling DatabaseInfo from existing SQLite files.
+    // Doing so will make a new m_databaseInfo which overrides the default one we created up above.
+
</ins><span class="cx">     return *m_databaseInfo;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -148,7 +176,17 @@
</span><span class="cx"> 
</span><span class="cx"> void SQLiteIDBBackingStore::deleteBackingStore()
</span><span class="cx"> {
</span><del>-    notImplemented();
</del><ins>+    String dbFilename = pathByAppendingComponent(m_absoluteDatabaseDirectory, &quot;IndexedDB.sqlite3&quot;);
+
+    LOG(IndexedDB, &quot;SQLiteIDBBackingStore::deleteBackingStore deleting file '%s' on disk&quot;, dbFilename.utf8().data());
+
+    if (m_sqliteDB) {
+        m_sqliteDB-&gt;close();
+        m_sqliteDB = nullptr;
+    }
+
+    SQLiteFileSystem::deleteDatabaseFile(dbFilename);
+    SQLiteFileSystem::deleteEmptyDatabaseDirectory(m_absoluteDatabaseDirectory);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace IDBServer
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbserverSQLiteIDBBackingStoreh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.h        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -33,11 +33,14 @@
</span><span class="cx"> #include &quot;IDBDatabaseInfo.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><ins>+
+class SQLiteDatabase;
+
</ins><span class="cx"> namespace IDBServer {
</span><span class="cx"> 
</span><span class="cx"> class SQLiteIDBBackingStore : public IDBBackingStore {
</span><span class="cx"> public:
</span><del>-    SQLiteIDBBackingStore(const IDBDatabaseIdentifier&amp;);
</del><ins>+    SQLiteIDBBackingStore(const IDBDatabaseIdentifier&amp;, const String&amp; databaseRootDirectory);
</ins><span class="cx">     
</span><span class="cx">     virtual ~SQLiteIDBBackingStore() override final;
</span><span class="cx"> 
</span><span class="lines">@@ -68,6 +71,10 @@
</span><span class="cx"> private:
</span><span class="cx">     IDBDatabaseIdentifier m_identifier;
</span><span class="cx">     std::unique_ptr&lt;IDBDatabaseInfo&gt; m_databaseInfo;
</span><ins>+
+    std::unique_ptr&lt;SQLiteDatabase&gt; m_sqliteDB;
+
+    String m_absoluteDatabaseDirectory;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace IDBServer
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.cpp        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -47,6 +47,13 @@
</span><span class="cx">     return server;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Ref&lt;InProcessIDBServer&gt; InProcessIDBServer::create(const String&amp; databaseDirectoryPath)
+{
+    Ref&lt;InProcessIDBServer&gt; server = adoptRef(*new InProcessIDBServer(databaseDirectoryPath));
+    server-&gt;m_server-&gt;registerConnection(server-&gt;connectionToClient());
+    return server;
+}
+
</ins><span class="cx"> InProcessIDBServer::InProcessIDBServer()
</span><span class="cx">     : m_server(IDBServer::IDBServer::create())
</span><span class="cx"> {
</span><span class="lines">@@ -55,6 +62,14 @@
</span><span class="cx">     m_connectionToClient = IDBServer::IDBConnectionToClient::create(*this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+InProcessIDBServer::InProcessIDBServer(const String&amp; databaseDirectoryPath)
+    : m_server(IDBServer::IDBServer::create(databaseDirectoryPath))
+{
+    relaxAdoptionRequirement();
+    m_connectionToServer = IDBClient::IDBConnectionToServer::create(*this);
+    m_connectionToClient = IDBServer::IDBConnectionToClient::create(*this);
+}
+
</ins><span class="cx"> uint64_t InProcessIDBServer::identifier() const
</span><span class="cx"> {
</span><span class="cx">     // An instance of InProcessIDBServer always has a 1:1 relationship with its instance of IDBServer.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesindexeddbsharedInProcessIDBServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/InProcessIDBServer.h        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -49,6 +49,7 @@
</span><span class="cx"> class InProcessIDBServer final : public IDBClient::IDBConnectionToServerDelegate, public IDBServer::IDBConnectionToClientDelegate, public RefCounted&lt;InProcessIDBServer&gt; {
</span><span class="cx"> public:
</span><span class="cx">     WEBCORE_EXPORT static Ref&lt;InProcessIDBServer&gt; create();
</span><ins>+    WEBCORE_EXPORT static Ref&lt;InProcessIDBServer&gt; create(const String&amp; databaseDirectoryPath);
</ins><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT IDBClient::IDBConnectionToServer&amp; connectionToServer() const;
</span><span class="cx">     IDBServer::IDBConnectionToClient&amp; connectionToClient() const;
</span><span class="lines">@@ -101,6 +102,7 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     InProcessIDBServer();
</span><ins>+    InProcessIDBServer(const String&amp; databaseDirectoryPath);
</ins><span class="cx"> 
</span><span class="cx">     Ref&lt;IDBServer::IDBServer&gt; m_server;
</span><span class="cx">     RefPtr&lt;IDBClient::IDBConnectionToServer&gt; m_connectionToServer;
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebKit/ChangeLog        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-01-14  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Support opening and deleting SQLite databases on disk.
+        https://bugs.webkit.org/show_bug.cgi?id=153084
+
+        Reviewed by Alex Christensen, Sam Weinig and Andy Estes (oh my!).
+
+        * Storage/WebDatabaseProvider.cpp:
+        (WebDatabaseProvider::idbConnectionToServerForSession):
+        * Storage/WebDatabaseProvider.h:
+
+        * WebKit.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2016-01-13  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r194900.
</span></span></pre></div>
<a id="trunkSourceWebKitStorageWebDatabaseProvidercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Storage/WebDatabaseProvider.cpp (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Storage/WebDatabaseProvider.cpp        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebKit/Storage/WebDatabaseProvider.cpp        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -53,8 +53,12 @@
</span><span class="cx"> WebCore::IDBClient::IDBConnectionToServer&amp; WebDatabaseProvider::idbConnectionToServerForSession(const WebCore::SessionID&amp; sessionID)
</span><span class="cx"> {
</span><span class="cx">     auto result = m_idbServerMap.add(sessionID.sessionID(), nullptr);
</span><del>-    if (result.isNewEntry)
-        result.iterator-&gt;value = WebCore::InProcessIDBServer::create();
</del><ins>+    if (result.isNewEntry) {
+        if (sessionID.isEphemeral())
+            result.iterator-&gt;value = WebCore::InProcessIDBServer::create();
+        else
+            result.iterator-&gt;value = WebCore::InProcessIDBServer::create(indexedDatabaseDirectoryPath());
+    }
</ins><span class="cx"> 
</span><span class="cx">     return result.iterator-&gt;value-&gt;connectionToServer();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitStorageWebDatabaseProviderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Storage/WebDatabaseProvider.h (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Storage/WebDatabaseProvider.h        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebKit/Storage/WebDatabaseProvider.h        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -49,6 +49,8 @@
</span><span class="cx"> private:
</span><span class="cx">     explicit WebDatabaseProvider();
</span><span class="cx"> 
</span><ins>+    static String indexedDatabaseDirectoryPath();
+
</ins><span class="cx"> #if ENABLE(INDEXED_DATABASE)
</span><span class="cx">     virtual RefPtr&lt;WebCore::IDBFactoryBackendInterface&gt; createIDBFactoryBackend() override;
</span><span class="cx">     HashMap&lt;uint64_t, RefPtr&lt;WebCore::InProcessIDBServer&gt;&gt; m_idbServerMap;
</span></span></pre></div>
<a id="trunkSourceWebKitWebKitxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -127,6 +127,7 @@
</span><span class="cx">                 511F3FD60CECC88F00852565 /* WebDatabaseManagerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 511F3FD20CECC88F00852565 /* WebDatabaseManagerPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 511F3FD70CECC88F00852565 /* WebDatabaseManagerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 511F3FD30CECC88F00852565 /* WebDatabaseManagerClient.h */; };
</span><span class="cx">                 511F3FD80CECC88F00852565 /* WebDatabaseManagerClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 511F3FD40CECC88F00852565 /* WebDatabaseManagerClient.mm */; };
</span><ins>+                512BDB531C471591006494DF /* WebDatabaseProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = 512BDB521C471591006494DF /* WebDatabaseProvider.mm */; };
</ins><span class="cx">                 51494CD60C7EBDE0004178C5 /* WebIconDatabaseClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 51494CD40C7EBDE0004178C5 /* WebIconDatabaseClient.h */; };
</span><span class="cx">                 51494CD70C7EBDE0004178C5 /* WebIconDatabaseClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51494CD50C7EBDE0004178C5 /* WebIconDatabaseClient.mm */; };
</span><span class="cx">                 5158F6EF106D862A00AF457C /* WebHistoryDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5158F6EE106D862A00AF457C /* WebHistoryDelegate.h */; };
</span><span class="lines">@@ -606,6 +607,7 @@
</span><span class="cx">                 511F3FD20CECC88F00852565 /* WebDatabaseManagerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebDatabaseManagerPrivate.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 511F3FD30CECC88F00852565 /* WebDatabaseManagerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebDatabaseManagerClient.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 511F3FD40CECC88F00852565 /* WebDatabaseManagerClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebDatabaseManagerClient.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                512BDB521C471591006494DF /* WebDatabaseProvider.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebDatabaseProvider.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 513D422E034CF55A00CA2ACD /* WebResourceLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebResourceLoadDelegate.h; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><span class="cx">                 51443F9A0429392B00CA2D3A /* WebPolicyDelegate.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebPolicyDelegate.h; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><span class="cx">                 51443F9B0429392B00CA2D3A /* WebPolicyDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPolicyDelegate.mm; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><span class="lines">@@ -1223,6 +1225,7 @@
</span><span class="cx">                                 511F3FD20CECC88F00852565 /* WebDatabaseManagerPrivate.h */,
</span><span class="cx">                                 1AA83F811A5C4AE400026EC6 /* WebDatabaseProvider.cpp */,
</span><span class="cx">                                 1AA83F821A5C4AE400026EC6 /* WebDatabaseProvider.h */,
</span><ins>+                                512BDB521C471591006494DF /* WebDatabaseProvider.mm */,
</ins><span class="cx">                                 A5DEFC0D11D5343E00885273 /* WebDatabaseQuotaManager.h */,
</span><span class="cx">                                 A5DEFC0E11D5343E00885273 /* WebDatabaseQuotaManager.mm */,
</span><span class="cx">                                 3AB02AF512C1319B00FBB694 /* WebStorageManager.mm */,
</span><span class="lines">@@ -2295,6 +2298,7 @@
</span><span class="cx">                                 939810C70824BF01008DF038 /* WebNSImageExtras.m in Sources */,
</span><span class="cx">                                 934C4A910F01406C009372C0 /* WebNSObjectExtras.mm in Sources */,
</span><span class="cx">                                 939810C80824BF01008DF038 /* WebNSPasteboardExtras.mm in Sources */,
</span><ins>+                                512BDB531C471591006494DF /* WebDatabaseProvider.mm in Sources */,
</ins><span class="cx">                                 939811190824BF01008DF038 /* WebNSPrintOperationExtras.m in Sources */,
</span><span class="cx">                                 A10C1D3B18202FC50036883A /* WebNSStringExtrasIOS.m in Sources */,
</span><span class="cx">                                 939811120824BF01008DF038 /* WebNSURLExtras.mm in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (195089 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2016-01-15 05:23:21 UTC (rev 195089)
+++ trunk/Source/WebKit/mac/ChangeLog        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2016-01-14  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Modern IDB: Support opening and deleting SQLite databases on disk.
+        https://bugs.webkit.org/show_bug.cgi?id=153084
+
+        Reviewed by Alex Christensen, Sam Weinig and Andy Estes (oh my!).
+
+        * Storage/WebDatabaseProvider.mm: Copied from Source/WebKit/Storage/WebDatabaseProvider.cpp.
+        (WebDatabaseProvider::indexedDatabaseDirectoryPath):
+
</ins><span class="cx"> 2016-01-14  Beth Dakin  &lt;bdakin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         WK1 and WK2 should share more candidate request code
</span></span></pre></div>
<a id="trunkSourceWebKitmacStorageWebDatabaseProvidermmfromrev195089trunkSourceWebKitStorageWebDatabaseProvidercpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebKit/mac/Storage/WebDatabaseProvider.mm (from rev 195089, trunk/Source/WebKit/Storage/WebDatabaseProvider.cpp) (0 => 195090)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/Storage/WebDatabaseProvider.mm                                (rev 0)
+++ trunk/Source/WebKit/mac/Storage/WebDatabaseProvider.mm        2016-01-15 05:40:39 UTC (rev 195090)
</span><span class="lines">@@ -0,0 +1,41 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple 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 INC. 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 INC. 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.
+ */
+
+#import &quot;WebDatabaseProvider.h&quot;
+#import &quot;WebDatabaseManagerPrivate.h&quot;
+
+#import &lt;WebCore/FileSystem.h&gt;
+
+String WebDatabaseProvider::indexedDatabaseDirectoryPath()
+{
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+    NSString *databasesDirectory = [defaults objectForKey:WebDatabaseDirectoryDefaultsKey];
+    if (!databasesDirectory || ![databasesDirectory isKindOfClass:[NSString class]])
+        databasesDirectory = WebCore::pathByAppendingComponent(ASCIILiteral(&quot;~/Library/WebKit/Databases/___IndexedDB&quot;), [[NSBundle mainBundle] bundleIdentifier]);
+    else
+        databasesDirectory = WebCore::pathByAppendingComponent(databasesDirectory, ASCIILiteral(&quot;___IndexedDB&quot;));
+    
+    return [databasesDirectory stringByStandardizingPath];
+}
</ins></span></pre>
</div>
</div>

</body>
</html>