Changeset 231676 in webkit


Ignore:
Timestamp:
May 10, 2018 4:35:32 PM (6 years ago)
Author:
Chris Dumez
Message:

[iOS] Release page load process assertion if the screen is locked
https://bugs.webkit.org/show_bug.cgi?id=185333

Reviewed by Geoff Garen.

We normally take a background process assertion during page loads to allow them to complete
even if the tab / app is backgrounded. We should however avoid doing so when the backgrounding
is caused by the screen locking. Keeping the process assertion in this case would prevent the
whole device from sleeping longer than it should, thus negatively impacting power.

  • UIProcess/Cocoa/NavigationState.h:
  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::NavigationState::NavigationState):
(WebKit::NavigationState::releaseNetworkActivityToken):
(WebKit::NavigationState::didChangeIsLoading):

  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::applicationDidEnterBackground):

Location:
trunk/Source/WebKit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r231664 r231676  
     12018-05-10  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Release page load process assertion if the screen is locked
     4        https://bugs.webkit.org/show_bug.cgi?id=185333
     5
     6        Reviewed by Geoff Garen.
     7
     8        We normally take a background process assertion during page loads to allow them to complete
     9        even if the tab / app is backgrounded. We should however avoid doing so when the backgrounding
     10        is caused by the screen locking. Keeping the process assertion in this case would prevent the
     11        whole device from sleeping longer than it should, thus negatively impacting power.
     12
     13        * UIProcess/Cocoa/NavigationState.h:
     14        * UIProcess/Cocoa/NavigationState.mm:
     15        (WebKit::NavigationState::NavigationState):
     16        (WebKit::NavigationState::releaseNetworkActivityToken):
     17        (WebKit::NavigationState::didChangeIsLoading):
     18        * UIProcess/ios/WebPageProxyIOS.mm:
     19        (WebKit::WebPageProxy::applicationDidEnterBackground):
     20
    1212018-05-10  Megan Gardner  <megan_gardner@apple.com>
    222
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h

    r231498 r231676  
    8383    void didFirstPaint();
    8484
     85#if PLATFORM(IOS)
     86    enum class NetworkActivityTokenReleaseReason { LoadCompleted, ScreenLocked };
     87    void releaseNetworkActivityToken(NetworkActivityTokenReleaseReason);
     88#endif
     89
    8590private:
    8691    class NavigationClient final : public API::NavigationClient {
     
    173178
    174179#if PLATFORM(IOS)
    175     void releaseNetworkActivityToken();
     180    void releaseNetworkActivityTokenAfterLoadCompletion() { releaseNetworkActivityToken(NetworkActivityTokenReleaseReason::LoadCompleted); }
    176181#endif
    177182
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r231663 r231676  
    9898    , m_historyDelegateMethods()
    9999#if PLATFORM(IOS)
    100     , m_releaseActivityTimer(RunLoop::current(), this, &NavigationState::releaseNetworkActivityToken)
     100    , m_releaseActivityTimer(RunLoop::current(), this, &NavigationState::releaseNetworkActivityTokenAfterLoadCompletion)
    101101#endif
    102102{
     
    11461146
    11471147#if PLATFORM(IOS)
    1148 void NavigationState::releaseNetworkActivityToken()
    1149 {
    1150     RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p UIProcess is releasing a background assertion because a page load completed", this);
    1151     ASSERT(m_activityToken);
     1148void NavigationState::releaseNetworkActivityToken(NetworkActivityTokenReleaseReason reason)
     1149{
     1150    if (!m_activityToken)
     1151        return;
     1152
     1153    switch (reason) {
     1154    case NetworkActivityTokenReleaseReason::LoadCompleted:
     1155        RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p NavigationState is releasing background process assertion because a page load completed", this);
     1156        break;
     1157    case NetworkActivityTokenReleaseReason::ScreenLocked:
     1158        RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p NavigationState is releasing background process assertion because the screen was locked", this);
     1159        break;
     1160    }
    11521161    m_activityToken = nullptr;
     1162    m_releaseActivityTimer.stop();
    11531163}
    11541164#endif
     
    11581168#if PLATFORM(IOS)
    11591169    if (m_webView->_page->pageLoadState().isLoading()) {
     1170        // We do not take a network activity token if a load starts after the screen has been locked.
     1171        if ([UIApp isSuspendedUnderLock])
     1172            return;
     1173
    11601174        if (m_releaseActivityTimer.isActive()) {
    1161             RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - A new page load started while the UIProcess was still holding a page load background assertion", this);
     1175            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState keeps its process network assertion because a new page load started", this);
    11621176            m_releaseActivityTimer.stop();
    1163         } else {
    1164             RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - UIProcess is taking a background assertion because a page load started", this);
    1165             ASSERT(!m_activityToken);
     1177        }
     1178        if (!m_activityToken) {
     1179            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState is taking a process network assertion because a page load started", this);
    11661180            m_activityToken = m_webView->_page->process().throttler().backgroundActivityToken();
    11671181        }
    11681182    } else if (m_activityToken) {
    11691183        if (m_webView._isBackground)
    1170             releaseNetworkActivityToken();
     1184            releaseNetworkActivityTokenAfterLoadCompletion();
    11711185        else {
    11721186            // The application is visible so we delay releasing the background activity for 3 seconds to give it a chance to start another navigation
    11731187            // before suspending the WebContent process <rdar://problem/27910964>.
    1174             RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - Page load completed and UIProcess will be releasing background assertion soon unless a new load starts", this);
     1188            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState will release its process network assertion soon because the page load completed", this);
    11751189            m_releaseActivityTimer.startOneShot(3_s);
    11761190        }
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r231498 r231676  
    3535#import "Logging.h"
    3636#import "NativeWebKeyboardEvent.h"
     37#import "NavigationState.h"
    3738#import "PageClient.h"
    3839#import "PrintInfo.h"
     
    678679{
    679680    bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
     681
     682    // We normally delay process suspension when the app is backgrounded until the current page load completes. However,
     683    // we do not want to do so when the screen is locked for power reasons.
     684    if (isSuspendedUnderLock)
     685        NavigationState::fromWebPage(*this).releaseNetworkActivityToken(NavigationState::NetworkActivityTokenReleaseReason::ScreenLocked);
    680686    m_process->send(Messages::WebPage::ApplicationDidEnterBackground(isSuspendedUnderLock), m_pageID);
    681687}
Note: See TracChangeset for help on using the changeset viewer.