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},
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) {

View File

@ -22,14 +22,13 @@ class CefAudioPushSink;
class CefBrowserHostImpl;
class CefAudioMirrorDestination
: public content::AudioMirroringManager::MirroringDestination {
: public base::RefCountedThreadSafe<CefAudioMirrorDestination>,
public content::AudioMirroringManager::MirroringDestination {
public:
CefAudioMirrorDestination(CefRefPtr<CefBrowserHostImpl> browser,
CefRefPtr<CefAudioHandler> 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>;
~CefAudioMirrorDestination() override = default;
void QueryForMatchesOnUIThread(
const std::set<content::GlobalFrameRoutingId>& candidates,
MatchesCallback results_callback);

View File

@ -2744,8 +2744,8 @@ bool CefBrowserHostImpl::StartAudioMirroring() {
if (client_.get()) {
CefRefPtr<CefAudioHandler> 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;
}

View File

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