Changeset 252011 in webkit


Ignore:
Timestamp:
Nov 4, 2019 1:36:24 PM (4 years ago)
Author:
Chris Dumez
Message:

[iOS][WK2] Simplify process assertion handling for the network process and service worker processes
https://bugs.webkit.org/show_bug.cgi?id=203633

Reviewed by Alex Christensen.

Simplify process assertion handling for the network process and service worker processes.
In particular, the following changes were made:

  1. Put the NetworkProcessProxy in charge of keeping the network process runnable instead of relying on the WebProcessPool to do it.
  2. Put the WebProcessProxy in charge of keeping the web process runnable due to service worker activity, instead of relying on the WebProcessPool to do it.
  3. Introduce a new Variant data type which can store a foreground activity, a background activity or no activity. This avoid having 2 separate and mutually-exclusive data members for foreground and background activities.
  4. The new code is a bit more correct because it makes sure the the activity we're holding is valid, instead of simply checking that it has an activity. This means that if the process assertion was previously invalidated, we will now properly take a new activity, which will re-take a process assertion.

This patch also reduces the #ifdefing for IOS_FAMILY, since ProcessThrottler and
ProcessAssertion exist on all platforms.

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::updateProcessAssertion):

  • UIProcess/Network/NetworkProcessProxy.h:
  • UIProcess/ProcessThrottler.cpp:

(WebKit::ProcessThrottler::isValidBackgroundActivity):
(WebKit::ProcessThrottler::isValidForegroundActivity):

  • UIProcess/ProcessThrottler.h:
  • UIProcess/WebProcessPool.cpp:

(WebKit::m_backgroundWebProcessCounter):
(WebKit::WebProcessPool::ensureNetworkProcess):
(WebKit::WebProcessPool::networkProcessCrashed):
(WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):
(WebKit::WebProcessPool::disconnectProcess):
(WebKit::WebProcessPool::terminateNetworkProcess):
(WebKit::WebProcessPool::updateProcessAssertions):

  • UIProcess/WebProcessPool.h:
  • UIProcess/WebProcessProxy.cpp:

(WebKit::WebProcessProxy::didSetAssertionState):
(WebKit::WebProcessProxy::updateServiceWorkerProcessAssertion):
(WebKit::WebProcessProxy::enableServiceWorkers):

  • UIProcess/WebProcessProxy.h:

(WebKit::WebProcessProxy::isStandaloneServiceWorkerProcess const):

Location:
trunk/Source/WebKit
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r251979 r252011  
     12019-11-04  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS][WK2] Simplify process assertion handling for the network process and service worker processes
     4        https://bugs.webkit.org/show_bug.cgi?id=203633
     5
     6        Reviewed by Alex Christensen.
     7
     8        Simplify process assertion handling for the network process and service worker processes.
     9        In particular, the following changes were made:
     10        1. Put the NetworkProcessProxy in charge of keeping the network process runnable instead
     11           of relying on the WebProcessPool to do it.
     12        2. Put the WebProcessProxy in charge of keeping the web process runnable due to service
     13           worker activity, instead of relying on the WebProcessPool to do it.
     14        3. Introduce a new Variant data type which can store a foreground activity, a background
     15           activity or no activity. This avoid having 2 separate and mutually-exclusive data
     16           members for foreground and background activities.
     17        4. The new code is a bit more correct because it makes sure the the activity we're holding
     18           is valid, instead of simply checking that it has an activity. This means that if the
     19           process assertion was previously invalidated, we will now properly take a new activity,
     20           which will re-take a process assertion.
     21
     22        This patch also reduces the #ifdefing for IOS_FAMILY, since ProcessThrottler and
     23        ProcessAssertion exist on all platforms.
     24
     25        * UIProcess/Network/NetworkProcessProxy.cpp:
     26        (WebKit::NetworkProcessProxy::updateProcessAssertion):
     27        * UIProcess/Network/NetworkProcessProxy.h:
     28        * UIProcess/ProcessThrottler.cpp:
     29        (WebKit::ProcessThrottler::isValidBackgroundActivity):
     30        (WebKit::ProcessThrottler::isValidForegroundActivity):
     31        * UIProcess/ProcessThrottler.h:
     32        * UIProcess/WebProcessPool.cpp:
     33        (WebKit::m_backgroundWebProcessCounter):
     34        (WebKit::WebProcessPool::ensureNetworkProcess):
     35        (WebKit::WebProcessPool::networkProcessCrashed):
     36        (WebKit::WebProcessPool::establishWorkerContextConnectionToNetworkProcess):
     37        (WebKit::WebProcessPool::disconnectProcess):
     38        (WebKit::WebProcessPool::terminateNetworkProcess):
     39        (WebKit::WebProcessPool::updateProcessAssertions):
     40        * UIProcess/WebProcessPool.h:
     41        * UIProcess/WebProcessProxy.cpp:
     42        (WebKit::WebProcessProxy::didSetAssertionState):
     43        (WebKit::WebProcessProxy::updateServiceWorkerProcessAssertion):
     44        (WebKit::WebProcessProxy::enableServiceWorkers):
     45        * UIProcess/WebProcessProxy.h:
     46        (WebKit::WebProcessProxy::isStandaloneServiceWorkerProcess const):
     47
    1482019-11-03  Jiewen Tan  <jiewen_tan@apple.com>
    249
  • trunk/Source/WebKit/UIProcess/Cocoa/DownloadClient.mm

    r251778 r252011  
    270270        RELEASE_LOG_IF(webPage->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - UIProcess is taking a background assertion because it is downloading a system preview", this);
    271271        ASSERT(!m_activity);
    272         m_activity = webPage->process().throttler().backgroundActivity("System preview download"_s);
     272        m_activity = webPage->process().throttler().backgroundActivity("System preview download"_s).moveToUniquePtr();
    273273    }
    274274#else
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r251778 r252011  
    12381238        if (!m_networkActivity) {
    12391239            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState is taking a process network assertion because a page load started", this);
    1240             m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s);
     1240            m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s).moveToUniquePtr();
    12411241        }
    12421242    } else if (m_networkActivity) {
     
    13481348    // Transfer our background assertion from the old process to the new one.
    13491349    if (m_networkActivity)
    1350         m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s);
     1350        m_networkActivity = m_webView->_page->process().throttler().backgroundActivity("Page Load"_s).moveToUniquePtr();
    13511351#endif
    13521352}
  • trunk/Source/WebKit/UIProcess/Cocoa/UIRemoteObjectRegistry.cpp

    r251778 r252011  
    3434std::unique_ptr<ProcessThrottler::BackgroundActivity> UIRemoteObjectRegistry::backgroundActivity(ASCIILiteral name)
    3535{
    36     return m_page.process().throttler().backgroundActivity(name);
     36    return m_page.process().throttler().backgroundActivity(name).moveToUniquePtr();
    3737}
    3838
  • trunk/Source/WebKit/UIProcess/GenericCallback.h

    r251778 r252011  
    7070    typedef const TypeTag* Type;
    7171
    72     explicit CallbackBase(Type type, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
     72    explicit CallbackBase(Type type, ProcessThrottler::ActivityVariant&& activity)
    7373        : m_type(type)
    7474        , m_callbackID(CallbackID::generateID())
     
    8080    Type m_type;
    8181    CallbackID m_callbackID;
    82     std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activity;
     82    ProcessThrottler::ActivityVariant m_activity;
    8383};
    8484
     
    8888    typedef Function<void (T..., Error)> CallbackFunction;
    8989
    90     static Ref<GenericCallback> create(CallbackFunction&& callback, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity = nullptr)
     90    static Ref<GenericCallback> create(CallbackFunction&& callback, ProcessThrottler::ActivityVariant&& activity = nullptr)
    9191    {
    9292        return adoptRef(*new GenericCallback(WTFMove(callback), WTFMove(activity)));
     
    127127
    128128private:
    129     GenericCallback(CallbackFunction&& callback, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
     129    GenericCallback(CallbackFunction&& callback, ProcessThrottler::ActivityVariant&& activity)
    130130        : CallbackBase(type(), WTFMove(activity))
    131131        , m_callback(WTFMove(callback))
     
    190190
    191191    template<typename... T>
    192     CallbackID put(Function<void(T...)>&& function, std::unique_ptr<ProcessThrottler::BackgroundActivity>&& activity)
     192    CallbackID put(Function<void(T...)>&& function, ProcessThrottler::ActivityVariant&& activity)
    193193    {
    194194        auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function), WTFMove(activity));
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r251778 r252011  
    10991099    if (!m_activityForHoldingLockedFiles) {
    11001100        RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because the Network process is holding locked files");
    1101         m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s);
     1101        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s).moveToUniquePtr();
    11021102    }
    11031103}
     
    11121112   
    11131113    RELEASE_LOG(ProcessSuspension, "%p - NetworkProcessProxy is taking a background assertion because the Network process is syncing cookies", this);
    1114     m_syncAllCookiesActivity = throttler().backgroundActivity("Syncing cookies"_s);
     1114    m_syncAllCookiesActivity = throttler().backgroundActivity("Syncing cookies"_s).moveToUniquePtr();
    11151115}
    11161116   
     
    12041204}
    12051205#endif
    1206 
    1207 void NetworkProcessProxy::sendProcessDidTransitionToForeground()
    1208 {
    1209     send(Messages::NetworkProcess::ProcessDidTransitionToForeground(), 0);
    1210 }
    1211 
    1212 void NetworkProcessProxy::sendProcessDidTransitionToBackground()
    1213 {
    1214     send(Messages::NetworkProcess::ProcessDidTransitionToBackground(), 0);
    1215 }
    12161206
    12171207#if ENABLE(SANDBOX_EXTENSIONS)
     
    13391329}
    13401330
     1331void NetworkProcessProxy::updateProcessAssertion()
     1332{
     1333    if (processPool().hasForegroundWebProcesses()) {
     1334        if (!ProcessThrottler::isValidForegroundActivity(m_activityFromWebProcesses)) {
     1335            m_activityFromWebProcesses = throttler().foregroundActivity("Networking for foreground view(s)"_s);
     1336            send(Messages::NetworkProcess::ProcessDidTransitionToForeground(), 0);
     1337        }
     1338        return;
     1339    }
     1340    if (processPool().hasBackgroundWebProcesses()) {
     1341        if (!ProcessThrottler::isValidBackgroundActivity(m_activityFromWebProcesses)) {
     1342            m_activityFromWebProcesses = throttler().backgroundActivity("Networking for foreground background view(s)"_s);
     1343            send(Messages::NetworkProcess::ProcessDidTransitionToBackground(), 0);
     1344        }
     1345        return;
     1346    }
     1347    m_activityFromWebProcesses = nullptr;
     1348}
     1349
    13411350} // namespace WebKit
    13421351
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.h

    r251778 r252011  
    161161#endif
    162162   
    163     void sendProcessDidTransitionToForeground();
    164     void sendProcessDidTransitionToBackground();
    165163    void synthesizeAppIsBackground(bool background);
    166164
     
    173171
    174172    ProcessThrottler& throttler() { return m_throttler; }
     173    void updateProcessAssertion();
     174
    175175    WebProcessPool& processPool() { return m_processPool; }
    176176
     
    280280    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activityForHoldingLockedFiles;
    281281    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_syncAllCookiesActivity;
     282    ProcessThrottler::ActivityVariant m_activityFromWebProcesses;
    282283   
    283284    unsigned m_syncAllCookiesCounter { 0 };
  • trunk/Source/WebKit/UIProcess/ProcessThrottler.cpp

    r251778 r252011  
    206206}
    207207
     208bool ProcessThrottler::isValidBackgroundActivity(const ProcessThrottler::ActivityVariant& activity)
     209{
     210    if (!WTF::holds_alternative<UniqueRef<ProcessThrottler::BackgroundActivity>>(activity))
     211        return false;
     212    return WTF::get<UniqueRef<ProcessThrottler::BackgroundActivity>>(activity)->isValid();
     213}
     214
     215bool ProcessThrottler::isValidForegroundActivity(const ProcessThrottler::ActivityVariant& activity)
     216{
     217    if (!WTF::holds_alternative<UniqueRef<ProcessThrottler::ForegroundActivity>>(activity))
     218        return false;
     219    return WTF::get<UniqueRef<ProcessThrottler::ForegroundActivity>>(activity)->isValid();
     220}
     221
    208222} // namespace WebKit
  • trunk/Source/WebKit/UIProcess/ProcessThrottler.h

    r251795 r252011  
    3232#include <wtf/RefCounter.h>
    3333#include <wtf/RunLoop.h>
     34#include <wtf/UniqueRef.h>
     35#include <wtf/Variant.h>
    3436#include <wtf/WeakPtr.h>
    3537
     
    8789
    8890    using ForegroundActivity = Activity<ActivityType::Foreground>;
    89     std::unique_ptr<ForegroundActivity> foregroundActivity(ASCIILiteral name);
     91    UniqueRef<ForegroundActivity> foregroundActivity(ASCIILiteral name);
    9092
    9193    using BackgroundActivity = Activity<ActivityType::Background>;
    92     std::unique_ptr<BackgroundActivity> backgroundActivity(ASCIILiteral name);
     94    UniqueRef<BackgroundActivity> backgroundActivity(ASCIILiteral name);
     95
     96    using ActivityVariant = Variant<std::nullptr_t, UniqueRef<BackgroundActivity>, UniqueRef<ForegroundActivity>>;
     97    static bool isValidBackgroundActivity(const ActivityVariant&);
     98    static bool isValidForegroundActivity(const ActivityVariant&);
    9399   
    94100    void didConnectToProcess(ProcessID);
     
    125131};
    126132
    127 inline auto ProcessThrottler::foregroundActivity(ASCIILiteral name) -> std::unique_ptr<ForegroundActivity>
     133inline auto ProcessThrottler::foregroundActivity(ASCIILiteral name) -> UniqueRef<ForegroundActivity>
    128134{
    129     return makeUnique<ForegroundActivity>(*this, name);
     135    return makeUniqueRef<ForegroundActivity>(*this, name);
    130136}
    131137
    132 inline auto ProcessThrottler::backgroundActivity(ASCIILiteral name) -> std::unique_ptr<BackgroundActivity>
     138inline auto ProcessThrottler::backgroundActivity(ASCIILiteral name) -> UniqueRef<BackgroundActivity>
    133139{
    134     return makeUnique<BackgroundActivity>(*this, name);
     140    return makeUniqueRef<BackgroundActivity>(*this, name);
    135141}
    136142
  • trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h

    r251778 r252011  
    144144#endif
    145145#if PLATFORM(IOS_FAMILY)
    146     std::unique_ptr<ProcessThrottler::ForegroundActivity> m_provisionalLoadActivity;
     146    UniqueRef<ProcessThrottler::ForegroundActivity> m_provisionalLoadActivity;
    147147#endif
    148148};
  • trunk/Source/WebKit/UIProcess/SuspendedPageProxy.cpp

    r251778 r252011  
    103103    , m_suspensionTimeoutTimer(RunLoop::main(), this, &SuspendedPageProxy::suspensionTimedOut)
    104104#if PLATFORM(IOS_FAMILY)
    105     , m_suspensionActivity(m_process->throttler().backgroundActivity("Page suspension for back/forward cache"_s))
     105    , m_suspensionActivity(m_process->throttler().backgroundActivity("Page suspension for back/forward cache"_s).moveToUniquePtr())
    106106#endif
    107107{
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r251976 r252011  
    19361936        if (!m_isVisibleActivity || !m_isVisibleActivity->isValid()) {
    19371937            RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because the view is visible");
    1938             m_isVisibleActivity = m_process->throttler().foregroundActivity("View is visible"_s);
     1938            m_isVisibleActivity = m_process->throttler().foregroundActivity("View is visible"_s).moveToUniquePtr();
    19391939        }
    19401940    } else if (m_isVisibleActivity) {
     
    19471947        if (!m_isAudibleActivity || !m_isAudibleActivity->isValid()) {
    19481948            RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because we are playing audio");
    1949             m_isAudibleActivity = m_process->throttler().foregroundActivity("View is playing audio"_s);
     1949            m_isAudibleActivity = m_process->throttler().foregroundActivity("View is playing audio"_s).moveToUniquePtr();
    19501950        }
    19511951    } else if (m_isAudibleActivity) {
     
    19581958        if (!m_isCapturingActivity || !m_isCapturingActivity->isValid()) {
    19591959            RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because media capture is active");
    1960             m_isCapturingActivity = m_process->throttler().foregroundActivity("View is capturing media"_s);
     1960            m_isCapturingActivity = m_process->throttler().foregroundActivity("View is capturing media"_s).moveToUniquePtr();
    19611961        }
    19621962    } else if (m_isCapturingActivity) {
     
    19681968        if (!m_alwaysRunsAtForegroundPriorityActivity || !m_alwaysRunsAtForegroundPriorityActivity->isValid()) {
    19691969            RELEASE_LOG_IF_ALLOWED(ProcessSuspension, "updateThrottleState: UIProcess is taking a foreground assertion because m_alwaysRunsAtForegroundPriority is true");
    1970             m_alwaysRunsAtForegroundPriorityActivity = m_process->throttler().foregroundActivity("View always runs at foreground priority"_s);
     1970            m_alwaysRunsAtForegroundPriorityActivity = m_process->throttler().foregroundActivity("View always runs at foreground priority"_s).moveToUniquePtr();
    19711971        }
    19721972    } else if (m_alwaysRunsAtForegroundPriorityActivity) {
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r251814 r252011  
    235235    , m_hiddenPageThrottlingTimer(RunLoop::main(), this, &WebProcessPool::updateHiddenPageThrottlingAutoIncreaseLimit)
    236236    , m_serviceWorkerProcessesTerminationTimer(RunLoop::main(), this, &WebProcessPool::terminateServiceWorkerProcesses)
    237 #if PLATFORM(IOS_FAMILY)
    238237    , m_foregroundWebProcessCounter([this](RefCounterEvent) { updateProcessAssertions(); })
    239238    , m_backgroundWebProcessCounter([this](RefCounterEvent) { updateProcessAssertions(); })
    240 #endif
    241239    , m_backForwardCache(makeUniqueRef<WebBackForwardCache>(*this))
    242240    , m_webProcessCache(makeUniqueRef<WebProcessCache>(*this))
     
    633631#endif
    634632
    635     if (m_didNetworkProcessCrash) {
    636         m_didNetworkProcessCrash = false;
    637         reinstateNetworkProcessAssertionState(*networkProcess);
    638     }
     633    networkProcess->updateProcessAssertion();
    639634
    640635    if (withWebsiteDataStore) {
     
    657652    ASSERT(m_networkProcess);
    658653    ASSERT(&networkProcessProxy == m_networkProcess.get());
    659     m_didNetworkProcessCrash = true;
    660654
    661655    for (auto& supplement : m_supplements.values())
     
    737731        RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), ServiceWorker, "WebProcessPool::establishWorkerContextConnectionToNetworkProcess creating a new service worker process %p, process identifier %d", serviceWorkerProcessProxy, serviceWorkerProcessProxy->processIdentifier());
    738732
    739         updateProcessAssertions();
    740733        initializeNewWebProcess(newProcessProxy, websiteDataStore);
    741734        m_processes.append(WTFMove(newProcessProxy));
     
    11311124        if (iterator != m_serviceWorkerProcesses.end() && iterator->value == process)
    11321125            m_serviceWorkerProcesses.remove(iterator);
    1133         updateProcessAssertions();
    11341126    }
    11351127#endif
     
    17101702    m_networkProcess->terminate();
    17111703    m_networkProcess = nullptr;
    1712     m_didNetworkProcessCrash = true;
    17131704}
    17141705
     
    20462037void WebProcessPool::updateProcessAssertions()
    20472038{
    2048 #if PLATFORM(IOS_FAMILY)
    20492039#if ENABLE(SERVICE_WORKER)
    2050     auto updateServiceWorkerProcessAssertion = [&] {
    2051         if (!m_serviceWorkerProcesses.isEmpty() && m_foregroundWebProcessCounter.value()) {
    2052             // FIXME: We can do better than this once we have process per origin.
    2053             for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) {
    2054                 auto registrableDomain = serviceWorkerProcess->registrableDomain();
    2055                 if (!m_foregroundActivitiesForServiceWorkerProcesses.contains(registrableDomain))
    2056                     m_foregroundActivitiesForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().foregroundActivity("Service Worker for visible view(s)"_s));
    2057             }
    2058             m_backgroundActivitiesForServiceWorkerProcesses.clear();
    2059             return;
    2060         }
    2061         if (!m_serviceWorkerProcesses.isEmpty() && m_backgroundWebProcessCounter.value()) {
    2062             // FIXME: We can do better than this once we have process per origin.
    2063             for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values()) {
    2064                 auto registrableDomain = serviceWorkerProcess->registrableDomain();
    2065                 if (!m_backgroundActivitiesForServiceWorkerProcesses.contains(registrableDomain))
    2066                     m_backgroundActivitiesForServiceWorkerProcesses.add(WTFMove(registrableDomain), serviceWorkerProcess->throttler().backgroundActivity("Service Worker for background view(s)"_s));
    2067             }
    2068             m_foregroundActivitiesForServiceWorkerProcesses.clear();
    2069             return;
    2070         }
    2071         m_foregroundActivitiesForServiceWorkerProcesses.clear();
    2072         m_backgroundActivitiesForServiceWorkerProcesses.clear();
    2073     };
    2074     updateServiceWorkerProcessAssertion();
    2075 #endif
    2076 
    2077     auto updateNetworkProcessAssertion = [&] {
    2078         auto& networkProcess = ensureNetworkProcess();
    2079 
    2080         if (m_foregroundWebProcessCounter.value()) {
    2081             if (!m_foregroundActivityForNetworkProcess) {
    2082                 m_foregroundActivityForNetworkProcess = networkProcess.throttler().foregroundActivity("Networking for foreground view(s)"_s);
    2083                 networkProcess.sendProcessDidTransitionToForeground();
    2084             }
    2085             m_backgroundActivityForNetworkProcess = nullptr;
    2086             return;
    2087         }
    2088         if (m_backgroundWebProcessCounter.value()) {
    2089             if (!m_backgroundActivityForNetworkProcess) {
    2090                 m_backgroundActivityForNetworkProcess = networkProcess.throttler().backgroundActivity("Networking for foreground background view(s)"_s);
    2091                 networkProcess.sendProcessDidTransitionToBackground();
    2092             }
    2093             m_foregroundActivityForNetworkProcess = nullptr;
    2094             return;
    2095         }
    2096         m_foregroundActivityForNetworkProcess = nullptr;
    2097         m_backgroundActivityForNetworkProcess = nullptr;
    2098     };
    2099     updateNetworkProcessAssertion();
    2100 #endif
    2101 }
    2102 
    2103 void WebProcessPool::reinstateNetworkProcessAssertionState(NetworkProcessProxy& newNetworkProcessProxy)
    2104 {
    2105 #if PLATFORM(IOS_FAMILY)
    2106     // The network process crashed; take new activities for the new network process.
    2107     if (m_backgroundActivityForNetworkProcess)
    2108         m_backgroundActivityForNetworkProcess = newNetworkProcessProxy.throttler().backgroundActivity("Networking for background view(s)"_s);
    2109     else if (m_foregroundActivityForNetworkProcess)
    2110         m_foregroundActivityForNetworkProcess = newNetworkProcessProxy.throttler().foregroundActivity("Networking for foreground view(s)"_s);
    2111 #else
    2112     UNUSED_PARAM(newNetworkProcessProxy);
    2113 #endif
     2040    for (auto* serviceWorkerProcess : m_serviceWorkerProcesses.values())
     2041        serviceWorkerProcess->updateServiceWorkerProcessAssertion();
     2042#endif
     2043    ensureNetworkProcess().updateProcessAssertion();
    21142044}
    21152045
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r251814 r252011  
    473473    static void unregisterProcessPoolCreationListener(uint64_t identifier);
    474474
    475 #if PLATFORM(IOS_FAMILY)
    476475    ForegroundWebProcessToken foregroundWebProcessToken() const { return ForegroundWebProcessToken(m_foregroundWebProcessCounter.count()); }
    477476    BackgroundWebProcessToken backgroundWebProcessToken() const { return BackgroundWebProcessToken(m_backgroundWebProcessCounter.count()); }
    478 #endif
     477    bool hasForegroundWebProcesses() const { return m_foregroundWebProcessCounter.value(); }
     478    bool hasBackgroundWebProcesses() const { return m_backgroundWebProcessCounter.value(); }
    479479
    480480    void processForNavigation(WebPageProxy&, const API::Navigation&, Ref<WebProcessProxy>&& sourceProcess, const URL& sourceURL, ProcessSwapRequestedByClient, Ref<WebsiteDataStore>&&, CompletionHandler<void(Ref<WebProcessProxy>&&, SuspendedPageProxy*, const String&)>&&);
     
    555555#endif
    556556
    557     void reinstateNetworkProcessAssertionState(NetworkProcessProxy&);
    558557    void updateProcessAssertions();
    559558
     
    697696    bool m_processTerminationEnabled { true };
    698697
    699     bool m_didNetworkProcessCrash { false };
    700698    std::unique_ptr<NetworkProcessProxy> m_networkProcess;
    701699
     
    760758    RunLoop::Timer<WebProcessPool> m_serviceWorkerProcessesTerminationTimer;
    761759
    762 #if PLATFORM(IOS_FAMILY)
    763760    ForegroundWebProcessCounter m_foregroundWebProcessCounter;
    764761    BackgroundWebProcessCounter m_backgroundWebProcessCounter;
    765     std::unique_ptr<ProcessThrottler::ForegroundActivity> m_foregroundActivityForNetworkProcess;
    766     std::unique_ptr<ProcessThrottler::BackgroundActivity> m_backgroundActivityForNetworkProcess;
    767 #if ENABLE(SERVICE_WORKER)
    768     HashMap<WebCore::RegistrableDomain, std::unique_ptr<ProcessThrottler::ForegroundActivity>> m_foregroundActivitiesForServiceWorkerProcesses;
    769     HashMap<WebCore::RegistrableDomain, std::unique_ptr<ProcessThrottler::BackgroundActivity>> m_backgroundActivitiesForServiceWorkerProcesses;
    770 #endif
    771 #endif
    772762
    773763    UniqueRef<WebBackForwardCache> m_backForwardCache;
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp

    r251831 r252011  
    12331233void WebProcessProxy::didSetAssertionState(AssertionState state)
    12341234{
    1235 #if PLATFORM(IOS_FAMILY)
    12361235    RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState(%u)", this, state);
    12371236
    1238     if (isRunningServiceWorkers() && !pageCount()) {
     1237    if (isStandaloneServiceWorkerProcess()) {
    12391238        RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::didSetAssertionState() release all assertions for network process because this is a service worker process without page", this);
    12401239        m_foregroundToken = nullptr;
     
    12501249        m_foregroundToken = nullptr;
    12511250        m_backgroundToken = nullptr;
     1251#if PLATFORM(IOS_FAMILY)
    12521252        for (auto& page : m_pageMap.values())
    12531253            page->processWillBecomeSuspended();
     1254#endif
    12541255        break;
    12551256
     
    12641265        m_foregroundToken = processPool().foregroundWebProcessToken();
    12651266        m_backgroundToken = nullptr;
     1267#if PLATFORM(IOS_FAMILY)
    12661268        for (auto& page : m_pageMap.values())
    12671269            page->processWillBecomeForeground();
     1270#endif
    12681271        break;
    12691272   
     
    12731276
    12741277    ASSERT(!m_backgroundToken || !m_foregroundToken);
    1275 #else
    1276     UNUSED_PARAM(state);
    1277 #endif
    12781278}
    12791279
     
    13001300    if (!m_activityForHoldingLockedFiles) {
    13011301        RELEASE_LOG(ProcessSuspension, "UIProcess is taking a background assertion because the WebContent process is holding locked files");
    1302         m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s);
     1302        m_activityForHoldingLockedFiles = m_throttler.backgroundActivity("Holding locked files"_s).moveToUniquePtr();
    13031303    }
    13041304}
     
    15581558    send(Messages::WebSWContextManagerConnection::UpdatePreferencesStore { store }, 0);
    15591559}
    1560 #endif
     1560
     1561void WebProcessProxy::updateServiceWorkerProcessAssertion()
     1562{
     1563    RELEASE_LOG(ProcessSuspension, "%p - WebProcessProxy::updateServiceWorkerProcessAssertion() PID: %d", this, processIdentifier());
     1564    ASSERT(m_serviceWorkerInformation);
     1565    if (!m_serviceWorkerInformation)
     1566        return;
     1567
     1568    // FIXME: We could do better if we knew which WebContent processes needed this service worker process.
     1569    if (processPool().hasForegroundWebProcesses()) {
     1570        if (!ProcessThrottler::isValidForegroundActivity(m_serviceWorkerInformation->activity))
     1571            m_serviceWorkerInformation->activity = m_throttler.foregroundActivity("Service Worker for foreground view(s)"_s);
     1572        return;
     1573    }
     1574    if (processPool().hasBackgroundWebProcesses()) {
     1575        if (!ProcessThrottler::isValidBackgroundActivity(m_serviceWorkerInformation->activity))
     1576            m_serviceWorkerInformation->activity = m_throttler.backgroundActivity("Service Worker for background view(s)"_s);
     1577        return;
     1578    }
     1579    m_serviceWorkerInformation->activity = nullptr;
     1580}
     1581#endif // ENABLE(SERVICE_WORKER)
    15611582
    15621583void WebProcessProxy::disableServiceWorkers()
     
    16061627#endif
    16071628        },
     1629        nullptr,
    16081630    };
     1631    updateServiceWorkerProcessAssertion();
    16091632}
    16101633
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.h

    r251814 r252011  
    9292struct WebsiteData;
    9393
    94 #if PLATFORM(IOS_FAMILY)
    9594enum ForegroundWebProcessCounterType { };
    9695typedef RefCounter<ForegroundWebProcessCounterType> ForegroundWebProcessCounter;
     
    9998typedef RefCounter<BackgroundWebProcessCounterType> BackgroundWebProcessCounter;
    10099typedef BackgroundWebProcessCounter::Token BackgroundWebProcessToken;
    101 #endif
    102100
    103101class WebProcessProxy : public AuxiliaryProcessProxy, public ResponsivenessTimer::Client, public ThreadSafeRefCounted<WebProcessProxy>, public CanMakeWeakPtr<WebProcessProxy>, private ProcessThrottlerClient {
     
    164162
    165163    bool isRunningServiceWorkers() const { return !!m_serviceWorkerInformation; }
     164    bool isStandaloneServiceWorkerProcess() const { return isRunningServiceWorkers() && !pageCount(); }
    166165
    167166    void didCreateWebPageInProcess(WebCore::PageIdentifier);
     
    340339    void updateServiceWorkerPreferencesStore(const WebPreferencesStore&);
    341340    bool hasServiceWorkerPageProxy(WebPageProxyIdentifier pageProxyID) { return m_serviceWorkerInformation && m_serviceWorkerInformation->serviceWorkerPageProxyID == pageProxyID; }
     341    void updateServiceWorkerProcessAssertion();
    342342#endif
    343343
     
    484484    ProcessThrottler m_throttler;
    485485    std::unique_ptr<ProcessThrottler::BackgroundActivity> m_activityForHoldingLockedFiles;
    486 #if PLATFORM(IOS_FAMILY)
    487486    ForegroundWebProcessToken m_foregroundToken;
    488487    BackgroundWebProcessToken m_backgroundToken;
     488#if PLATFORM(IOS_FAMILY)
    489489    bool m_hasSentMessageToUnblockAccessibilityServer { false };
    490490    std::unique_ptr<WebCore::DeferrableOneShotTimer> m_unexpectedActivityTimer;
     
    527527        WebCore::PageIdentifier serviceWorkerPageID;
    528528        ServiceWorkerInitializationData initializationData;
     529        ProcessThrottler::ActivityVariant activity;
    529530    };
    530531    Optional<ServiceWorkerInformation> m_serviceWorkerInformation;
Note: See TracChangeset for help on using the changeset viewer.