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

Unified Diff: chrome/browser/android/thumbnail/thumbnail_cache.cc

Issue 2244783005: Android: Don't evict thumbnails for last visible tab on stop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Android: Don't evict thumbnails for last visible tab on stop Created 4 years, 4 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
Index: chrome/browser/android/thumbnail/thumbnail_cache.cc
diff --git a/chrome/browser/android/thumbnail/thumbnail_cache.cc b/chrome/browser/android/thumbnail/thumbnail_cache.cc
index 307bbe382983e3f57b8e360b8947001577c54a96..f39525cd3bc10d7d416e8ff956cc8fab373440ba 100644
--- a/chrome/browser/android/thumbnail/thumbnail_cache.cc
+++ b/chrome/browser/android/thumbnail/thumbnail_cache.cc
@@ -8,6 +8,7 @@
#include <cmath>
#include <utility>
+#include "base/android/application_status_listener.h"
#include "base/android/path_utils.h"
#include "base/big_endian.h"
#include "base/files/file.h"
@@ -131,6 +132,8 @@ ThumbnailCache::ThumbnailCache(size_t default_cache_size,
ui_resource_provider_(NULL),
weak_factory_(this) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ memory_pressure_.reset(new base::MemoryPressureListener(
+ base::Bind(&ThumbnailCache::OnMemoryPressure, base::Unretained(this))));
}
ThumbnailCache::~ThumbnailCache() {
@@ -445,8 +448,23 @@ void ThumbnailCache::RemoveFromReadQueue(TabId tab_id) {
}
void ThumbnailCache::OnUIResourcesWereEvicted() {
- cache_.Clear();
- approximation_cache_.Clear();
+ if (visible_ids_.empty()) {
+ cache_.Clear();
+ approximation_cache_.Clear();
+ } else {
+ TabId last_tab = visible_ids_.front();
+ std::unique_ptr<Thumbnail> thumbnail = cache_.Remove(last_tab);
+ cache_.Clear();
+ std::unique_ptr<Thumbnail> approximation =
+ approximation_cache_.Remove(last_tab);
+ approximation_cache_.Clear();
+
+ // Keep the thumbnail for app resume if it wasn't uploaded yet.
+ if (thumbnail.get() && !thumbnail->ui_resource_id())
+ cache_.Put(last_tab, std::move(thumbnail));
+ if (approximation.get() && !approximation->ui_resource_id())
+ approximation_cache_.Put(last_tab, std::move(approximation));
+ }
}
void ThumbnailCache::InvalidateCachedThumbnail(Thumbnail* thumbnail) {
@@ -613,7 +631,12 @@ void ThumbnailCache::PostCompressionTask(
if (thumbnail->time_stamp() != time_stamp)
return;
thumbnail->SetCompressedBitmap(compressed_data, content_size);
- thumbnail->CreateUIResource();
+ // Don't upload the texture if we are being paused/stopped because
+ // the context will go away anyways.
+ if (base::android::ApplicationStatusListener::GetState() ==
+ base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
+ thumbnail->CreateUIResource();
+ }
}
WriteThumbnailIfNecessary(tab_id, std::move(compressed_data), scale,
content_size);
@@ -909,3 +932,11 @@ std::pair<SkBitmap, float> ThumbnailCache::CreateApproximation(
return std::make_pair(dst_bitmap, new_scale * scale);
}
+
+void ThumbnailCache::OnMemoryPressure(
+ base::MemoryPressureListener::MemoryPressureLevel level) {
+ if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
+ cache_.Clear();
+ approximation_cache_.Clear();
+ }
+}
« no previous file with comments | « chrome/browser/android/thumbnail/thumbnail_cache.h ('k') | content/browser/renderer_host/render_widget_host_view_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698