| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 else | 120 else |
| 121 session_controllers_manager_.OnPause(player_id); | 121 session_controllers_manager_.OnPause(player_id); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void MediaWebContentsObserver::OnMediaPlaying( | 124 void MediaWebContentsObserver::OnMediaPlaying( |
| 125 RenderFrameHost* render_frame_host, | 125 RenderFrameHost* render_frame_host, |
| 126 int delegate_id, | 126 int delegate_id, |
| 127 bool has_video, | 127 bool has_video, |
| 128 bool has_audio, | 128 bool has_audio, |
| 129 bool is_remote, | 129 bool is_remote, |
| 130 base::TimeDelta duration) { | 130 media::MediaContentType media_content_type) { |
| 131 // Ignore the videos playing remotely and don't hold the wake lock for the | 131 // Ignore the videos playing remotely and don't hold the wake lock for the |
| 132 // screen. TODO(dalecurtis): Is this correct? It means observers will not | 132 // screen. TODO(dalecurtis): Is this correct? It means observers will not |
| 133 // receive play and pause messages. | 133 // receive play and pause messages. |
| 134 if (is_remote) | 134 if (is_remote) |
| 135 return; | 135 return; |
| 136 | 136 |
| 137 const MediaPlayerId id(render_frame_host, delegate_id); | 137 const MediaPlayerId id(render_frame_host, delegate_id); |
| 138 if (has_audio) { | 138 if (has_audio) { |
| 139 AddMediaPlayerEntry(id, &active_audio_players_); | 139 AddMediaPlayerEntry(id, &active_audio_players_); |
| 140 | 140 |
| 141 // If we don't have audio stream monitoring, allocate the audio power save | 141 // If we don't have audio stream monitoring, allocate the audio power save |
| 142 // blocker here instead of during NotifyNavigationStateChanged(). | 142 // blocker here instead of during NotifyNavigationStateChanged(). |
| 143 if (!audio_power_save_blocker_ && | 143 if (!audio_power_save_blocker_ && |
| 144 !AudioStreamMonitor::monitoring_available()) { | 144 !AudioStreamMonitor::monitoring_available()) { |
| 145 CreateAudioPowerSaveBlocker(); | 145 CreateAudioPowerSaveBlocker(); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 if (has_video) { | 149 if (has_video) { |
| 150 AddMediaPlayerEntry(id, &active_video_players_); | 150 AddMediaPlayerEntry(id, &active_video_players_); |
| 151 | 151 |
| 152 // If we're not hidden and have just created a player, create a blocker. | 152 // If we're not hidden and have just created a player, create a blocker. |
| 153 if (!video_power_save_blocker_ && | 153 if (!video_power_save_blocker_ && |
| 154 !static_cast<WebContentsImpl*>(web_contents())->IsHidden()) { | 154 !static_cast<WebContentsImpl*>(web_contents())->IsHidden()) { |
| 155 CreateVideoPowerSaveBlocker(); | 155 CreateVideoPowerSaveBlocker(); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 if (!session_controllers_manager_.RequestPlay( | 159 if (!session_controllers_manager_.RequestPlay(id, has_audio, is_remote, |
| 160 id, has_audio, is_remote, duration)) { | 160 media_content_type)) { |
| 161 return; | 161 return; |
| 162 } | 162 } |
| 163 | 163 |
| 164 // Notify observers of the new player. | 164 // Notify observers of the new player. |
| 165 DCHECK(has_audio || has_video); | 165 DCHECK(has_audio || has_video); |
| 166 static_cast<WebContentsImpl*>(web_contents())->MediaStartedPlaying(id); | 166 static_cast<WebContentsImpl*>(web_contents())->MediaStartedPlaying(id); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void MediaWebContentsObserver::ClearPowerSaveBlockers( | 169 void MediaWebContentsObserver::ClearPowerSaveBlockers( |
| 170 RenderFrameHost* render_frame_host) { | 170 RenderFrameHost* render_frame_host) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (it == player_map->end()) | 255 if (it == player_map->end()) |
| 256 return; | 256 return; |
| 257 | 257 |
| 258 for (int delegate_id : it->second) | 258 for (int delegate_id : it->second) |
| 259 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); | 259 removed_players->insert(MediaPlayerId(render_frame_host, delegate_id)); |
| 260 | 260 |
| 261 player_map->erase(it); | 261 player_map->erase(it); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace content | 264 } // namespace content |
| OLD | NEW |