Title: [149688] trunk/Source
Revision
149688
Author
ander...@apple.com
Date
2013-05-07 12:42:03 -0700 (Tue, 07 May 2013)

Log Message

The storage database tracker should know when databases come and go
https://bugs.webkit.org/show_bug.cgi?id=115748

Reviewed by Andreas Kling.

Source/WebCore:

Export symbol needed by WebKit2.

* WebCore.exp.in:

Source/WebKit2:

* UIProcess/Storage/LocalStorageDatabase.cpp:
(WebKit::LocalStorageDatabase::openDatabase):
If we've opened the database successfully, call LocalStorageDatabaseTracker::didOpenDatabaseWithOrigin.

(WebKit::LocalStorageDatabase::tryToOpenDatabase):
Remove a FIXME; we run all storage related things on the same thread.

(WebKit::LocalStorageDatabase::close):
Close the database. If it's empty, call LocalStorageDatabaseTracker::deleteEmptyDatabaseWithOrigin.

(WebKit::LocalStorageDatabase::databaseIsEmpty):
Helper function for determining whether a database is empty.

* UIProcess/Storage/LocalStorageDatabase.h:
* UIProcess/Storage/LocalStorageDatabaseTracker.cpp:
(WebKit::LocalStorageDatabaseTracker::databaseFilename):
Add ".localstorage" to the filename.

(WebKit::LocalStorageDatabaseTracker::didOpenDatabaseWithOrigin):
(WebKit::LocalStorageDatabaseTracker::deleteEmptyDatabaseWithOrigin):
Add empty stubs.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149687 => 149688)


--- trunk/Source/WebCore/ChangeLog	2013-05-07 19:11:39 UTC (rev 149687)
+++ trunk/Source/WebCore/ChangeLog	2013-05-07 19:42:03 UTC (rev 149688)
@@ -1,3 +1,14 @@
+2013-05-07  Anders Carlsson  <ander...@apple.com>
+
+        The storage database tracker should know when databases come and go
+        https://bugs.webkit.org/show_bug.cgi?id=115748
+
+        Reviewed by Andreas Kling.
+
+        Export symbol needed by WebKit2.
+
+        * WebCore.exp.in:
+
 2013-05-07  Darin Adler  <da...@apple.com>
 
         Use OwnPtr instead of deleteAllValues in SVGResourcesCache

Modified: trunk/Source/WebCore/WebCore.exp.in (149687 => 149688)


--- trunk/Source/WebCore/WebCore.exp.in	2013-05-07 19:11:39 UTC (rev 149687)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-05-07 19:42:03 UTC (rev 149688)
@@ -468,6 +468,7 @@
 __ZN7WebCore15ProtectionSpaceC1Ev
 __ZN7WebCore15ResourceRequest21httpPipeliningEnabledEv
 __ZN7WebCore15ResourceRequest24setHTTPPipeliningEnabledEb
+__ZN7WebCore15SQLiteStatement12getColumnIntEi
 __ZN7WebCore15SQLiteStatement13getColumnTextEi
 __ZN7WebCore15SQLiteStatement21getColumnBlobAsStringEi
 __ZN7WebCore15SQLiteStatement22isColumnDeclaredAsBlobEi

Modified: trunk/Source/WebKit2/ChangeLog (149687 => 149688)


--- trunk/Source/WebKit2/ChangeLog	2013-05-07 19:11:39 UTC (rev 149687)
+++ trunk/Source/WebKit2/ChangeLog	2013-05-07 19:42:03 UTC (rev 149688)
@@ -1,3 +1,32 @@
+2013-05-07  Anders Carlsson  <ander...@apple.com>
+
+        The storage database tracker should know when databases come and go
+        https://bugs.webkit.org/show_bug.cgi?id=115748
+
+        Reviewed by Andreas Kling.
+
+        * UIProcess/Storage/LocalStorageDatabase.cpp:
+        (WebKit::LocalStorageDatabase::openDatabase):
+        If we've opened the database successfully, call LocalStorageDatabaseTracker::didOpenDatabaseWithOrigin.
+
+        (WebKit::LocalStorageDatabase::tryToOpenDatabase):
+        Remove a FIXME; we run all storage related things on the same thread.
+
+        (WebKit::LocalStorageDatabase::close):
+        Close the database. If it's empty, call LocalStorageDatabaseTracker::deleteEmptyDatabaseWithOrigin.
+
+        (WebKit::LocalStorageDatabase::databaseIsEmpty):
+        Helper function for determining whether a database is empty.
+        
+        * UIProcess/Storage/LocalStorageDatabase.h:
+        * UIProcess/Storage/LocalStorageDatabaseTracker.cpp:
+        (WebKit::LocalStorageDatabaseTracker::databaseFilename):
+        Add ".localstorage" to the filename.
+
+        (WebKit::LocalStorageDatabaseTracker::didOpenDatabaseWithOrigin):
+        (WebKit::LocalStorageDatabaseTracker::deleteEmptyDatabaseWithOrigin):
+        Add empty stubs.
+
 2013-05-07  Brady Eidson  <beid...@apple.com>
 
         Add JoinExistingSession to the Networking XPC.

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp (149687 => 149688)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp	2013-05-07 19:11:39 UTC (rev 149687)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp	2013-05-07 19:42:03 UTC (rev 149688)
@@ -73,8 +73,12 @@
     ASSERT(!m_database.isOpen());
     ASSERT(!m_failedToOpenDatabase);
 
-    if (!tryToOpenDatabase(openingStrategy))
+    if (!tryToOpenDatabase(openingStrategy)) {
         m_failedToOpenDatabase = true;
+        return;
+    }
+
+    m_tracker->didOpenDatabaseWithOrigin(m_securityOrigin.get());
 }
 
 bool LocalStorageDatabase::tryToOpenDatabase(DatabaseOpeningStrategy openingStrategy)
@@ -87,10 +91,6 @@
         return false;
     }
 
-    // FIXME:
-    // A StorageTracker thread may have been scheduled to delete the db we're
-    // reopening, so cancel possible deletion.
-
     if (!m_database.open(m_databaseFilename)) {
         LOG_ERROR("Failed to open database file %s for local storage", m_databaseFilename.utf8().data());
         return false;
@@ -219,7 +219,13 @@
         m_changedItems.clear();
     }
 
-    // FIXME: Delete the database if it's empty.
+    bool isEmpty = databaseIsEmpty();
+
+    if (m_database.isOpen())
+        m_database.close();
+
+    if (isEmpty)
+        m_tracker->deleteEmptyDatabaseWithOrigin(m_securityOrigin.get());
 }
 
 void LocalStorageDatabase::itemDidChange(const String& key, const String& value)
@@ -321,4 +327,24 @@
     transaction.commit();
 }
 
+bool LocalStorageDatabase::databaseIsEmpty()
+{
+    if (!m_database.isOpen())
+        return false;
+
+    SQLiteStatement query(m_database, "SELECT COUNT(*) FROM ItemTable");
+    if (query.prepare() != SQLResultOk) {
+        LOG_ERROR("Unable to count number of rows in ItemTable for local storage");
+        return false;
+    }
+
+    int result = query.step();
+    if (result != SQLResultRow) {
+        LOG_ERROR("No results when counting number of rows in ItemTable for local storage");
+        return false;
+    }
+
+    return !query.getColumnInt(0);
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h (149687 => 149688)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h	2013-05-07 19:11:39 UTC (rev 149687)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h	2013-05-07 19:42:03 UTC (rev 149688)
@@ -76,6 +76,8 @@
     void updateDatabase();
     void updateDatabaseWithChangedItems(const HashMap<String, String>&);
 
+    bool databaseIsEmpty();
+
     RefPtr<WorkQueue> m_queue;
     RefPtr<LocalStorageDatabaseTracker> m_tracker;
     RefPtr<WebCore::SecurityOrigin> m_securityOrigin;

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp (149687 => 149688)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp	2013-05-07 19:11:39 UTC (rev 149687)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.cpp	2013-05-07 19:42:03 UTC (rev 149688)
@@ -57,9 +57,17 @@
 
 String LocalStorageDatabaseTracker::databaseFilename(SecurityOrigin* securityOrigin) const
 {
-    return databaseFilename(securityOrigin->databaseIdentifier());
+    return databaseFilename(securityOrigin->databaseIdentifier() + ".localstorage");
 }
 
+void LocalStorageDatabaseTracker::didOpenDatabaseWithOrigin(WebCore::SecurityOrigin*)
+{
+}
+
+void LocalStorageDatabaseTracker::deleteEmptyDatabaseWithOrigin(WebCore::SecurityOrigin*)
+{
+}
+
 void LocalStorageDatabaseTracker::setLocalStorageDirectoryInternal(const String& localStorageDirectory)
 {
     if (m_database.isOpen())

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h (149687 => 149688)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h	2013-05-07 19:11:39 UTC (rev 149687)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabaseTracker.h	2013-05-07 19:42:03 UTC (rev 149688)
@@ -50,6 +50,9 @@
     void setLocalStorageDirectory(const String&);
     String databaseFilename(WebCore::SecurityOrigin*) const;
 
+    void didOpenDatabaseWithOrigin(WebCore::SecurityOrigin*);
+    void deleteEmptyDatabaseWithOrigin(WebCore::SecurityOrigin*);
+
 private:
     explicit LocalStorageDatabaseTracker(PassRefPtr<WorkQueue>);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to