Don't allow sudden termination while writing to local storage.
authorroger_fong@apple.com <roger_fong@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jun 2014 06:45:17 +0000 (06:45 +0000)
committerroger_fong@apple.com <roger_fong@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jun 2014 06:45:17 +0000 (06:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134254.
<rdar://problem/15093854>.

Reviewed by Darin Adler.

* UIProcess/Storage/LocalStorageDatabase.cpp:
(WebKit::LocalStorageDatabase::scheduleDatabaseUpdate):
Disable sudden termination when a database update is scheduled.
(WebKit::LocalStorageDatabase::updateDatabase):
Re-enable sudden termination when the update completes.
* UIProcess/Storage/LocalStorageDatabase.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170471 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.cpp
Source/WebKit2/UIProcess/Storage/LocalStorageDatabase.h

index 96fa2aefaa2044bca5bea30464686ad251188cd7..e6c35d659a7e717295f92b2bafc31f75048a7ad9 100644 (file)
@@ -1,3 +1,18 @@
+2014-06-24  Roger Fong  <roger_fong@apple.com>
+
+        Don't allow sudden termination while writing to local storage.
+        https://bugs.webkit.org/show_bug.cgi?id=134254.
+        <rdar://problem/15093854>.
+
+        Reviewed by Darin Adler.
+
+        * UIProcess/Storage/LocalStorageDatabase.cpp:
+        (WebKit::LocalStorageDatabase::scheduleDatabaseUpdate):
+        Disable sudden termination when a database update is scheduled.
+        (WebKit::LocalStorageDatabase::updateDatabase):
+        Re-enable sudden termination when the update completes.
+        * UIProcess/Storage/LocalStorageDatabase.h:
+
 2014-06-25  Benjamin Poulain  <bpoulain@apple.com>
 
         [iOS][WK2] Update the long press interactions correctly when an overflow scroll view scrolls
index 4f3b5af1485a7647306f777a2018c970f37bba6f..6ebd2ff660fc1caae8cc8572590658cfadc982f2 100644 (file)
@@ -33,6 +33,7 @@
 #include <WebCore/SQLiteTransaction.h>
 #include <WebCore/SecurityOrigin.h>
 #include <WebCore/StorageMap.h>
+#include <WebCore/SuddenTermination.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
@@ -240,6 +241,9 @@ void LocalStorageDatabase::scheduleDatabaseUpdate()
     if (m_didScheduleDatabaseUpdate)
         return;
 
+    if (!m_disableSuddenTerminationWhileWritingToLocalStorage)
+        m_disableSuddenTerminationWhileWritingToLocalStorage = std::make_unique<SuddenTerminationDisabler>();
+
     m_didScheduleDatabaseUpdate = true;
 
     RefPtr<LocalStorageDatabase> localStorageDatabase(this);
@@ -260,6 +264,8 @@ void LocalStorageDatabase::updateDatabase()
     if (m_changedItems.size() <= maximumItemsToUpdate) {
         // There are few enough changed items that we can just always write all of them.
         m_changedItems.swap(changedItems);
+        updateDatabaseWithChangedItems(changedItems);
+        m_disableSuddenTerminationWhileWritingToLocalStorage = nullptr;
     } else {
         for (int i = 0; i < maximumItemsToUpdate; ++i) {
             auto it = m_changedItems.begin();
@@ -272,9 +278,8 @@ void LocalStorageDatabase::updateDatabase()
 
         // Reschedule the update for the remaining items.
         scheduleDatabaseUpdate();
+        updateDatabaseWithChangedItems(changedItems);
     }
-
-    updateDatabaseWithChangedItems(changedItems);
 }
 
 void LocalStorageDatabase::updateDatabaseWithChangedItems(const HashMap<String, String>& changedItems)
index 1acd6b253d4d2744166e8dc511fb371257d93754..92553a72434ac5dd64b4887efeeca6b11fbc5722 100644 (file)
@@ -37,6 +37,7 @@ class WorkQueue;
 namespace WebCore {
 class SecurityOrigin;
 class StorageMap;
+class SuddenTerminationDisabler;
 }
 
 namespace WebKit {
@@ -91,6 +92,8 @@ private:
     bool m_didScheduleDatabaseUpdate;
     bool m_shouldClearItems;
     HashMap<String, String> m_changedItems;
+
+    std::unique_ptr<WebCore::SuddenTerminationDisabler> m_disableSuddenTerminationWhileWritingToLocalStorage;
 };