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

Unified Diff: media/blink/webmediaplayer_impl.h

Issue 2490783002: Refactor WebMediaPlayerDelegate interface. (Closed)
Patch Set: Fix did_play_ to only be set once per play. 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
Index: media/blink/webmediaplayer_impl.h
diff --git a/media/blink/webmediaplayer_impl.h b/media/blink/webmediaplayer_impl.h
index 9e0d97c2abd313ee331e6a6cbbdd4132bd35317e..0ff7c4513a882446f1f3bf8592f1e367c628be0b 100644
--- a/media/blink/webmediaplayer_impl.h
+++ b/media/blink/webmediaplayer_impl.h
@@ -187,9 +187,10 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
void setPoster(const blink::WebURL& poster) override;
// WebMediaPlayerDelegate::Observer implementation.
- void OnHidden() override;
- void OnShown() override;
- bool OnSuspendRequested(bool must_suspend) override;
+ void OnFrameHidden() override;
+ void OnFrameClosed() override;
+ void OnFrameShown() override;
+ void OnIdleTimeout() override;
void OnPlay() override;
void OnPause() override;
void OnVolumeMultiplierUpdate(double multiplier) override;
@@ -226,20 +227,18 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// intersection.
void ActivateViewportIntersectionMonitoring(bool activate);
- // Distinct states that |delegate_| can be in.
- // TODO(sandersd): This should move into WebMediaPlayerDelegate.
- // (Public for testing.)
+ // Distinct states that |delegate_| can be in. (Public for testing.)
enum class DelegateState {
GONE,
PLAYING,
PAUSED,
- ENDED,
};
// Playback state variables computed together in UpdatePlayState().
// (Public for testing.)
struct PlayState {
DelegateState delegate_state;
+ bool is_idle;
bool is_memory_reporting_enabled;
bool is_suspended;
};
@@ -344,7 +343,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
bool is_streaming,
bool is_suspended,
bool is_backgrounded);
- void SetDelegateState(DelegateState new_state);
+ void SetDelegateState(DelegateState new_state, bool is_idle);
void SetMemoryReportingState(bool is_memory_reporting_enabled);
void SetSuspendState(bool is_suspended);
@@ -359,6 +358,15 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// paused state after some idle timeout.
void ScheduleIdlePauseTimer();
+ // Returns |true| before HaveFutureData whenever there has been loading
+ // progress and we have not been resumed for at least kLoadingToIdleTimeout
+ // since then.
+ //
+ // This is used to delay suspension long enough for preroll to complete, which
+ // is necessay because play() will not be called before HaveFutureData (and
+ // thus we think we are idle forever).
+ bool IsPrerollAttemptNeeded();
+
void CreateWatchTimeReporter();
// Returns true if the player is hidden.
@@ -370,16 +378,6 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
blink::WebLocalFrame* frame_;
- // The playback state last reported to |delegate_|, to avoid setting duplicate
- // states. (Which can have undesired effects like resetting the idle timer.)
- DelegateState delegate_state_;
-
- // Set when OnSuspendRequested() is called with |must_suspend| unset.
- bool is_idle_;
-
- // Set when OnSuspendRequested() is called with |must_suspend| set.
- bool must_suspend_;
-
blink::WebMediaPlayer::NetworkState network_state_;
blink::WebMediaPlayer::ReadyState ready_state_;
blink::WebMediaPlayer::ReadyState highest_ready_state_;
@@ -569,8 +567,8 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
GURL fallback_url_;
bool use_fallback_path_;
- // Called some-time after OnHidden() if the media was suspended in a playing
- // state as part of the call to OnHidden().
+ // Called sometime after the media is suspended in a playing state in
+ // OnFrameHidden(), causing the state to change to paused.
base::OneShotTimer background_pause_timer_;
// Monitors the watch time of the played content.
@@ -581,17 +579,18 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
int underflow_count_;
std::unique_ptr<base::ElapsedTimer> underflow_timer_;
- // The last time didLoadingProgress() returned true.
- base::TimeTicks last_time_loading_progressed_;
+ // Used to track loading progress, used by IsPrerollAttemptNeeded().
+ // |preroll_attempt_pending_| indicates that the clock has been reset
+ // (awaiting a resume to start), while |preroll_attempt_start_time_| tracks
+ // when a preroll attempt began.
+ bool preroll_attempt_pending_;
+ base::TimeTicks preroll_attempt_start_time_;
std::unique_ptr<base::TickClock> tick_clock_;
// Monitors the player events.
base::WeakPtr<MediaObserver> observer_;
- // Whether the player is currently in autoplay muted state.
- bool autoplay_muted_ = false;
-
DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl);
};

Powered by Google App Engine
This is Rietveld 408576698