Fix dangling pointers in CefAudioMirrorDestination (fixes issue #2713).

This commit is contained in:
Riku Palomäki 2019-07-16 21:42:39 +00:00 committed by Marshall Greenblatt
parent 1086495096
commit 367c6eb704
4 changed files with 13 additions and 10 deletions

View File

@ -29,7 +29,7 @@ void CefAudioMirrorDestination::Start() {
FROM_HERE, {content::BrowserThread::IO}, FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&content::AudioMirroringManager::StartMirroring, base::BindOnce(&content::AudioMirroringManager::StartMirroring,
base::Unretained(mirroring_manager_), base::Unretained(mirroring_manager_),
base::Unretained(this))); base::RetainedRef(this)));
} }
void CefAudioMirrorDestination::Stop() { void CefAudioMirrorDestination::Stop() {
@ -39,7 +39,7 @@ void CefAudioMirrorDestination::Stop() {
FROM_HERE, {content::BrowserThread::IO}, FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&content::AudioMirroringManager::StopMirroring, base::BindOnce(&content::AudioMirroringManager::StopMirroring,
base::Unretained(mirroring_manager_), base::Unretained(mirroring_manager_),
base::Unretained(this))); base::RetainedRef(this)));
} }
// Asynchronously query whether this MirroringDestination wants to consume // Asynchronously query whether this MirroringDestination wants to consume
@ -56,7 +56,7 @@ void CefAudioMirrorDestination::QueryForMatches(
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI}, FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&CefAudioMirrorDestination::QueryForMatchesOnUIThread, base::BindOnce(&CefAudioMirrorDestination::QueryForMatchesOnUIThread,
base::Unretained(this), candidates, base::RetainedRef(this), candidates,
media::BindToCurrentLoop(std::move(results_callback)))); media::BindToCurrentLoop(std::move(results_callback))));
} }
@ -99,7 +99,7 @@ media::AudioPushSink* CefAudioMirrorDestination::AddPushInput(
return new CefAudioPushSink( return new CefAudioPushSink(
params, browser_, cef_audio_handler_, params, browser_, cef_audio_handler_,
base::Bind(&CefAudioMirrorDestination::ReleasePushInput, base::Bind(&CefAudioMirrorDestination::ReleasePushInput,
base::Unretained(this))); base::RetainedRef(this)));
} }
void CefAudioMirrorDestination::ReleasePushInput(CefAudioPushSink* sink) { void CefAudioMirrorDestination::ReleasePushInput(CefAudioPushSink* sink) {

View File

@ -22,14 +22,13 @@ class CefAudioPushSink;
class CefBrowserHostImpl; class CefBrowserHostImpl;
class CefAudioMirrorDestination class CefAudioMirrorDestination
: public content::AudioMirroringManager::MirroringDestination { : public base::RefCountedThreadSafe<CefAudioMirrorDestination>,
public content::AudioMirroringManager::MirroringDestination {
public: public:
CefAudioMirrorDestination(CefRefPtr<CefBrowserHostImpl> browser, CefAudioMirrorDestination(CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> cef_audio_handler, CefRefPtr<CefAudioHandler> cef_audio_handler,
content::AudioMirroringManager* mirroring_manager); content::AudioMirroringManager* mirroring_manager);
virtual ~CefAudioMirrorDestination() = default;
// Start mirroring. This needs to be triggered on the IO thread. // Start mirroring. This needs to be triggered on the IO thread.
void Start(); void Start();
@ -65,6 +64,10 @@ class CefAudioMirrorDestination
const media::AudioParameters& params) override; const media::AudioParameters& params) override;
private: private:
friend class base::RefCountedThreadSafe<CefAudioMirrorDestination>;
~CefAudioMirrorDestination() override = default;
void QueryForMatchesOnUIThread( void QueryForMatchesOnUIThread(
const std::set<content::GlobalFrameRoutingId>& candidates, const std::set<content::GlobalFrameRoutingId>& candidates,
MatchesCallback results_callback); MatchesCallback results_callback);

View File

@ -2744,8 +2744,8 @@ bool CefBrowserHostImpl::StartAudioMirroring() {
if (client_.get()) { if (client_.get()) {
CefRefPtr<CefAudioHandler> audio_handler = client_->GetAudioHandler(); CefRefPtr<CefAudioHandler> audio_handler = client_->GetAudioHandler();
if (audio_handler.get()) { if (audio_handler.get()) {
audio_mirror_destination_.reset(new CefAudioMirrorDestination( audio_mirror_destination_ = new CefAudioMirrorDestination(
this, audio_handler, content::AudioMirroringManager::GetInstance())); this, audio_handler, content::AudioMirroringManager::GetInstance());
audio_mirror_destination_->Start(); audio_mirror_destination_->Start();
return true; return true;
} }

View File

@ -666,7 +666,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
bool is_background_host_ = false; bool is_background_host_ = false;
// Used to mirror audio streams // Used to mirror audio streams
std::unique_ptr<CefAudioMirrorDestination> audio_mirror_destination_; scoped_refptr<CefAudioMirrorDestination> audio_mirror_destination_;
// Used with auto-resize. // Used with auto-resize.
bool auto_resize_enabled_ = false; bool auto_resize_enabled_ = false;