Changeset 219274 in webkit


Ignore:
Timestamp:
Jul 7, 2017 5:07:13 PM (7 years ago)
Author:
Brent Fulgham
Message:

[WK2] Use a rolling 30-day uptime for processing statistics
https://bugs.webkit.org/show_bug.cgi?id=174235
<rdar://problem/33164381>

Reviewed by Chris Dumez.

Source/WebCore:

Add a KeyedDecoder specialization for Deque.

  • platform/KeyedCoding.h:

(WebCore::KeyedDecoder::decodeObjects):

Source/WebKit2:

  • UIProcess/API/Cocoa/WKWebsiteDataStore.cpp:

(WebKit::WKWebsiteDataStore::_resourceLoadStatisticsResetToConsistentState): Initialize time-to-live to zero by default.

  • UIProcess/Storage/ResourceLoadStatisticsStore.cpp:

(WebKit::ResourceLoadStatisticsStore::createEncoderFromData): Write out vector
of operating dates.
(WebKit::ResourceLoadStatisticsStore::readDataFromDecoder): Read in vector of
operating dates.
(WebKit::ResourceLoadStatisticsStore::hasHadRecentUserInteraction): Check new
convenience method.
(WebKit::ResourceLoadStatisticsStore::markTodayAsOperatingDate): Added.
(WebKit::ResourceLoadStatisticsStore::hasStatisticsExpired): Added.

  • UIProcess/Storage/ResourceLoadStatisticsStore.h:
  • UIProcess/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded): When reading
a new data file, update the current operating date (if needed).
(WebKit::WebResourceLoadStatisticsStore::handleDailyTasks): Roll uptime dates as
needed, then handle telemetry.

  • UIProcess/WebResourceLoadStatisticsStore.h:

Source/WTF:

Modify Deque to allow it to be used in a template specialization in KeyedDecoder.

  • wtf/Deque.h:
Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r219260 r219274  
     12017-07-07  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [WK2] Use a rolling 30-day uptime for processing statistics
     4        https://bugs.webkit.org/show_bug.cgi?id=174235
     5        <rdar://problem/33164381>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Modify Deque to allow it to be used in a template specialization in KeyedDecoder.
     10
     11        * wtf/Deque.h:
     12
    1132017-07-07  Commit Queue  <commit-queue@webkit.org>
    214
  • trunk/Source/WTF/wtf/Deque.h

    r214636 r219274  
    4747    WTF_MAKE_FAST_ALLOCATED;
    4848public:
     49    typedef T ValueType;
     50
    4951    typedef DequeIterator<T, inlineCapacity> iterator;
    5052    typedef DequeConstIterator<T, inlineCapacity> const_iterator;
  • trunk/Source/WebCore/ChangeLog

    r219272 r219274  
     12017-07-07  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [WK2] Use a rolling 30-day uptime for processing statistics
     4        https://bugs.webkit.org/show_bug.cgi?id=174235
     5        <rdar://problem/33164381>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Add a KeyedDecoder specialization for Deque.
     10
     11        * platform/KeyedCoding.h:
     12        (WebCore::KeyedDecoder::decodeObjects):
     13
    1142017-07-07  Daniel Bates  <dabates@apple.com>
    215
  • trunk/Source/WebCore/platform/KeyedCoding.h

    r210758 r219274  
    11/*
    2  * Copyright (C) 2013 Apple Inc. All rights reserved.
     2 * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727
    2828#include <functional>
     29#include <wtf/Deque.h>
    2930#include <wtf/Forward.h>
    3031#include <wtf/Vector.h>
     
    105106    }
    106107
    107     template<typename T, typename F>
    108     bool decodeObjects(const String& key, Vector<T>& objects, F&& function)
     108    template<typename ContainerType, typename F>
     109    bool decodeObjects(const String& key, ContainerType& objects, F&& function)
    109110    {
    110111        if (!beginArray(key))
     
    113114        bool result = true;
    114115        while (beginArrayElement()) {
    115             T element;
     116            typename ContainerType::ValueType element;
    116117            if (!function(*this, element)) {
    117118                result = false;
  • trunk/Source/WebKit2/ChangeLog

    r219271 r219274  
     12017-07-07  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [WK2] Use a rolling 30-day uptime for processing statistics
     4        https://bugs.webkit.org/show_bug.cgi?id=174235
     5        <rdar://problem/33164381>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * UIProcess/API/Cocoa/WKWebsiteDataStore.cpp:
     10        (WebKit::WKWebsiteDataStore::_resourceLoadStatisticsResetToConsistentState): Initialize time-to-live to zero by default.
     11        * UIProcess/Storage/ResourceLoadStatisticsStore.cpp:
     12        (WebKit::ResourceLoadStatisticsStore::createEncoderFromData): Write out vector
     13        of operating dates.
     14        (WebKit::ResourceLoadStatisticsStore::readDataFromDecoder): Read in vector of
     15        operating dates.
     16        (WebKit::ResourceLoadStatisticsStore::hasHadRecentUserInteraction): Check new
     17        convenience method.
     18        (WebKit::ResourceLoadStatisticsStore::markTodayAsOperatingDate): Added.
     19        (WebKit::ResourceLoadStatisticsStore::hasStatisticsExpired): Added.
     20        * UIProcess/Storage/ResourceLoadStatisticsStore.h:
     21        * UIProcess/WebResourceLoadStatisticsStore.cpp:
     22        (WebKit::WebResourceLoadStatisticsStore::readDataFromDiskIfNeeded): When reading
     23        a new data file, update the current operating date (if needed).
     24        (WebKit::WebResourceLoadStatisticsStore::handleDailyTasks): Roll uptime dates as
     25        needed, then handle telemetry.
     26        * UIProcess/WebResourceLoadStatisticsStore.h:
     27
    1282017-07-07  Wenson Hsieh  <wenson_hsieh@apple.com>
    229
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r219071 r219274  
    11/*
    2  * Copyright (C) 2014, 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    441441        return;
    442442
    443     store->setTimeToLiveUserInteraction(24_h * 30.);
     443    store->setTimeToLiveUserInteraction(0_s);
    444444    store->setTimeToLiveCookiePartitionFree(24_h);
    445445    store->setMinimumTimeBetweenDataRecordsRemoval(1_h);
  • trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp

    r219242 r219274  
    4040using namespace WebCore;
    4141
    42 const unsigned statisticsModelVersion { 5 };
    43 
     42const unsigned statisticsModelVersion { 6 };
     43const unsigned operatingDatesWindow { 30 };
     44   
    4445Ref<ResourceLoadStatisticsStore> ResourceLoadStatisticsStore::create()
    4546{
     
    9091    });
    9192
     93    encoder->encodeObjects("operatingDates", m_operatingDates.begin(), m_operatingDates.end(), [](KeyedEncoder& encoderInner, WallTime date) {
     94        encoderInner.encodeDouble("date", date.secondsSinceEpoch().value());
     95    });
     96   
    9297    return encoder;
    9398}
     
    129134        m_resourceStatisticsMap.set(statistics.highLevelDomain, WTFMove(statistics));
    130135    }
     136
     137    succeeded = decoder.decodeObjects("operatingDates", m_operatingDates, [](KeyedDecoder& decoder, WallTime& wallTime) {
     138        double value;
     139        if (!decoder.decodeDouble("date", value))
     140            return false;
     141       
     142        wallTime = WallTime::fromRawSeconds(value);
     143        return true;
     144    });
     145
     146    if (!succeeded)
     147        return;
    131148   
    132149    fireShouldPartitionCookiesHandler({ }, prevalentResourceDomainsWithoutUserInteraction, true);
     
    137154    ASSERT(!RunLoop::isMain());
    138155    m_resourceStatisticsMap.clear();
    139    
     156    m_operatingDates.clear();
     157
    140158    fireShouldPartitionCookiesHandler({ }, { }, true);
    141159}
     
    294312        return false;
    295313
    296     if (WallTime::now() > resourceStatistic.mostRecentUserInteractionTime + m_timeToLiveUserInteraction) {
     314    if (hasStatisticsExpired(resourceStatistic)) {
    297315        // Drop privacy sensitive data because we no longer need it.
    298316        // Set timestamp to 0 so that statistics merge will know
     
    404422    m_dataRecordsRemovalPending = false;
    405423}
    406    
    407 }
     424
     425void ResourceLoadStatisticsStore::includeTodayAsOperatingDateIfNecessary()
     426{
     427    if (!m_operatingDates.isEmpty() && (WallTime::now() - m_operatingDates.last() < 24_h))
     428        return;
     429
     430    while (m_operatingDates.size() >= operatingDatesWindow)
     431        m_operatingDates.removeFirst();
     432
     433    m_operatingDates.append(WallTime::now());
     434}
     435   
     436bool ResourceLoadStatisticsStore::hasStatisticsExpired(const ResourceLoadStatistics& resourceStatistic) const
     437{
     438    if (m_operatingDates.size() >= operatingDatesWindow) {
     439        if (resourceStatistic.mostRecentUserInteractionTime < m_operatingDates.first())
     440            return true;
     441    }
     442
     443    // If we don't meet the real criteria for an expired statistic, check the user
     444    // setting for a tighter restriction (mainly for testing).
     445    if (m_timeToLiveUserInteraction) {
     446        if (WallTime::now() > resourceStatistic.mostRecentUserInteractionTime + m_timeToLiveUserInteraction)
     447            return true;
     448    }
     449   
     450    return false;
     451}
     452   
     453}
  • trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h

    r219260 r219274  
    2626#pragma once
    2727
     28#include <wtf/Deque.h>
    2829#include <wtf/Function.h>
    2930#include <wtf/HashMap.h>
     
    100101    void dataRecordsWereRemoved();
    101102
     103    void includeTodayAsOperatingDateIfNecessary();
     104
    102105private:
    103106    ResourceLoadStatisticsStore() = default;
    104107
    105108    bool shouldPartitionCookies(const WebCore::ResourceLoadStatistics&) const;
     109    bool hasStatisticsExpired(const WebCore::ResourceLoadStatistics&) const;
    106110
    107111    HashMap<String, WebCore::ResourceLoadStatistics> m_resourceStatisticsMap;
     112    Deque<WTF::WallTime> m_operatingDates;
    108113
    109114    WTF::Function<void()> m_dataAddedHandler;
     
    113118    WTF::Function<void()> m_fireTelemetryHandler;
    114119
    115     Seconds m_timeToLiveUserInteraction { 24_h * 30. };
     120    Seconds m_timeToLiveUserInteraction { 0_s };
    116121    Seconds m_timeToLiveCookiePartitionFree { 24_h };
    117122    Seconds m_grandfatheringTime { 1_h };
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp

    r219220 r219274  
    9595    , m_statisticsQueue(WorkQueue::create("WebResourceLoadStatisticsStore Process Data Queue", WorkQueue::Type::Serial, WorkQueue::QOS::Utility))
    9696    , m_statisticsStoragePath(resourceLoadStatisticsDirectory)
    97     , m_telemetryOneShotTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::telemetryTimerFired)
    98     , m_telemetryRepeatedTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::telemetryTimerFired)
     97    , m_telemetryOneShotTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::submitTelemetryIfNecessary)
     98    , m_telemetryRepeatedTimer(RunLoop::main(), this, &WebResourceLoadStatisticsStore::performDailyTasks)
    9999{
    100100    ASSERT(RunLoop::isMain());
     
    273273    if (coreStore().isEmpty())
    274274        grandfatherExistingWebsiteData();
     275
     276    coreStore().includeTodayAsOperatingDateIfNecessary();
    275277}
    276278   
     
    527529}
    528530
    529 void WebResourceLoadStatisticsStore::telemetryTimerFired()
     531void WebResourceLoadStatisticsStore::performDailyTasks()
     532{
     533    ASSERT(RunLoop::isMain());
     534
     535    coreStore().includeTodayAsOperatingDateIfNecessary();
     536
     537    submitTelemetryIfNecessary();
     538}
     539
     540void WebResourceLoadStatisticsStore::submitTelemetryIfNecessary()
    530541{
    531542    ASSERT(RunLoop::isMain());
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h

    r219220 r219274  
    133133    void syncWithExistingStatisticsStorageIfNeeded();
    134134    void refreshFromDisk();
    135     void telemetryTimerFired();
     135    void submitTelemetryIfNecessary();
    136136    void submitTelemetry();
    137137    bool hasStatisticsFileChangedSinceLastSync(const String& path);
     138    void performDailyTasks();
    138139
    139140#if PLATFORM(COCOA)
Note: See TracChangeset for help on using the changeset viewer.