Title: [149631] trunk/Source/WebKit2
Revision
149631
Author
[email protected]
Date
2013-05-06 13:13:08 -0700 (Mon, 06 May 2013)

Log Message

Handle closing the local storage database
https://bugs.webkit.org/show_bug.cgi?id=115669

Reviewed by Beth Dakin.

* UIProcess/Storage/LocalStorageDatabase.cpp:
(WebKit::LocalStorageDatabase::LocalStorageDatabase):
Initialize m_isClosed.

(WebKit::LocalStorageDatabase::~LocalStorageDatabase):
Assert that m_isClosed is false.

(WebKit::LocalStorageDatabase::close):
Set m_isClosed to true and write any pending changes to disk.

(WebKit::LocalStorageDatabase::updateDatabase):
Compute the changed items and pass them to updateDatabaseWithChangedItems.

(WebKit::LocalStorageDatabase::updateDatabaseWithChangedItems):
Split out the code that actually writes to the database from updateDatabase and into this function.

* UIProcess/Storage/LocalStorageDatabase.h:
* UIProcess/Storage/StorageManager.cpp:
(WebKit::StorageManager::StorageArea::~StorageArea):
Call close().

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (149630 => 149631)


--- trunk/Source/WebKit2/ChangeLog	2013-05-06 19:49:08 UTC (rev 149630)
+++ trunk/Source/WebKit2/ChangeLog	2013-05-06 20:13:08 UTC (rev 149631)
@@ -1,3 +1,31 @@
+2013-05-06  Anders Carlsson  <[email protected]>
+
+        Handle closing the local storage database
+        https://bugs.webkit.org/show_bug.cgi?id=115669
+
+        Reviewed by Beth Dakin.
+
+        * UIProcess/Storage/LocalStorageDatabase.cpp:
+        (WebKit::LocalStorageDatabase::LocalStorageDatabase):
+        Initialize m_isClosed.
+    
+        (WebKit::LocalStorageDatabase::~LocalStorageDatabase):
+        Assert that m_isClosed is false.
+
+        (WebKit::LocalStorageDatabase::close):
+        Set m_isClosed to true and write any pending changes to disk.
+
+        (WebKit::LocalStorageDatabase::updateDatabase):
+        Compute the changed items and pass them to updateDatabaseWithChangedItems.
+
+        (WebKit::LocalStorageDatabase::updateDatabaseWithChangedItems):
+        Split out the code that actually writes to the database from updateDatabase and into this function.
+
+        * UIProcess/Storage/LocalStorageDatabase.h:
+        * UIProcess/Storage/StorageManager.cpp:
+        (WebKit::StorageManager::StorageArea::~StorageArea):
+        Call close().
+
 2013-05-06  Zan Dobersek  <[email protected]>
 
         [WK2] Make the WebNetworkInfoManagerProxy a supplement to the WebContext

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp (149630 => 149631)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp	2013-05-06 19:49:08 UTC (rev 149630)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp	2013-05-06 20:13:08 UTC (rev 149631)
@@ -53,6 +53,7 @@
     , m_queue(queue)
     , m_failedToOpenDatabase(false)
     , m_didImportItems(false)
+    , m_isClosed(false)
     , m_didScheduleDatabaseUpdate(false)
     , m_shouldClearItems(false)
 {
@@ -60,6 +61,7 @@
 
 LocalStorageDatabase::~LocalStorageDatabase()
 {
+    ASSERT(m_isClosed);
 }
 
 void LocalStorageDatabase::openDatabase(DatabaseOpeningStrategy openingStrategy)
@@ -203,6 +205,19 @@
     scheduleDatabaseUpdate();
 }
 
+void LocalStorageDatabase::close()
+{
+    ASSERT(!m_isClosed);
+    m_isClosed = true;
+
+    if (m_didScheduleDatabaseUpdate) {
+        updateDatabaseWithChangedItems(m_changedItems);
+        m_changedItems.clear();
+    }
+
+    // FIXME: Delete the database if it's empty.
+}
+
 void LocalStorageDatabase::itemDidChange(const String& key, const String& value)
 {
     m_changedItems.set(key, value);
@@ -220,10 +235,35 @@
 
 void LocalStorageDatabase::updateDatabase()
 {
+    if (m_isClosed)
+        return;
+
     ASSERT(m_didScheduleDatabaseUpdate);
-
     m_didScheduleDatabaseUpdate = false;
 
+    HashMap<String, String> changedItems;
+    if (m_changedItems.size() <= maximumItemsToUpdate) {
+        // There are few enough changed items that we can just always write all of them.
+        m_changedItems.swap(changedItems);
+    } else {
+        for (int i = 0; i < maximumItemsToUpdate; ++i) {
+            auto it = m_changedItems.begin();
+            changedItems.add(it->key, it->value);
+
+            m_changedItems.remove(it);
+        }
+
+        ASSERT(changedItems.size() <= maximumItemsToUpdate);
+
+        // Reschedule the update for the remaining items.
+        scheduleDatabaseUpdate();
+    }
+
+    updateDatabaseWithChangedItems(changedItems);
+}
+
+void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, String>& changedItems)
+{
     if (m_shouldClearItems) {
         m_shouldClearItems = false;
 
@@ -240,24 +280,6 @@
         }
     }
 
-    HashMap<String, String> changedItems;
-    if (m_changedItems.size() > maximumItemsToUpdate) {
-        for (int i = 0; i < maximumItemsToUpdate; ++i) {
-            auto it = m_changedItems.begin();
-            changedItems.add(it->key, it->value);
-
-            m_changedItems.remove(it);
-        }
-
-        // Reschedule the update for the remaining items.
-        scheduleDatabaseUpdate();
-    } else {
-        // There are few enough changed items that we can just always write all of them.
-        m_changedItems.swap(changedItems);
-    }
-
-    ASSERT(changedItems.size() <= maximumItemsToUpdate);
-
     SQLiteStatement insertStatement(m_database, "INSERT INTO ItemTable VALUES (?, ?)");
     if (insertStatement.prepare() != SQLResultOk) {
         LOG_ERROR("Failed to prepare insert statement - cannot write to local storage database");

Modified: trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h (149630 => 149631)


--- trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h	2013-05-06 19:49:08 UTC (rev 149630)
+++ trunk/Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h	2013-05-06 20:13:08 UTC (rev 149631)
@@ -52,6 +52,9 @@
     void removeItem(const String& key);
     void clear();
 
+    // Will block until all pending changes have been written to disk.
+    void close();
+
 private:
     LocalStorageDatabase(const String& databaseFilename, PassRefPtr<WorkQueue>);
 
@@ -68,6 +71,7 @@
 
     void scheduleDatabaseUpdate();
     void updateDatabase();
+    void updateDatabaseWithChangedItems(const HashMap<String, String>&);
 
     String m_databaseFilename;
     RefPtr<WorkQueue> m_queue;
@@ -75,6 +79,7 @@
     WebCore::SQLiteDatabase m_database;
     bool m_failedToOpenDatabase;
     bool m_didImportItems;
+    bool m_isClosed;
 
     bool m_didScheduleDatabaseUpdate;
     bool m_shouldClearItems;

Modified: trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp (149630 => 149631)


--- trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp	2013-05-06 19:49:08 UTC (rev 149630)
+++ trunk/Source/WebKit2/UIProcess/Storage/StorageManager.cpp	2013-05-06 20:13:08 UTC (rev 149631)
@@ -117,6 +117,9 @@
 {
     ASSERT(m_eventListeners.isEmpty());
 
+    if (m_localStorageDatabase)
+        m_localStorageDatabase->close();
+
     if (m_localStorageNamespace)
         m_localStorageNamespace->didDestroyStorageArea(this);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to