| 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" |
| 11 #include "content/browser/media/audible_metrics.h" | 11 #include "content/browser/media/audible_metrics.h" |
| 12 #include "content/browser/media/audio_stream_monitor.h" | 12 #include "content/browser/media/audio_stream_monitor.h" |
| 13 #include "content/browser/power_save_blocker_impl.h" | 13 #include "content/browser/power_save_blocker_impl.h" |
| 14 #include "content/browser/web_contents/web_contents_impl.h" | 14 #include "content/browser/web_contents/web_contents_impl.h" |
| 15 #include "content/common/media/media_player_delegate_messages.h" | 15 #include "content/common/media/media_player_delegate_messages.h" |
| 16 #include "content/public/browser/power_save_blocker_factory.h" |
| 16 #include "content/public/browser/render_frame_host.h" | 17 #include "content/public/browser/render_frame_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 static base::LazyInstance<AudibleMetrics>::Leaky g_audible_metrics = | 25 static base::LazyInstance<AudibleMetrics>::Leaky g_audible_metrics = |
| 25 LAZY_INSTANCE_INITIALIZER; | 26 LAZY_INSTANCE_INITIALIZER; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 MaybeReleasePowerSaveBlockers(); | 174 MaybeReleasePowerSaveBlockers(); |
| 174 | 175 |
| 175 // Notify all observers the player has been "paused". | 176 // Notify all observers the player has been "paused". |
| 176 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents()); | 177 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents()); |
| 177 for (const auto& id : removed_players) | 178 for (const auto& id : removed_players) |
| 178 wci->MediaStoppedPlaying(id); | 179 wci->MediaStoppedPlaying(id); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void MediaWebContentsObserver::CreateAudioPowerSaveBlocker() { | 182 void MediaWebContentsObserver::CreateAudioPowerSaveBlocker() { |
| 182 DCHECK(!audio_power_save_blocker_); | 183 DCHECK(!audio_power_save_blocker_); |
| 183 audio_power_save_blocker_ = PowerSaveBlocker::Create( | 184 audio_power_save_blocker_ = CreatePowerSaveBlocker( |
| 184 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 185 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 185 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio"); | 186 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio"); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void MediaWebContentsObserver::CreateVideoPowerSaveBlocker() { | 189 void MediaWebContentsObserver::CreateVideoPowerSaveBlocker() { |
| 189 DCHECK(!video_power_save_blocker_); | 190 DCHECK(!video_power_save_blocker_); |
| 190 DCHECK(!active_video_players_.empty()); | 191 DCHECK(!active_video_players_.empty()); |
| 191 video_power_save_blocker_ = PowerSaveBlocker::Create( | 192 video_power_save_blocker_ = CreatePowerSaveBlocker( |
| 192 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 193 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
| 193 PowerSaveBlocker::kReasonVideoPlayback, "Playing video"); | 194 PowerSaveBlocker::kReasonVideoPlayback, "Playing video"); |
| 194 #if defined(OS_ANDROID) | 195 #if defined(OS_ANDROID) |
| 195 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) | 196 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) |
| 196 ->InitDisplaySleepBlocker(web_contents()); | 197 ->InitDisplaySleepBlocker(web_contents()); |
| 197 #endif | 198 #endif |
| 198 } | 199 } |
| 199 | 200 |
| 200 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() { | 201 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() { |
| 201 // If there are no more audio players and we don't have audio stream | 202 // If there are no more audio players and we don't have audio stream |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (it == player_map->end()) | 245 if (it == player_map->end()) |
| 245 return; | 246 return; |
| 246 | 247 |
| 247 for (int delegate_id : it->second) | 248 for (int delegate_id : it->second) |
| 248 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); | 249 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); |
| 249 | 250 |
| 250 player_map->erase(it); | 251 player_map->erase(it); |
| 251 } | 252 } |
| 252 | 253 |
| 253 } // namespace content | 254 } // namespace content |
| OLD | NEW |