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_factory.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" | |
17 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
18 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "device/power_save_blocker/power_save_blocker_impl.h" |
19 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 static base::LazyInstance<AudibleMetrics>::Leaky g_audible_metrics = | 25 static base::LazyInstance<AudibleMetrics>::Leaky g_audible_metrics = |
26 LAZY_INSTANCE_INITIALIZER; | 26 LAZY_INSTANCE_INITIALIZER; |
27 | 27 |
28 } // anonymous namespace | 28 } // anonymous namespace |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 | 178 |
179 // Notify all observers the player has been "paused". | 179 // Notify all observers the player has been "paused". |
180 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents()); | 180 WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents()); |
181 for (const auto& id : removed_players) | 181 for (const auto& id : removed_players) |
182 wci->MediaStoppedPlaying(id); | 182 wci->MediaStoppedPlaying(id); |
183 } | 183 } |
184 | 184 |
185 void MediaWebContentsObserver::CreateAudioPowerSaveBlocker() { | 185 void MediaWebContentsObserver::CreateAudioPowerSaveBlocker() { |
186 DCHECK(!audio_power_save_blocker_); | 186 DCHECK(!audio_power_save_blocker_); |
187 audio_power_save_blocker_ = CreatePowerSaveBlocker( | 187 audio_power_save_blocker_ = CreatePowerSaveBlocker( |
188 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 188 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
189 PowerSaveBlocker::kReasonAudioPlayback, "Playing audio"); | 189 device::PowerSaveBlocker::kReasonAudioPlayback, "Playing audio"); |
190 } | 190 } |
191 | 191 |
192 void MediaWebContentsObserver::CreateVideoPowerSaveBlocker() { | 192 void MediaWebContentsObserver::CreateVideoPowerSaveBlocker() { |
193 DCHECK(!video_power_save_blocker_); | 193 DCHECK(!video_power_save_blocker_); |
194 DCHECK(!active_video_players_.empty()); | 194 DCHECK(!active_video_players_.empty()); |
195 video_power_save_blocker_ = CreatePowerSaveBlocker( | 195 video_power_save_blocker_ = CreatePowerSaveBlocker( |
196 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 196 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
197 PowerSaveBlocker::kReasonVideoPlayback, "Playing video"); | 197 device::PowerSaveBlocker::kReasonVideoPlayback, "Playing video"); |
198 #if defined(OS_ANDROID) | 198 #if defined(OS_ANDROID) |
199 if (web_contents()->GetNativeView()) { | 199 if (web_contents()->GetNativeView()) { |
200 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( | 200 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( |
201 web_contents()->GetNativeView())); | 201 web_contents()->GetNativeView())); |
202 static_cast<PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) | 202 static_cast<device::PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) |
203 ->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); | 203 ->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); |
204 } | 204 } |
205 #endif | 205 #endif |
206 } | 206 } |
207 | 207 |
208 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() { | 208 void MediaWebContentsObserver::MaybeReleasePowerSaveBlockers() { |
209 // If there are no more audio players and we don't have audio stream | 209 // If there are no more audio players and we don't have audio stream |
210 // monitoring, release the audio power save blocker here instead of during | 210 // monitoring, release the audio power save blocker here instead of during |
211 // NotifyNavigationStateChanged(). | 211 // NotifyNavigationStateChanged(). |
212 if (active_audio_players_.empty() && | 212 if (active_audio_players_.empty() && |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if (it == player_map->end()) | 252 if (it == player_map->end()) |
253 return; | 253 return; |
254 | 254 |
255 for (int delegate_id : it->second) | 255 for (int delegate_id : it->second) |
256 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); | 256 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); |
257 | 257 |
258 player_map->erase(it); | 258 player_map->erase(it); |
259 } | 259 } |
260 | 260 |
261 } // namespace content | 261 } // namespace content |
OLD | NEW |