Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/thumbnails/thumbnail_service_impl.cc

Issue 59903010: Ensure using chrome://thumb2/... adds the URL as a forced URL in TopSites so that a thumbnail is ca… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Take 2. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/time/time.h"
9 #include "chrome/browser/history/history_service.h" 10 #include "chrome/browser/history/history_service.h"
10 #include "chrome/browser/search/search.h" 11 #include "chrome/browser/search/search.h"
11 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h" 12 #include "chrome/browser/thumbnails/content_based_thumbnailing_algorithm.h"
12 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" 13 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h"
13 #include "chrome/browser/thumbnails/thumbnailing_context.h" 14 #include "chrome/browser/thumbnails/thumbnailing_context.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
18 using content::BrowserThread;
19
17 namespace { 20 namespace {
18 21
19 // The thumbnail size in DIP. 22 // The thumbnail size in DIP.
20 const int kThumbnailWidth = 212; 23 const int kThumbnailWidth = 212;
21 const int kThumbnailHeight = 132; 24 const int kThumbnailHeight = 132;
22 25
23 // True if thumbnail retargeting feature is enabled (Finch/flags). 26 // True if thumbnail retargeting feature is enabled (Finch/flags).
24 bool IsThumbnailRetargetingEnabled() { 27 bool IsThumbnailRetargetingEnabled() {
25 if (!chrome::IsInstantExtendedAPIEnabled()) 28 if (!chrome::IsInstantExtendedAPIEnabled())
26 return false; 29 return false;
27 30
28 return CommandLine::ForCurrentProcess()->HasSwitch( 31 return CommandLine::ForCurrentProcess()->HasSwitch(
29 switches::kEnableThumbnailRetargeting); 32 switches::kEnableThumbnailRetargeting);
30 } 33 }
31 34
35 void AddForcedURLOnUIThread(scoped_refptr<history::TopSites> top_sites,
36 const GURL& url) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
38
39 if (top_sites.get() != NULL)
40 top_sites->AddForcedURL(url, base::Time::Now());
41 }
42
32 } // namespace 43 } // namespace
33 44
34 namespace thumbnails { 45 namespace thumbnails {
35 46
36 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) 47 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile)
37 : top_sites_(profile->GetTopSites()), 48 : top_sites_(profile->GetTopSites()),
38 use_thumbnail_retargeting_(IsThumbnailRetargetingEnabled()) { 49 use_thumbnail_retargeting_(IsThumbnailRetargetingEnabled()) {
39 } 50 }
40 51
41 ThumbnailServiceImpl::~ThumbnailServiceImpl() { 52 ThumbnailServiceImpl::~ThumbnailServiceImpl() {
(...skipping 12 matching lines...) Expand all
54 const GURL& url, 65 const GURL& url,
55 bool prefix_match, 66 bool prefix_match,
56 scoped_refptr<base::RefCountedMemory>* bytes) { 67 scoped_refptr<base::RefCountedMemory>* bytes) {
57 scoped_refptr<history::TopSites> local_ptr(top_sites_); 68 scoped_refptr<history::TopSites> local_ptr(top_sites_);
58 if (local_ptr.get() == NULL) 69 if (local_ptr.get() == NULL)
59 return false; 70 return false;
60 71
61 return local_ptr->GetPageThumbnail(url, prefix_match, bytes); 72 return local_ptr->GetPageThumbnail(url, prefix_match, bytes);
62 } 73 }
63 74
75 void ThumbnailServiceImpl::AddForcedURL(const GURL& url) {
76 scoped_refptr<history::TopSites> local_ptr(top_sites_);
77 if (local_ptr.get() == NULL)
78 return;
79
80 // Adding
81 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
82 base::Bind(AddForcedURLOnUIThread, local_ptr, url));
83 }
84
64 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() 85 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm()
65 const { 86 const {
66 const gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight); 87 const gfx::Size thumbnail_size(kThumbnailWidth, kThumbnailHeight);
67 if (use_thumbnail_retargeting_) 88 if (use_thumbnail_retargeting_)
68 return new ContentBasedThumbnailingAlgorithm(thumbnail_size); 89 return new ContentBasedThumbnailingAlgorithm(thumbnail_size);
69 return new SimpleThumbnailCrop(thumbnail_size); 90 return new SimpleThumbnailCrop(thumbnail_size);
70 } 91 }
71 92
72 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { 93 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) {
73 scoped_refptr<history::TopSites> local_ptr(top_sites_); 94 scoped_refptr<history::TopSites> local_ptr(top_sites_);
(...skipping 23 matching lines...) Expand all
97 } 118 }
98 119
99 void ThumbnailServiceImpl::ShutdownOnUIThread() { 120 void ThumbnailServiceImpl::ShutdownOnUIThread() {
100 // Since each call uses its own scoped_refptr, we can just clear the reference 121 // Since each call uses its own scoped_refptr, we can just clear the reference
101 // here by assigning null. If another call is completed, it added its own 122 // here by assigning null. If another call is completed, it added its own
102 // reference. 123 // reference.
103 top_sites_ = NULL; 124 top_sites_ = NULL;
104 } 125 }
105 126
106 } // namespace thumbnails 127 } // namespace thumbnails
OLDNEW
« no previous file with comments | « chrome/browser/thumbnails/thumbnail_service_impl.h ('k') | chrome/browser/ui/webui/ntp/thumbnail_list_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698