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

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: Updated the browser test 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
« no previous file with comments | « no previous file | content/renderer/media/renderer_webmediaplayer_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/time/default_tick_clock.h" 15 #include "base/time/default_tick_clock.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
18 #include "content/public/renderer/render_frame_observer.h" 18 #include "content/public/renderer/render_frame_observer.h"
19 #include "media/blink/webmediaplayer_delegate.h" 19 #include "media/blink/webmediaplayer_delegate.h"
20 20
21 #if defined(OS_ANDROID)
22 #include "base/time/time.h"
23 #endif // OS_ANDROID
24
21 namespace blink { 25 namespace blink {
22 class WebMediaPlayer; 26 class WebMediaPlayer;
23 } 27 }
24 28
25 namespace media { 29 namespace media {
26 30
27 // An interface to allow a WebMediaPlayerImpl to communicate changes of state 31 // An interface to allow a WebMediaPlayerImpl to communicate changes of state
28 // to objects that need to know. 32 // to objects that need to know.
29 class CONTENT_EXPORT RendererWebMediaPlayerDelegate 33 class CONTENT_EXPORT RendererWebMediaPlayerDelegate
30 : public content::RenderFrameObserver, 34 : public content::RenderFrameObserver,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 double multiplier); 80 double multiplier);
77 81
78 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion 82 // Adds or removes a delegate from |idle_delegate_map_|. The first insertion
79 // or last removal will start or stop |idle_cleanup_timer_| respectively. 83 // or last removal will start or stop |idle_cleanup_timer_| respectively.
80 void AddIdleDelegate(int delegate_id); 84 void AddIdleDelegate(int delegate_id);
81 void RemoveIdleDelegate(int delegate_id); 85 void RemoveIdleDelegate(int delegate_id);
82 86
83 // Runs periodically to suspend idle delegates in |idle_delegate_map_|. 87 // Runs periodically to suspend idle delegates in |idle_delegate_map_|.
84 void CleanupIdleDelegates(); 88 void CleanupIdleDelegates();
85 89
90 // Setter for |is_playing_background_video_| that updates the metrics.
91 void SetIsPlayingBackgroundVideo(bool is_playing);
92
86 bool has_played_media_ = false; 93 bool has_played_media_ = false;
87 IDMap<Observer> id_map_; 94 IDMap<Observer> id_map_;
88 95
89 // Tracks which delegates have entered an idle state. After some period of 96 // Tracks which delegates have entered an idle state. After some period of
90 // inactivity these players will be suspended to release unused resources. 97 // inactivity these players will be suspended to release unused resources.
91 bool idle_cleanup_running_ = false; 98 bool idle_cleanup_running_ = false;
92 std::map<int, base::TimeTicks> idle_delegate_map_; 99 std::map<int, base::TimeTicks> idle_delegate_map_;
93 base::RepeatingTimer idle_cleanup_timer_; 100 base::RepeatingTimer idle_cleanup_timer_;
94 101
95 // Amount of time allowed to elapse after a delegate enters the paused before 102 // Amount of time allowed to elapse after a delegate enters the paused before
96 // the delegate is suspended. 103 // the delegate is suspended.
97 base::TimeDelta idle_timeout_; 104 base::TimeDelta idle_timeout_;
98 105
99 // The polling interval used for checking the delegates to see if any have 106 // The polling interval used for checking the delegates to see if any have
100 // exceeded |idle_timeout_| since their last pause state. 107 // exceeded |idle_timeout_| since their last pause state.
101 base::TimeDelta idle_cleanup_interval_; 108 base::TimeDelta idle_cleanup_interval_;
102 109
103 // Clock used for calculating when delegates have expired. May be overridden 110 // Clock used for calculating when delegates have expired. May be overridden
104 // for testing. 111 // for testing.
105 std::unique_ptr<base::DefaultTickClock> default_tick_clock_; 112 std::unique_ptr<base::DefaultTickClock> default_tick_clock_;
106 base::TickClock* tick_clock_; 113 base::TickClock* tick_clock_;
107 114
108 // If a video is playing in the background. Set when user resumes a video 115 // 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 116 // allowing it to play and reset when either user pauses it or it goes
110 // foreground. 117 // foreground.
111 bool is_playing_background_video_ = false; 118 bool is_playing_background_video_ = false;
112 119
120 #if defined(OS_ANDROID)
121 // Keeps track of when the background video playback started for metrics.
122 base::TimeTicks background_video_playing_start_time_;
123 #endif // OS_ANDROID
124
113 // The currently playing local videos. Used to determine whether 125 // The currently playing local videos. Used to determine whether
114 // OnMediaDelegatePlay() should allow the videos to play in the background or 126 // OnMediaDelegatePlay() should allow the videos to play in the background or
115 // not. 127 // not.
116 std::set<int> playing_videos_; 128 std::set<int> playing_videos_;
117 129
118 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate); 130 DISALLOW_COPY_AND_ASSIGN(RendererWebMediaPlayerDelegate);
119 }; 131 };
120 132
121 } // namespace media 133 } // namespace media
122 134
123 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_ 135 #endif // CONTENT_RENDERER_MEDIA_RENDERER_WEBMEDIAPLAYER_DELEGATE_H_
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/renderer_webmediaplayer_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698