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_factory.h" | |
14 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
15 #include "content/common/media/media_player_delegate_messages.h" | 14 #include "content/common/media/media_player_delegate_messages.h" |
16 #include "content/public/browser/render_frame_host.h" | 15 #include "content/public/browser/render_frame_host.h" |
17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "device/power_save_blocker/power_save_blocker.h" |
18 #include "device/power_save_blocker/power_save_blocker_impl.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 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 MaybeReleasePowerSaveBlockers(); | 177 MaybeReleasePowerSaveBlockers(); |
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_ = device::PowerSaveBlocker::CreateWithTaskRunners( |
188 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 188 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
189 device::PowerSaveBlocker::kReasonAudioPlayback, "Playing audio"); | 189 device::PowerSaveBlocker::kReasonAudioPlayback, "Playing audio", |
| 190 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
| 191 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
190 } | 192 } |
191 | 193 |
192 void MediaWebContentsObserver::CreateVideoPowerSaveBlocker() { | 194 void MediaWebContentsObserver::CreateVideoPowerSaveBlocker() { |
193 DCHECK(!video_power_save_blocker_); | 195 DCHECK(!video_power_save_blocker_); |
194 DCHECK(!active_video_players_.empty()); | 196 DCHECK(!active_video_players_.empty()); |
195 video_power_save_blocker_ = CreatePowerSaveBlocker( | 197 video_power_save_blocker_ = device::PowerSaveBlocker::CreateWithTaskRunners( |
196 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | 198 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, |
197 device::PowerSaveBlocker::kReasonVideoPlayback, "Playing video"); | 199 device::PowerSaveBlocker::kReasonVideoPlayback, "Playing video", |
| 200 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
| 201 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
198 #if defined(OS_ANDROID) | 202 #if defined(OS_ANDROID) |
199 if (web_contents()->GetNativeView()) { | 203 if (web_contents()->GetNativeView()) { |
200 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( | 204 view_weak_factory_.reset(new base::WeakPtrFactory<ui::ViewAndroid>( |
201 web_contents()->GetNativeView())); | 205 web_contents()->GetNativeView())); |
202 static_cast<device::PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) | 206 static_cast<device::PowerSaveBlockerImpl*>(video_power_save_blocker_.get()) |
203 ->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); | 207 ->InitDisplaySleepBlocker(view_weak_factory_->GetWeakPtr()); |
204 } | 208 } |
205 #endif | 209 #endif |
206 } | 210 } |
207 | 211 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 if (it == player_map->end()) | 256 if (it == player_map->end()) |
253 return; | 257 return; |
254 | 258 |
255 for (int delegate_id : it->second) | 259 for (int delegate_id : it->second) |
256 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); | 260 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); |
257 | 261 |
258 player_map->erase(it); | 262 player_map->erase(it); |
259 } | 263 } |
260 | 264 |
261 } // namespace content | 265 } // namespace content |
OLD | NEW |