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/command_line.h" |
8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
9 #include "chrome/browser/history/history_service.h" | 9 #include "chrome/browser/history/history_service.h" |
10 #include "chrome/browser/search/search.h" | 10 #include "chrome/browser/search/search.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 // True if thumbnail retargeting feature is enabled (Finch/flags). | 22 // True if thumbnail retargeting feature is enabled (Finch/flags). |
23 bool IsThumbnailRetargetingEnabled() { | 23 bool IsThumbnailRetargetingEnabled() { |
24 if (!chrome::IsInstantExtendedAPIEnabled()) | 24 if (!chrome::IsInstantExtendedAPIEnabled()) |
25 return false; | 25 return false; |
26 | 26 |
27 return CommandLine::ForCurrentProcess()->HasSwitch( | 27 return CommandLine::ForCurrentProcess()->HasSwitch( |
28 switches::kEnableThumbnailRetargeting); | 28 switches::kEnableThumbnailRetargeting); |
29 } | 29 } |
30 | 30 |
31 } | 31 } // namespace |
32 | 32 |
33 namespace thumbnails { | 33 namespace thumbnails { |
34 | 34 |
35 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) | 35 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) |
36 : top_sites_(profile->GetTopSites()), | 36 : top_sites_(profile->GetTopSites()), |
37 use_thumbnail_retargeting_(IsThumbnailRetargetingEnabled()){ | 37 use_thumbnail_retargeting_(IsThumbnailRetargetingEnabled()) { |
38 } | 38 } |
39 | 39 |
40 ThumbnailServiceImpl::~ThumbnailServiceImpl() { | 40 ThumbnailServiceImpl::~ThumbnailServiceImpl() { |
41 } | 41 } |
42 | 42 |
43 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, | 43 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, |
44 const gfx::Image& thumbnail) { | 44 const gfx::Image& thumbnail) { |
45 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 45 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
46 if (local_ptr.get() == NULL) | 46 if (local_ptr.get() == NULL) |
47 return false; | 47 return false; |
48 | 48 |
49 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); | 49 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); |
50 } | 50 } |
51 | 51 |
52 bool ThumbnailServiceImpl::GetPageThumbnail( | 52 bool ThumbnailServiceImpl::GetPageThumbnail( |
53 const GURL& url, | 53 const GURL& url, |
| 54 bool prefix_match, |
54 scoped_refptr<base::RefCountedMemory>* bytes) { | 55 scoped_refptr<base::RefCountedMemory>* bytes) { |
55 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 56 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
56 if (local_ptr.get() == NULL) | 57 if (local_ptr.get() == NULL) |
57 return false; | 58 return false; |
58 | 59 |
59 return local_ptr->GetPageThumbnail(url, bytes); | 60 return local_ptr->GetPageThumbnail(url, prefix_match, bytes); |
60 } | 61 } |
61 | 62 |
62 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() | 63 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() |
63 const { | 64 const { |
64 const gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); | 65 const gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); |
65 if (use_thumbnail_retargeting_) | 66 if (use_thumbnail_retargeting_) |
66 return new ContentBasedThumbnailingAlgorithm(thumbnail_size); | 67 return new ContentBasedThumbnailingAlgorithm(thumbnail_size); |
67 return new SimpleThumbnailCrop(thumbnail_size); | 68 return new SimpleThumbnailCrop(thumbnail_size); |
68 } | 69 } |
69 | 70 |
(...skipping 25 matching lines...) Expand all Loading... |
95 } | 96 } |
96 | 97 |
97 void ThumbnailServiceImpl::ShutdownOnUIThread() { | 98 void ThumbnailServiceImpl::ShutdownOnUIThread() { |
98 // Since each call uses its own scoped_refptr, we can just clear the reference | 99 // Since each call uses its own scoped_refptr, we can just clear the reference |
99 // here by assigning null. If another call is completed, it added its own | 100 // here by assigning null. If another call is completed, it added its own |
100 // reference. | 101 // reference. |
101 top_sites_ = NULL; | 102 top_sites_ = NULL; |
102 } | 103 } |
103 | 104 |
104 } // namespace thumbnails | 105 } // namespace thumbnails |
OLD | NEW |