alloy: Fix shutdown assert if OneShotTimer is deleted on the wrong thread

This commit is contained in:
Marshall Greenblatt 2022-01-25 16:15:23 -05:00
parent 1e1133ec66
commit 303280dd71
2 changed files with 12 additions and 4 deletions

View File

@ -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<base::OneShotTimer>();
// 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));

View File

@ -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<base::OneShotTimer> recently_audible_timer_;
};
#endif // CEF_LIBCEF_BROWSER_ALLOY_ALLOY_BROWSER_HOST_IMPL_H_