| OLD | NEW |
| 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 Loading... |
| 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()) | |
| 47 return; | |
| 48 | |
| 49 AudioStreamMonitor* audio_stream_monitor = | 46 AudioStreamMonitor* audio_stream_monitor = |
| 50 static_cast<WebContentsImpl*>(web_contents())->audio_stream_monitor(); | 47 static_cast<WebContentsImpl*>(web_contents())->audio_stream_monitor(); |
| 51 | 48 |
| 52 if (audio_stream_monitor->WasRecentlyAudible()) { | 49 if (audio_stream_monitor->WasRecentlyAudible()) { |
| 53 if (!audio_power_save_blocker_) | 50 if (!audio_power_save_blocker_) |
| 54 CreateAudioPowerSaveBlocker(); | 51 CreateAudioPowerSaveBlocker(); |
| 55 } else { | 52 } else { |
| 56 audio_power_save_blocker_.reset(); | 53 audio_power_save_blocker_.reset(); |
| 57 } | 54 } |
| 58 | 55 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 bool has_audio, | 122 bool has_audio, |
| 126 bool is_remote, | 123 bool is_remote, |
| 127 media::MediaContentType media_content_type) { | 124 media::MediaContentType media_content_type) { |
| 128 // Ignore the videos playing remotely and don't hold the wake lock for the | 125 // Ignore the videos playing remotely and don't hold the wake lock for the |
| 129 // screen. TODO(dalecurtis): Is this correct? It means observers will not | 126 // screen. TODO(dalecurtis): Is this correct? It means observers will not |
| 130 // receive play and pause messages. | 127 // receive play and pause messages. |
| 131 if (is_remote) | 128 if (is_remote) |
| 132 return; | 129 return; |
| 133 | 130 |
| 134 const MediaPlayerId id(render_frame_host, delegate_id); | 131 const MediaPlayerId id(render_frame_host, delegate_id); |
| 135 if (has_audio) { | 132 if (has_audio) |
| 136 AddMediaPlayerEntry(id, &active_audio_players_); | 133 AddMediaPlayerEntry(id, &active_audio_players_); |
| 137 | 134 |
| 138 // If we don't have audio stream monitoring, allocate the audio power save | |
| 139 // blocker here instead of during NotifyNavigationStateChanged(). | |
| 140 if (!audio_power_save_blocker_ && | |
| 141 !AudioStreamMonitor::monitoring_available()) { | |
| 142 CreateAudioPowerSaveBlocker(); | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 if (has_video) { | 135 if (has_video) { |
| 147 AddMediaPlayerEntry(id, &active_video_players_); | 136 AddMediaPlayerEntry(id, &active_video_players_); |
| 148 | 137 |
| 149 // If we're not hidden and have just created a player, create a blocker. | 138 // If we're not hidden and have just created a player, create a blocker. |
| 150 if (!video_power_save_blocker_ && | 139 if (!video_power_save_blocker_ && |
| 151 !static_cast<WebContentsImpl*>(web_contents())->IsHidden()) { | 140 !static_cast<WebContentsImpl*>(web_contents())->IsHidden()) { |
| 152 CreateVideoPowerSaveBlocker(); | 141 CreateVideoPowerSaveBlocker(); |
| 153 } | 142 } |
| 154 } | 143 } |
| 155 | 144 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 186 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 198 #if defined(OS_ANDROID) | 187 #if defined(OS_ANDROID) |
| 199 if (web_contents()->GetNativeView()) { | 188 if (web_contents()->GetNativeView()) { |
| 200 video_power_save_blocker_.get()->InitDisplaySleepBlocker( | 189 video_power_save_blocker_.get()->InitDisplaySleepBlocker( |
| 201 web_contents()->GetNativeView()); | 190 web_contents()->GetNativeView()); |
| 202 } | 191 } |
| 203 #endif | 192 #endif |
| 204 } | 193 } |
| 205 | 194 |
| 206 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() { | 195 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() { |
| 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 | |
| 209 // NotifyNavigationStateChanged(). | |
| 210 if (active_audio_players_.empty() && | |
| 211 !AudioStreamMonitor::monitoring_available()) { | |
| 212 audio_power_save_blocker_.reset(); | |
| 213 } | |
| 214 | |
| 215 // If there are no more video players, clear the video power save blocker. | 196 // If there are no more video players, clear the video power save blocker. |
| 216 if (active_video_players_.empty()) | 197 if (active_video_players_.empty()) |
| 217 video_power_save_blocker_.reset(); | 198 video_power_save_blocker_.reset(); |
| 218 } | 199 } |
| 219 | 200 |
| 220 void MediaWebContentsObserver::AddMediaPlayerEntry( | 201 void MediaWebContentsObserver::AddMediaPlayerEntry( |
| 221 const MediaPlayerId& id, | 202 const MediaPlayerId& id, |
| 222 ActiveMediaPlayerMap* player_map) { | 203 ActiveMediaPlayerMap* player_map) { |
| 223 (*player_map)[id.first].insert(id.second); | 204 (*player_map)[id.first].insert(id.second); |
| 224 } | 205 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 250 if (it == player_map->end()) | 231 if (it == player_map->end()) |
| 251 return; | 232 return; |
| 252 | 233 |
| 253 for (int delegate_id : it->second) | 234 for (int delegate_id : it->second) |
| 254 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); | 235 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); |
| 255 | 236 |
| 256 player_map->erase(it); | 237 player_map->erase(it); |
| 257 } | 238 } |
| 258 | 239 |
| 259 } // namespace content | 240 } // namespace content |
| OLD | NEW |