#include "chrome/browser/media/media_engagement_contents_observer.h"
#include <memory>
#include "base/functional/bind.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "chrome/browser/media/media_engagement_preloaded_list.h"
#include "chrome/browser/media/media_engagement_service.h"
#include "chrome/browser/media/media_engagement_session.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "media/base/media_switches.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/mojom/autoplay/autoplay.mojom.h"
#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#endif
namespace {
void SendEngagementLevelToFrame(const url::Origin& origin,
content::RenderFrameHost* render_frame_host) { … }
}
const gfx::Size MediaEngagementContentsObserver::kSignificantSize = …;
const base::TimeDelta MediaEngagementContentsObserver::kMaxShortPlaybackTime = …;
const base::TimeDelta
MediaEngagementContentsObserver::kSignificantMediaPlaybackTime = …;
MediaEngagementContentsObserver::MediaEngagementContentsObserver(
content::WebContents* web_contents,
MediaEngagementService* service)
: … { … }
MediaEngagementContentsObserver::~MediaEngagementContentsObserver() = default;
MediaEngagementContentsObserver::PlaybackTimer::PlaybackTimer(
base::Clock* clock)
: … { … }
MediaEngagementContentsObserver::PlaybackTimer::~PlaybackTimer() = default;
void MediaEngagementContentsObserver::PlaybackTimer::Start() { … }
void MediaEngagementContentsObserver::PlaybackTimer::Stop() { … }
bool MediaEngagementContentsObserver::PlaybackTimer::IsRunning() const { … }
base::TimeDelta MediaEngagementContentsObserver::PlaybackTimer::Elapsed()
const { … }
void MediaEngagementContentsObserver::PlaybackTimer::Reset() { … }
void MediaEngagementContentsObserver::WebContentsDestroyed() { … }
void MediaEngagementContentsObserver::ClearPlayerStates() { … }
void MediaEngagementContentsObserver::RegisterAudiblePlayersWithSession() { … }
void MediaEngagementContentsObserver::DidFinishNavigation(
content::NavigationHandle* navigation_handle) { … }
MediaEngagementContentsObserver::PlayerState::PlayerState(base::Clock* clock)
: … { … }
MediaEngagementContentsObserver::PlayerState::~PlayerState() = default;
MediaEngagementContentsObserver::PlayerState::PlayerState(PlayerState&&) =
default;
MediaEngagementContentsObserver::PlayerState&
MediaEngagementContentsObserver::GetPlayerState(
const content::MediaPlayerId& id) { … }
void MediaEngagementContentsObserver::MediaStartedPlaying(
const MediaPlayerInfo& media_player_info,
const content::MediaPlayerId& media_player_id) { … }
void MediaEngagementContentsObserver::MediaMutedStatusChanged(
const content::MediaPlayerId& id,
bool muted) { … }
void MediaEngagementContentsObserver::MediaResized(
const gfx::Size& size,
const content::MediaPlayerId& id) { … }
void MediaEngagementContentsObserver::MediaDestroyed(
const content::MediaPlayerId& id) { … }
void MediaEngagementContentsObserver::MediaStoppedPlaying(
const MediaPlayerInfo& media_player_info,
const content::MediaPlayerId& media_player_id,
WebContentsObserver::MediaStoppedReason reason) { … }
void MediaEngagementContentsObserver::AudioContextPlaybackStarted(
const AudioContextId& audio_context_id) { … }
void MediaEngagementContentsObserver::AudioContextPlaybackStopped(
const AudioContextId& audio_context_id) { … }
void MediaEngagementContentsObserver::DidUpdateAudioMutingState(bool muted) { … }
bool MediaEngagementContentsObserver::IsPlayerStateComplete(
const PlayerState& state) { … }
void MediaEngagementContentsObserver::OnSignificantMediaPlaybackTimeForPlayer(
const content::MediaPlayerId& id) { … }
void MediaEngagementContentsObserver::OnSignificantMediaPlaybackTimeForPage() { … }
void MediaEngagementContentsObserver::
OnSignificantAudioContextPlaybackTimeForPage() { … }
void MediaEngagementContentsObserver::MaybeInsertRemoveSignificantPlayer(
const content::MediaPlayerId& id) { … }
bool MediaEngagementContentsObserver::IsSignificantPlayer(
const content::MediaPlayerId& id) { … }
void MediaEngagementContentsObserver::UpdatePlayerTimer(
const content::MediaPlayerId& id) { … }
bool MediaEngagementContentsObserver::AreConditionsMet() const { … }
void MediaEngagementContentsObserver::UpdatePageTimer() { … }
bool MediaEngagementContentsObserver::AreAudioContextConditionsMet() const { … }
void MediaEngagementContentsObserver::UpdateAudioContextTimer() { … }
void MediaEngagementContentsObserver::SetTaskRunnerForTest(
scoped_refptr<base::SequencedTaskRunner> task_runner) { … }
void MediaEngagementContentsObserver::ReadyToCommitNavigation(
content::NavigationHandle* handle) { … }
content::WebContents* MediaEngagementContentsObserver::GetOpener() const { … }
scoped_refptr<MediaEngagementSession>
MediaEngagementContentsObserver::GetOrCreateSession(
content::NavigationHandle* navigation_handle,
content::WebContents* opener) const { … }