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 #ifndef CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ | 5 #ifndef CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ |
6 #define CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ | 6 #define CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "content/public/browser/url_data_source.h" | 14 #include "content/public/browser/url_data_source.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 class Profile; | 17 class Profile; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class RefCountedMemory; | 20 class RefCountedMemory; |
21 } | 21 } |
22 | 22 |
23 namespace gfx { | 23 namespace gfx { |
24 class Image; | 24 class Image; |
25 } | 25 } |
26 | 26 |
27 namespace image_fetcher { | 27 namespace image_fetcher { |
28 class ImageFetcher; | 28 class ImageFetcher; |
| 29 struct RequestMetadata; |
29 } | 30 } |
30 | 31 |
31 namespace thumbnails { | 32 namespace thumbnails { |
32 class ThumbnailService; | 33 class ThumbnailService; |
33 } | 34 } |
34 | 35 |
35 // ThumbnailSource is the gateway between network-level chrome: requests for | 36 // ThumbnailSource is the gateway between network-level chrome: requests for |
36 // thumbnails and the history/top-sites backend that serves these. | 37 // thumbnails and the history/top-sites backend that serves these. |
37 class ThumbnailSource : public content::URLDataSource { | 38 class ThumbnailSource : public content::URLDataSource { |
38 public: | 39 public: |
(...skipping 18 matching lines...) Expand all Loading... |
57 void ExtractPageAndThumbnailUrls(const std::string& path, | 58 void ExtractPageAndThumbnailUrls(const std::string& path, |
58 GURL* page_url, | 59 GURL* page_url, |
59 GURL* fallback_thumbnail_url); | 60 GURL* fallback_thumbnail_url); |
60 | 61 |
61 private: | 62 private: |
62 // Returns a JPEG-encoded |bitmap| to the |callback| if valid, or the default | 63 // Returns a JPEG-encoded |bitmap| to the |callback| if valid, or the default |
63 // thumbnail. | 64 // thumbnail. |
64 void SendFetchedUrlImage( | 65 void SendFetchedUrlImage( |
65 const content::URLDataSource::GotDataCallback& callback, | 66 const content::URLDataSource::GotDataCallback& callback, |
66 const std::string& url, | 67 const std::string& url, |
67 const gfx::Image& image); | 68 const gfx::Image& image, |
| 69 const image_fetcher::RequestMetadata& metadata); |
68 | 70 |
69 // Raw PNG representation of the thumbnail to show when the thumbnail | 71 // Raw PNG representation of the thumbnail to show when the thumbnail |
70 // database doesn't have a thumbnail for a webpage. | 72 // database doesn't have a thumbnail for a webpage. |
71 scoped_refptr<base::RefCountedMemory> default_thumbnail_; | 73 scoped_refptr<base::RefCountedMemory> default_thumbnail_; |
72 | 74 |
73 // ThumbnailService. | 75 // ThumbnailService. |
74 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service_; | 76 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service_; |
75 | 77 |
76 // ImageFetcher. | 78 // ImageFetcher. |
77 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | 79 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; |
78 | 80 |
79 // Indicate that, when a URL for which we don't have a thumbnail is requested | 81 // Indicate that, when a URL for which we don't have a thumbnail is requested |
80 // from this source, then Chrome should capture a thumbnail next time it | 82 // from this source, then Chrome should capture a thumbnail next time it |
81 // navigates to this URL. This is useful when the thumbnail URLs are generated | 83 // navigates to this URL. This is useful when the thumbnail URLs are generated |
82 // by an external service rather than TopSites, so Chrome can learn about the | 84 // by an external service rather than TopSites, so Chrome can learn about the |
83 // URLs for which it should get thumbnails. Sources that capture thumbnails | 85 // URLs for which it should get thumbnails. Sources that capture thumbnails |
84 // are also be more lenient when matching thumbnail URLs by checking for | 86 // are also be more lenient when matching thumbnail URLs by checking for |
85 // existing thumbnails in the database that contain a URL matching the prefix | 87 // existing thumbnails in the database that contain a URL matching the prefix |
86 // of the requested URL. | 88 // of the requested URL. |
87 const bool capture_thumbnails_; | 89 const bool capture_thumbnails_; |
88 | 90 |
89 base::WeakPtrFactory<ThumbnailSource> weak_ptr_factory_; | 91 base::WeakPtrFactory<ThumbnailSource> weak_ptr_factory_; |
90 | 92 |
91 DISALLOW_COPY_AND_ASSIGN(ThumbnailSource); | 93 DISALLOW_COPY_AND_ASSIGN(ThumbnailSource); |
92 }; | 94 }; |
93 | 95 |
94 #endif // CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ | 96 #endif // CHROME_BROWSER_SEARCH_THUMBNAIL_SOURCE_H_ |
OLD | NEW |