| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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.h" | 5 #include "chrome/browser/history/top_sites.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/profile.h" | 8 #include "chrome/browser/profile.h" |
| 9 #include "chrome/browser/history/top_sites_database.h" | 9 #include "chrome/browser/history/top_sites_database.h" |
| 10 #include "chrome/browser/history/page_usage_data.h" | 10 #include "chrome/browser/history/page_usage_data.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 { | 40 { |
| 41 AutoLock lock(lock_); | 41 AutoLock lock(lock_); |
| 42 MostVisitedURLList top_urls = db_->GetTopURLs(); | 42 MostVisitedURLList top_urls = db_->GetTopURLs(); |
| 43 StoreMostVisited(&top_urls); | 43 StoreMostVisited(&top_urls); |
| 44 } // Lock is released here. | 44 } // Lock is released here. |
| 45 | 45 |
| 46 for (size_t i = 0; i < top_sites_.size(); i++) { | 46 for (size_t i = 0; i < top_sites_.size(); i++) { |
| 47 MostVisitedURL url = top_sites_[i]; | 47 MostVisitedURL url = top_sites_[i]; |
| 48 Images thumbnail; | 48 Images thumbnail; |
| 49 if (db_->GetPageThumbnail(url, &thumbnail)) { | 49 if (db_->GetPageThumbnail(url, &thumbnail)) { |
| 50 SetPageThumbnail(url.url, thumbnail.thumbnail, thumbnail.thumbnail_score); | 50 SetPageThumbnailNoDB(url.url, thumbnail.thumbnail, |
| 51 thumbnail.thumbnail_score); |
| 51 } | 52 } |
| 52 } | 53 } |
| 53 } | 54 } |
| 54 | 55 |
| 55 // Public wrapper that encodes the bitmap into RefCountedBytes. | 56 // Public function that encodes the bitmap into RefCountedBytes and |
| 57 // updates the database. |
| 56 bool TopSites::SetPageThumbnail(const GURL& url, | 58 bool TopSites::SetPageThumbnail(const GURL& url, |
| 57 const SkBitmap& thumbnail, | 59 const SkBitmap& thumbnail, |
| 58 const ThumbnailScore& score) { | 60 const ThumbnailScore& score) { |
| 59 scoped_refptr<RefCountedBytes> thumbnail_data = new RefCountedBytes; | 61 scoped_refptr<RefCountedBytes> thumbnail_data = new RefCountedBytes; |
| 60 SkAutoLockPixels thumbnail_lock(thumbnail); | 62 SkAutoLockPixels thumbnail_lock(thumbnail); |
| 61 bool encoded = gfx::JPEGCodec::Encode( | 63 bool encoded = gfx::JPEGCodec::Encode( |
| 62 reinterpret_cast<unsigned char*>(thumbnail.getAddr32(0, 0)), | 64 reinterpret_cast<unsigned char*>(thumbnail.getAddr32(0, 0)), |
| 63 gfx::JPEGCodec::FORMAT_BGRA, thumbnail.width(), | 65 gfx::JPEGCodec::FORMAT_BGRA, thumbnail.width(), |
| 64 thumbnail.height(), | 66 thumbnail.height(), |
| 65 static_cast<int>(thumbnail.rowBytes()), 90, | 67 static_cast<int>(thumbnail.rowBytes()), 90, |
| 66 &thumbnail_data->data); | 68 &thumbnail_data->data); |
| 67 if (!encoded) | 69 if (!encoded) |
| 68 return false; | 70 return false; |
| 69 return SetPageThumbnail(url, thumbnail_data, score); | 71 if (!SetPageThumbnailNoDB(url, thumbnail_data, score)) |
| 72 return false; |
| 73 |
| 74 // Update the database. |
| 75 if (!db_.get()) |
| 76 return true; |
| 77 std::map<GURL, size_t>::iterator found = canonical_urls_.find(url); |
| 78 if (found == canonical_urls_.end()) |
| 79 return false; |
| 80 size_t index = found->second; |
| 81 |
| 82 MostVisitedURL& most_visited = top_sites_[index]; |
| 83 db_->SetPageThumbnail(most_visited, index, top_images_[most_visited.url]); |
| 84 return true; |
| 70 } | 85 } |
| 71 | 86 |
| 72 // private | 87 // private |
| 73 bool TopSites::SetPageThumbnail(const GURL& url, | 88 bool TopSites::SetPageThumbnailNoDB(const GURL& url, |
| 74 const RefCountedBytes* thumbnail_data, | 89 const RefCountedBytes* thumbnail_data, |
| 75 const ThumbnailScore& score) { | 90 const ThumbnailScore& score) { |
| 76 AutoLock lock(lock_); | 91 AutoLock lock(lock_); |
| 77 | 92 |
| 78 std::map<GURL, size_t>::iterator found = canonical_urls_.find(url); | 93 std::map<GURL, size_t>::iterator found = canonical_urls_.find(url); |
| 79 if (found == canonical_urls_.end()) | 94 if (found == canonical_urls_.end()) |
| 80 return false; // This URL is not known to us. | 95 return false; // This URL is not known to us. |
| 81 MostVisitedURL& most_visited = top_sites_[found->second]; | 96 MostVisitedURL& most_visited = top_sites_[found->second]; |
| 82 Images& image = top_images_[most_visited.url]; | 97 Images& image = top_images_[most_visited.url]; |
| 83 | 98 |
| 84 // When comparing the thumbnail scores, we need to take into account the | 99 // When comparing the thumbnail scores, we need to take into account the |
| 85 // redirect hops, which are not generated when the thumbnail is because the | 100 // redirect hops, which are not generated when the thumbnail is because the |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 MostVisitedURLList pages) { | 288 MostVisitedURLList pages) { |
| 274 AutoLock lock(lock_); | 289 AutoLock lock(lock_); |
| 275 UpdateMostVisited(&pages); | 290 UpdateMostVisited(&pages); |
| 276 } | 291 } |
| 277 | 292 |
| 278 void TopSites::SetMockHistoryService(MockHistoryService* mhs) { | 293 void TopSites::SetMockHistoryService(MockHistoryService* mhs) { |
| 279 mock_history_service_ = mhs; | 294 mock_history_service_ = mhs; |
| 280 } | 295 } |
| 281 | 296 |
| 282 } // namespace history | 297 } // namespace history |
| OLD | NEW |