OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/history/top_sites_likely_impl.h" | 5 #include "chrome/browser/history/top_sites_likely_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return false; // It's not a real webpage. | 219 return false; // It's not a real webpage. |
220 | 220 |
221 scoped_refptr<base::RefCountedBytes> thumbnail_data; | 221 scoped_refptr<base::RefCountedBytes> thumbnail_data; |
222 if (!EncodeBitmap(thumbnail, &thumbnail_data)) | 222 if (!EncodeBitmap(thumbnail, &thumbnail_data)) |
223 return false; | 223 return false; |
224 | 224 |
225 if (add_temp_thumbnail) { | 225 if (add_temp_thumbnail) { |
226 // Always remove the existing entry and then add it back. That way if we end | 226 // Always remove the existing entry and then add it back. That way if we end |
227 // up with too many temp thumbnails we'll prune the oldest first. | 227 // up with too many temp thumbnails we'll prune the oldest first. |
228 RemoveTemporaryThumbnailByURL(url); | 228 RemoveTemporaryThumbnailByURL(url); |
229 AddTemporaryThumbnail(url, thumbnail_data, score); | 229 AddTemporaryThumbnail(url, thumbnail_data.get(), score); |
230 return true; | 230 return true; |
231 } | 231 } |
232 | 232 |
233 return SetPageThumbnailEncoded(url, thumbnail_data, score); | 233 return SetPageThumbnailEncoded(url, thumbnail_data.get(), score); |
234 } | 234 } |
235 | 235 |
236 bool TopSitesLikelyImpl::SetPageThumbnailToJPEGBytes( | 236 bool TopSitesLikelyImpl::SetPageThumbnailToJPEGBytes( |
237 const GURL& url, | 237 const GURL& url, |
238 const base::RefCountedMemory* memory, | 238 const base::RefCountedMemory* memory, |
239 const ThumbnailScore& score) { | 239 const ThumbnailScore& score) { |
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
241 | 241 |
242 if (!loaded_) { | 242 if (!loaded_) { |
243 // TODO(sky): I need to cache these and apply them after the load | 243 // TODO(sky): I need to cache these and apply them after the load |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 DCHECK_EQ(history_state_, HISTORY_MIGRATING); | 363 DCHECK_EQ(history_state_, HISTORY_MIGRATING); |
364 | 364 |
365 history_state_ = HISTORY_LOADED; | 365 history_state_ = HISTORY_LOADED; |
366 | 366 |
367 SetTopSites(data.most_visited); | 367 SetTopSites(data.most_visited); |
368 | 368 |
369 for (size_t i = 0; i < data.most_visited.size(); ++i) { | 369 for (size_t i = 0; i < data.most_visited.size(); ++i) { |
370 URLToThumbnailMap::const_iterator image_i = | 370 URLToThumbnailMap::const_iterator image_i = |
371 data.url_to_thumbnail_map.find(data.most_visited[i].url); | 371 data.url_to_thumbnail_map.find(data.most_visited[i].url); |
372 if (image_i != data.url_to_thumbnail_map.end()) { | 372 if (image_i != data.url_to_thumbnail_map.end()) { |
373 SetPageThumbnailEncoded(data.most_visited[i].url, | 373 SetPageThumbnailEncoded( |
374 image_i->second, | 374 data.most_visited[i].url, image_i->second.get(), ThumbnailScore()); |
375 ThumbnailScore()); | |
376 } | 375 } |
377 } | 376 } |
378 | 377 |
379 MoveStateToLoaded(); | 378 MoveStateToLoaded(); |
380 | 379 |
381 ResetThreadSafeImageCache(); | 380 ResetThreadSafeImageCache(); |
382 | 381 |
383 // We've scheduled all the thumbnails and top sites to be written to the top | 382 // We've scheduled all the thumbnails and top sites to be written to the top |
384 // sites db, but it hasn't happened yet. Schedule a request on the db thread | 383 // sites db, but it hasn't happened yet. Schedule a request on the db thread |
385 // that notifies us when done. When done we'll know everything was written and | 384 // that notifies us when done. When done we'll know everything was written and |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 // See if we have any tmp thumbnails for the new sites. | 788 // See if we have any tmp thumbnails for the new sites. |
790 if (!temp_images_.empty()) { | 789 if (!temp_images_.empty()) { |
791 for (size_t i = 0; i < top_sites.size(); ++i) { | 790 for (size_t i = 0; i < top_sites.size(); ++i) { |
792 const MostVisitedURL& mv = top_sites[i]; | 791 const MostVisitedURL& mv = top_sites[i]; |
793 GURL canonical_url = cache_->GetCanonicalURL(mv.url); | 792 GURL canonical_url = cache_->GetCanonicalURL(mv.url); |
794 // At the time we get the thumbnail redirects aren't known, so we have to | 793 // At the time we get the thumbnail redirects aren't known, so we have to |
795 // iterate through all the images. | 794 // iterate through all the images. |
796 for (TempImages::iterator it = temp_images_.begin(); | 795 for (TempImages::iterator it = temp_images_.begin(); |
797 it != temp_images_.end(); ++it) { | 796 it != temp_images_.end(); ++it) { |
798 if (canonical_url == cache_->GetCanonicalURL(it->first)) { | 797 if (canonical_url == cache_->GetCanonicalURL(it->first)) { |
799 SetPageThumbnailEncoded(mv.url, | 798 SetPageThumbnailEncoded( |
800 it->second.thumbnail, | 799 mv.url, it->second.thumbnail.get(), it->second.thumbnail_score); |
801 it->second.thumbnail_score); | |
802 temp_images_.erase(it); | 800 temp_images_.erase(it); |
803 break; | 801 break; |
804 } | 802 } |
805 } | 803 } |
806 } | 804 } |
807 } | 805 } |
808 | 806 |
809 if (top_sites.size() >= kTopSitesNumber) | 807 if (top_sites.size() >= kTopSitesNumber) |
810 temp_images_.clear(); | 808 temp_images_.clear(); |
811 | 809 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 SetTopSites(pages); | 939 SetTopSites(pages); |
942 | 940 |
943 // Used only in testing. | 941 // Used only in testing. |
944 content::NotificationService::current()->Notify( | 942 content::NotificationService::current()->Notify( |
945 chrome::NOTIFICATION_TOP_SITES_UPDATED, | 943 chrome::NOTIFICATION_TOP_SITES_UPDATED, |
946 content::Source<TopSitesLikelyImpl>(this), | 944 content::Source<TopSitesLikelyImpl>(this), |
947 content::Details<CancelableRequestProvider::Handle>(&handle)); | 945 content::Details<CancelableRequestProvider::Handle>(&handle)); |
948 } | 946 } |
949 | 947 |
950 } // namespace history | 948 } // namespace history |
OLD | NEW |