Resource Load Statistics: Make debug mode always partition prevalent resources
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 21:11:50 +0000 (21:11 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 21:11:50 +0000 (21:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183468
<rdar://problem/38269437>

Reviewed by Brent Fulgham.

After some testing we decided that a 30 second timeout in ITP debug mode just makes
it confusing. We should instead always partition prevalent resources in debug mode
to make it easy to understand. The partitioned state is what developers want to test
anyway.

* UIProcess/Cocoa/WebResourceLoadStatisticsStoreCocoa.mm:
(WebKit::WebResourceLoadStatisticsStore::registerUserDefaultsIfNeeded):
    Minor change to include 0 as valid setting.
* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::setResourceLoadStatisticsDebugMode):
    Now just stores the setting of debug mode instead of changing the timeout.
(WebKit::WebResourceLoadStatisticsStore::logUserInteraction):
    Now does not disable partitioning under debug mode.
(WebKit::WebResourceLoadStatisticsStore::shouldPartitionCookies const):
    Now returns true for prevalent resources with user interaction under debug mode.
(WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioning):
    Removed duplicate debug logging statement.
* UIProcess/WebResourceLoadStatisticsStore.h:
    Added member m_debugModeEnabled.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/WebResourceLoadStatisticsStoreCocoa.mm
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.h

index cacabbd..80b0ccd 100644 (file)
@@ -1,3 +1,31 @@
+2018-03-08  John Wilander  <wilander@apple.com>
+
+        Resource Load Statistics: Make debug mode always partition prevalent resources
+        https://bugs.webkit.org/show_bug.cgi?id=183468
+        <rdar://problem/38269437>
+
+        Reviewed by Brent Fulgham.
+
+        After some testing we decided that a 30 second timeout in ITP debug mode just makes
+        it confusing. We should instead always partition prevalent resources in debug mode
+        to make it easy to understand. The partitioned state is what developers want to test
+        anyway.
+
+        * UIProcess/Cocoa/WebResourceLoadStatisticsStoreCocoa.mm:
+        (WebKit::WebResourceLoadStatisticsStore::registerUserDefaultsIfNeeded):
+            Minor change to include 0 as valid setting.
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::setResourceLoadStatisticsDebugMode):
+            Now just stores the setting of debug mode instead of changing the timeout.
+        (WebKit::WebResourceLoadStatisticsStore::logUserInteraction):
+            Now does not disable partitioning under debug mode.
+        (WebKit::WebResourceLoadStatisticsStore::shouldPartitionCookies const):
+            Now returns true for prevalent resources with user interaction under debug mode.            
+        (WebKit::WebResourceLoadStatisticsStore::updateCookiePartitioning):
+            Removed duplicate debug logging statement.
+        * UIProcess/WebResourceLoadStatisticsStore.h:
+            Added member m_debugModeEnabled.
+
 2018-03-08  Brent Fulgham  <bfulgham@apple.com>
 
         Remove WebCookieManager and messaging from WebContent process.
index 20faf9f..171a8c2 100644 (file)
@@ -38,15 +38,15 @@ void WebResourceLoadStatisticsStore::registerUserDefaultsIfNeeded()
             setTimeToLiveUserInteraction(timeToLiveUserInteraction);
 
         Seconds timeToLiveCookiePartitionFree([[NSUserDefaults standardUserDefaults] doubleForKey:@"ResourceLoadStatisticsTimeToLiveCookiePartitionFree"]);
-        if (timeToLiveCookiePartitionFree > 0_s && timeToLiveCookiePartitionFree <= 24_h)
+        if (timeToLiveCookiePartitionFree >= 0_s && timeToLiveCookiePartitionFree <= 24_h)
             setTimeToLiveCookiePartitionFree(timeToLiveCookiePartitionFree);
 
         Seconds minimumTimeBetweenDataRecordsRemoval([[NSUserDefaults standardUserDefaults] doubleForKey:@"ResourceLoadStatisticsMinimumTimeBetweenDataRecordsRemoval"]);
-        if (minimumTimeBetweenDataRecordsRemoval > 0_s && minimumTimeBetweenDataRecordsRemoval < 1_h)
+        if (minimumTimeBetweenDataRecordsRemoval >= 0_s && minimumTimeBetweenDataRecordsRemoval < 1_h)
             setMinimumTimeBetweenDataRecordsRemoval(minimumTimeBetweenDataRecordsRemoval);
 
         Seconds grandfatheringTime([[NSUserDefaults standardUserDefaults] doubleForKey:@"ResourceLoadStatisticsGrandfatheringTime"]);
-        if (grandfatheringTime > 0_s && grandfatheringTime <= 24_h * 7)
+        if (grandfatheringTime >= 0_s && grandfatheringTime <= 24_h * 7)
             setGrandfatheringTime(grandfatheringTime);
 
         setDebugLogggingEnabled([[NSUserDefaults standardUserDefaults] boolForKey:@"ResourceLoadStatisticsDebugLoggingEnabled"]);
index dcbd781..ff03783 100644 (file)
@@ -443,10 +443,10 @@ void WebResourceLoadStatisticsStore::submitTelemetry()
 
 void WebResourceLoadStatisticsStore::setResourceLoadStatisticsDebugMode(bool enable)
 {
-    if (enable)
-        setTimeToLiveCookiePartitionFree(30_s);
-    else
-        resetParametersToDefaultValues();
+    m_debugModeEnabled = enable;
+#if !RELEASE_LOG_DISABLED
+    RELEASE_LOG_INFO_IF(m_debugLoggingEnabled, ResourceLoadStatisticsDebug, "ITP Debug Mode %{public}s.", (m_debugModeEnabled ? "enabled" : "disabled"));
+#endif
 }
 
 void WebResourceLoadStatisticsStore::logUserInteraction(const URL& url)
@@ -459,8 +459,12 @@ void WebResourceLoadStatisticsStore::logUserInteraction(const URL& url)
         statistics.hadUserInteraction = true;
         statistics.mostRecentUserInteractionTime = WallTime::now();
 
-        if (statistics.isMarkedForCookiePartitioning || statistics.isMarkedForCookieBlocking)
-            updateCookiePartitioningForDomains({ }, { }, { primaryDomain }, ShouldClearFirst::No, []() { });
+        if (m_debugModeEnabled) {
+            if (statistics.isMarkedForCookieBlocking)
+                updateCookiePartitioningForDomains({ primaryDomain }, { }, { }, ShouldClearFirst::No, []() { });
+        } else
+            if (statistics.isMarkedForCookiePartitioning || statistics.isMarkedForCookieBlocking)
+                updateCookiePartitioningForDomains({ }, { }, { primaryDomain }, ShouldClearFirst::No, []() { });
     });
 }
 
@@ -955,6 +959,9 @@ void WebResourceLoadStatisticsStore::mergeStatistics(Vector<ResourceLoadStatisti
 
 bool WebResourceLoadStatisticsStore::shouldPartitionCookies(const ResourceLoadStatistics& statistic) const
 {
+    if (m_debugModeEnabled)
+        return statistic.isPrevalentResource && statistic.hadUserInteraction;
+
     return statistic.isPrevalentResource && statistic.hadUserInteraction && WallTime::now() > statistic.mostRecentUserInteractionTime + m_parameters.timeToLiveCookiePartitionFree;
 }
 
@@ -1003,7 +1010,6 @@ void WebResourceLoadStatisticsStore::updateCookiePartitioning(CompletionHandler<
                 isFirstDomain = false;
             }
             RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to partition cookies in third-party contexts for %{public}s.", domainsToPartitionBuilder.toString().utf8().data());
-            RELEASE_LOG_INFO(ResourceLoadStatisticsDebug, "About to partition cookies in third-party contexts for %s.", domainsToPartitionBuilder.toString().utf8().data());
         }
 
         if (!domainsToBlock.isEmpty()) {
index f0ae29b..40f42d0 100644 (file)
@@ -224,6 +224,7 @@ private:
 #endif
     bool m_dataRecordsBeingRemoved { false };
 
+    bool m_debugModeEnabled { false };
     bool m_debugLoggingEnabled { false };
 
     Function<void (const String&)> m_statisticsTestingCallback;