| 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/command_line.h" |
| 7 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 8 #include "chrome/browser/history/history_service.h" | 9 #include "chrome/browser/history/history_service.h" |
| 10 #include "chrome/browser/search/search.h" |
| 11 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h" |
| 9 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" | 12 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" |
| 10 #include "chrome/browser/thumbnails/thumbnailing_context.h" | 13 #include "chrome/browser/thumbnails/thumbnailing_context.h" |
| 14 #include "chrome/common/chrome_switches.h" |
| 11 | 15 |
| 12 namespace { | 16 namespace { |
| 13 | 17 |
| 14 // The thumbnail size in DIP. | 18 // The thumbnail size in DIP. |
| 15 const int kThumbnailWidth = 212; | 19 const int kThumbnailWidth = 212; |
| 16 const int kThumbnailHeight = 132; | 20 const int kThumbnailHeight = 132; |
| 17 | 21 |
| 22 // True if thumbnail retargeting feature is enabled (Finch/flags). |
| 23 bool IsThumbnailRetargetingEnabled() { |
| 24 if (!chrome::IsInstantExtendedAPIEnabled()) |
| 25 return false; |
| 26 |
| 27 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 28 switches::kEnableThumbnailRetargeting); |
| 29 } |
| 30 |
| 18 } | 31 } |
| 19 | 32 |
| 20 namespace thumbnails { | 33 namespace thumbnails { |
| 21 | 34 |
| 22 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) | 35 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) |
| 23 : top_sites_(profile->GetTopSites()) { | 36 : top_sites_(profile->GetTopSites()), |
| 37 use_thumbnail_retargeting_(IsThumbnailRetargetingEnabled()){ |
| 24 } | 38 } |
| 25 | 39 |
| 26 ThumbnailServiceImpl::~ThumbnailServiceImpl() { | 40 ThumbnailServiceImpl::~ThumbnailServiceImpl() { |
| 27 } | 41 } |
| 28 | 42 |
| 29 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, | 43 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, |
| 30 const gfx::Image& thumbnail) { | 44 const gfx::Image& thumbnail) { |
| 31 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 45 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
| 32 if (local_ptr.get() == NULL) | 46 if (local_ptr.get() == NULL) |
| 33 return false; | 47 return false; |
| 34 | 48 |
| 35 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); | 49 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); |
| 36 } | 50 } |
| 37 | 51 |
| 38 bool ThumbnailServiceImpl::GetPageThumbnail( | 52 bool ThumbnailServiceImpl::GetPageThumbnail( |
| 39 const GURL& url, | 53 const GURL& url, |
| 40 scoped_refptr<base::RefCountedMemory>* bytes) { | 54 scoped_refptr<base::RefCountedMemory>* bytes) { |
| 41 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 55 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
| 42 if (local_ptr.get() == NULL) | 56 if (local_ptr.get() == NULL) |
| 43 return false; | 57 return false; |
| 44 | 58 |
| 45 return local_ptr->GetPageThumbnail(url, bytes); | 59 return local_ptr->GetPageThumbnail(url, bytes); |
| 46 } | 60 } |
| 47 | 61 |
| 48 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() | 62 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() |
| 49 const { | 63 const { |
| 50 return new SimpleThumbnailCrop(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 64 const gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); |
| 65 if (use_thumbnail_retargeting_) |
| 66 return new ContentBasedThumbnailingAlgorithm(thumbnail_size); |
| 67 return new SimpleThumbnailCrop(thumbnail_size); |
| 51 } | 68 } |
| 52 | 69 |
| 53 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { | 70 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { |
| 54 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 71 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
| 55 | 72 |
| 56 if (local_ptr.get() == NULL) | 73 if (local_ptr.get() == NULL) |
| 57 return false; | 74 return false; |
| 58 | 75 |
| 59 // Skip if the given URL is not appropriate for history. | 76 // Skip if the given URL is not appropriate for history. |
| 60 if (!HistoryService::CanAddURL(url)) | 77 if (!HistoryService::CanAddURL(url)) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 77 return true; | 94 return true; |
| 78 } | 95 } |
| 79 | 96 |
| 80 void ThumbnailServiceImpl::ShutdownOnUIThread() { | 97 void ThumbnailServiceImpl::ShutdownOnUIThread() { |
| 81 // Since each call uses its own scoped_refptr, we can just clear the reference | 98 // Since each call uses its own scoped_refptr, we can just clear the reference |
| 82 // here by assigning null. If another call is completed, it added its own | 99 // here by assigning null. If another call is completed, it added its own |
| 83 // reference. | 100 // reference. |
| 84 top_sites_ = NULL; | 101 top_sites_ = NULL; |
| 85 } | 102 } |
| 86 | 103 |
| 87 } | 104 } // namespace thumbnails |
| OLD | NEW |