| 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_impl.h" | 5 #include "chrome/browser/history/top_sites_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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 base::MessageLoopProxy::current(), | 205 base::MessageLoopProxy::current(), |
| 206 callback)); | 206 callback)); |
| 207 return; | 207 return; |
| 208 } | 208 } |
| 209 filtered_urls = thread_safe_cache_->top_sites(); | 209 filtered_urls = thread_safe_cache_->top_sites(); |
| 210 } | 210 } |
| 211 callback.Run(filtered_urls); | 211 callback.Run(filtered_urls); |
| 212 } | 212 } |
| 213 | 213 |
| 214 bool TopSitesImpl::GetPageThumbnail( | 214 bool TopSitesImpl::GetPageThumbnail( |
| 215 const GURL& url, scoped_refptr<base::RefCountedMemory>* bytes) { | 215 const GURL& url, |
| 216 bool prefix_match, |
| 217 scoped_refptr<base::RefCountedMemory>* bytes) { |
| 216 // WARNING: this may be invoked on any thread. | 218 // WARNING: this may be invoked on any thread. |
| 219 // Perform exact match. |
| 217 { | 220 { |
| 218 base::AutoLock lock(lock_); | 221 base::AutoLock lock(lock_); |
| 219 if (thread_safe_cache_->GetPageThumbnail(url, bytes)) | 222 if (thread_safe_cache_->GetPageThumbnail(url, bytes)) |
| 220 return true; | 223 return true; |
| 221 } | 224 } |
| 222 | 225 |
| 223 // Resource bundle is thread safe. | 226 // Resource bundle is thread safe. |
| 224 for (size_t i = 0; i < arraysize(kPrepopulatedPages); i++) { | 227 for (size_t i = 0; i < arraysize(kPrepopulatedPages); i++) { |
| 225 if (url == prepopulated_page_urls_[i]) { | 228 if (url == prepopulated_page_urls_[i]) { |
| 226 *bytes = ResourceBundle::GetSharedInstance(). | 229 *bytes = ResourceBundle::GetSharedInstance(). |
| 227 LoadDataResourceBytesForScale( | 230 LoadDataResourceBytesForScale( |
| 228 kPrepopulatedPages[i].thumbnail_id, | 231 kPrepopulatedPages[i].thumbnail_id, |
| 229 ui::SCALE_FACTOR_100P); | 232 ui::SCALE_FACTOR_100P); |
| 230 return true; | 233 return true; |
| 231 } | 234 } |
| 232 } | 235 } |
| 233 | 236 |
| 237 if (prefix_match) { |
| 238 // Still not found, so strip "?query#ref", and perform prefix match. |
| 239 GURL::Replacements replacements; |
| 240 replacements.ClearQuery(); |
| 241 replacements.ClearRef(); |
| 242 GURL url_stripped(url.ReplaceComponents(replacements)); |
| 243 base::AutoLock lock(lock_); |
| 244 GURL canonical_url( |
| 245 thread_safe_cache_->GetCanonicalURLForPrefix(url_stripped)); |
| 246 if (thread_safe_cache_->GetPageThumbnail(canonical_url, bytes)) |
| 247 return true; |
| 248 } |
| 234 return false; | 249 return false; |
| 235 } | 250 } |
| 236 | 251 |
| 237 bool TopSitesImpl::GetPageThumbnailScore(const GURL& url, | 252 bool TopSitesImpl::GetPageThumbnailScore(const GURL& url, |
| 238 ThumbnailScore* score) { | 253 ThumbnailScore* score) { |
| 239 // WARNING: this may be invoked on any thread. | 254 // WARNING: this may be invoked on any thread. |
| 240 base::AutoLock lock(lock_); | 255 base::AutoLock lock(lock_); |
| 241 return thread_safe_cache_->GetPageThumbnailScore(url, score); | 256 return thread_safe_cache_->GetPageThumbnailScore(url, score); |
| 242 } | 257 } |
| 243 | 258 |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 SetTopSites(pages); | 785 SetTopSites(pages); |
| 771 | 786 |
| 772 // Used only in testing. | 787 // Used only in testing. |
| 773 content::NotificationService::current()->Notify( | 788 content::NotificationService::current()->Notify( |
| 774 chrome::NOTIFICATION_TOP_SITES_UPDATED, | 789 chrome::NOTIFICATION_TOP_SITES_UPDATED, |
| 775 content::Source<TopSitesImpl>(this), | 790 content::Source<TopSitesImpl>(this), |
| 776 content::Details<CancelableRequestProvider::Handle>(&handle)); | 791 content::Details<CancelableRequestProvider::Handle>(&handle)); |
| 777 } | 792 } |
| 778 | 793 |
| 779 } // namespace history | 794 } // namespace history |
| OLD | NEW |