Title: [198055] trunk/Source
Revision
198055
Author
[email protected]
Date
2016-03-11 16:36:17 -0800 (Fri, 11 Mar 2016)

Log Message

Move prevalent resource classifier from WebCore to WebKit.
https://bugs.webkit.org/show_bug.cgi?id=155242
<rdar://problem/24913272>

Patch by John Wilander <[email protected]> on 2016-03-11
Reviewed by Andy Estes.

Source/WebCore:

No new tests since we have yet to decide how to set up tests for prevalent resources.

* loader/ResourceLoadObserver.cpp:
(WebCore::ResourceLoadObserver::logFrameNavigation):
(WebCore::ResourceLoadObserver::logSubresourceLoading):
    - Removed calls to old classifier in WebCore.
* loader/ResourceLoadStatistics.cpp:
(WebCore::encodeHashCountedSet):
(WebCore::ResourceLoadStatistics::checkAndSetAsPrevalentResourceIfNecessary): Deleted.
(WebCore::ResourceLoadStatistics::hasPrevalentResourceCharacteristics): Deleted.
* loader/ResourceLoadStatistics.h:
    - Deleted old classification functions.
* loader/ResourceLoadStatisticsStore.cpp:
(WebCore::ResourceLoadStatisticsStore::create):
(WebCore::ResourceLoadStatisticsStore::fireDataModificationHandler):
(WebCore::ResourceLoadStatisticsStore::hasEnoughDataForStatisticsProcessing):
    - New function to allow for checks before calls to processStatistics.
(WebCore::ResourceLoadStatisticsStore::processStatistics):
    - New function that receives a lamda and executes it on every entry in its statistics map.
* loader/ResourceLoadStatisticsStore.h:

Source/WebKit2:

* UIProcess/WebResourceLoadStatisticsStore.cpp:
(WebKit::WebResourceLoadStatisticsStore::create):
(WebKit::WebResourceLoadStatisticsStore::~WebResourceLoadStatisticsStore):
(WebKit::hasPrevalentResourceCharacteristics):
(WebKit::classifyPrevalentResources):
    - Moved these two functions from WebCore.
(WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
    - Calls processStatistics with a lamda function to classify prevalent resources.
* WebKit2.xcodeproj/project.pbxproj:
    - Fixed the ordering of source files.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (198054 => 198055)


--- trunk/Source/WebCore/ChangeLog	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebCore/ChangeLog	2016-03-12 00:36:17 UTC (rev 198055)
@@ -1,3 +1,32 @@
+2016-03-11  John Wilander  <[email protected]>
+
+        Move prevalent resource classifier from WebCore to WebKit.
+        https://bugs.webkit.org/show_bug.cgi?id=155242
+        <rdar://problem/24913272>
+
+        Reviewed by Andy Estes.
+
+        No new tests since we have yet to decide how to set up tests for prevalent resources.
+
+        * loader/ResourceLoadObserver.cpp:
+        (WebCore::ResourceLoadObserver::logFrameNavigation):
+        (WebCore::ResourceLoadObserver::logSubresourceLoading):
+            - Removed calls to old classifier in WebCore.
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::encodeHashCountedSet):
+        (WebCore::ResourceLoadStatistics::checkAndSetAsPrevalentResourceIfNecessary): Deleted.
+        (WebCore::ResourceLoadStatistics::hasPrevalentResourceCharacteristics): Deleted.
+        * loader/ResourceLoadStatistics.h:
+            - Deleted old classification functions.
+        * loader/ResourceLoadStatisticsStore.cpp:
+        (WebCore::ResourceLoadStatisticsStore::create):
+        (WebCore::ResourceLoadStatisticsStore::fireDataModificationHandler):
+        (WebCore::ResourceLoadStatisticsStore::hasEnoughDataForStatisticsProcessing):
+            - New function to allow for checks before calls to processStatistics.
+        (WebCore::ResourceLoadStatisticsStore::processStatistics):
+            - New function that receives a lamda and executes it on every entry in its statistics map.
+        * loader/ResourceLoadStatisticsStore.h:
+
 2016-03-11  Jiewen Tan  <[email protected]>
 
         WebKit should not be redirected to an invalid URL

Modified: trunk/Source/WebCore/loader/ResourceLoadObserver.cpp (198054 => 198055)


--- trunk/Source/WebCore/loader/ResourceLoadObserver.cpp	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebCore/loader/ResourceLoadObserver.cpp	2016-03-12 00:36:17 UTC (rev 198055)
@@ -142,7 +142,6 @@
         }
     }
 
-    targetStatistics.checkAndSetAsPrevalentResourceIfNecessary(m_store->size());
     m_store->fireDataModificationHandler();
 }
     
@@ -205,7 +204,6 @@
         targetStatistics.subresourceHasBeenSubresourceCountDividedByTotalNumberOfOriginsVisited = static_cast<double>(targetStatistics.subresourceHasBeenSubresourceCount) / totalVisited;
     }
     
-    targetStatistics.checkAndSetAsPrevalentResourceIfNecessary(m_store->size());
     m_store->fireDataModificationHandler();
 }
     

Modified: trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp (198054 => 198055)


--- trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebCore/loader/ResourceLoadStatistics.cpp	2016-03-12 00:36:17 UTC (rev 198055)
@@ -32,37 +32,6 @@
 
 namespace WebCore {
 
-static const unsigned minimumOriginsVisitedForPrevalenceClassification = 100;
-
-// Sub frame thresholds
-static const unsigned subframeUnderTopFrameOriginsThresholdAbsolute = 3;
-
-// Subresource thresholds
-static const unsigned subresourceUnderTopFrameOriginsThresholdAbsolute = 5;
-static const unsigned subresourceHasBeenRedirectedFromToUniqueDomainsThresholdAbsolute = 3;
-static const unsigned redirectedToOtherPrevalentResourceOriginsThresholdAbsolute = 2;
-
-bool ResourceLoadStatistics::checkAndSetAsPrevalentResourceIfNecessary(unsigned originsVisitedSoFar)
-{
-    if (originsVisitedSoFar < minimumOriginsVisitedForPrevalenceClassification || isPrevalentResource)
-        return false;
-
-    if (hasPrevalentResourceCharacteristics()) {
-        isPrevalentResource = true;
-        return true;
-    }
-
-    return false;
-}
-
-bool ResourceLoadStatistics::hasPrevalentResourceCharacteristics() const
-{
-    return subframeUnderTopFrameOrigins.size() > subframeUnderTopFrameOriginsThresholdAbsolute
-        || subresourceUnderTopFrameOrigins.size() > subresourceUnderTopFrameOriginsThresholdAbsolute
-        || subresourceUniqueRedirectsTo.size() > subresourceHasBeenRedirectedFromToUniqueDomainsThresholdAbsolute
-        || redirectedToOtherPrevalentResourceOrigins.size() > redirectedToOtherPrevalentResourceOriginsThresholdAbsolute;
-}
-
 typedef WTF::HashMap<String, unsigned, StringHash, HashTraits<String>, HashTraits<unsigned>>::KeyValuePairType ResourceLoadStatisticsValue;
 
 static void encodeHashCountedSet(KeyedEncoder& encoder, const String& label, const HashCountedSet<String>& hashCountedSet)

Modified: trunk/Source/WebCore/loader/ResourceLoadStatistics.h (198054 => 198055)


--- trunk/Source/WebCore/loader/ResourceLoadStatistics.h	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebCore/loader/ResourceLoadStatistics.h	2016-03-12 00:36:17 UTC (rev 198055)
@@ -42,11 +42,6 @@
 
     ResourceLoadStatistics() = default;
 
-    bool checkAndSetAsPrevalentResourceIfNecessary(unsigned originsVisitedSoFar);
-
-    bool hasPrevalentRedirection() const;
-    bool hasPrevalentResourceCharacteristics() const;
-
     void encode(KeyedEncoder&) const;
     bool decode(KeyedDecoder&);
 

Modified: trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp (198054 => 198055)


--- trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.cpp	2016-03-12 00:36:17 UTC (rev 198055)
@@ -41,6 +41,8 @@
 
 namespace WebCore {
 
+static const unsigned minimumOriginsLoadedForProcessing = 100;
+
 Ref<ResourceLoadStatisticsStore> ResourceLoadStatisticsStore::create()
 {
     return adoptRef(*new ResourceLoadStatisticsStore());
@@ -137,4 +139,15 @@
         m_dataAddedHandler();
 }
 
+bool ResourceLoadStatisticsStore::hasEnoughDataForStatisticsProcessing()
+{
+    return m_resourceStatisticsMap.size() >= minimumOriginsLoadedForProcessing;
 }
+
+void ResourceLoadStatisticsStore::processStatistics(std::function<void(ResourceLoadStatistics&)>&& processFunction)
+{
+    ASSERT(hasEnoughDataForStatisticsProcessing());
+    for (auto& resourceStatistic : m_resourceStatisticsMap.values())
+        processFunction(resourceStatistic);
+}
+}

Modified: trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h (198054 => 198055)


--- trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebCore/loader/ResourceLoadStatisticsStore.h	2016-03-12 00:36:17 UTC (rev 198055)
@@ -60,6 +60,8 @@
 
     void fireDataModificationHandler();
 
+    WEBCORE_EXPORT bool hasEnoughDataForStatisticsProcessing();
+    WEBCORE_EXPORT void processStatistics(std::function<void(ResourceLoadStatistics&)>&&);
 private:
     ResourceLoadStatisticsStore() = default;
 

Modified: trunk/Source/WebKit2/ChangeLog (198054 => 198055)


--- trunk/Source/WebKit2/ChangeLog	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-12 00:36:17 UTC (rev 198055)
@@ -1,3 +1,22 @@
+2016-03-11  John Wilander  <[email protected]>
+
+        Move prevalent resource classifier from WebCore to WebKit.
+        https://bugs.webkit.org/show_bug.cgi?id=155242
+        <rdar://problem/24913272>
+
+        Reviewed by Andy Estes.
+
+        * UIProcess/WebResourceLoadStatisticsStore.cpp:
+        (WebKit::WebResourceLoadStatisticsStore::create):
+        (WebKit::WebResourceLoadStatisticsStore::~WebResourceLoadStatisticsStore):
+        (WebKit::hasPrevalentResourceCharacteristics):
+        (WebKit::classifyPrevalentResources):
+            - Moved these two functions from WebCore.
+        (WebKit::WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated):
+            - Calls processStatistics with a lamda function to classify prevalent resources.
+        * WebKit2.xcodeproj/project.pbxproj:
+            - Fixed the ordering of source files.
+
 2016-03-11  Sam Weinig  <[email protected]>
 
         WebKit needs a new sandbox profile addition for DataDetectors

Modified: trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp (198054 => 198055)


--- trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp	2016-03-12 00:36:17 UTC (rev 198055)
@@ -30,13 +30,21 @@
 #include "WebProcessPool.h"
 #include "WebResourceLoadStatisticsStoreMessages.h"
 #include <WebCore/KeyedCoding.h>
-#include <WebCore/ResourceLoadStatisticsStore.h>
+#include <WebCore/ResourceLoadStatistics.h>
 #include <wtf/threads/BinarySemaphore.h>
 
 using namespace WebCore;
 
 namespace WebKit {
 
+// Sub frame classification thresholds
+static const unsigned subframeUnderTopFrameOriginsThreshold = 3;
+    
+// Subresource classification thresholds
+static const unsigned subresourceUnderTopFrameOriginsThreshold = 5;
+static const unsigned subresourceHasBeenRedirectedFromToUniqueDomainsThreshold = 3;
+static const unsigned redirectedToOtherPrevalentResourceOriginsThreshold = 2;
+
 Ref<WebResourceLoadStatisticsStore> WebResourceLoadStatisticsStore::create(const String& resourceLoadStatisticsDirectory)
 {
     return adoptRef(*new WebResourceLoadStatisticsStore(resourceLoadStatisticsDirectory));
@@ -53,11 +61,37 @@
 {
 }
 
+static inline bool hasPrevalentResourceCharacteristics(const ResourceLoadStatistics& resourceStatistic)
+{
+    return resourceStatistic.subframeUnderTopFrameOrigins.size() > subframeUnderTopFrameOriginsThreshold
+        || resourceStatistic.subresourceUnderTopFrameOrigins.size() > subresourceUnderTopFrameOriginsThreshold
+        || resourceStatistic.subresourceUniqueRedirectsTo.size() > subresourceHasBeenRedirectedFromToUniqueDomainsThreshold
+        || resourceStatistic.redirectedToOtherPrevalentResourceOrigins.size() > redirectedToOtherPrevalentResourceOriginsThreshold;
+}
+    
+static inline void classifyPrevalentResources(ResourceLoadStatistics& resourceStatistic, Vector<String>& prevalentResources, Vector<String>& prevalentResourcesWithUserInteraction)
+{
+    if (resourceStatistic.isPrevalentResource || hasPrevalentResourceCharacteristics(resourceStatistic)) {
+        resourceStatistic.isPrevalentResource = true;
+        if (resourceStatistic.hadUserInteraction)
+            prevalentResourcesWithUserInteraction.append(resourceStatistic.highLevelDomain);
+        else
+            prevalentResources.append(resourceStatistic.highLevelDomain);
+    }
+}
+
 void WebResourceLoadStatisticsStore::resourceLoadStatisticsUpdated(const Vector<WebCore::ResourceLoadStatistics>& origins)
 {
     coreStore().mergeStatistics(origins);
-    // TODO: Analyze statistics to recognize prevalent domains. <rdar://problem/24913272>
-    // TODO: Notify individual WebProcesses of prevalent domains. <rdar://problem/24703099>
+
+    Vector<String> prevalentResources, prevalentResourcesWithUserInteraction;
+    if (coreStore().hasEnoughDataForStatisticsProcessing()) {
+        coreStore().processStatistics([this, &prevalentResources, &prevalentResourcesWithUserInteraction] (ResourceLoadStatistics& resourceStatistic) {
+            classifyPrevalentResources(resourceStatistic, prevalentResources, prevalentResourcesWithUserInteraction);
+        });
+    }
+
+    // FIXME: Notify individual WebProcesses of prevalent domains using the two vectors populated by the classifier. <rdar://problem/24703099>
     auto encoder = coreStore().createEncoderFromData();
     
     writeEncoderToDisk(*encoder.get(), "full_browsing_session");

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (198054 => 198055)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-03-11 23:59:04 UTC (rev 198054)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2016-03-12 00:36:17 UTC (rev 198055)
@@ -5824,9 +5824,6 @@
 				86E67A22190F411800004AB7 /* ProcessThrottler.cpp */,
 				86E67A21190F411800004AB7 /* ProcessThrottler.h */,
 				83048AE51ACA45DC0082C832 /* ProcessThrottlerClient.h */,
-				7A9CD8C01C77984900D9F6C7 /* WebResourceLoadStatisticsStore.cpp */,
-				7A9CD8C11C77984900D9F6C7 /* WebResourceLoadStatisticsStore.h */,
-				7A9CD8C21C779AD600D9F6C7 /* WebResourceLoadStatisticsStore.messages.in */,
 				BC111B08112F5E3C00337BAB /* ResponsivenessTimer.cpp */,
 				1A30066C1110F4F70031937C /* ResponsivenessTimer.h */,
 				51A4D5A816CAC4FF000E615E /* StatisticsRequest.cpp */,
@@ -5923,6 +5920,9 @@
 				BC111B0D112F5E4F00337BAB /* WebProcessProxy.cpp */,
 				BC032DCF10F4389F0058C15A /* WebProcessProxy.h */,
 				BCEE7AB312817095009827DA /* WebProcessProxy.messages.in */,
+				7A9CD8C01C77984900D9F6C7 /* WebResourceLoadStatisticsStore.cpp */,
+				7A9CD8C11C77984900D9F6C7 /* WebResourceLoadStatisticsStore.h */,
+				7A9CD8C21C779AD600D9F6C7 /* WebResourceLoadStatisticsStore.messages.in */,
 			);
 			path = UIProcess;
 			sourceTree = "<group>";
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to