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

Side by Side Diff: content/browser/media/media_web_contents_observer.cc

Issue 2496173003: Communicate audio state to renderer process on Android. (Closed)
Patch Set: Second iteration Created 4 years, 1 month 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "content/browser/media/media_web_contents_observer.h" 5 #include "content/browser/media/media_web_contents_observer.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 25 matching lines...) Expand all
36 g_audible_metrics.Get().UpdateAudibleWebContentsState(web_contents(), false); 36 g_audible_metrics.Get().UpdateAudibleWebContentsState(web_contents(), false);
37 } 37 }
38 38
39 void MediaWebContentsObserver::RenderFrameDeleted( 39 void MediaWebContentsObserver::RenderFrameDeleted(
40 RenderFrameHost* render_frame_host) { 40 RenderFrameHost* render_frame_host) {
41 ClearPowerSaveBlockers(render_frame_host); 41 ClearPowerSaveBlockers(render_frame_host);
42 session_controllers_manager_.RenderFrameDeleted(render_frame_host); 42 session_controllers_manager_.RenderFrameDeleted(render_frame_host);
43 } 43 }
44 44
45 void MediaWebContentsObserver::MaybeUpdateAudibleState() { 45 void MediaWebContentsObserver::MaybeUpdateAudibleState() {
46 if (!AudioStreamMonitor::monitoring_available()) 46 if (!AudioStreamMonitor::power_level_monitoring_available())
DaleCurtis 2016/11/15 19:26:01 I think this can be removed now as well as some of
altimin 2016/11/16 12:52:46 I'm a little hesitant about it — it is really a go
DaleCurtis 2016/11/16 22:16:51 Sorry if I was unclear, there should be no behavio
altimin 2016/11/17 16:13:26 Oh, I finally figured it out (previously I thought
47 return; 47 return;
48 48
49 AudioStreamMonitor* audio_stream_monitor = 49 AudioStreamMonitor* audio_stream_monitor =
50 static_cast<WebContentsImpl*>(web_contents())->audio_stream_monitor(); 50 static_cast<WebContentsImpl*>(web_contents())->audio_stream_monitor();
51 51
52 if (audio_stream_monitor->WasRecentlyAudible()) { 52 if (audio_stream_monitor->WasRecentlyAudible()) {
53 if (!audio_power_save_blocker_) 53 if (!audio_power_save_blocker_)
54 CreateAudioPowerSaveBlocker(); 54 CreateAudioPowerSaveBlocker();
55 } else { 55 } else {
56 audio_power_save_blocker_.reset(); 56 audio_power_save_blocker_.reset();
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (is_remote) 131 if (is_remote)
132 return; 132 return;
133 133
134 const MediaPlayerId id(render_frame_host, delegate_id); 134 const MediaPlayerId id(render_frame_host, delegate_id);
135 if (has_audio) { 135 if (has_audio) {
136 AddMediaPlayerEntry(id, &active_audio_players_); 136 AddMediaPlayerEntry(id, &active_audio_players_);
137 137
138 // If we don't have audio stream monitoring, allocate the audio power save 138 // If we don't have audio stream monitoring, allocate the audio power save
139 // blocker here instead of during NotifyNavigationStateChanged(). 139 // blocker here instead of during NotifyNavigationStateChanged().
140 if (!audio_power_save_blocker_ && 140 if (!audio_power_save_blocker_ &&
141 !AudioStreamMonitor::monitoring_available()) { 141 !AudioStreamMonitor::power_level_monitoring_available()) {
142 CreateAudioPowerSaveBlocker(); 142 CreateAudioPowerSaveBlocker();
143 } 143 }
144 } 144 }
145 145
146 if (has_video) { 146 if (has_video) {
147 AddMediaPlayerEntry(id, &active_video_players_); 147 AddMediaPlayerEntry(id, &active_video_players_);
148 148
149 // If we're not hidden and have just created a player, create a blocker. 149 // If we're not hidden and have just created a player, create a blocker.
150 if (!video_power_save_blocker_ && 150 if (!video_power_save_blocker_ &&
151 !static_cast<WebContentsImpl*>(web_contents())->IsHidden()) { 151 !static_cast<WebContentsImpl*>(web_contents())->IsHidden()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 web_contents()->GetNativeView()); 201 web_contents()->GetNativeView());
202 } 202 }
203 #endif 203 #endif
204 } 204 }
205 205
206 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() { 206 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() {
207 // If there are no more audio players and we don't have audio stream 207 // If there are no more audio players and we don't have audio stream
208 // monitoring, release the audio power save blocker here instead of during 208 // monitoring, release the audio power save blocker here instead of during
209 // NotifyNavigationStateChanged(). 209 // NotifyNavigationStateChanged().
210 if (active_audio_players_.empty() && 210 if (active_audio_players_.empty() &&
211 !AudioStreamMonitor::monitoring_available()) { 211 !AudioStreamMonitor::power_level_monitoring_available()) {
212 audio_power_save_blocker_.reset(); 212 audio_power_save_blocker_.reset();
213 } 213 }
214 214
215 // If there are no more video players, clear the video power save blocker. 215 // If there are no more video players, clear the video power save blocker.
216 if (active_video_players_.empty()) 216 if (active_video_players_.empty())
217 video_power_save_blocker_.reset(); 217 video_power_save_blocker_.reset();
218 } 218 }
219 219
220 void MediaWebContentsObserver::AddMediaPlayerEntry( 220 void MediaWebContentsObserver::AddMediaPlayerEntry(
221 const MediaPlayerId& id, 221 const MediaPlayerId& id,
(...skipping 28 matching lines...) Expand all
250 if (it == player_map->end()) 250 if (it == player_map->end())
251 return; 251 return;
252 252
253 for (int delegate_id : it->second) 253 for (int delegate_id : it->second)
254 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); 254 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id));
255 255
256 player_map->erase(it); 256 player_map->erase(it);
257 } 257 }
258 258
259 } // namespace content 259 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698