Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/thumbnails/thumbnail_service_impl.h" | 5 #include "chrome/browser/thumbnails/thumbnail_service_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted_memory.h" | 7 #include "base/memory/ref_counted_memory.h" |
| 8 #include "chrome/browser/history/history.h" | 8 #include "chrome/browser/history/history.h" |
| 9 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" | |
| 10 #include "chrome/browser/thumbnails/thumbnailing_context.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 // The thumbnail size in DIP. | |
| 15 static const int kThumbnailWidth = 212; | |
|
sky
2013/01/17 20:18:36
don't need static here.
motek.
2013/01/18 18:38:41
Done.
| |
| 16 static const int kThumbnailHeight = 132; | |
| 17 | |
| 18 } | |
| 9 | 19 |
| 10 namespace thumbnails { | 20 namespace thumbnails { |
| 11 | 21 |
| 12 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) | 22 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) |
| 13 : top_sites_(profile->GetTopSites()) { | 23 : top_sites_(profile->GetTopSites()) { |
| 14 } | 24 } |
| 15 | 25 |
| 16 ThumbnailServiceImpl::~ThumbnailServiceImpl() { | 26 ThumbnailServiceImpl::~ThumbnailServiceImpl() { |
| 17 } | 27 } |
| 18 | 28 |
| 19 bool ThumbnailServiceImpl::SetPageThumbnail(const GURL& url, | 29 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, |
| 20 const gfx::Image& thumbnail, | 30 const gfx::Image& thumbnail) { |
| 21 const ThumbnailScore& score) { | |
| 22 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 31 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
| 23 if (local_ptr == NULL) | 32 if (local_ptr == NULL) |
| 24 return false; | 33 return false; |
| 25 | 34 |
| 26 return local_ptr->SetPageThumbnail(url, thumbnail, score); | 35 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); |
| 27 } | 36 } |
| 28 | 37 |
| 29 bool ThumbnailServiceImpl::GetPageThumbnail( | 38 bool ThumbnailServiceImpl::GetPageThumbnail( |
| 30 const GURL& url, | 39 const GURL& url, |
| 31 scoped_refptr<base::RefCountedMemory>* bytes) { | 40 scoped_refptr<base::RefCountedMemory>* bytes) { |
| 32 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 41 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
| 33 if (local_ptr == NULL) | 42 if (local_ptr == NULL) |
| 34 return false; | 43 return false; |
| 35 | 44 |
| 36 return local_ptr->GetPageThumbnail(url, bytes); | 45 return local_ptr->GetPageThumbnail(url, bytes); |
| 37 } | 46 } |
| 38 | 47 |
| 48 ThumbnailingAlgorithm* ThumbnailServiceImpl::CreateThumbnailingAlgorithm() | |
| 49 const { | |
| 50 return new SimpleThumbnailCrop(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | |
| 51 } | |
| 52 | |
| 39 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { | 53 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { |
| 40 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 54 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
| 41 | 55 |
| 42 if (local_ptr == NULL) | 56 if (local_ptr == NULL) |
| 43 return false; | 57 return false; |
| 44 | 58 |
| 45 // Skip if the given URL is not appropriate for history. | 59 // Skip if the given URL is not appropriate for history. |
| 46 if (!HistoryService::CanAddURL(url)) | 60 if (!HistoryService::CanAddURL(url)) |
| 47 return false; | 61 return false; |
| 48 // Skip if the top sites list is full, and the URL is not known. | 62 // Skip if the top sites list is full, and the URL is not known. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 64 } | 78 } |
| 65 | 79 |
| 66 void ThumbnailServiceImpl::ShutdownOnUIThread() { | 80 void ThumbnailServiceImpl::ShutdownOnUIThread() { |
| 67 // Since each call uses its own scoped_refptr, we can just clear the reference | 81 // Since each call uses its own scoped_refptr, we can just clear the reference |
| 68 // here by assigning null. If another call is completed, it added its own | 82 // here by assigning null. If another call is completed, it added its own |
| 69 // reference. | 83 // reference. |
| 70 top_sites_ = NULL; | 84 top_sites_ = NULL; |
| 71 } | 85 } |
| 72 | 86 |
| 73 } | 87 } |
| OLD | NEW |