⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245319 in webkit


Ignore:
Timestamp:
May 14, 2019, 10:24:03 PM (7 years ago)
Author:
Kocsen Chung
Message:

Cherry-pick r245255. rdar://problem/50141840

Take out MediaPlayback UI assertion when any WebProcess is playing audible media
https://bugs.webkit.org/show_bug.cgi?id=197798

Reviewed by Chris Dumez.

To keep the system from suspending the UIProcess (and all the other constellation of processes that
are necessary to play media), take a UIProcess assertion with the MediaPlayback reason whenever there
is a WebContent process that is playing audible media.

  • Platform/spi/ios/AssertionServicesSPI.h:
  • UIProcess/ProcessAssertion.h:
  • UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::updatePlayingMediaDidChange):
  • UIProcess/WebProcessPool.cpp: (WebKit::WebProcessPool::setWebProcessIsPlayingAudibleMedia): (WebKit::WebProcessPool::clearWebProcessIsPlayingAudibleMedia):
  • UIProcess/WebProcessPool.h:
  • UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::webPageMediaStateDidChange):
  • UIProcess/WebProcessProxy.h:
  • UIProcess/ios/ProcessAssertionIOS.mm: (WebKit::toBKSProcessAssertionReason): (WebKit::ProcessAssertion::ProcessAssertion):
  • WebProcess/WebProcess.h:

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

Location:
branches/safari-608.1.24-branch/Source/WebKit
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-608.1.24-branch/Source/WebKit/ChangeLog

    r245310 r245319  
     12019-05-14  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r245255. rdar://problem/50141840
     4
     5    Take out MediaPlayback UI assertion when any WebProcess is playing audible media
     6    https://bugs.webkit.org/show_bug.cgi?id=197798
     7   
     8    Reviewed by Chris Dumez.
     9   
     10    To keep the system from suspending the UIProcess (and all the other constellation of processes that
     11    are necessary to play media), take a UIProcess assertion with the MediaPlayback reason whenever there
     12    is a WebContent process that is playing audible media.
     13   
     14    * Platform/spi/ios/AssertionServicesSPI.h:
     15    * UIProcess/ProcessAssertion.h:
     16    * UIProcess/WebPageProxy.cpp:
     17    (WebKit::WebPageProxy::updatePlayingMediaDidChange):
     18    * UIProcess/WebProcessPool.cpp:
     19    (WebKit::WebProcessPool::setWebProcessIsPlayingAudibleMedia):
     20    (WebKit::WebProcessPool::clearWebProcessIsPlayingAudibleMedia):
     21    * UIProcess/WebProcessPool.h:
     22    * UIProcess/WebProcessProxy.cpp:
     23    (WebKit::WebProcessProxy::webPageMediaStateDidChange):
     24    * UIProcess/WebProcessProxy.h:
     25    * UIProcess/ios/ProcessAssertionIOS.mm:
     26    (WebKit::toBKSProcessAssertionReason):
     27    (WebKit::ProcessAssertion::ProcessAssertion):
     28    * WebProcess/WebProcess.h:
     29   
     30   
     31    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245255 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     32
     33    2019-05-13  Jer Noble  <jer.noble@apple.com>
     34
     35            Take out MediaPlayback UI assertion when any WebProcess is playing audible media
     36            https://bugs.webkit.org/show_bug.cgi?id=197798
     37
     38            Reviewed by Chris Dumez.
     39
     40            To keep the system from suspending the UIProcess (and all the other constellation of processes that
     41            are necessary to play media), take a UIProcess assertion with the MediaPlayback reason whenever there
     42            is a WebContent process that is playing audible media.
     43
     44            * Platform/spi/ios/AssertionServicesSPI.h:
     45            * UIProcess/ProcessAssertion.h:
     46            * UIProcess/WebPageProxy.cpp:
     47            (WebKit::WebPageProxy::updatePlayingMediaDidChange):
     48            * UIProcess/WebProcessPool.cpp:
     49            (WebKit::WebProcessPool::setWebProcessIsPlayingAudibleMedia):
     50            (WebKit::WebProcessPool::clearWebProcessIsPlayingAudibleMedia):
     51            * UIProcess/WebProcessPool.h:
     52            * UIProcess/WebProcessProxy.cpp:
     53            (WebKit::WebProcessProxy::webPageMediaStateDidChange):
     54            * UIProcess/WebProcessProxy.h:
     55            * UIProcess/ios/ProcessAssertionIOS.mm:
     56            (WebKit::toBKSProcessAssertionReason):
     57            (WebKit::ProcessAssertion::ProcessAssertion):
     58            * WebProcess/WebProcess.h:
     59
    1602019-05-14  Alan Coon  <alancoon@apple.com>
    261
  • branches/safari-608.1.24-branch/Source/WebKit/Platform/spi/ios/AssertionServicesSPI.h

    r244091 r245319  
    7070
    7171enum {
     72    BKSProcessAssertionReasonMediaPlayback = 1,
    7273    BKSProcessAssertionReasonFinishTask = 4,
    7374    BKSProcessAssertionReasonExtension = 13,
  • branches/safari-608.1.24-branch/Source/WebKit/UIProcess/ProcessAssertion.h

    r244091 r245319  
    5353    FinishTask,
    5454    FinishTaskUnbounded,
     55    MediaPlayback,
    5556};
    5657
  • branches/safari-608.1.24-branch/Source/WebKit/UIProcess/WebPageProxy.cpp

    r245228 r245319  
    10391039
    10401040    stopAllURLSchemeTasks();
     1041    updatePlayingMediaDidChange(MediaProducer::IsNotPlaying);
    10411042}
    10421043
     
    70537054        m_pageLoadState.reset(transaction);
    70547055    }
     7056
     7057    updatePlayingMediaDidChange(MediaProducer::IsNotPlaying);
    70557058
    70567059    // FIXME: <rdar://problem/38676604> In case of process swaps, the old process should gracefully suspend instead of terminating.
     
    80758078    focusManager->updatePlaybackAttributesFromMediaState(this, sourceElementID, newState);
    80768079#endif
    8077     updatePlayingMediaDidChange(newState);
     8080    if (!m_isClosed)
     8081        updatePlayingMediaDidChange(newState);
    80788082}
    80798083
     
    81138117    if ((oldState & MediaProducer::HasAudioOrVideo) != (m_mediaState & MediaProducer::HasAudioOrVideo))
    81148118        videoControlsManagerDidChange();
     8119
     8120    m_process->webPageMediaStateDidChange(*this);
    81158121}
    81168122
  • branches/safari-608.1.24-branch/Source/WebKit/UIProcess/WebProcessPool.cpp

    r245075 r245319  
    11011101{
    11021102    ASSERT(m_processes.contains(process));
     1103    ASSERT(!m_processesPlayingAudibleMedia.contains(process->coreProcessIdentifier()));
    11031104
    11041105    if (m_prewarmedProcess == process) {
     
    25762577}
    25772578
     2579void WebProcessPool::setWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier processID)
     2580{
     2581    auto* process = WebProcessProxy::processForIdentifier(processID);
     2582    ASSERT(process);
     2583
     2584    RELEASE_LOG(ProcessSuspension, "Web process pid %u is now playing audible media", (unsigned)process->processIdentifier());
     2585
     2586    if (m_processesPlayingAudibleMedia.isEmpty()) {
     2587        RELEASE_LOG(ProcessSuspension, "The number of processes playing audible media is now one. Taking UI process assertion.");
     2588
     2589        ASSERT(!m_uiProcessMediaPlaybackAssertion);
     2590        m_uiProcessMediaPlaybackAssertion = std::make_unique<ProcessAssertion>(getCurrentProcessID(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);
     2591    }
     2592
     2593    auto result = m_processesPlayingAudibleMedia.add(processID, nullptr);
     2594    ASSERT(result.isNewEntry);
     2595    result.iterator->value = std::make_unique<ProcessAssertion>(process->processIdentifier(), "WebKit Media Playback"_s, AssertionState::Foreground, AssertionReason::MediaPlayback);
     2596}
     2597
     2598void WebProcessPool::clearWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier processID)
     2599{
     2600    auto result = m_processesPlayingAudibleMedia.take(processID);
     2601    ASSERT_UNUSED(result, result);
     2602
     2603    auto* process = WebProcessProxy::processForIdentifier(processID);
     2604    ASSERT(process);
     2605    RELEASE_LOG(ProcessSuspension, "Web process pid %u is no longer playing audible media", (unsigned)process->processIdentifier());
     2606
     2607    if (m_processesPlayingAudibleMedia.isEmpty()) {
     2608        RELEASE_LOG(ProcessSuspension, "The number of processes playing audible media now zero. Releasing UI process assertion.");
     2609
     2610        ASSERT(m_uiProcessMediaPlaybackAssertion);
     2611        m_uiProcessMediaPlaybackAssertion = nullptr;
     2612    }
     2613}
     2614
    25782615} // namespace WebKit
  • branches/safari-608.1.24-branch/Source/WebKit/UIProcess/WebProcessPool.h

    r244521 r245319  
    506506    void clearWebProcessHasUploads(WebCore::ProcessIdentifier);
    507507
     508    void setWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier);
     509    void clearWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier);
     510
    508511    void disableDelayedWebProcessLaunch() { m_isDelayedWebProcessLaunchDisabled = true; }
    509512
     
    791794    HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>> m_processesWithUploads;
    792795    std::unique_ptr<ProcessAssertion> m_uiProcessUploadAssertion;
     796
     797    HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>> m_processesPlayingAudibleMedia;
     798    std::unique_ptr<ProcessAssertion> m_uiProcessMediaPlaybackAssertion;
     799
    793800#if PLATFORM(IOS)
    794801    // FIXME: Delayed process launch is currently disabled on iOS for performance reasons (rdar://problem/49074131).
  • branches/safari-608.1.24-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp

    r245310 r245319  
    12171217#endif
    12181218}
    1219    
     1219
     1220void WebProcessProxy::webPageMediaStateDidChange(WebPageProxy&)
     1221{
     1222    bool newHasAudibleWebPage = WTF::anyOf(m_pageMap.values(), [] (auto& page) { return page->isPlayingAudio(); });
     1223    if (m_hasAudibleWebPage == newHasAudibleWebPage)
     1224        return;
     1225    m_hasAudibleWebPage = newHasAudibleWebPage;
     1226
     1227    if (m_hasAudibleWebPage)
     1228        processPool().setWebProcessIsPlayingAudibleMedia(coreProcessIdentifier());
     1229    else
     1230        processPool().clearWebProcessIsPlayingAudibleMedia(coreProcessIdentifier());
     1231}
     1232
    12201233void WebProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles)
    12211234{
  • branches/safari-608.1.24-branch/Source/WebKit/UIProcess/WebProcessProxy.h

    r244091 r245319  
    307307#endif
    308308
     309    void webPageMediaStateDidChange(WebPageProxy&);
     310
    309311protected:
    310312    static uint64_t generatePageID();
     
    486488    bool m_hasCommittedAnyProvisionalLoads { false };
    487489    bool m_isPrewarmed;
     490    bool m_hasAudibleWebPage { false };
    488491
    489492#if PLATFORM(WATCHOS)
  • branches/safari-608.1.24-branch/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm

    r244761 r245319  
    182182    case AssertionReason::FinishTaskUnbounded:
    183183        return BKSProcessAssertionReasonFinishTaskUnbounded;
     184    case AssertionReason::MediaPlayback:
     185        return BKSProcessAssertionReasonMediaPlayback;
    184186    }
    185187}
Note: See TracChangeset for help on using the changeset viewer.