diff --git a/libcef/browser/audio_mirror_destination.cc b/libcef/browser/audio_mirror_destination.cc index e295886b8..d74f83aca 100644 --- a/libcef/browser/audio_mirror_destination.cc +++ b/libcef/browser/audio_mirror_destination.cc @@ -29,7 +29,7 @@ void CefAudioMirrorDestination::Start() { FROM_HERE, {content::BrowserThread::IO}, base::BindOnce(&content::AudioMirroringManager::StartMirroring, base::Unretained(mirroring_manager_), - base::Unretained(this))); + base::RetainedRef(this))); } void CefAudioMirrorDestination::Stop() { @@ -39,7 +39,7 @@ void CefAudioMirrorDestination::Stop() { FROM_HERE, {content::BrowserThread::IO}, base::BindOnce(&content::AudioMirroringManager::StopMirroring, base::Unretained(mirroring_manager_), - base::Unretained(this))); + base::RetainedRef(this))); } // Asynchronously query whether this MirroringDestination wants to consume @@ -56,7 +56,7 @@ void CefAudioMirrorDestination::QueryForMatches( base::PostTaskWithTraits( FROM_HERE, {content::BrowserThread::UI}, base::BindOnce(&CefAudioMirrorDestination::QueryForMatchesOnUIThread, - base::Unretained(this), candidates, + base::RetainedRef(this), candidates, media::BindToCurrentLoop(std::move(results_callback)))); } @@ -99,7 +99,7 @@ media::AudioPushSink* CefAudioMirrorDestination::AddPushInput( return new CefAudioPushSink( params, browser_, cef_audio_handler_, base::Bind(&CefAudioMirrorDestination::ReleasePushInput, - base::Unretained(this))); + base::RetainedRef(this))); } void CefAudioMirrorDestination::ReleasePushInput(CefAudioPushSink* sink) { diff --git a/libcef/browser/audio_mirror_destination.h b/libcef/browser/audio_mirror_destination.h index 68dc93047..e4b0caf08 100644 --- a/libcef/browser/audio_mirror_destination.h +++ b/libcef/browser/audio_mirror_destination.h @@ -22,14 +22,13 @@ class CefAudioPushSink; class CefBrowserHostImpl; class CefAudioMirrorDestination - : public content::AudioMirroringManager::MirroringDestination { + : public base::RefCountedThreadSafe, + public content::AudioMirroringManager::MirroringDestination { public: CefAudioMirrorDestination(CefRefPtr browser, CefRefPtr cef_audio_handler, content::AudioMirroringManager* mirroring_manager); - virtual ~CefAudioMirrorDestination() = default; - // Start mirroring. This needs to be triggered on the IO thread. void Start(); @@ -65,6 +64,10 @@ class CefAudioMirrorDestination const media::AudioParameters& params) override; private: + friend class base::RefCountedThreadSafe; + + ~CefAudioMirrorDestination() override = default; + void QueryForMatchesOnUIThread( const std::set& candidates, MatchesCallback results_callback); diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 88555b068..55b05999d 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -2744,8 +2744,8 @@ bool CefBrowserHostImpl::StartAudioMirroring() { if (client_.get()) { CefRefPtr audio_handler = client_->GetAudioHandler(); if (audio_handler.get()) { - audio_mirror_destination_.reset(new CefAudioMirrorDestination( - this, audio_handler, content::AudioMirroringManager::GetInstance())); + audio_mirror_destination_ = new CefAudioMirrorDestination( + this, audio_handler, content::AudioMirroringManager::GetInstance()); audio_mirror_destination_->Start(); return true; } diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index af10d6236..5e5270811 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -666,7 +666,7 @@ class CefBrowserHostImpl : public CefBrowserHost, bool is_background_host_ = false; // Used to mirror audio streams - std::unique_ptr audio_mirror_destination_; + scoped_refptr audio_mirror_destination_; // Used with auto-resize. bool auto_resize_enabled_ = false;