Title: [228495] trunk/Source
Revision
228495
Author
wilan...@apple.com
Date
2018-02-14 16:52:29 -0800 (Wed, 14 Feb 2018)

Log Message

Resource Load Statistics: Make sure WebResourceLoadStatisticsStore::mergeWithDataFromDecoder() can ingest older plist versions and not reset the database
https://bugs.webkit.org/show_bug.cgi?id=182812
<rdar://problem/37511406>

Reviewed by Brent Fulgham.

Source/WebCore:

No new tests. Tested manually between versions of Safari.

* loader/ResourceLoadStatistics.cpp:
(WebCore::ResourceLoadStatistics::decode):
    Now only expects these fields for model version 11 or higher:
    - topFrameUniqueRedirectsTo
    - topFrameUniqueRedirectsFrom
    - subresourceUniqueRedirectsFrom
    - timesAccessedAsFirstPartyDueToUserInteraction
    - timesAccessedAsFirstPartyDueToStorageAccessAPI
* loader/ResourceLoadStatistics.h:

Source/WebKit:

* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::mergeWithDataFromDecoder):
    Now does the following:
    - Logs when there is a model version mismatch.
    - Does not ingest statistics if the version on disk is newer than the supported one.
    - Does ingest statistics if the version on disk is older than the supported one.
    - Passes on the version found on disk to WebCore::ResourceLoadStatistics::decode().

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (228494 => 228495)


--- trunk/Source/WebCore/ChangeLog	2018-02-15 00:13:56 UTC (rev 228494)
+++ trunk/Source/WebCore/ChangeLog	2018-02-15 00:52:29 UTC (rev 228495)
@@ -1,3 +1,23 @@
+2018-02-14  John Wilander  <wilan...@apple.com>
+
+        Resource Load Statistics: Make sure WebResourceLoadStatisticsStore::mergeWithDataFromDecoder() can ingest older plist versions and not reset the database
+        https://bugs.webkit.org/show_bug.cgi?id=182812
+        <rdar://problem/37511406>
+
+        Reviewed by Brent Fulgham.
+
+        No new tests. Tested manually between versions of Safari.
+
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::ResourceLoadStatistics::decode):
+            Now only expects these fields for model version 11 or higher:
+            - topFrameUniqueRedirectsTo
+            - topFrameUniqueRedirectsFrom
+            - subresourceUniqueRedirectsFrom
+            - timesAccessedAsFirstPartyDueToUserInteraction
+            - timesAccessedAsFirstPartyDueToStorageAccessAPI
+        * loader/ResourceLoadStatistics.h:
+
 2018-02-14  Basuke Suzuki  <basuke.suz...@sony.com>
 
         [WinCairo] Fix several build warnings under WebCore/platform

Modified: trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp (228494 => 228495)


--- trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp	2018-02-15 00:13:56 UTC (rev 228494)
+++ trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp	2018-02-15 00:52:29 UTC (rev 228495)
@@ -118,7 +118,7 @@
     });
 }
 
-bool ResourceLoadStatistics::decode(KeyedDecoder& decoder)
+bool ResourceLoadStatistics::decode(KeyedDecoder& decoder, unsigned modelVersion)
 {
     if (!decoder.decodeString("PrevalentResourceOrigin", highLevelDomain))
         return false;
@@ -131,8 +131,10 @@
     decodeHashSet(decoder, "storageAccessUnderTopFrameOrigins", storageAccessUnderTopFrameOrigins);
 
     // Top frame stats
-    decodeHashCountedSet(decoder, "topFrameUniqueRedirectsTo", topFrameUniqueRedirectsTo);
-    decodeHashCountedSet(decoder, "topFrameUniqueRedirectsFrom", topFrameUniqueRedirectsFrom);
+    if (modelVersion >= 11) {
+        decodeHashCountedSet(decoder, "topFrameUniqueRedirectsTo", topFrameUniqueRedirectsTo);
+        decodeHashCountedSet(decoder, "topFrameUniqueRedirectsFrom", topFrameUniqueRedirectsFrom);
+    }
 
     // Subframe stats
     decodeHashCountedSet(decoder, "subframeUnderTopFrameOrigins", subframeUnderTopFrameOrigins);
@@ -140,7 +142,8 @@
     // Subresource stats
     decodeHashCountedSet(decoder, "subresourceUnderTopFrameOrigins", subresourceUnderTopFrameOrigins);
     decodeHashCountedSet(decoder, "subresourceUniqueRedirectsTo", subresourceUniqueRedirectsTo);
-    decodeHashCountedSet(decoder, "subresourceUniqueRedirectsFrom", subresourceUniqueRedirectsFrom);
+    if (modelVersion >= 11)
+        decodeHashCountedSet(decoder, "subresourceUniqueRedirectsFrom", subresourceUniqueRedirectsFrom);
 
     // Prevalent Resource
     if (!decoder.decodeBool("isPrevalentResource", isPrevalentResource))
@@ -162,11 +165,12 @@
         return false;
     lastSeen = WallTime::fromRawSeconds(lastSeenTimeAsDouble);
 
-    if (!decoder.decodeUInt32("timesAccessedAsFirstPartyDueToUserInteraction", timesAccessedAsFirstPartyDueToUserInteraction))
-        timesAccessedAsFirstPartyDueToUserInteraction = 0;
-    if (!decoder.decodeUInt32("timesAccessedAsFirstPartyDueToStorageAccessAPI", timesAccessedAsFirstPartyDueToStorageAccessAPI))
-        timesAccessedAsFirstPartyDueToStorageAccessAPI = 0;
-
+    if (modelVersion >= 11) {
+        if (!decoder.decodeUInt32("timesAccessedAsFirstPartyDueToUserInteraction", timesAccessedAsFirstPartyDueToUserInteraction))
+            timesAccessedAsFirstPartyDueToUserInteraction = 0;
+        if (!decoder.decodeUInt32("timesAccessedAsFirstPartyDueToStorageAccessAPI", timesAccessedAsFirstPartyDueToStorageAccessAPI))
+            timesAccessedAsFirstPartyDueToStorageAccessAPI = 0;
+    }
     return true;
 }
 

Modified: trunk/Source/WebCore/loader/ResourceLoadStatistics.h (228494 => 228495)


--- trunk/Source/WebCore/loader/ResourceLoadStatistics.h	2018-02-15 00:13:56 UTC (rev 228494)
+++ trunk/Source/WebCore/loader/ResourceLoadStatistics.h	2018-02-15 00:52:29 UTC (rev 228495)
@@ -54,7 +54,7 @@
     WEBCORE_EXPORT static String primaryDomain(const String& host);
 
     WEBCORE_EXPORT void encode(KeyedEncoder&) const;
-    WEBCORE_EXPORT bool decode(KeyedDecoder&);
+    WEBCORE_EXPORT bool decode(KeyedDecoder&, unsigned modelVersion);
 
     String toString() const;
 

Modified: trunk/Source/WebKit/ChangeLog (228494 => 228495)


--- trunk/Source/WebKit/ChangeLog	2018-02-15 00:13:56 UTC (rev 228494)
+++ trunk/Source/WebKit/ChangeLog	2018-02-15 00:52:29 UTC (rev 228495)
@@ -1,3 +1,19 @@
+2018-02-14  John Wilander  <wilan...@apple.com>
+
+        Resource Load Statistics: Make sure WebResourceLoadStatisticsStore::mergeWithDataFromDecoder() can ingest older plist versions and not reset the database
+        https://bugs.webkit.org/show_bug.cgi?id=182812
+        <rdar://problem/37511406>
+
+        Reviewed by Brent Fulgham.
+
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::mergeWithDataFromDecoder):
+            Now does the following:
+            - Logs when there is a model version mismatch.
+            - Does not ingest statistics if the version on disk is newer than the supported one.
+            - Does ingest statistics if the version on disk is older than the supported one.
+            - Passes on the version found on disk to WebCore::ResourceLoadStatistics::decode().
+
 2018-02-14  Daniel Bates  <daba...@apple.com>
 
         Disallow cross-origin subresources from asking for credentials

Modified: trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp (228494 => 228495)


--- trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-02-15 00:13:56 UTC (rev 228494)
+++ trunk/Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp	2018-02-15 00:52:29 UTC (rev 228495)
@@ -803,9 +803,14 @@
     if (!decoder.decodeUInt32("version", versionOnDisk))
         return;
 
-    if (versionOnDisk != statisticsModelVersion)
+    if (versionOnDisk > statisticsModelVersion) {
+        WTFLogAlways("Found resource load statistics on disk with model version %u whereas the highest supported version is %u. Resetting.", versionOnDisk, statisticsModelVersion);
         return;
+    }
 
+    if (versionOnDisk < statisticsModelVersion)
+        WTFLogAlways("Found resource load statistics on disk with model version %u and the current version is %u. Ingesting old statistics.", versionOnDisk, statisticsModelVersion);
+
     double endOfGrandfatheringTimestamp;
     if (decoder.decodeDouble("endOfGrandfatheringTimestamp", endOfGrandfatheringTimestamp))
         m_endOfGrandfatheringTimestamp = WallTime::fromRawSeconds(endOfGrandfatheringTimestamp);
@@ -813,8 +818,8 @@
         m_endOfGrandfatheringTimestamp = { };
 
     Vector<ResourceLoadStatistics> loadedStatistics;
-    bool succeeded = decoder.decodeObjects("browsingStatistics", loadedStatistics, [](KeyedDecoder& decoderInner, ResourceLoadStatistics& statistics) {
-        return statistics.decode(decoderInner);
+    bool succeeded = decoder.decodeObjects("browsingStatistics", loadedStatistics, [versionOnDisk](KeyedDecoder& decoderInner, ResourceLoadStatistics& statistics) {
+        return statistics.decode(decoderInner, versionOnDisk);
     });
 
     if (!succeeded)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to