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_service.h" | 8 #include "chrome/browser/history/history_service.h" |
9 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" | 9 #include "chrome/browser/thumbnails/simple_thumbnail_crop.h" |
10 #include "chrome/browser/thumbnails/thumbnailing_context.h" | 10 #include "chrome/browser/thumbnails/thumbnailing_context.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) | 22 ThumbnailServiceImpl::ThumbnailServiceImpl(Profile* profile) |
23 : top_sites_(profile->GetTopSites()) { | 23 : top_sites_(profile->GetTopSites()) { |
24 } | 24 } |
25 | 25 |
26 ThumbnailServiceImpl::~ThumbnailServiceImpl() { | 26 ThumbnailServiceImpl::~ThumbnailServiceImpl() { |
27 } | 27 } |
28 | 28 |
29 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, | 29 bool ThumbnailServiceImpl::SetPageThumbnail(const ThumbnailingContext& context, |
30 const gfx::Image& thumbnail) { | 30 const gfx::Image& thumbnail) { |
31 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 31 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
32 if (local_ptr == NULL) | 32 if (local_ptr.get() == NULL) |
33 return false; | 33 return false; |
34 | 34 |
35 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); | 35 return local_ptr->SetPageThumbnail(context.url, thumbnail, context.score); |
36 } | 36 } |
37 | 37 |
38 bool ThumbnailServiceImpl::GetPageThumbnail( | 38 bool ThumbnailServiceImpl::GetPageThumbnail( |
39 const GURL& url, | 39 const GURL& url, |
40 scoped_refptr<base::RefCountedMemory>* bytes) { | 40 scoped_refptr<base::RefCountedMemory>* bytes) { |
41 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 41 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
42 if (local_ptr == NULL) | 42 if (local_ptr.get() == NULL) |
43 return false; | 43 return false; |
44 | 44 |
45 return local_ptr->GetPageThumbnail(url, bytes); | 45 return local_ptr->GetPageThumbnail(url, bytes); |
46 } | 46 } |
47 | 47 |
48 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() | 48 ThumbnailingAlgorithm* ThumbnailServiceImpl::GetThumbnailingAlgorithm() |
49 const { | 49 const { |
50 return new SimpleThumbnailCrop(gfx::Size(kThumbnailWidth, kThumbnailHeight)); | 50 return new SimpleThumbnailCrop(gfx::Size(kThumbnailWidth, kThumbnailHeight)); |
51 } | 51 } |
52 | 52 |
53 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { | 53 bool ThumbnailServiceImpl::ShouldAcquirePageThumbnail(const GURL& url) { |
54 scoped_refptr<history::TopSites> local_ptr(top_sites_); | 54 scoped_refptr<history::TopSites> local_ptr(top_sites_); |
55 | 55 |
56 if (local_ptr == NULL) | 56 if (local_ptr.get() == NULL) |
57 return false; | 57 return false; |
58 | 58 |
59 // Skip if the given URL is not appropriate for history. | 59 // Skip if the given URL is not appropriate for history. |
60 if (!HistoryService::CanAddURL(url)) | 60 if (!HistoryService::CanAddURL(url)) |
61 return false; | 61 return false; |
62 // 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. |
63 if (local_ptr->IsFull() && !local_ptr->IsKnownURL(url)) | 63 if (local_ptr->IsFull() && !local_ptr->IsKnownURL(url)) |
64 return false; | 64 return false; |
65 // Skip if we don't have to udpate the existing thumbnail. | 65 // Skip if we don't have to udpate the existing thumbnail. |
66 ThumbnailScore current_score; | 66 ThumbnailScore current_score; |
(...skipping 11 matching lines...) Expand all Loading... |
78 } | 78 } |
79 | 79 |
80 void ThumbnailServiceImpl::ShutdownOnUIThread() { | 80 void ThumbnailServiceImpl::ShutdownOnUIThread() { |
81 // 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 |
82 // 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 |
83 // reference. | 83 // reference. |
84 top_sites_ = NULL; | 84 top_sites_ = NULL; |
85 } | 85 } |
86 | 86 |
87 } | 87 } |
OLD | NEW |