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

Unified Diff: chrome/browser/tab_contents/thumbnail_generator.cc

Issue 6389001: Add heuristics to skip thumbnail generation when it's unnecessary. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor cleanup Created 9 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
Index: chrome/browser/tab_contents/thumbnail_generator.cc
diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc
index 39d61f7d6414536ca0f57e79a189078dc04c57e3..1625e8030525510dc48e606a85258d449340c3e8 100644
--- a/chrome/browser/tab_contents/thumbnail_generator.cc
+++ b/chrome/browser/tab_contents/thumbnail_generator.cc
@@ -632,11 +632,10 @@ SkBitmap ThumbnailGenerator::GetClippedBitmap(const SkBitmap& bitmap,
void ThumbnailGenerator::UpdateThumbnailIfNecessary(
TabContents* tab_contents, const GURL& url) {
- if (tab_contents->profile()->IsOffTheRecord() ||
- (url.SchemeIs("chrome") && url.host() == "newtab"))
+ history::TopSites* top_sites = tab_contents->profile()->GetTopSites();
+ // Skip if we don't need to update the thumbnail.
+ if (!ShouldUpdateThumbnail(tab_contents->profile(), top_sites, url))
return;
- // TODO(satorux): Add more conditions here to avoid unnecessary
- // thumbnail generation.
ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
const int options = ThumbnailGenerator::kClippedThumbnail;
@@ -656,10 +655,31 @@ void ThumbnailGenerator::UpdateThumbnailIfNecessary(
(clip_result == ThumbnailGenerator::kTallerThanWide ||
clip_result == ThumbnailGenerator::kNotClipped);
- history::TopSites* top_sites = tab_contents->profile()->GetTopSites();
top_sites->SetPageThumbnail(url, thumbnail, score);
- VLOG(1) << "Thumbnail taken for " << url
- << ", at_top: " << score.at_top
- << ", boring_score: " << score.boring_score
- << ", good_clipping: " << score.good_clipping;
+ VLOG(1) << "Thumbnail taken for " << url << ": " << score.ToString();
+}
+
+bool ThumbnailGenerator::ShouldUpdateThumbnail(Profile* profile,
+ history::TopSites* top_sites,
+ const GURL& url) {
+ if (!profile || !top_sites)
+ return false;
+ // Skip if it's in the off-the-record mode.
+ if (profile->IsOffTheRecord())
+ return false;
+ // Skip if the given URL is not appropriate for history.
+ if (!HistoryService::CanAddURL(url))
+ return false;
+ // Skip if the top sites list is full, and the URL is not known.
+ const bool is_known = top_sites->IsKnownURL(url);
+ if (top_sites->IsFull() && !is_known)
+ return false;
+ // Skip if we don't have to udpate the existing thumbnail.
+ ThumbnailScore current_score;
+ if (is_known &&
+ top_sites->GetPageThumbnailScore(url, &current_score) &&
+ !ShouldGenerateThumbnail(current_score))
+ return false;
+
+ return true;
}

Powered by Google App Engine
This is Rietveld 408576698