Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: content/browser/media/android/browser_media_player_manager.cc

Issue 2794283003: Remove MediaThrottler and MediaThrottleInfoBar (Closed)
Patch Set: Deleted Java code Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/android/browser_media_player_manager.h" 5 #include "content/browser/media/android/browser_media_player_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/android/scoped_java_ref.h" 9 #include "base/android/scoped_java_ref.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h" 12 #include "content/browser/frame_host/render_frame_host_impl.h"
13 #include "content/browser/media/android/media_resource_getter_impl.h" 13 #include "content/browser/media/android/media_resource_getter_impl.h"
14 #include "content/browser/media/android/media_throttler.h"
15 #include "content/browser/media/android/media_web_contents_observer_android.h" 14 #include "content/browser/media/android/media_web_contents_observer_android.h"
16 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
17 #include "content/browser/web_contents/web_contents_impl.h" 16 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/common/media/media_player_messages_android.h" 17 #include "content/common/media/media_player_messages_android.h"
19 #include "content/public/browser/browser_context.h" 18 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/content_browser_client.h" 20 #include "content/public/browser/content_browser_client.h"
22 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_process_host.h" 22 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 61
63 // static 62 // static
64 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor( 63 void BrowserMediaPlayerManager::RegisterMediaUrlInterceptor(
65 media::MediaUrlInterceptor* media_url_interceptor) { 64 media::MediaUrlInterceptor* media_url_interceptor) {
66 media_url_interceptor_ = media_url_interceptor; 65 media_url_interceptor_ = media_url_interceptor;
67 } 66 }
68 67
69 // static 68 // static
70 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create( 69 BrowserMediaPlayerManager* BrowserMediaPlayerManager::Create(
71 RenderFrameHost* rfh) { 70 RenderFrameHost* rfh) {
72 if (g_factory) 71 // In chrome, |g_factory| should be set to create a RemoteMediaPlayerManager,
73 return g_factory(rfh); 72 // since RegisterFactory() should be called from
74 return new BrowserMediaPlayerManager(rfh); 73 // ChromeMainDelegateAndroid::BasicStartupComplete.
74 //
75 // In webview, no factory should be set, and returning a nullptr should be
76 // handled by the caller.
77 return g_factory != nullptr ? g_factory(rfh) : nullptr;
75 } 78 }
76 79
77 #if !defined(USE_AURA) 80 #if !defined(USE_AURA)
78 ContentViewCore* BrowserMediaPlayerManager::GetContentViewCore() const { 81 ContentViewCore* BrowserMediaPlayerManager::GetContentViewCore() const {
79 return ContentViewCoreImpl::FromWebContents(web_contents()); 82 return ContentViewCoreImpl::FromWebContents(web_contents());
80 } 83 }
81 #endif 84 #endif
82 85
83 std::unique_ptr<MediaPlayerAndroid> 86 std::unique_ptr<MediaPlayerAndroid>
84 BrowserMediaPlayerManager::CreateMediaPlayer( 87 BrowserMediaPlayerManager::CreateMediaPlayer(
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 return; 368 return;
366 369
367 AddPlayer(std::move(player), media_player_params.delegate_id); 370 AddPlayer(std::move(player), media_player_params.delegate_id);
368 } 371 }
369 372
370 void BrowserMediaPlayerManager::OnStart(int player_id) { 373 void BrowserMediaPlayerManager::OnStart(int player_id) {
371 MediaPlayerAndroid* player = GetPlayer(player_id); 374 MediaPlayerAndroid* player = GetPlayer(player_id);
372 if (!player) 375 if (!player)
373 return; 376 return;
374 377
375 if (RequestDecoderResources(player_id, false)) { 378 RequestDecoderResources(player_id, false);
376 StartInternal(player_id); 379
377 } else if (WebContentsDelegate* delegate = web_contents_->GetDelegate()){ 380 player->Start();
378 delegate->RequestMediaDecodePermission( 381 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) {
379 web_contents_, 382 video_view_->OpenVideo();
380 base::Bind(&BrowserMediaPlayerManager::OnPlaybackPermissionGranted, 383 fullscreen_player_is_released_ = false;
381 weak_ptr_factory_.GetWeakPtr(), player_id));
382 } 384 }
383 } 385 }
384 386
385 void BrowserMediaPlayerManager::OnSeek( 387 void BrowserMediaPlayerManager::OnSeek(
386 int player_id, 388 int player_id,
387 const base::TimeDelta& time) { 389 const base::TimeDelta& time) {
388 MediaPlayerAndroid* player = GetPlayer(player_id); 390 MediaPlayerAndroid* player = GetPlayer(player_id);
389 if (player) 391 if (player)
390 player->SeekTo(time); 392 player->SeekTo(time);
391 } 393 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 players_.erase(it); 479 players_.erase(it);
478 players_.push_back(std::move(player)); 480 players_.push_back(std::move(player));
479 break; 481 break;
480 } 482 }
481 } 483 }
482 return previous_player; 484 return previous_player;
483 } 485 }
484 486
485 bool BrowserMediaPlayerManager::RequestDecoderResources( 487 bool BrowserMediaPlayerManager::RequestDecoderResources(
486 int player_id, bool temporary) { 488 int player_id, bool temporary) {
487 if (!MediaThrottler::GetInstance()->RequestDecoderResources())
488 return false;
489
490 ActivePlayerMap::iterator it; 489 ActivePlayerMap::iterator it;
491 // The player is already active, ignore it. A long running player should not 490 // The player is already active, ignore it. A long running player should not
492 // request temporary permissions. 491 // request temporary permissions.
493 if ((it = active_players_.find(player_id)) != active_players_.end()) { 492 if ((it = active_players_.find(player_id)) != active_players_.end()) {
494 DCHECK(!temporary || it->second); 493 DCHECK(!temporary || it->second);
495 return true; 494 return true;
496 } 495 }
497 496
498 if (!temporary) { 497 if (!temporary) {
499 int long_running_player = 0; 498 int long_running_player = 0;
(...skipping 18 matching lines...) Expand all
518 517
519 active_players_[player_id] = temporary; 518 active_players_[player_id] = temporary;
520 return true; 519 return true;
521 } 520 }
522 521
523 void BrowserMediaPlayerManager::OnDecoderResourcesReleased(int player_id) { 522 void BrowserMediaPlayerManager::OnDecoderResourcesReleased(int player_id) {
524 if (active_players_.find(player_id) == active_players_.end()) 523 if (active_players_.find(player_id) == active_players_.end())
525 return; 524 return;
526 525
527 active_players_.erase(player_id); 526 active_players_.erase(player_id);
528 MediaThrottler::GetInstance()->OnDecodeRequestFinished();
529 } 527 }
530 528
531 int BrowserMediaPlayerManager::RoutingID() { 529 int BrowserMediaPlayerManager::RoutingID() {
532 return render_frame_host_->GetRoutingID(); 530 return render_frame_host_->GetRoutingID();
533 } 531 }
534 532
535 bool BrowserMediaPlayerManager::Send(IPC::Message* msg) { 533 bool BrowserMediaPlayerManager::Send(IPC::Message* msg) {
536 return render_frame_host_->Send(msg); 534 return render_frame_host_->Send(msg);
537 } 535 }
538 536
539 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer( 537 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer(
540 MediaPlayerAndroid* player) { 538 MediaPlayerAndroid* player) {
541 ReleasePlayer(player); 539 ReleasePlayer(player);
542 } 540 }
543 541
544 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { 542 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) {
545 player->Release(); 543 player->Release();
546 } 544 }
547 545
548 void BrowserMediaPlayerManager::OnPlaybackPermissionGranted(
549 int player_id, bool granted) {
550 if (!granted)
551 return;
552
553 MediaThrottler::GetInstance()->Reset();
554 StartInternal(player_id);
555 }
556
557 void BrowserMediaPlayerManager::StartInternal(int player_id) {
558 MediaPlayerAndroid* player = GetPlayer(player_id);
559 if (!player)
560 return;
561 player->Start();
562 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) {
563 video_view_->OpenVideo();
564 fullscreen_player_is_released_ = false;
565 }
566 }
567
568 } // namespace content 546 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698