Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 2658513003: [Cleanup] Rename Hidden to Background in WMPI.
Patch Set: More renames in the comments etc Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/webmediaplayer_impl.cc
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index 0ab7b54d2cfdf4ee3dc09c257d782eea66e0c312..da39318d924ab3816ffe1bf0136aac04b38e74de 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -206,7 +206,7 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
opaque_(false),
playback_rate_(0.0),
paused_(true),
- paused_when_hidden_(false),
+ paused_when_background_(false),
seeking_(false),
pending_suspend_resume_cycle_(false),
ended_(false),
@@ -453,8 +453,8 @@ void WebMediaPlayerImpl::pause() {
// paused state.
paused_ = true;
- // No longer paused because it was hidden.
- paused_when_hidden_ = false;
+ // No longer paused because it was backgrounded.
+ paused_when_background_ = false;
#if defined(OS_ANDROID) // WMPI_CAST
if (isRemote()) {
@@ -1117,8 +1117,8 @@ void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) {
// actions from artificially inflating the underflow count.
underflow_count_ = 0;
- // Background video optimizations are delayed when shown/hidden if pipeline
- // is seeking.
+ // Background video optimizations are delayed when if pipeline
+ // is seeking when the video goes to the background or the foreground.
UpdateBackgroundVideoOptimizationState();
}
@@ -1405,10 +1405,8 @@ void WebMediaPlayerImpl::OnFrameHidden() {
if (watch_time_reporter_)
watch_time_reporter_->OnHidden();
- // OnFrameHidden() can be called when frame is closed, then IsHidden() will
- // return false, so check explicitly.
- if (IsHidden()) {
- if (ShouldPauseVideoWhenHidden()) {
+ if (IsBackgrounded()) {
+ if (ShouldPauseVideoWhenBackground()) {
PauseVideoIfNeeded();
return;
} else {
@@ -1436,10 +1434,10 @@ void WebMediaPlayerImpl::OnFrameShown() {
watch_time_reporter_->OnShown();
// Only track the time to the first frame if playing or about to play because
- // of being shown and only for videos we would optimize background playback
- // for.
+ // of being foregrounded and only for videos we would optimize background
+ // playback for.
if ((!paused_ && IsBackgroundOptimizationCandidate()) ||
- paused_when_hidden_) {
+ paused_when_background_) {
VideoFrameCompositor::OnNewProcessedFrameCB new_processed_frame_cb =
BIND_TO_RENDER_LOOP1(
&WebMediaPlayerImpl::ReportTimeFromForegroundToFirstFrame,
@@ -1450,8 +1448,8 @@ void WebMediaPlayerImpl::OnFrameShown() {
base::Unretained(compositor_), new_processed_frame_cb));
}
- if (paused_when_hidden_) {
- paused_when_hidden_ = false;
+ if (paused_when_background_) {
+ paused_when_background_ = false;
OnPlay(); // Calls UpdatePlayState() so return afterwards.
return;
}
@@ -1804,7 +1802,7 @@ void WebMediaPlayerImpl::UpdatePlayState() {
#endif
bool is_suspended = pipeline_controller_.IsSuspended();
- bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden();
+ bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsBackgrounded();
PlayState state = UpdatePlayState_ComputePlayState(
is_remote, is_streaming, is_suspended, is_backgrounded);
SetDelegateState(state.delegate_state, state.is_idle);
@@ -1949,7 +1947,7 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote,
// the have future data state; see didLoadingProgress().
//
// TODO(sandersd): Make the delegate suspend idle players immediately when
- // hidden.
+ // in the background.
bool idle_suspended =
!is_streaming && is_stale && paused_ && !seeking_ && !overlay_enabled_;
@@ -2103,9 +2101,12 @@ void WebMediaPlayerImpl::CreateWatchTimeReporter() {
watch_time_reporter_->OnShown();
}
-bool WebMediaPlayerImpl::IsHidden() const {
+bool WebMediaPlayerImpl::IsBackgrounded() const {
DCHECK(main_task_runner_->BelongsToCurrentThread());
+ // Nothing related to the media being in the background should matter if the
+ // frame is closed. However, the delegate might call OnFrameHidden() when
+ // closed so specifically exclude this case.
return delegate_->IsFrameHidden() && !delegate_->IsFrameClosed();
}
@@ -2123,7 +2124,7 @@ void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) {
client_->activateViewportIntersectionMonitoring(activate);
}
-bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const {
+bool WebMediaPlayerImpl::ShouldPauseVideoWhenBackground() const {
#if !defined(OS_ANDROID)
// On desktop, this behavior is behind the feature flag.
if (!IsBackgroundVideoTrackOptimizationEnabled())
@@ -2134,7 +2135,7 @@ bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const {
return !hasAudio() && IsBackgroundOptimizationCandidate();
}
-bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const {
+bool WebMediaPlayerImpl::ShouldDisableVideoWhenBackground() const {
// This optimization is behind the flag on all platforms.
if (!IsBackgroundVideoTrackOptimizationEnabled())
return false;
@@ -2174,8 +2175,8 @@ bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const {
}
void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() {
- if (IsHidden()) {
- if (ShouldPauseVideoWhenHidden())
+ if (IsBackgrounded()) {
+ if (ShouldPauseVideoWhenBackground())
PauseVideoIfNeeded();
else
DisableVideoTrackIfNeeded();
@@ -2185,17 +2186,17 @@ void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() {
}
void WebMediaPlayerImpl::PauseVideoIfNeeded() {
- DCHECK(IsHidden());
+ DCHECK(IsBackgrounded());
// Don't pause video while the pipeline is stopped, resuming or seeking.
// Also if the video is paused already.
if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_ || paused_)
return;
- // OnPause() will set |paused_when_hidden_| to false and call
+ // OnPause() will set |paused_when_background_| to false and call
// UpdatePlayState(), so set the flag to true after and then return.
OnPause();
- paused_when_hidden_ = true;
+ paused_when_background_ = true;
}
void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() {
@@ -2214,13 +2215,13 @@ void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() {
}
void WebMediaPlayerImpl::DisableVideoTrackIfNeeded() {
- DCHECK(IsHidden());
+ DCHECK(IsBackgrounded());
// Don't change video track while the pipeline is resuming or seeking.
if (is_pipeline_resuming_ || seeking_)
return;
- if (!video_track_disabled_ && ShouldDisableVideoWhenHidden()) {
+ if (!video_track_disabled_ && ShouldDisableVideoWhenBackground()) {
video_track_disabled_ = true;
selectedVideoTrackChanged(nullptr);
}
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698