OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/android/media_player_manager_impl.h" | 5 #include "content/browser/android/media_player_manager_impl.h" |
6 | 6 |
7 #include "content/browser/android/media_resource_getter_impl.h" | 7 #include "content/browser/android/media_resource_getter_impl.h" |
8 #include "content/browser/web_contents/web_contents_view_android.h" | 8 #include "content/browser/web_contents/web_contents_view_android.h" |
9 #include "content/common/media/media_player_messages_android.h" | 9 #include "content/common/media/media_player_messages_android.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 player->SetVideoSurface(surface); | 122 player->SetVideoSurface(surface); |
123 Send(new MediaPlayerMsg_DidEnterFullscreen( | 123 Send(new MediaPlayerMsg_DidEnterFullscreen( |
124 routing_id(), player->player_id())); | 124 routing_id(), player->player_id())); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 void MediaPlayerManagerImpl::OnInitialize( | 128 void MediaPlayerManagerImpl::OnInitialize( |
129 int player_id, const GURL& url, | 129 int player_id, const GURL& url, |
130 bool is_media_source, | 130 bool is_media_source, |
131 const GURL& first_party_for_cookies) { | 131 const GURL& first_party_for_cookies) { |
132 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); | 132 RemovePlayer(player_id); |
133 it != players_.end(); ++it) { | |
134 if ((*it)->player_id() == player_id) { | |
135 players_.erase(it); | |
136 break; | |
137 } | |
138 } | |
139 | 133 |
140 RenderProcessHost* host = render_view_host()->GetProcess(); | 134 RenderProcessHost* host = render_view_host()->GetProcess(); |
141 players_.push_back(media::MediaPlayerAndroid::Create( | 135 AddPlayer(media::MediaPlayerAndroid::Create( |
142 player_id, url, is_media_source, first_party_for_cookies, | 136 player_id, url, is_media_source, first_party_for_cookies, |
143 host->GetBrowserContext()->IsOffTheRecord(), this)); | 137 host->GetBrowserContext()->IsOffTheRecord(), this)); |
144 } | 138 } |
145 | 139 |
146 media::MediaResourceGetter* MediaPlayerManagerImpl::GetMediaResourceGetter() { | 140 media::MediaResourceGetter* MediaPlayerManagerImpl::GetMediaResourceGetter() { |
147 if (!media_resource_getter_.get()) { | 141 if (!media_resource_getter_.get()) { |
148 RenderProcessHost* host = render_view_host()->GetProcess(); | 142 RenderProcessHost* host = render_view_host()->GetProcess(); |
149 BrowserContext* context = host->GetBrowserContext(); | 143 BrowserContext* context = host->GetBrowserContext(); |
150 StoragePartition* partition = host->GetStoragePartition(); | 144 StoragePartition* partition = host->GetStoragePartition(); |
151 fileapi::FileSystemContext* file_system_context = | 145 fileapi::FileSystemContext* file_system_context = |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 void MediaPlayerManagerImpl::OnReleaseResources(int player_id) { | 188 void MediaPlayerManagerImpl::OnReleaseResources(int player_id) { |
195 MediaPlayerAndroid* player = GetPlayer(player_id); | 189 MediaPlayerAndroid* player = GetPlayer(player_id); |
196 // Don't release the fullscreen player when tab visibility changes, | 190 // Don't release the fullscreen player when tab visibility changes, |
197 // it will be released when user hit the back/home button or when | 191 // it will be released when user hit the back/home button or when |
198 // OnDestroyPlayer is called. | 192 // OnDestroyPlayer is called. |
199 if (player && player_id != fullscreen_player_id_) | 193 if (player && player_id != fullscreen_player_id_) |
200 player->Release(); | 194 player->Release(); |
201 } | 195 } |
202 | 196 |
203 void MediaPlayerManagerImpl::OnDestroyPlayer(int player_id) { | 197 void MediaPlayerManagerImpl::OnDestroyPlayer(int player_id) { |
204 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); | 198 RemovePlayer(player_id); |
205 it != players_.end(); ++it) { | |
206 if ((*it)->player_id() == player_id) { | |
207 players_.erase(it); | |
208 break; | |
209 } | |
210 } | |
211 if (fullscreen_player_id_ == player_id) | 199 if (fullscreen_player_id_ == player_id) |
212 fullscreen_player_id_ = -1; | 200 fullscreen_player_id_ = -1; |
213 } | 201 } |
214 | 202 |
215 void MediaPlayerManagerImpl::DestroyAllMediaPlayers() { | 203 void MediaPlayerManagerImpl::DestroyAllMediaPlayers() { |
216 players_.clear(); | 204 players_.clear(); |
217 if (fullscreen_player_id_ != -1) { | 205 if (fullscreen_player_id_ != -1) { |
218 video_view_.DestroyContentVideoView(); | 206 video_view_.DestroyContentVideoView(); |
219 fullscreen_player_id_ = -1; | 207 fullscreen_player_id_ = -1; |
220 } | 208 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 routing_id(), (*it)->player_id())); | 372 routing_id(), (*it)->player_id())); |
385 } | 373 } |
386 } | 374 } |
387 } | 375 } |
388 | 376 |
389 void MediaPlayerManagerImpl::ReleaseMediaResources( | 377 void MediaPlayerManagerImpl::ReleaseMediaResources( |
390 MediaPlayerAndroid* player) { | 378 MediaPlayerAndroid* player) { |
391 // Nothing needs to be done. | 379 // Nothing needs to be done. |
392 } | 380 } |
393 | 381 |
| 382 void MediaPlayerManagerImpl::AddPlayer(MediaPlayerAndroid* player) { |
| 383 DCHECK(!GetPlayer(player->player_id())); |
| 384 players_.push_back(player); |
| 385 } |
| 386 |
| 387 void MediaPlayerManagerImpl::RemovePlayer(int player_id) { |
| 388 for (ScopedVector<MediaPlayerAndroid>::iterator it = players_.begin(); |
| 389 it != players_.end(); ++it) { |
| 390 if ((*it)->player_id() == player_id) { |
| 391 players_.erase(it); |
| 392 break; |
| 393 } |
| 394 } |
| 395 } |
| 396 |
394 } // namespace content | 397 } // namespace content |
OLD | NEW |