| Index: chrome/browser/history/top_sites.cc
|
| diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
|
| index e1e40670f3c9fde4a12d3794f869840e2c6ea734..1c01459a6123a1c84b91c142ef8f94c8a604739d 100644
|
| --- a/chrome/browser/history/top_sites.cc
|
| +++ b/chrome/browser/history/top_sites.cc
|
| @@ -253,6 +253,41 @@ bool TopSites::SetPageThumbnail(const GURL& url,
|
| return SetPageThumbnailEncoded(url, thumbnail_data, score);
|
| }
|
|
|
| +bool TopSites::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 TopSites::GetMostVisitedURLs(const GetMostVisitedURLsCallback& callback) {
|
| MostVisitedURLList filtered_urls;
|
| @@ -536,9 +571,10 @@ bool TopSites::IsFull() {
|
| TopSites::~TopSites() {
|
| }
|
|
|
| -bool TopSites::SetPageThumbnailNoDB(const GURL& url,
|
| - const base::RefCountedBytes* thumbnail_data,
|
| - const ThumbnailScore& score) {
|
| +bool TopSites::SetPageThumbnailNoDB(
|
| + const GURL& url,
|
| + const base::RefCountedMemory* thumbnail_data,
|
| + const ThumbnailScore& score) {
|
| // This should only be invoked when we know about the url.
|
| DCHECK(cache_->IsKnownURL(url));
|
|
|
| @@ -558,7 +594,7 @@ bool TopSites::SetPageThumbnailNoDB(const GURL& url,
|
| 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();
|
| @@ -566,7 +602,7 @@ bool TopSites::SetPageThumbnailNoDB(const GURL& url,
|
| }
|
|
|
| bool TopSites::SetPageThumbnailEncoded(const GURL& url,
|
| - const base::RefCountedBytes* thumbnail,
|
| + const base::RefCountedMemory* thumbnail,
|
| const ThumbnailScore& score) {
|
| if (!SetPageThumbnailNoDB(url, thumbnail, score))
|
| return false;
|
| @@ -611,14 +647,14 @@ void TopSites::RemoveTemporaryThumbnailByURL(const GURL& url) {
|
| }
|
|
|
| void TopSites::AddTemporaryThumbnail(const GURL& url,
|
| - const base::RefCountedBytes* thumbnail,
|
| + 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);
|
| }
|
|
|