Chromium Code Reviews| Index: media/blink/webmediaplayer_impl.cc |
| diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc |
| index 832433691bd68828415cd0e6ee98628d11754c88..46e3dc8698a18b3479276f54b9cf28786cc6bbbe 100644 |
| --- a/media/blink/webmediaplayer_impl.cc |
| +++ b/media/blink/webmediaplayer_impl.cc |
| @@ -1113,11 +1113,19 @@ void WebMediaPlayerImpl::OnVideoOpacityChange(bool opaque) { |
| void WebMediaPlayerImpl::OnHidden() { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| UpdatePlayState(); |
| + |
| + // If the user doesn't come back to the suspended media in some time (chosen |
| + // by dice roll) then pause the media so the user isn't surprised later. |
| + if (pipeline_controller_.IsSuspended() && !paused_) { |
|
sandersd (OOO until July 31)
2016/06/08 23:16:27
We shouldn't schedule this while casting either. P
DaleCurtis
2016/06/10 00:02:11
Done. I don't understand your concerns about HAVE_
|
| + background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
| + this, &WebMediaPlayerImpl::OnPause); |
| + } |
| } |
| void WebMediaPlayerImpl::OnShown() { |
| DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| must_suspend_ = false; |
| + background_pause_timer_.Stop(); |
| UpdatePlayState(); |
| } |
| @@ -1408,10 +1416,11 @@ void WebMediaPlayerImpl::UpdatePlayState() { |
| #else |
| bool is_remote = false; |
| #endif |
| + bool is_suspended = pipeline_controller_.IsSuspended(); |
| bool is_backgrounded = |
| IsBackgroundedSuspendEnabled() && delegate_ && delegate_->IsHidden(); |
| - PlayState state = |
| - UpdatePlayState_ComputePlayState(is_remote, is_backgrounded); |
| + PlayState state = UpdatePlayState_ComputePlayState(is_remote, is_suspended, |
| + is_backgrounded); |
| SetDelegateState(state.delegate_state); |
| SetMemoryReportingState(state.is_memory_reporting_enabled); |
| SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); |
| @@ -1502,6 +1511,7 @@ void WebMediaPlayerImpl::SetSuspendState(bool is_suspended) { |
| WebMediaPlayerImpl::PlayState |
| WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, |
| + bool is_suspended, |
| bool is_backgrounded) { |
| PlayState result; |
| @@ -1516,8 +1526,10 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, |
| bool have_future_data = |
| highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; |
| - // Background suspend is not enabled for audio-only players. |
| + // Background suspend is not enabled for audio-only players unless paused, |
| + // though in the case of audio-only the session should be kept. |
| bool background_suspended = is_backgrounded && have_metadata && hasVideo(); |
| + bool background_audio_suspended = is_backgrounded && have_metadata && paused_; |
|
sandersd (OOO until July 31)
2016/06/08 23:16:27
Should be |have_future_data| as a prerequisite for
DaleCurtis
2016/06/10 00:02:11
That's not what will happen since background_audio
|
| // Idle suspend is enabled once there is future data. We don't want to idle |
| // suspend before that because play() may never be triggered to leave the idle |
| @@ -1532,8 +1544,13 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, |
| bool idle_suspended = is_idle_ && have_future_data; |
| // Combined suspend state. |
| - result.is_suspended = |
| - is_remote || must_suspend_ || idle_suspended || background_suspended; |
| + result.is_suspended = is_remote || must_suspend_ || idle_suspended || |
| + background_suspended || background_audio_suspended; |
| + |
| + // If we're already suspended and the target state is unsuspended, check to |
| + // see if we really must resume right now or can just wait for user action. |
| + if (is_suspended && !result.is_suspended && paused_) |
|
sandersd (OOO until July 31)
2016/06/08 23:16:27
Better to move all the conditions up so that the a
DaleCurtis
2016/06/10 00:02:11
I prefer the current phrasing for readability, but
sandersd (OOO until July 31)
2016/06/10 01:15:09
I feel strongly because the this version doesn't m
DaleCurtis
2016/06/10 18:20:31
Done.
|
| + result.is_suspended = !seeking_ && have_future_data; |
| // We do not treat |playback_rate_| == 0 as paused. For the media session, |
| // being paused implies displaying a play button, which is incorrect in this |
| @@ -1571,7 +1588,7 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, |
| result.delegate_state = DelegateState::PLAYING; |
| } |
| - // It's not critical if some cases where memory usage can change are missed, |
| + // It's not critical if some cases where memory usage can change are missed, |
| // since media memory changes are usually gradual. |
| result.is_memory_reporting_enabled = |
| can_play && !result.is_suspended && !paused_; |