Title: [255156] trunk
Revision
255156
Author
[email protected]
Date
2020-01-27 11:16:23 -0800 (Mon, 27 Jan 2020)

Log Message

Delete the ITP storage file that is not being used (plist or database file) when switching to a new storage type
https://bugs.webkit.org/show_bug.cgi?id=206601
<rdar://problem/58696521>

Reviewed by Alex Christensen.

Source/WebKit:

This patch also deletes the temporary files SQLite creates when
constructing a new database.

* NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):

Tools:

This patch caused some API tests to fail which relied on the ITP files
always existing. Now the tests ensure the respective file exists when
switching between in-memory and database storage before running the tests.

* TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
(ensureITPFileIsCreated):
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (255155 => 255156)


--- trunk/Source/WebKit/ChangeLog	2020-01-27 19:09:32 UTC (rev 255155)
+++ trunk/Source/WebKit/ChangeLog	2020-01-27 19:16:23 UTC (rev 255156)
@@ -1,3 +1,17 @@
+2020-01-27  Kate Cheney  <[email protected]>
+
+        Delete the ITP storage file that is not being used (plist or database file) when switching to a new storage type
+        https://bugs.webkit.org/show_bug.cgi?id=206601
+        <rdar://problem/58696521>
+
+        Reviewed by Alex Christensen.
+
+        This patch also deletes the temporary files SQLite creates when
+        constructing a new database.
+
+        * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::WebResourceLoadStatisticsStore):
+
 2020-01-27  Brent Fulgham  <[email protected]>
 
         Remove locationd entitlements from the WebContent process

Modified: trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp (255155 => 255156)


--- trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2020-01-27 19:09:32 UTC (rev 255155)
+++ trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp	2020-01-27 19:16:23 UTC (rev 255156)
@@ -163,9 +163,23 @@
 
             auto memoryStore = makeUnique<ResourceLoadStatisticsMemoryStore>(*this, m_statisticsQueue, shouldIncludeLocalhost);
             downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore.get()).populateFromMemoryStore(*memoryStore);
+
+            auto legacyPlistFilePath = FileSystem::pathByAppendingComponent(resourceLoadStatisticsDirectory, "full_browsing_session_resourceLog.plist");
+            if (FileSystem::fileExists(legacyPlistFilePath))
+                FileSystem::deleteFile(legacyPlistFilePath);
+
         } else {
             m_statisticsStore = makeUnique<ResourceLoadStatisticsMemoryStore>(*this, m_statisticsQueue, shouldIncludeLocalhost);
             m_persistentStorage = makeUnique<ResourceLoadStatisticsPersistentStorage>(downcast<ResourceLoadStatisticsMemoryStore>(*m_statisticsStore), m_statisticsQueue, resourceLoadStatisticsDirectory);
+
+            auto databaseStorageFilePath = FileSystem::pathByAppendingComponent(resourceLoadStatisticsDirectory, "observations.db");
+            auto databaseStorageTemporaryWalFilePath = FileSystem::pathByAppendingComponent(resourceLoadStatisticsDirectory, "observations.db-wal");
+            auto databaseStorageTemporaryShmFilePath = FileSystem::pathByAppendingComponent(resourceLoadStatisticsDirectory, "observations.db-shm");
+            if (FileSystem::fileExists(databaseStorageFilePath)) {
+                FileSystem::deleteFile(databaseStorageFilePath);
+                FileSystem::deleteFile(databaseStorageTemporaryWalFilePath);
+                FileSystem::deleteFile(databaseStorageTemporaryShmFilePath);
+            }
         }
 
         // FIXME(193297): This should be revised after the UIProcess version goes away.

Modified: trunk/Tools/ChangeLog (255155 => 255156)


--- trunk/Tools/ChangeLog	2020-01-27 19:09:32 UTC (rev 255155)
+++ trunk/Tools/ChangeLog	2020-01-27 19:16:23 UTC (rev 255156)
@@ -1,3 +1,19 @@
+2020-01-27  Kate Cheney  <[email protected]>
+
+        Delete the ITP storage file that is not being used (plist or database file) when switching to a new storage type
+        https://bugs.webkit.org/show_bug.cgi?id=206601
+        <rdar://problem/58696521>
+
+        Reviewed by Alex Christensen.
+
+        This patch caused some API tests to fail which relied on the ITP files
+        always existing. Now the tests ensure the respective file exists when 
+        switching between in-memory and database storage before running the tests.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm:
+        (ensureITPFileIsCreated):
+        (TEST):
+
 2020-01-27  Ryan Haddad  <[email protected]>
 
         Unreviewed, rolling out r255131.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm (255155 => 255156)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2020-01-27 19:09:32 UTC (rev 255155)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm	2020-01-27 19:16:23 UTC (rev 255156)
@@ -82,6 +82,20 @@
     return defaultDatabaseEnabled;
 }
 
+static void ensureITPFileIsCreated()
+{
+    static bool doneFlag;
+    auto *dataStore = [WKWebsiteDataStore defaultDataStore];
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [dataStore _setResourceLoadStatisticsEnabled:YES];
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
+    [dataStore _setUseITPDatabase:true completionHandler: ^(void) {
+        doneFlag = true;
+    }];
+    TestWebKitAPI::Util::run(&doneFlag);
+    [dataStore _setResourceLoadStatisticsEnabled:NO];
+}
+
 TEST(ResourceLoadStatistics, GrandfatherCallback)
 {
     auto *dataStore = [WKWebsiteDataStore defaultDataStore];
@@ -286,6 +300,11 @@
             callbackFlag = true;
         }];
 
+        // Since the ITP Database is enabled, the plist file has been deleted. We need to create it again.
+        [[NSFileManager defaultManager] createDirectoryAtURL:statisticsDirectoryURL withIntermediateDirectories:YES attributes:nil error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:testResourceURL toURL:targetURL error:nil];
+        EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]);
+
         [dataStore _setUseITPDatabase:false completionHandler: ^(void) {
             doneFlag = true;
         }];
@@ -300,15 +319,8 @@
 {
     auto *dataStore = [WKWebsiteDataStore defaultDataStore];
 
-    NSURL *statisticsDirectoryURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/ResourceLoadStatistics" stringByExpandingTildeInPath] isDirectory:YES];
-    NSURL *targetURL = [statisticsDirectoryURL URLByAppendingPathComponent:@"observations.db"];
-    NSURL *testResourceURL = [[NSBundle mainBundle] URLForResource:@"EmptyGrandfatheredResourceLoadStatistics" withExtension:@"plist" subdirectory:@"TestWebKitAPI.resources"];
+    ensureITPFileIsCreated();
 
-    [[NSFileManager defaultManager] createDirectoryAtURL:statisticsDirectoryURL withIntermediateDirectories:YES attributes:nil error:nil];
-    [[NSFileManager defaultManager] copyItemAtURL:testResourceURL toURL:targetURL error:nil];
-
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]);
-
     static bool callbackFlag;
     static bool doneFlag;
 
@@ -336,6 +348,8 @@
             callbackFlag = true;
         }];
 
+        ensureITPFileIsCreated();
+
         [dataStore _setUseITPDatabase:true completionHandler: ^(void) {
             doneFlag = true;
         }];
@@ -390,6 +404,11 @@
             callbackFlag = true;
         }];
 
+        // Since the ITP Database is enabled, the plist file has been deleted. We need to create it again.
+        [[NSFileManager defaultManager] createDirectoryAtURL:statisticsDirectoryURL withIntermediateDirectories:YES attributes:nil error:nil];
+        [[NSFileManager defaultManager] copyItemAtURL:testResourceURL toURL:targetURL error:nil];
+        EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]);
+
         [dataStore _setUseITPDatabase:false completionHandler: ^(void) {
             doneFlag = true;
         }];
@@ -418,13 +437,8 @@
     NSURL *statisticsDirectoryURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/ResourceLoadStatistics" stringByExpandingTildeInPath] isDirectory:YES];
     NSURL *targetURL = [statisticsDirectoryURL URLByAppendingPathComponent:@"observations.db"];
 
-    NSURL *testResourceURL = [[NSBundle mainBundle] URLForResource:@"EmptyGrandfatheredResourceLoadStatistics" withExtension:@"plist" subdirectory:@"TestWebKitAPI.resources"];
+    ensureITPFileIsCreated();
 
-    [[NSFileManager defaultManager] createDirectoryAtURL:statisticsDirectoryURL withIntermediateDirectories:YES attributes:nil error:nil];
-    [[NSFileManager defaultManager] copyItemAtURL:testResourceURL toURL:targetURL error:nil];
-
-    EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]);
-
     static bool callbackFlag;
     static bool doneFlag;
 
@@ -452,6 +466,8 @@
             callbackFlag = true;
         }];
 
+        ensureITPFileIsCreated();
+
         [dataStore _setUseITPDatabase:true completionHandler: ^(void) {
             doneFlag = true;
         }];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to