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

Unified Diff: chrome/browser/media/android/remote/remote_media_player_manager.cc

Issue 1634173002: Reduce and limit video poster memory usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix empty poster handling. Also clear poster url when player destroyed. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media/android/remote/remote_media_player_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/android/remote/remote_media_player_manager.cc
diff --git a/chrome/browser/media/android/remote/remote_media_player_manager.cc b/chrome/browser/media/android/remote/remote_media_player_manager.cc
index 375e7e07528e490abe8d991ea7559d27a039404b..351376507edb8bd9e17d39b4ca44ad880de547ab 100644
--- a/chrome/browser/media/android/remote/remote_media_player_manager.cc
+++ b/chrome/browser/media/android/remote/remote_media_player_manager.cc
@@ -12,6 +12,8 @@
using media::MediaPlayerAndroid;
+static const int MAX_POSTER_BITMAP_SIZE = 1024 * 1024;
+
namespace remote_media {
RemoteMediaPlayerManager::RemoteMediaPlayerManager(
@@ -50,6 +52,7 @@ void RemoteMediaPlayerManager::OnDestroyPlayer(int player_id) {
RemoteMediaPlayerBridge* player = GetRemotePlayer(player_id);
if (player)
player->OnPlayerDestroyed();
+ poster_urls_.erase(player_id);
BrowserMediaPlayerManager::OnDestroyPlayer(player_id);
}
@@ -86,27 +89,30 @@ int RemoteMediaPlayerManager::GetTabId() {
return tab->GetAndroidId();
}
-void RemoteMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) {
+void RemoteMediaPlayerManager::FetchPosterBitmap(int player_id) {
RemoteMediaPlayerBridge* player = GetRemotePlayer(player_id);
-
- if (player && url.is_empty()) {
- player->SetPosterBitmap(std::vector<SkBitmap>());
- } else {
- // TODO(aberent) OnSetPoster is called when the attributes of the video
- // element are parsed, which may be before OnInitialize is called. We are
- // here relying on the image fetch taking longer than the delay until
- // OnInitialize is called, and hence the player is created. This is not
- // guaranteed.
- content::WebContents::ImageDownloadCallback callback = base::Bind(
- &RemoteMediaPlayerManager::DidDownloadPoster,
- weak_ptr_factory_.GetWeakPtr(), player_id);
- web_contents()->DownloadImage(
- url,
- false, // is_favicon, false so that cookies will be used.
- 0, // max_bitmap_size, 0 means no limit.
- false, // normal cache policy.
- callback);
+ if (poster_urls_.count(player_id) == 0 ||
+ poster_urls_[player_id].is_empty()) {
+ if (player)
+ player->SetPosterBitmap(std::vector<SkBitmap>());
+ return;
}
+ content::WebContents::ImageDownloadCallback callback =
+ base::Bind(&RemoteMediaPlayerManager::DidDownloadPoster,
+ weak_ptr_factory_.GetWeakPtr(), player_id);
+ web_contents()->DownloadImage(
+ poster_urls_[player_id],
+ false, // is_favicon, false so that cookies will be used.
+ MAX_POSTER_BITMAP_SIZE, // max_bitmap_size, 0 means no limit.
+ false, // normal cache policy.
+ callback);
+}
+
+void RemoteMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) {
+ // OnSetPoster is called when the attibutes of the video element are parsed,
+ // which may be before OnInitialize is called, so we can't assume that the
+ // players wil exist.
+ poster_urls_[player_id] = url;
}
void RemoteMediaPlayerManager::ReleaseResources(int player_id) {
@@ -171,6 +177,9 @@ void RemoteMediaPlayerManager::SwitchToRemotePlayer(
Send(new MediaPlayerMsg_DidMediaPlayerPlay(RoutingID(), player_id));
Send(new MediaPlayerMsg_ConnectedToRemoteDevice(RoutingID(), player_id,
casting_message));
+ // The remote player will want the poster bitmap, however, to avoid wasting
+ // memory we don't fetch it until we are likely to need it.
+ FetchPosterBitmap(player_id);
}
void RemoteMediaPlayerManager::SwitchToLocalPlayer(int player_id) {
« no previous file with comments | « chrome/browser/media/android/remote/remote_media_player_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698