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

Side by Side Diff: content/renderer/media/renderer_webmediaplayer_delegate.h

Issue 2218963003: Added metrics for background video playback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added PowerObserver Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_
6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ 6 #define CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
11 11
12 #include "base/id_map.h" 12 #include "base/id_map.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/power_monitor/power_observer.h"
15 #include "base/time/default_tick_clock.h" 16 #include "base/time/default_tick_clock.h"
17 #include "base/time/time.h"
16 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
17 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
18 #include "content/public/renderer/render_frame_observer.h" 20 #include "content/public/renderer/render_frame_observer.h"
19 #include "media/blink/webmediaplayer_delegate.h" 21 #include "media/blink/webmediaplayer_delegate.h"
20 22
21 namespace blink { 23 namespace blink {
22 class WebMediaPlayer; 24 class WebMediaPlayer;
23 } 25 }
24 26
25 namespace media { 27 namespace media {
26 28
27 // An interface to allow a WebMediaPlayerImpl to communicate changes of state 29 // An interface to allow a WebMediaPlayerImpl to communicate changes of state
28 // to objects that need to know. 30 // to objects that need to know.
29 class CONTENT_EXPORT RendererWebMediaPlayerDelegate 31 class CONTENT_EXPORT RendererWebMediaPlayerDelegate
30 : public content::RenderFrameObserver, 32 : public content::RenderFrameObserver,
33 public NON_EXPORTED_BASE(base::PowerObserver),
31 public NON_EXPORTED_BASE(WebMediaPlayerDelegate), 34 public NON_EXPORTED_BASE(WebMediaPlayerDelegate),
32 public NON_EXPORTED_BASE( 35 public NON_EXPORTED_BASE(
33 base::SupportsWeakPtr<RendererWebMediaPlayerDelegate>) { 36 base::SupportsWeakPtr<RendererWebMediaPlayerDelegate>) {
34 public: 37 public:
35 explicit RendererWebMediaPlayerDelegate(content::RenderFrame* render_frame); 38 explicit RendererWebMediaPlayerDelegate(content::RenderFrame* render_frame);
36 ~RendererWebMediaPlayerDelegate() override; 39 ~RendererWebMediaPlayerDelegate() override;
37 40
38 // Returns true if this RenderFrame has ever seen media playback before. 41 // Returns true if this RenderFrame has ever seen media playback before.
39 bool has_played_media() const { return has_played_media_; } 42 bool has_played_media() const { return has_played_media_; }
40 43
44 // PowerObserver implementation.
45 void OnSuspend() override;
46 void OnResume() override;
47
41 // WebMediaPlayerDelegate implementation. 48 // WebMediaPlayerDelegate implementation.
42 int AddObserver(Observer* observer) override; 49 int AddObserver(Observer* observer) override;
43 void RemoveObserver(int delegate_id) override; 50 void RemoveObserver(int delegate_id) override;
44 void DidPlay(int delegate_id, 51 void DidPlay(int delegate_id,
45 bool has_video, 52 bool has_video,
46 bool has_audio, 53 bool has_audio,
47 bool is_remote, 54 bool is_remote,
48 base::TimeDelta duration) override; 55 base::TimeDelta duration) override;
49 void DidPause(int delegate_id, bool reached_end_of_stream) override; 56 void DidPause(int delegate_id, bool reached_end_of_stream) override;
50 void PlayerGone(int delegate_id) override; 57 void PlayerGone(int delegate_id) override;
(...skipping 25 matching lines...) Expand all
76 double multiplier); 83 double multiplier);
77 84
78 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion 85 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion
79 // or last removal will start or stop |idle_cleanup_timer_| respectively. 86 // or last removal will start or stop |idle_cleanup_timer_| respectively.
80 void AddIdleDelegate(int delegate_id); 87 void AddIdleDelegate(int delegate_id);
81 void RemoveIdleDelegate(int delegate_id); 88 void RemoveIdleDelegate(int delegate_id);
82 89
83 // Runs periodically to suspend idle delegates in |idle_delegate_map_|. 90 // Runs periodically to suspend idle delegates in |idle_delegate_map_|.
84 void CleanupIdleDelegates(); 91 void CleanupIdleDelegates();
85 92
93 // Setter for |is_playing_background_video_| that updates the metrics.
94 void SetIsPlayingBackgroundVideo(bool is_playing);
95
86 bool has_played_media_ = false; 96 bool has_played_media_ = false;
87 IDMap<Observer> id_map_; 97 IDMap<Observer> id_map_;
88 98
89 // Tracks which delegates have entered an idle state. After some period of 99 // Tracks which delegates have entered an idle state. After some period of
90 // inactivity these players will be suspended to release unused resources. 100 // inactivity these players will be suspended to release unused resources.
91 bool idle_cleanup_running_ = false; 101 bool idle_cleanup_running_ = false;
92 std::map<int, base::TimeTicks> idle_delegate_map_; 102 std::map<int, base::TimeTicks> idle_delegate_map_;
93 base::RepeatingTimer idle_cleanup_timer_; 103 base::RepeatingTimer idle_cleanup_timer_;
94 104
95 // Amount of time allowed to elapse after a delegate enters the paused before 105 // Amount of time allowed to elapse after a delegate enters the paused before
96 // the delegate is suspended. 106 // the delegate is suspended.
97 base::TimeDelta idle_timeout_; 107 base::TimeDelta idle_timeout_;
98 108
99 // The polling interval used for checking the delegates to see if any have 109 // The polling interval used for checking the delegates to see if any have
100 // exceeded |idle_timeout_| since their last pause state. 110 // exceeded |idle_timeout_| since their last pause state.
101 base::TimeDelta idle_cleanup_interval_; 111 base::TimeDelta idle_cleanup_interval_;
102 112
103 // Clock used for calculating when delegates have expired. May be overridden 113 // Clock used for calculating when delegates have expired. May be overridden
104 // for testing. 114 // for testing.
105 std::unique_ptr<base::DefaultTickClock> default_tick_clock_; 115 std::unique_ptr<base::DefaultTickClock> default_tick_clock_;
106 base::TickClock* tick_clock_; 116 base::TickClock* tick_clock_;
107 117
108 // If a video is playing in the background. Set when user resumes a video 118 // If a video is playing in the background. Set when user resumes a video
109 // allowing it to play and reset when either user pauses it or it goes 119 // allowing it to play and reset when either user pauses it or it goes
110 // foreground. 120 // foreground.
111 bool is_playing_background_video_ = false; 121 bool is_playing_background_video_ = false;
112 122
123 // Keeps track of when the background video playback started for metrics.
124 base::TimeTicks background_video_playing_start_time_;
125
126 // Keeps track of for how long the device was in a power suspended state.
127 base::TimeTicks power_suspended_time_;
128
113 // The currently playing local videos. Used to determine whether 129 // The currently playing local videos. Used to determine whether
114 // OnMediaDelegatePlay() should allow the videos to play in the background or 130 // OnMediaDelegatePlay() should allow the videos to play in the background or
115 // not. 131 // not.
116 std::set<int> playing_videos_; 132 std::set<int> playing_videos_;
117 133
118 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); 134 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate);
119 }; 135 };
120 136
121 } // namespace media 137 } // namespace media
122 138
123 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ 139 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698