Changeset 247380 in webkit


Ignore:
Timestamp:
Jul 11, 2019 7:35:07 PM (5 years ago)
Author:
Chris Dumez
Message:

Drop non thread-safe usage of WeakPtr in PlaybackSessionInterfaceAVKit
https://bugs.webkit.org/show_bug.cgi?id=199698

Reviewed by Eric Carlson.

The PlaybackSessionInterfaceAVKit constructor was making a weakPtr on the UI Thread
of an WebThread object. The WeakPtr would then be used as a data member throughout
the class on the UIThread. This is not thread-safe.

This patch switches to using a raw pointer instead of a WeakPtr. This is a partial
rollout of r243337, which turned the raw pointer into a WeakPtr for hardening
purposes. For extra safety, this patch updates the VideoFullscreenControllerContext
so that it notifies its clients (i.e. PlaybackSessionInterfaceAVKit) that it is
getting destroyed, so that they can null-out their m_playbackSessionModel data
member. This gives the sames guarantees than WeakPtr but in a thread-safe way.

  • platform/cocoa/PlaybackSessionModel.h:

(WebCore::PlaybackSessionModelClient::modelDestroyed):

  • platform/ios/PlaybackSessionInterfaceAVKit.h:
  • platform/ios/PlaybackSessionInterfaceAVKit.mm:

(WebCore::PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit):
(WebCore::PlaybackSessionInterfaceAVKit::~PlaybackSessionInterfaceAVKit):
(WebCore::PlaybackSessionInterfaceAVKit::playbackSessionModel const):
(WebCore::PlaybackSessionInterfaceAVKit::modelDestroyed):

  • platform/ios/WebVideoFullscreenControllerAVKit.mm:

(VideoFullscreenControllerContext::~VideoFullscreenControllerContext):
(VideoFullscreenControllerContext::addClient):
(VideoFullscreenControllerContext::removeClient):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r247379 r247380  
     12019-07-11  Chris Dumez  <cdumez@apple.com>
     2
     3        Drop non thread-safe usage of WeakPtr in PlaybackSessionInterfaceAVKit
     4        https://bugs.webkit.org/show_bug.cgi?id=199698
     5
     6        Reviewed by Eric Carlson.
     7
     8        The PlaybackSessionInterfaceAVKit constructor was making a weakPtr on the UI Thread
     9        of an WebThread object. The WeakPtr would then be used as a data member throughout
     10        the class on the UIThread. This is not thread-safe.
     11
     12        This patch switches to using a raw pointer instead of a WeakPtr. This is a partial
     13        rollout of r243337, which turned the raw pointer into a WeakPtr for hardening
     14        purposes. For extra safety, this patch updates the VideoFullscreenControllerContext
     15        so that it notifies its clients (i.e. PlaybackSessionInterfaceAVKit) that it is
     16        getting destroyed, so that they can null-out their m_playbackSessionModel data
     17        member. This gives the sames guarantees than WeakPtr but in a thread-safe way.
     18
     19        * platform/cocoa/PlaybackSessionModel.h:
     20        (WebCore::PlaybackSessionModelClient::modelDestroyed):
     21        * platform/ios/PlaybackSessionInterfaceAVKit.h:
     22        * platform/ios/PlaybackSessionInterfaceAVKit.mm:
     23        (WebCore::PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit):
     24        (WebCore::PlaybackSessionInterfaceAVKit::~PlaybackSessionInterfaceAVKit):
     25        (WebCore::PlaybackSessionInterfaceAVKit::playbackSessionModel const):
     26        (WebCore::PlaybackSessionInterfaceAVKit::modelDestroyed):
     27        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
     28        (VideoFullscreenControllerContext::~VideoFullscreenControllerContext):
     29        (VideoFullscreenControllerContext::addClient):
     30        (VideoFullscreenControllerContext::removeClient):
     31
    1322019-07-11  Simon Fraser  <simon.fraser@apple.com>
    233
  • trunk/Source/WebCore/platform/cocoa/PlaybackSessionModel.h

    r243337 r247380  
    111111    virtual void pictureInPictureActiveChanged(bool) { }
    112112    virtual void ensureControlsManager() { }
     113    virtual void modelDestroyed() { }
    113114};
    114115
  • trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h

    r243337 r247380  
    7878    WEBCORE_EXPORT void mutedChanged(bool) override;
    7979    WEBCORE_EXPORT void volumeChanged(double) override;
     80    WEBCORE_EXPORT void modelDestroyed() override;
    8081
    8182    WEBCORE_EXPORT virtual void invalidate();
     
    8788
    8889    RetainPtr<WebAVPlayerController> m_playerController;
    89     WeakPtr<PlaybackSessionModel> m_playbackSessionModel;
     90    PlaybackSessionModel* m_playbackSessionModel { nullptr };
    9091};
    9192
  • trunk/Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm

    r243338 r247380  
    5252PlaybackSessionInterfaceAVKit::PlaybackSessionInterfaceAVKit(PlaybackSessionModel& model)
    5353    : m_playerController(adoptNS([[WebAVPlayerController alloc] init]))
    54     , m_playbackSessionModel(makeWeakPtr(model))
    55 {
     54    , m_playbackSessionModel(&model)
     55{
     56    ASSERT(isUIThread());
    5657    model.addClient(*this);
    5758    [m_playerController setPlaybackSessionInterface:this];
     
    7273PlaybackSessionInterfaceAVKit::~PlaybackSessionInterfaceAVKit()
    7374{
     75    ASSERT(isUIThread());
    7476    [m_playerController setPlaybackSessionInterface:nullptr];
    7577    [m_playerController setExternalPlaybackActive:false];
     
    8082PlaybackSessionModel* PlaybackSessionInterfaceAVKit::playbackSessionModel() const
    8183{
    82     return m_playbackSessionModel.get();
     84    return m_playbackSessionModel;
    8385}
    8486
     
    220222}
    221223
     224void PlaybackSessionInterfaceAVKit::modelDestroyed()
     225{
     226    ASSERT(isUIThread());
     227    invalidate();
     228    ASSERT(!m_playbackSessionModel);
     229}
     230
    222231}
    223232
  • trunk/Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm

    r240355 r247380  
    109109        return adoptRef(*new VideoFullscreenControllerContext);
    110110    }
     111
     112    ~VideoFullscreenControllerContext();
    111113
    112114    void setController(WebVideoFullscreenController* controller) { m_controller = controller; }
     
    217219};
    218220
     221VideoFullscreenControllerContext::~VideoFullscreenControllerContext()
     222{
     223    auto notifyClientsModelWasDestroyed = [this] {
     224        while (!m_playbackClients.isEmpty())
     225            (*m_playbackClients.begin())->modelDestroyed();
     226    };
     227    if (isUIThread())
     228        notifyClientsModelWasDestroyed();
     229    else
     230        dispatch_sync(dispatch_get_main_queue(), WTFMove(notifyClientsModelWasDestroyed));
     231}
     232
    219233#pragma mark VideoFullscreenChangeObserver
    220234
     
    544558void VideoFullscreenControllerContext::addClient(VideoFullscreenModelClient& client)
    545559{
     560    ASSERT(isUIThread());
    546561    ASSERT(!m_fullscreenClients.contains(&client));
    547562    m_fullscreenClients.add(&client);
     
    550565void VideoFullscreenControllerContext::removeClient(VideoFullscreenModelClient& client)
    551566{
     567    ASSERT(isUIThread());
    552568    ASSERT(m_fullscreenClients.contains(&client));
    553569    m_fullscreenClients.remove(&client);
Note: See TracChangeset for help on using the changeset viewer.