Changeset 245255 in webkit


Ignore:
Timestamp:
May 13, 2019 3:01:12 PM (5 years ago)
Author:
jer.noble@apple.com
Message:

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:
Location:
trunk/Source/WebKit
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245252 r245255  
     12019-05-13  Jer Noble  <jer.noble@apple.com>
     2
     3        Take out MediaPlayback UI assertion when any WebProcess is playing audible media
     4        https://bugs.webkit.org/show_bug.cgi?id=197798
     5
     6        Reviewed by Chris Dumez.
     7
     8        To keep the system from suspending the UIProcess (and all the other constellation of processes that
     9        are necessary to play media), take a UIProcess assertion with the MediaPlayback reason whenever there
     10        is a WebContent process that is playing audible media.
     11
     12        * Platform/spi/ios/AssertionServicesSPI.h:
     13        * UIProcess/ProcessAssertion.h:
     14        * UIProcess/WebPageProxy.cpp:
     15        (WebKit::WebPageProxy::updatePlayingMediaDidChange):
     16        * UIProcess/WebProcessPool.cpp:
     17        (WebKit::WebProcessPool::setWebProcessIsPlayingAudibleMedia):
     18        (WebKit::WebProcessPool::clearWebProcessIsPlayingAudibleMedia):
     19        * UIProcess/WebProcessPool.h:
     20        * UIProcess/WebProcessProxy.cpp:
     21        (WebKit::WebProcessProxy::webPageMediaStateDidChange):
     22        * UIProcess/WebProcessProxy.h:
     23        * UIProcess/ios/ProcessAssertionIOS.mm:
     24        (WebKit::toBKSProcessAssertionReason):
     25        (WebKit::ProcessAssertion::ProcessAssertion):
     26        * WebProcess/WebProcess.h:
     27
    1282019-05-13  Per Arne Vollan  <pvollan@apple.com>
    229
  • trunk/Source/WebKit/Platform/spi/ios/AssertionServicesSPI.h

    r244091 r245255  
    7070
    7171enum {
     72    BKSProcessAssertionReasonMediaPlayback = 1,
    7273    BKSProcessAssertionReasonFinishTask = 4,
    7374    BKSProcessAssertionReasonExtension = 13,
  • trunk/Source/WebKit/UIProcess/ProcessAssertion.h

    r244091 r245255  
    5353    FinishTask,
    5454    FinishTaskUnbounded,
     55    MediaPlayback,
    5556};
    5657
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r245198 r245255  
    10381038
    10391039    stopAllURLSchemeTasks();
     1040    updatePlayingMediaDidChange(MediaProducer::IsNotPlaying);
    10401041}
    10411042
     
    70717072        m_pageLoadState.reset(transaction);
    70727073    }
     7074
     7075    updatePlayingMediaDidChange(MediaProducer::IsNotPlaying);
    70737076
    70747077    // FIXME: <rdar://problem/38676604> In case of process swaps, the old process should gracefully suspend instead of terminating.
     
    80938096    focusManager->updatePlaybackAttributesFromMediaState(this, sourceElementID, newState);
    80948097#endif
    8095     updatePlayingMediaDidChange(newState);
     8098    if (!m_isClosed)
     8099        updatePlayingMediaDidChange(newState);
    80968100}
    80978101
     
    81318135    if ((oldState & MediaProducer::HasAudioOrVideo) != (m_mediaState & MediaProducer::HasAudioOrVideo))
    81328136        videoControlsManagerDidChange();
     8137
     8138    m_process->webPageMediaStateDidChange(*this);
    81338139}
    81348140
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

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

    r245149 r245255  
    506506    void clearWebProcessHasUploads(WebCore::ProcessIdentifier);
    507507
     508    void setWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier);
     509    void clearWebProcessIsPlayingAudibleMedia(WebCore::ProcessIdentifier);
     510
    508511    void disableDelayedWebProcessLaunch() { m_isDelayedWebProcessLaunchDisabled = true; }
    509512
     
    789792    HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>> m_processesWithUploads;
    790793    std::unique_ptr<ProcessAssertion> m_uiProcessUploadAssertion;
     794
     795    HashMap<WebCore::ProcessIdentifier, std::unique_ptr<ProcessAssertion>> m_processesPlayingAudibleMedia;
     796    std::unique_ptr<ProcessAssertion> m_uiProcessMediaPlaybackAssertion;
     797
    791798#if PLATFORM(IOS)
    792799    // FIXME: Delayed process launch is currently disabled on iOS for performance reasons (rdar://problem/49074131).
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp

    r245151 r245255  
    12101210#endif
    12111211}
    1212    
     1212
     1213void WebProcessProxy::webPageMediaStateDidChange(WebPageProxy&)
     1214{
     1215    bool newHasAudibleWebPage = WTF::anyOf(m_pageMap.values(), [] (auto& page) { return page->isPlayingAudio(); });
     1216    if (m_hasAudibleWebPage == newHasAudibleWebPage)
     1217        return;
     1218    m_hasAudibleWebPage = newHasAudibleWebPage;
     1219
     1220    if (m_hasAudibleWebPage)
     1221        processPool().setWebProcessIsPlayingAudibleMedia(coreProcessIdentifier());
     1222    else
     1223        processPool().clearWebProcessIsPlayingAudibleMedia(coreProcessIdentifier());
     1224}
     1225
    12131226void WebProcessProxy::setIsHoldingLockedFiles(bool isHoldingLockedFiles)
    12141227{
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.h

    r244091 r245255  
    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)
  • trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm

    r244761 r245255  
    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.