Title: [219933] branches/safari-604-branch/Source/WebKit

Diff

Modified: branches/safari-604-branch/Source/WebKit/ChangeLog (219932 => 219933)


--- branches/safari-604-branch/Source/WebKit/ChangeLog	2017-07-26 09:52:14 UTC (rev 219932)
+++ branches/safari-604-branch/Source/WebKit/ChangeLog	2017-07-26 09:52:16 UTC (rev 219933)
@@ -1,5 +1,34 @@
 2017-07-26  Jason Marcell  <[email protected]>
 
+        Cherry-pick r219845. rdar://problem/33523884
+
+    2017-07-24  Chris Dumez  <[email protected]>
+
+            Fix lifetime management issue in ResourceLoadStatisticsPersistentStorage::scheduleOrWriteMemoryStore()
+            https://bugs.webkit.org/show_bug.cgi?id=174790
+
+            Reviewed by Brady Eidson.
+
+            Fix lifetime management issue in ResourceLoadStatisticsPersistentStorage::scheduleOrWriteMemoryStore().
+            WorkQueue::dispatchAfter() keeps the WorkQueue alive because its implementation keeps a strong ref to
+            |this|. As a result, the lambda passed to dispatchAfter(), which calls writeMemoryStoreToDisk(), can
+            get executed after the store is gone.
+
+            To address the issue, we now use a RunLoop::Timer to schedule the write, instead of a
+            WorkQueue::dispatchAfter() call. This way, we are guaranteed that the callback will not get called
+            after the store has been destroyed.
+
+            * UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp:
+            (WebKit::ResourceLoadStatisticsPersistentStorage::ResourceLoadStatisticsPersistentStorage):
+            (WebKit::ResourceLoadStatisticsPersistentStorage::asyncWriteTimerFired):
+            (WebKit::ResourceLoadStatisticsPersistentStorage::scheduleOrWriteMemoryStore):
+            (WebKit::ResourceLoadStatisticsPersistentStorage::finishAllPendingWorkSynchronously):
+            (WebKit::ResourceLoadStatisticsPersistentStorage::ref):
+            (WebKit::ResourceLoadStatisticsPersistentStorage::deref):
+            * UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h:
+
+2017-07-26  Jason Marcell  <[email protected]>
+
         Cherry-pick r219765. rdar://problem/33523818
 
     2017-07-22  Wenson Hsieh  <[email protected]>

Modified: branches/safari-604-branch/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp (219932 => 219933)


--- branches/safari-604-branch/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp	2017-07-26 09:52:14 UTC (rev 219932)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp	2017-07-26 09:52:16 UTC (rev 219933)
@@ -85,6 +85,7 @@
 ResourceLoadStatisticsPersistentStorage::ResourceLoadStatisticsPersistentStorage(WebResourceLoadStatisticsStore& store, const String& storageDirectoryPath)
     : m_memoryStore(store)
     , m_storageDirectoryPath(storageDirectoryPath)
+    , m_asyncWriteTimer(RunLoop::main(), this, &ResourceLoadStatisticsPersistentStorage::asyncWriteTimerFired)
 {
 }
 
@@ -237,6 +238,14 @@
         m_memoryStore.grandfatherExistingWebsiteData();
 }
 
+void ResourceLoadStatisticsPersistentStorage::asyncWriteTimerFired()
+{
+    ASSERT(RunLoop::isMain());
+    m_memoryStore.statisticsQueue().dispatch([this] () mutable {
+        writeMemoryStoreToDisk();
+    });
+}
+
 void ResourceLoadStatisticsPersistentStorage::writeMemoryStoreToDisk()
 {
     ASSERT(!RunLoop::isMain());
@@ -280,8 +289,8 @@
         if (!m_hasPendingWrite) {
             m_hasPendingWrite = true;
             Seconds delay = minimumWriteInterval - timeSinceLastWrite + 1_s;
-            m_memoryStore.statisticsQueue().dispatchAfter(delay, [this] () mutable {
-                writeMemoryStoreToDisk();
+            RunLoop::main().dispatch([this, protectedThis = makeRef(*this), delay] {
+                m_asyncWriteTimer.startOneShot(delay);
             });
         }
         return;
@@ -305,6 +314,8 @@
 
 void ResourceLoadStatisticsPersistentStorage::finishAllPendingWorkSynchronously()
 {
+    m_asyncWriteTimer.stop();
+
     BinarySemaphore semaphore;
     // Make sure any pending work in our queue is finished before we terminate.
     m_memoryStore.statisticsQueue().dispatch([&semaphore, this] {
@@ -316,6 +327,16 @@
     semaphore.wait(WallTime::infinity());
 }
 
+void ResourceLoadStatisticsPersistentStorage::ref()
+{
+    m_memoryStore.ref();
+}
+
+void ResourceLoadStatisticsPersistentStorage::deref()
+{
+    m_memoryStore.deref();
+}
+
 #if !PLATFORM(IOS)
 void ResourceLoadStatisticsPersistentStorage::excludeFromBackup() const
 {

Modified: branches/safari-604-branch/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h (219932 => 219933)


--- branches/safari-604-branch/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h	2017-07-26 09:52:14 UTC (rev 219932)
+++ branches/safari-604-branch/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h	2017-07-26 09:52:16 UTC (rev 219933)
@@ -27,6 +27,7 @@
 
 #include <wtf/Forward.h>
 #include <wtf/MonotonicTime.h>
+#include <wtf/RunLoop.h>
 #include <wtf/WallTime.h>
 #include <wtf/text/WTFString.h>
 
@@ -49,6 +50,9 @@
 
     void finishAllPendingWorkSynchronously();
 
+    void ref();
+    void deref();
+
 private:
     String storageDirectoryPath() const;
     String resourceLogFilePath() const;
@@ -61,9 +65,11 @@
     void populateMemoryStoreFromDisk();
     void excludeFromBackup() const;
     void refreshMemoryStoreFromDisk();
+    void asyncWriteTimerFired();
 
     WebResourceLoadStatisticsStore& m_memoryStore;
     const String m_storageDirectoryPath;
+    RunLoop::Timer<ResourceLoadStatisticsPersistentStorage> m_asyncWriteTimer;
     std::unique_ptr<WebCore::FileMonitor> m_fileMonitor;
     WallTime m_lastStatisticsFileSyncTime;
     MonotonicTime m_lastStatisticsWriteTime;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to