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/advanced_thumbnail_crop.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 |
18 } | 22 } |
19 | 23 |
20 namespace thumbnails { | 24 namespace thumbnails { |
21 | 25 |
22 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) | 26 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) |
23 : top_sites_(profile->GetTopSites()) { | 27 : top_sites_(profile->GetTopSites()), |
| 28 use_thumbnail_retargetting_(GetThumbnailRetargettingEnabled()){ |
24 } | 29 } |
25 | 30 |
26 ThumbnailServiceImpl::~ThumbnailServiceImpl() { | 31 ThumbnailServiceImpl::~ThumbnailServiceImpl() { |
27 } | 32 } |
28 | 33 |
29 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, | 34 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, |
30 const gfx::Image& thumbnail) { | 35 const gfx::Image& thumbnail) { |
31 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 36 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
32 if (local_ptr == NULL) | 37 if (local_ptr == NULL) |
33 return false; | 38 return false; |
34 | 39 |
35 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); | 40 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); |
36 } | 41 } |
37 | 42 |
38 bool ThumbnailServiceImpl::GetPageThumbnail( | 43 bool ThumbnailServiceImpl::GetPageThumbnail( |
39 const GURL& url, | 44 const GURL& url, |
40 scoped_refptr<base::RefCountedMemory>* bytes) { | 45 scoped_refptr<base::RefCountedMemory>* bytes) { |
41 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 46 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
42 if (local_ptr == NULL) | 47 if (local_ptr == NULL) |
43 return false; | 48 return false; |
44 | 49 |
45 return local_ptr->GetPageThumbnail(url, bytes); | 50 return local_ptr->GetPageThumbnail(url, bytes); |
46 } | 51 } |
47 | 52 |
48 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() | 53 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() |
49 const { | 54 const { |
50 return new SimpleThumbnailCrop(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 55 const gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); |
| 56 if (use_thumbnail_retargetting_) |
| 57 return new AdvancedThumbnailCrop(thumbnail_size); |
| 58 return new SimpleThumbnailCrop(thumbnail_size); |
51 } | 59 } |
52 | 60 |
53 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { | 61 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { |
54 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 62 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
55 | 63 |
56 if (local_ptr == NULL) | 64 if (local_ptr == NULL) |
57 return false; | 65 return false; |
58 | 66 |
59 // Skip if the given URL is not appropriate for history. | 67 // Skip if the given URL is not appropriate for history. |
60 if (!HistoryService::CanAddURL(url)) | 68 if (!HistoryService::CanAddURL(url)) |
(...skipping 16 matching lines...) Expand all Loading... |
77 return true; | 85 return true; |
78 } | 86 } |
79 | 87 |
80 void ThumbnailServiceImpl::ShutdownOnUIThread() { | 88 void ThumbnailServiceImpl::ShutdownOnUIThread() { |
81 // Since each call uses its own scoped_refptr, we can just clear the reference | 89 // 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 | 90 // here by assigning null. If another call is completed, it added its own |
83 // reference. | 91 // reference. |
84 top_sites_ = NULL; | 92 top_sites_ = NULL; |
85 } | 93 } |
86 | 94 |
| 95 // static |
| 96 bool ThumbnailServiceImpl::GetThumbnailRetargettingEnabled() { |
| 97 if (!chrome::IsInstantExtendedAPIEnabled()) |
| 98 return false; |
| 99 |
| 100 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 101 switches::kEnableThumbnailRetargetting); |
87 } | 102 } |
| 103 |
| 104 } // namespace thumbnails |
OLD | NEW |