Title: [219530] trunk/Source/WebKit
Revision
219530
Author
bfulg...@apple.com
Date
2017-07-14 15:52:52 -0700 (Fri, 14 Jul 2017)

Log Message

Monitor directory for new statistics files after a delete operation
https://bugs.webkit.org/show_bug.cgi?id=174521
<rdar://problem/33322189>

Reviewed by Chris Dumez.

Create a FileMonitor to watch the data directory when the statistics file is
deleted by an external process. If it sees the file get created externally, merge
those data into the in-memory store.

* UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp:
(WebKit::ResourceLoadStatisticsPersistentStorage::startMonitoringDisk): Added.
(WebKit::ResourceLoadStatisticsPersistentStorage::monitorDirectoryForNewStatistics):
* UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (219529 => 219530)


--- trunk/Source/WebKit/ChangeLog	2017-07-14 22:51:36 UTC (rev 219529)
+++ trunk/Source/WebKit/ChangeLog	2017-07-14 22:52:52 UTC (rev 219530)
@@ -1,3 +1,20 @@
+2017-07-14  Brent Fulgham  <bfulg...@apple.com>
+
+        Monitor directory for new statistics files after a delete operation
+        https://bugs.webkit.org/show_bug.cgi?id=174521
+        <rdar://problem/33322189>
+
+        Reviewed by Chris Dumez.
+
+        Create a FileMonitor to watch the data directory when the statistics file is
+        deleted by an external process. If it sees the file get created externally, merge
+        those data into the in-memory store.
+
+        * UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp:
+        (WebKit::ResourceLoadStatisticsPersistentStorage::startMonitoringDisk): Added.
+        (WebKit::ResourceLoadStatisticsPersistentStorage::monitorDirectoryForNewStatistics):
+        * UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h:
+
 2017-07-14  Matt Lewis  <jlew...@apple.com>
 
         Unreviewed, rolling out r219516.

Modified: trunk/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp (219529 => 219530)


--- trunk/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp	2017-07-14 22:51:36 UTC (rev 219529)
+++ trunk/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.cpp	2017-07-14 22:52:52 UTC (rev 219530)
@@ -108,7 +108,7 @@
 
 String ResourceLoadStatisticsPersistentStorage::resourceLogFilePath() const
 {
-    String storagePath = this->storageDirectoryPath();
+    String storagePath = storageDirectoryPath();
     if (storagePath.isEmpty())
         return emptyString();
 
@@ -134,11 +134,45 @@
         case FileMonitor::FileChangeType::Removal:
             m_memoryStore.clearInMemory();
             m_fileMonitor = nullptr;
+            monitorDirectoryForNewStatistics();
             break;
         }
     });
 }
 
+void ResourceLoadStatisticsPersistentStorage::monitorDirectoryForNewStatistics()
+{
+    String storagePath = storageDirectoryPath();
+    ASSERT(!storagePath.isEmpty());
+
+    if (!fileExists(storagePath)) {
+        if (!makeAllDirectories(storagePath)) {
+            RELEASE_LOG_ERROR(ResourceLoadStatistics, "ResourceLoadStatisticsPersistentStorage: Failed to create directory path %s", storagePath.utf8().data());
+            return;
+        }
+    }
+
+    m_fileMonitor = std::make_unique<FileMonitor>(storagePath, m_memoryStore.statisticsQueue(), [this] (FileMonitor::FileChangeType type) {
+        ASSERT(!RunLoop::isMain());
+        if (type == FileMonitor::FileChangeType::Removal) {
+            // Directory was removed!
+            m_fileMonitor = nullptr;
+            return;
+        }
+
+        String resourceLogPath = resourceLogFilePath();
+        ASSERT(!resourceLogPath.isEmpty());
+
+        if (!fileExists(resourceLogPath))
+            return;
+
+        m_fileMonitor = nullptr;
+
+        refreshMemoryStoreFromDisk();
+        startMonitoringDisk();
+    });
+}
+
 void ResourceLoadStatisticsPersistentStorage::stopMonitoringDisk()
 {
     ASSERT(!RunLoop::isMain());
@@ -177,6 +211,7 @@
     String filePath = resourceLogFilePath();
     if (filePath.isEmpty() || !fileExists(filePath)) {
         m_memoryStore.grandfatherExistingWebsiteData();
+        monitorDirectoryForNewStatistics();
         return;
     }
 
@@ -214,7 +249,7 @@
     if (!rawData)
         return;
 
-    auto storagePath = this->storageDirectoryPath();
+    auto storagePath = storageDirectoryPath();
     if (!storagePath.isEmpty()) {
         makeAllDirectories(storagePath);
         excludeFromBackup();
@@ -228,7 +263,7 @@
     unlockAndCloseFile(handle);
 
     if (writtenBytes != static_cast<int64_t>(rawData->size()))
-        RELEASE_LOG_ERROR(ResourceLoadStatistics, "WebResourceLoadStatisticsStore: We only wrote %d out of %zu bytes to disk", static_cast<unsigned>(writtenBytes), rawData->size());
+        RELEASE_LOG_ERROR(ResourceLoadStatistics, "ResourceLoadStatisticsPersistentStorage: We only wrote %d out of %zu bytes to disk", static_cast<unsigned>(writtenBytes), rawData->size());
 
     m_lastStatisticsFileSyncTime = WallTime::now();
     m_lastStatisticsWriteTime = MonotonicTime::now();
@@ -265,7 +300,7 @@
     stopMonitoringDisk();
 
     if (!deleteFile(filePath))
-        RELEASE_LOG_ERROR(ResourceLoadStatistics, "Unable to delete statistics file: %s", filePath.utf8().data());
+        RELEASE_LOG_ERROR(ResourceLoadStatistics, "ResourceLoadStatisticsPersistentStorage: Unable to delete statistics file: %s", filePath.utf8().data());
 }
 
 void ResourceLoadStatisticsPersistentStorage::finishAllPendingWorkSynchronously()

Modified: trunk/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h (219529 => 219530)


--- trunk/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h	2017-07-14 22:51:36 UTC (rev 219529)
+++ trunk/Source/WebKit/UIProcess/Storage/ResourceLoadStatisticsPersistentStorage.h	2017-07-14 22:52:52 UTC (rev 219530)
@@ -55,6 +55,7 @@
 
     void startMonitoringDisk();
     void stopMonitoringDisk();
+    void monitorDirectoryForNewStatistics();
 
     void writeMemoryStoreToDisk();
     void populateMemoryStoreFromDisk();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to