Resource Load Statistics: Make sure WebResourceLoadStatisticsStore::mergeWithDataFrom...
authorwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Feb 2018 00:52:29 +0000 (00:52 +0000)
committerwilander@apple.com <wilander@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Feb 2018 00:52:29 +0000 (00:52 +0000)
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().

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

Source/WebCore/ChangeLog
Source/WebCore/loader/ResourceLoadStatistics.cpp
Source/WebCore/loader/ResourceLoadStatistics.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/WebResourceLoadStatisticsStore.cpp

index 7d85e82..5d83dba 100644 (file)
@@ -1,3 +1,23 @@
+2018-02-14  John Wilander  <wilander@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.Suzuki@sony.com>
 
         [WinCairo] Fix several build warnings under WebCore/platform
index 1817d20..f5ad6b8 100644 (file)
@@ -118,7 +118,7 @@ static void decodeHashSet(KeyedDecoder& decoder, const String& label, HashSet<St
     });
 }
 
-bool ResourceLoadStatistics::decode(KeyedDecoder& decoder)
+bool ResourceLoadStatistics::decode(KeyedDecoder& decoder, unsigned modelVersion)
 {
     if (!decoder.decodeString("PrevalentResourceOrigin", highLevelDomain))
         return false;
@@ -131,8 +131,10 @@ bool ResourceLoadStatistics::decode(KeyedDecoder& decoder)
     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 @@ bool ResourceLoadStatistics::decode(KeyedDecoder& decoder)
     // 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 @@ bool ResourceLoadStatistics::decode(KeyedDecoder& decoder)
         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;
 }
 
index ece388b..3d93f47 100644 (file)
@@ -54,7 +54,7 @@ struct ResourceLoadStatistics {
     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;
 
index 233984a..21bfb59 100644 (file)
@@ -1,3 +1,19 @@
+2018-02-14  John Wilander  <wilander@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  <dabates@apple.com>
 
         Disallow cross-origin subresources from asking for credentials
index b1a6b8d..8817934 100644 (file)
@@ -803,8 +803,13 @@ void WebResourceLoadStatisticsStore::mergeWithDataFromDecoder(KeyedDecoder& deco
     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))
@@ -813,8 +818,8 @@ void WebResourceLoadStatisticsStore::mergeWithDataFromDecoder(KeyedDecoder& deco
         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)