From 303280dd711b164b2f081fc30dfac4b4fa64decb Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 25 Jan 2022 16:15:23 -0500 Subject: [PATCH] alloy: Fix shutdown assert if OneShotTimer is deleted on the wrong thread --- libcef/browser/alloy/alloy_browser_host_impl.cc | 14 +++++++++++--- libcef/browser/alloy/alloy_browser_host_impl.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index bd8d6d129..c27dfb4d6 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -765,7 +765,10 @@ void AlloyBrowserHostImpl::DestroyBrowser() { menu_manager_.reset(nullptr); // Delete the audio capturer - recently_audible_timer_.Stop(); + if (recently_audible_timer_) { + recently_audible_timer_->Stop(); + recently_audible_timer_.reset(); + } audio_capturer_.reset(nullptr); CefBrowserHostBase::DestroyBrowser(); @@ -1501,14 +1504,19 @@ void AlloyBrowserHostImpl::DidFinishNavigation( void AlloyBrowserHostImpl::OnAudioStateChanged(bool audible) { if (audible) { - recently_audible_timer_.Stop(); + if (recently_audible_timer_) + recently_audible_timer_->Stop(); + StartAudioCapturer(); } else if (audio_capturer_) { + if (!recently_audible_timer_) + recently_audible_timer_ = std::make_unique(); + // If you have a media playing that has a short quiet moment, web_contents // will immediately switch to non-audible state. We don't want to stop // audio stream so quickly, let's give the stream some time to resume // playing. - recently_audible_timer_.Start( + recently_audible_timer_->Start( FROM_HERE, kRecentlyAudibleTimeout, base::BindOnce(&AlloyBrowserHostImpl::OnRecentlyAudibleTimerFired, this)); diff --git a/libcef/browser/alloy/alloy_browser_host_impl.h b/libcef/browser/alloy/alloy_browser_host_impl.h index 51f7f9cd5..421f42c02 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.h +++ b/libcef/browser/alloy/alloy_browser_host_impl.h @@ -370,7 +370,7 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase, // Timer for determining when "recently audible" transitions to false. This // starts running when a tab stops being audible, and is canceled if it starts // being audible again before it fires. - base::OneShotTimer recently_audible_timer_; + std::unique_ptr recently_audible_timer_; }; #endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_HOST_IMPL_H_