Commit 50cf2ba5 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Use RecentlyAudibleHelper for tab audibility updates

This moves Browser away from listening to for INVALIDATE_TYPE_AUDIO for
audibility state changes.

This is part of a refactor detailed in the attached bug.

Bug: 846374
Change-Id: I09cd8395c16bba812e9417f2ca6364d43864d39b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1854214
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705204}
parent e73df51a
......@@ -2320,6 +2320,10 @@ void Browser::ScheduleUIUpdate(WebContents* source, unsigned changed_flags) {
if (tab_strip_model_->GetIndexOfWebContents(source) == TabStripModel::kNoTab)
return;
// We ignore |INVALIDATE_TYPE_AUDIO| since we subscribe to
// RecentlyAudibleHelper via |OnTabAudibilityChanged()|.
changed_flags &= ~content::INVALIDATE_TYPE_AUDIO;
// Do some synchronous updates.
if (changed_flags & content::INVALIDATE_TYPE_URL) {
if (source == tab_strip_model_->GetActiveWebContents()) {
......@@ -2409,8 +2413,8 @@ void Browser::ProcessPendingUIUpdates() {
}
// Updates that don't depend upon the selected state go here.
if (flags & (content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE |
content::INVALIDATE_TYPE_AUDIO)) {
if (flags &
(content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) {
tab_strip_model_->UpdateWebContentsStateAt(
tab_strip_model_->GetIndexOfWebContents(contents),
TabChangeType::kAll);
......@@ -2588,10 +2592,16 @@ void Browser::SetAsDelegate(WebContents* web_contents, bool set_delegate) {
zoom::ZoomController::FromWebContents(web_contents)->AddObserver(this);
content_translate_driver->AddObserver(this);
BookmarkTabHelper::FromWebContents(web_contents)->AddObserver(this);
audibility_subscriptions_[web_contents] =
RecentlyAudibleHelper::FromWebContents(web_contents)
->RegisterCallback(
base::BindRepeating(&Browser::OnTabAudibilityChanged,
base::Unretained(this), web_contents));
} else {
zoom::ZoomController::FromWebContents(web_contents)->RemoveObserver(this);
content_translate_driver->RemoveObserver(this);
BookmarkTabHelper::FromWebContents(web_contents)->RemoveObserver(this);
audibility_subscriptions_.erase(web_contents);
}
}
......@@ -2903,3 +2913,9 @@ BackgroundContents* Browser::CreateBackgroundContents(
return contents;
}
void Browser::OnTabAudibilityChanged(content::WebContents* contents,
bool recently_audible) {
tab_strip_model_->UpdateWebContentsStateAt(
tab_strip_model_->GetIndexOfWebContents(contents), TabChangeType::kAll);
}
......@@ -29,6 +29,7 @@
#include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
#include "chrome/browser/ui/profile_chooser_constants.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/unload_controller.h"
#include "components/content_settings/core/common/content_settings.h"
......@@ -1007,6 +1008,10 @@ class Browser : public TabStripModelObserver,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace);
// Callback for RecentlyAudibleHelper.
void OnTabAudibilityChanged(content::WebContents* contents,
bool recently_audible);
// Data members /////////////////////////////////////////////////////////////
std::vector<InterstitialObserver*> interstitial_observers_;
......@@ -1148,6 +1153,13 @@ class Browser : public TabStripModelObserver,
extension_browser_window_helper_;
#endif
// These subscriptions are returned by RecentlyAudibleHelper when registering
// a callback. They de-register the callback when destroyed and safely handle
// destruction of the associated RecentlyAudibleHelper.
std::map<content::WebContents*,
std::unique_ptr<RecentlyAudibleHelper::Subscription>>
audibility_subscriptions_;
// The following factory is used for chrome update coalescing.
base::WeakPtrFactory<Browser> chrome_updater_factory_{this};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment