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

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

Issue 2794283003: Remove MediaThrottler and MediaThrottleInfoBar (Closed)
Patch Set: Drop IPCs on webview 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) {
71 // In chrome, |g_factory| should be set to create a RemoteMediaPlayerManager,
72 // since RegisterFactory() should be called from
73 // ChromeMainDelegateAndroid::BasicStartupComplete.
74 //
75 // In webview, no factory should be set, and returning a nullptr should be
76 // handled by the caller.
72 if (g_factory) 77 if (g_factory)
DaleCurtis 2017/04/10 23:49:47 Ternary if you want.
tguilbert 2017/04/11 00:15:55 Done.
73 return g_factory(rfh); 78 return g_factory(rfh);
74 return new BrowserMediaPlayerManager(rfh); 79 return nullptr;
75 } 80 }
76 81
77 #if !defined(USE_AURA) 82 #if !defined(USE_AURA)
78 ContentViewCore* BrowserMediaPlayerManager::GetContentViewCore() const { 83 ContentViewCore* BrowserMediaPlayerManager::GetContentViewCore() const {
79 return ContentViewCoreImpl::FromWebContents(web_contents()); 84 return ContentViewCoreImpl::FromWebContents(web_contents());
80 } 85 }
81 #endif 86 #endif
82 87
83 std::unique_ptr<MediaPlayerAndroid> 88 std::unique_ptr<MediaPlayerAndroid>
84 BrowserMediaPlayerManager::CreateMediaPlayer( 89 BrowserMediaPlayerManager::CreateMediaPlayer(
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 return; 370 return;
366 371
367 AddPlayer(std::move(player), media_player_params.delegate_id); 372 AddPlayer(std::move(player), media_player_params.delegate_id);
368 } 373 }
369 374
370 void BrowserMediaPlayerManager::OnStart(int player_id) { 375 void BrowserMediaPlayerManager::OnStart(int player_id) {
371 MediaPlayerAndroid* player = GetPlayer(player_id); 376 MediaPlayerAndroid* player = GetPlayer(player_id);
372 if (!player) 377 if (!player)
373 return; 378 return;
374 379
375 if (RequestDecoderResources(player_id, false)) { 380 RequestDecoderResources(player_id, false);
376 StartInternal(player_id); 381
377 } else if (WebContentsDelegate* delegate = web_contents_->GetDelegate()){ 382 player->Start();
378 delegate->RequestMediaDecodePermission( 383 if (fullscreen_player_id_ == player_id && fullscreen_player_is_released_) {
379 web_contents_, 384 video_view_->OpenVideo();
380 base::Bind(&BrowserMediaPlayerManager::OnPlaybackPermissionGranted, 385 fullscreen_player_is_released_ = false;
381 weak_ptr_factory_.GetWeakPtr(), player_id));
382 } 386 }
383 } 387 }
384 388
385 void BrowserMediaPlayerManager::OnSeek( 389 void BrowserMediaPlayerManager::OnSeek(
386 int player_id, 390 int player_id,
387 const base::TimeDelta& time) { 391 const base::TimeDelta& time) {
388 MediaPlayerAndroid* player = GetPlayer(player_id); 392 MediaPlayerAndroid* player = GetPlayer(player_id);
389 if (player) 393 if (player)
390 player->SeekTo(time); 394 player->SeekTo(time);
391 } 395 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 players_.erase(it); 481 players_.erase(it);
478 players_.push_back(std::move(player)); 482 players_.push_back(std::move(player));
479 break; 483 break;
480 } 484 }
481 } 485 }
482 return previous_player; 486 return previous_player;
483 } 487 }
484 488
485 bool BrowserMediaPlayerManager::RequestDecoderResources( 489 bool BrowserMediaPlayerManager::RequestDecoderResources(
486 int player_id, bool temporary) { 490 int player_id, bool temporary) {
487 if (!MediaThrottler::GetInstance()->RequestDecoderResources())
488 return false;
489
490 ActivePlayerMap::iterator it; 491 ActivePlayerMap::iterator it;
491 // The player is already active, ignore it. A long running player should not 492 // The player is already active, ignore it. A long running player should not
492 // request temporary permissions. 493 // request temporary permissions.
493 if ((it = active_players_.find(player_id)) != active_players_.end()) { 494 if ((it = active_players_.find(player_id)) != active_players_.end()) {
494 DCHECK(!temporary || it->second); 495 DCHECK(!temporary || it->second);
495 return true; 496 return true;
496 } 497 }
497 498
498 if (!temporary) { 499 if (!temporary) {
499 int long_running_player = 0; 500 int long_running_player = 0;
(...skipping 18 matching lines...) Expand all
518 519
519 active_players_[player_id] = temporary; 520 active_players_[player_id] = temporary;
520 return true; 521 return true;
521 } 522 }
522 523
523 void BrowserMediaPlayerManager::OnDecoderResourcesReleased(int player_id) { 524 void BrowserMediaPlayerManager::OnDecoderResourcesReleased(int player_id) {
524 if (active_players_.find(player_id) == active_players_.end()) 525 if (active_players_.find(player_id) == active_players_.end())
525 return; 526 return;
526 527
527 active_players_.erase(player_id); 528 active_players_.erase(player_id);
528 MediaThrottler::GetInstance()->OnDecodeRequestFinished();
529 } 529 }
530 530
531 int BrowserMediaPlayerManager::RoutingID() { 531 int BrowserMediaPlayerManager::RoutingID() {
532 return render_frame_host_->GetRoutingID(); 532 return render_frame_host_->GetRoutingID();
533 } 533 }
534 534
535 bool BrowserMediaPlayerManager::Send(IPC::Message* msg) { 535 bool BrowserMediaPlayerManager::Send(IPC::Message* msg) {
536 return render_frame_host_->Send(msg); 536 return render_frame_host_->Send(msg);
537 } 537 }
538 538
539 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer( 539 void BrowserMediaPlayerManager::ReleaseFullscreenPlayer(
540 MediaPlayerAndroid* player) { 540 MediaPlayerAndroid* player) {
541 ReleasePlayer(player); 541 ReleasePlayer(player);
542 } 542 }
543 543
544 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) { 544 void BrowserMediaPlayerManager::ReleasePlayer(MediaPlayerAndroid* player) {
545 player->Release(); 545 player->Release();
546 } 546 }
547 547
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 548 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698