Index: chrome/browser/history/top_sites_likely_impl.cc |
diff --git a/chrome/browser/history/top_sites_likely_impl.cc b/chrome/browser/history/top_sites_likely_impl.cc |
index 54dc285472f35ec7b392f6fe689cadf4c8f10deb..1215ac538358c1d2c70fb21815a49b782254292b 100644 |
--- a/chrome/browser/history/top_sites_likely_impl.cc |
+++ b/chrome/browser/history/top_sites_likely_impl.cc |
@@ -233,6 +233,41 @@ bool TopSitesLikelyImpl::SetPageThumbnail(const GURL& url, |
return SetPageThumbnailEncoded(url, thumbnail_data, score); |
} |
+bool TopSitesLikelyImpl::SetPageThumbnailToJPEGBytes( |
+ const GURL& url, |
+ const base::RefCountedMemory* memory, |
+ const ThumbnailScore& score) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (!loaded_) { |
+ // TODO(sky): I need to cache these and apply them after the load |
+ // completes. |
+ return false; |
+ } |
+ |
+ bool add_temp_thumbnail = false; |
+ if (!IsKnownURL(url)) { |
+ if (!IsFull()) { |
+ add_temp_thumbnail = true; |
+ } else { |
+ return false; // This URL is not known to us. |
+ } |
+ } |
+ |
+ if (!HistoryService::CanAddURL(url)) |
+ return false; // It's not a real webpage. |
+ |
+ if (add_temp_thumbnail) { |
+ // Always remove the existing entry and then add it back. That way if we end |
+ // up with too many temp thumbnails we'll prune the oldest first. |
+ RemoveTemporaryThumbnailByURL(url); |
+ AddTemporaryThumbnail(url, memory, score); |
+ return true; |
+ } |
+ |
+ return SetPageThumbnailEncoded(url, memory, score); |
+} |
+ |
// WARNING: this function may be invoked on any thread. |
void TopSitesLikelyImpl::GetMostVisitedURLs( |
const GetMostVisitedURLsCallback& callback) { |
@@ -521,7 +556,7 @@ TopSitesLikelyImpl::~TopSitesLikelyImpl() { |
bool TopSitesLikelyImpl::SetPageThumbnailNoDB( |
const GURL& url, |
- const base::RefCountedBytes* thumbnail_data, |
+ const base::RefCountedMemory* thumbnail_data, |
const ThumbnailScore& score) { |
// This should only be invoked when we know about the url. |
DCHECK(cache_->IsKnownURL(url)); |
@@ -542,7 +577,7 @@ bool TopSitesLikelyImpl::SetPageThumbnailNoDB( |
image->thumbnail.get()) |
return false; // The one we already have is better. |
- image->thumbnail = const_cast<base::RefCountedBytes*>(thumbnail_data); |
+ image->thumbnail = const_cast<base::RefCountedMemory*>(thumbnail_data); |
image->thumbnail_score = new_score_with_redirects; |
ResetThreadSafeImageCache(); |
@@ -551,7 +586,7 @@ bool TopSitesLikelyImpl::SetPageThumbnailNoDB( |
bool TopSitesLikelyImpl::SetPageThumbnailEncoded( |
const GURL& url, |
- const base::RefCountedBytes* thumbnail, |
+ const base::RefCountedMemory* thumbnail, |
const ThumbnailScore& score) { |
if (!SetPageThumbnailNoDB(url, thumbnail, score)) |
return false; |
@@ -595,15 +630,16 @@ void TopSitesLikelyImpl::RemoveTemporaryThumbnailByURL(const GURL& url) { |
} |
} |
-void TopSitesLikelyImpl::AddTemporaryThumbnail(const GURL& url, |
- const base::RefCountedBytes* thumbnail, |
- const ThumbnailScore& score) { |
+void TopSitesLikelyImpl::AddTemporaryThumbnail( |
+ const GURL& url, |
+ const base::RefCountedMemory* thumbnail, |
+ const ThumbnailScore& score) { |
if (temp_images_.size() == kMaxTempTopImages) |
temp_images_.erase(temp_images_.begin()); |
TempImage image; |
image.first = url; |
- image.second.thumbnail = const_cast<base::RefCountedBytes*>(thumbnail); |
+ image.second.thumbnail = const_cast<base::RefCountedMemory*>(thumbnail); |
image.second.thumbnail_score = score; |
temp_images_.push_back(image); |
} |