diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-12 05:21:38 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-12 05:21:38 +0000 |
commit | 6a28dbe4309086ed12679a10ef3b4f620061e5f6 (patch) | |
tree | 7ca4c3bca0b2683573d8f7b5143249a66f5feb99 | |
parent | 94b1514f818507917b955a69608fa83c0c7f8bcd (diff) | |
download | chromium_src-6a28dbe4309086ed12679a10ef3b4f620061e5f6.zip chromium_src-6a28dbe4309086ed12679a10ef3b4f620061e5f6.tar.gz chromium_src-6a28dbe4309086ed12679a10ef3b4f620061e5f6.tar.bz2 |
Add TopSites::GetTemporaryThumbnailScore().
This will make the in-browser thumbnailing more efficient. Before this
change, we regenerated a thumbnail even when we had a good thumbnail,
if it's not yet saved (this occurred when the top site list was not yet full)
BUG=65936
TEST=confirm that the in-browser thumbnailing doesn't regenerate a thumbnail when we already have one.
Review URL: http://codereview.chromium.org/6813040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81216 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/history/top_sites.cc | 13 | ||||
-rw-r--r-- | chrome/browser/history/top_sites.h | 5 | ||||
-rw-r--r-- | chrome/browser/history/top_sites_unittest.cc | 5 | ||||
-rw-r--r-- | chrome/browser/tab_contents/thumbnail_generator.cc | 12 |
4 files changed, 31 insertions, 4 deletions
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc index 71d3316..d1ea4a4 100644 --- a/chrome/browser/history/top_sites.cc +++ b/chrome/browser/history/top_sites.cc @@ -257,6 +257,19 @@ bool TopSites::GetPageThumbnailScore(const GURL& url, return thread_safe_cache_->GetPageThumbnailScore(url, score); } +bool TopSites::GetTemporaryPageThumbnailScore(const GURL& url, + ThumbnailScore* score) { + for (TempImages::iterator i = temp_images_.begin(); i != temp_images_.end(); + ++i) { + if (i->first == url) { + *score = i->second.thumbnail_score; + return true; + } + } + return false; +} + + // Returns the index of |url| in |urls|, or -1 if not found. static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { for (size_t i = 0; i < urls.size(); i++) { diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h index 3e20488..bfe78cb 100644 --- a/chrome/browser/history/top_sites.h +++ b/chrome/browser/history/top_sites.h @@ -84,6 +84,11 @@ class TopSites // be copied to |score|. virtual bool GetPageThumbnailScore(const GURL& url, ThumbnailScore* score); + // Get a temporary thumbnail score for a given page. Returns true iff we + // have the thumbnail score. Useful when checking if we should update a + // thumbnail for a given page. The score will be copied to |score|. + bool GetTemporaryPageThumbnailScore(const GURL& url, ThumbnailScore* score); + // Invoked from History if migration is needed. If this is invoked it will // be before HistoryLoaded is invoked. void MigrateFromHistory(); diff --git a/chrome/browser/history/top_sites_unittest.cc b/chrome/browser/history/top_sites_unittest.cc index a806b8d..c197231 100644 --- a/chrome/browser/history/top_sites_unittest.cc +++ b/chrome/browser/history/top_sites_unittest.cc @@ -1098,6 +1098,11 @@ TEST_F(TopSitesTest, AddTemporaryThumbnail) { // We shouldn't get the thumnail back though (the url isn't in to sites yet). scoped_refptr<RefCountedBytes> out; EXPECT_FALSE(top_sites()->GetPageThumbnail(unknown_url, &out)); + // But we should be able to get the temporary page thumbnail score. + ThumbnailScore out_score; + EXPECT_TRUE(top_sites()->GetTemporaryPageThumbnailScore(unknown_url, + &out_score)); + EXPECT_TRUE(medium_score.Equals(out_score)); std::vector<MostVisitedURL> list; diff --git a/chrome/browser/tab_contents/thumbnail_generator.cc b/chrome/browser/tab_contents/thumbnail_generator.cc index 6acae58..f9c2d58 100644 --- a/chrome/browser/tab_contents/thumbnail_generator.cc +++ b/chrome/browser/tab_contents/thumbnail_generator.cc @@ -671,15 +671,19 @@ bool ThumbnailGenerator::ShouldUpdateThumbnail(Profile* profile, 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) + if (top_sites->IsFull() && !top_sites->IsKnownURL(url)) return false; // Skip if we don't have to udpate the existing thumbnail. ThumbnailScore current_score; - if (is_known && - top_sites->GetPageThumbnailScore(url, ¤t_score) && + if (top_sites->GetPageThumbnailScore(url, ¤t_score) && !current_score.ShouldConsiderUpdating()) return false; + // Skip if we don't have to udpate the temporary thumbnail (i.e. the one + // not yet saved). + ThumbnailScore temporary_score; + if (top_sites->GetTemporaryPageThumbnailScore(url, &temporary_score) && + !temporary_score.ShouldConsiderUpdating()) + return false; return true; } |