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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 return; | 284 return; |
285 } | 285 } |
286 filtered_urls = thread_safe_cache_->top_sites(); | 286 filtered_urls = thread_safe_cache_->top_sites(); |
287 } | 287 } |
288 callback.Run(filtered_urls); | 288 callback.Run(filtered_urls); |
289 } | 289 } |
290 | 290 |
291 bool TopSitesImpl::GetPageThumbnail( | 291 bool TopSitesImpl::GetPageThumbnail( |
292 const GURL& url, scoped_refptr<base::RefCountedMemory>* bytes) { | 292 const GURL& url, scoped_refptr<base::RefCountedMemory>* bytes) { |
293 // WARNING: this may be invoked on any thread. | 293 // WARNING: this may be invoked on any thread. |
| 294 // Perform exact match. |
294 { | 295 { |
295 base::AutoLock lock(lock_); | 296 base::AutoLock lock(lock_); |
296 if (thread_safe_cache_->GetPageThumbnail(url, bytes)) | 297 if (thread_safe_cache_->GetPageThumbnail(url, bytes)) |
297 return true; | 298 return true; |
298 } | 299 } |
299 | 300 |
300 // Resource bundle is thread safe. | 301 // Resource bundle is thread safe. |
301 for (size_t i = 0; i < arraysize(kPrepopulatedPages); i++) { | 302 for (size_t i = 0; i < arraysize(kPrepopulatedPages); i++) { |
302 if (url == prepopulated_page_urls_[i]) { | 303 if (url == prepopulated_page_urls_[i]) { |
303 *bytes = ResourceBundle::GetSharedInstance(). | 304 *bytes = ResourceBundle::GetSharedInstance(). |
304 LoadDataResourceBytesForScale( | 305 LoadDataResourceBytesForScale( |
305 kPrepopulatedPages[i].thumbnail_id, | 306 kPrepopulatedPages[i].thumbnail_id, |
306 ui::SCALE_FACTOR_100P); | 307 ui::SCALE_FACTOR_100P); |
307 return true; | 308 return true; |
308 } | 309 } |
309 } | 310 } |
310 | 311 |
| 312 // Still not found, so trim query, and perform prefix match. |
| 313 { |
| 314 GURL::Replacements replacements; |
| 315 replacements.ClearQuery(); |
| 316 GURL url_no_query(url.ReplaceComponents(replacements)); |
| 317 base::AutoLock lock(lock_); |
| 318 if (thread_safe_cache_->GetPageThumbnailForPrefix(url_no_query, bytes)) |
| 319 return true; |
| 320 } |
311 return false; | 321 return false; |
312 } | 322 } |
313 | 323 |
314 bool TopSitesImpl::GetPageThumbnailScore(const GURL& url, | 324 bool TopSitesImpl::GetPageThumbnailScore(const GURL& url, |
315 ThumbnailScore* score) { | 325 ThumbnailScore* score) { |
316 // WARNING: this may be invoked on any thread. | 326 // WARNING: this may be invoked on any thread. |
317 base::AutoLock lock(lock_); | 327 base::AutoLock lock(lock_); |
318 return thread_safe_cache_->GetPageThumbnailScore(url, score); | 328 return thread_safe_cache_->GetPageThumbnailScore(url, score); |
319 } | 329 } |
320 | 330 |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 SetTopSites(pages); | 946 SetTopSites(pages); |
937 | 947 |
938 // Used only in testing. | 948 // Used only in testing. |
939 content::NotificationService::current()->Notify( | 949 content::NotificationService::current()->Notify( |
940 chrome::NOTIFICATION_TOP_SITES_UPDATED, | 950 chrome::NOTIFICATION_TOP_SITES_UPDATED, |
941 content::Source<TopSitesImpl>(this), | 951 content::Source<TopSitesImpl>(this), |
942 content::Details<CancelableRequestProvider::Handle>(&handle)); | 952 content::Details<CancelableRequestProvider::Handle>(&handle)); |
943 } | 953 } |
944 | 954 |
945 } // namespace history | 955 } // namespace history |
OLD | NEW |