OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 const ThumbnailScore& score) { | 174 const ThumbnailScore& score) { |
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
176 | 176 |
177 if (!loaded_) { | 177 if (!loaded_) { |
178 // TODO(sky): I need to cache these and apply them after the load | 178 // TODO(sky): I need to cache these and apply them after the load |
179 // completes. | 179 // completes. |
180 return false; | 180 return false; |
181 } | 181 } |
182 | 182 |
183 bool add_temp_thumbnail = false; | 183 bool add_temp_thumbnail = false; |
184 if (!cache_->IsKnownURL(url)) { | 184 if (!IsKnownURL(url)) { |
185 if (cache_->top_sites().size() < kTopSitesNumber) { | 185 if (!IsFull()) { |
186 add_temp_thumbnail = true; | 186 add_temp_thumbnail = true; |
187 } else { | 187 } else { |
188 return false; // This URL is not known to us. | 188 return false; // This URL is not known to us. |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 if (!HistoryService::CanAddURL(url)) | 192 if (!HistoryService::CanAddURL(url)) |
193 return false; // It's not a real webpage. | 193 return false; // It's not a real webpage. |
194 | 194 |
195 scoped_refptr<RefCountedBytes> thumbnail_data; | 195 scoped_refptr<RefCountedBytes> thumbnail_data; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls)); | 230 request->ForwardResult(GetTopSitesCallback::TupleType(filtered_urls)); |
231 } | 231 } |
232 | 232 |
233 bool TopSites::GetPageThumbnail(const GURL& url, | 233 bool TopSites::GetPageThumbnail(const GURL& url, |
234 scoped_refptr<RefCountedBytes>* bytes) { | 234 scoped_refptr<RefCountedBytes>* bytes) { |
235 // WARNING: this may be invoked on any thread. | 235 // WARNING: this may be invoked on any thread. |
236 base::AutoLock lock(lock_); | 236 base::AutoLock lock(lock_); |
237 return thread_safe_cache_->GetPageThumbnail(url, bytes); | 237 return thread_safe_cache_->GetPageThumbnail(url, bytes); |
238 } | 238 } |
239 | 239 |
| 240 bool TopSites::GetPageThumbnailScore(const GURL& url, |
| 241 ThumbnailScore* score) { |
| 242 // WARNING: this may be invoked on any thread. |
| 243 base::AutoLock lock(lock_); |
| 244 return thread_safe_cache_->GetPageThumbnailScore(url, score); |
| 245 } |
| 246 |
240 // Returns the index of |url| in |urls|, or -1 if not found. | 247 // Returns the index of |url| in |urls|, or -1 if not found. |
241 static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { | 248 static int IndexOf(const MostVisitedURLList& urls, const GURL& url) { |
242 for (size_t i = 0; i < urls.size(); i++) { | 249 for (size_t i = 0; i < urls.size(); i++) { |
243 if (urls[i].url == url) | 250 if (urls[i].url == url) |
244 return i; | 251 return i; |
245 } | 252 } |
246 return -1; | 253 return -1; |
247 } | 254 } |
248 | 255 |
249 void TopSites::MigrateFromHistory() { | 256 void TopSites::MigrateFromHistory() { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 if (hs) { | 449 if (hs) { |
443 return hs->QueryMostVisitedURLs( | 450 return hs->QueryMostVisitedURLs( |
444 num_results_to_request_from_history(), | 451 num_results_to_request_from_history(), |
445 kDaysOfHistory, | 452 kDaysOfHistory, |
446 &cancelable_consumer_, | 453 &cancelable_consumer_, |
447 NewCallback(this, &TopSites::OnTopSitesAvailableFromHistory)); | 454 NewCallback(this, &TopSites::OnTopSitesAvailableFromHistory)); |
448 } | 455 } |
449 return 0; | 456 return 0; |
450 } | 457 } |
451 | 458 |
| 459 bool TopSites::IsKnownURL(const GURL& url) { |
| 460 return loaded_ && cache_->IsKnownURL(url); |
| 461 } |
| 462 |
| 463 bool TopSites::IsFull() { |
| 464 return loaded_ && cache_->top_sites().size() >= kTopSitesNumber; |
| 465 } |
| 466 |
452 TopSites::~TopSites() { | 467 TopSites::~TopSites() { |
453 } | 468 } |
454 | 469 |
455 bool TopSites::SetPageThumbnailNoDB(const GURL& url, | 470 bool TopSites::SetPageThumbnailNoDB(const GURL& url, |
456 const RefCountedBytes* thumbnail_data, | 471 const RefCountedBytes* thumbnail_data, |
457 const ThumbnailScore& score) { | 472 const ThumbnailScore& score) { |
458 // This should only be invoked when we know about the url. | 473 // This should only be invoked when we know about the url. |
459 DCHECK(cache_->IsKnownURL(url)); | 474 DCHECK(cache_->IsKnownURL(url)); |
460 | 475 |
461 const MostVisitedURL& most_visited = | 476 const MostVisitedURL& most_visited = |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); | 732 for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); |
718 i != indices_to_delete.rend(); i++) { | 733 i != indices_to_delete.rend(); i++) { |
719 size_t index = *i; | 734 size_t index = *i; |
720 RemovePinnedURL(new_top_sites[index].url); | 735 RemovePinnedURL(new_top_sites[index].url); |
721 new_top_sites.erase(new_top_sites.begin() + index); | 736 new_top_sites.erase(new_top_sites.begin() + index); |
722 } | 737 } |
723 SetTopSites(new_top_sites); | 738 SetTopSites(new_top_sites); |
724 } | 739 } |
725 StartQueryForMostVisited(); | 740 StartQueryForMostVisited(); |
726 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { | 741 } else if (type == NotificationType::NAV_ENTRY_COMMITTED) { |
727 if (cache_->top_sites().size() < kTopSitesNumber) { | 742 if (!IsFull()) { |
728 NavigationController::LoadCommittedDetails* load_details = | 743 NavigationController::LoadCommittedDetails* load_details = |
729 Details<NavigationController::LoadCommittedDetails>(details).ptr(); | 744 Details<NavigationController::LoadCommittedDetails>(details).ptr(); |
730 if (!load_details) | 745 if (!load_details) |
731 return; | 746 return; |
732 const GURL& url = load_details->entry->url(); | 747 const GURL& url = load_details->entry->url(); |
733 if (!cache_->IsKnownURL(url) && HistoryService::CanAddURL(url)) { | 748 if (!cache_->IsKnownURL(url) && HistoryService::CanAddURL(url)) { |
734 // To avoid slamming history we throttle requests when the url updates. | 749 // To avoid slamming history we throttle requests when the url updates. |
735 // To do otherwise negatively impacts perf tests. | 750 // To do otherwise negatively impacts perf tests. |
736 RestartQueryForTopSitesTimer(GetUpdateDelay()); | 751 RestartQueryForTopSitesTimer(GetUpdateDelay()); |
737 } | 752 } |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 SetTopSites(pages); | 917 SetTopSites(pages); |
903 | 918 |
904 // Used only in testing. | 919 // Used only in testing. |
905 NotificationService::current()->Notify( | 920 NotificationService::current()->Notify( |
906 NotificationType::TOP_SITES_UPDATED, | 921 NotificationType::TOP_SITES_UPDATED, |
907 Source<TopSites>(this), | 922 Source<TopSites>(this), |
908 Details<CancelableRequestProvider::Handle>(&handle)); | 923 Details<CancelableRequestProvider::Handle>(&handle)); |
909 } | 924 } |
910 | 925 |
911 } // namespace history | 926 } // namespace history |
OLD | NEW |