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_FAVICON_FAVICON_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
6 #define CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 6 #define CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/task/cancelable_task_tracker.h" | 13 #include "base/task/cancelable_task_tracker.h" |
14 #include "components/favicon_base/favicon_callback.h" | 14 #include "components/favicon_base/favicon_callback.h" |
15 #include "components/favicon_base/favicon_types.h" | 15 #include "components/favicon_base/favicon_types.h" |
16 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
17 #include "ui/base/layout.h" | |
18 | 17 |
19 class GURL; | 18 class GURL; |
20 class HistoryService; | 19 class HistoryService; |
21 struct ImportedFaviconUsage; | 20 struct ImportedFaviconUsage; |
22 class Profile; | 21 class Profile; |
23 | 22 |
24 // The favicon service provides methods to access favicons. It calls the history | 23 // The favicon service provides methods to access favicons. It calls the history |
25 // backend behind the scenes. | 24 // backend behind the scenes. |
26 class FaviconService : public KeyedService { | 25 class FaviconService : public KeyedService { |
27 public: | 26 public: |
(...skipping 16 matching lines...) Expand all Loading... |
44 }; | 43 }; |
45 | 44 |
46 // We usually pass parameters with pointer to avoid copy. This function is a | 45 // We usually pass parameters with pointer to avoid copy. This function is a |
47 // helper to run FaviconResultsCallback with pointer parameters. | 46 // helper to run FaviconResultsCallback with pointer parameters. |
48 static void FaviconResultsCallbackRunner( | 47 static void FaviconResultsCallbackRunner( |
49 const favicon_base::FaviconResultsCallback& callback, | 48 const favicon_base::FaviconResultsCallback& callback, |
50 const std::vector<favicon_base::FaviconRawBitmapResult>* results); | 49 const std::vector<favicon_base::FaviconRawBitmapResult>* results); |
51 | 50 |
52 // The first argument of |callback| is a |const FaviconImageResult&|. Of which | 51 // The first argument of |callback| is a |const FaviconImageResult&|. Of which |
53 // |FaviconImageResult::image| is constructed from the bitmaps for the | 52 // |FaviconImageResult::image| is constructed from the bitmaps for the |
54 // passed in URL and icon types which most which closely match the passed in | 53 // passed in URL and icon types which most wich closely match the passed in |
55 // |desired_size_in_dip| at the scale factors supported by the current | 54 // |desired_size_in_dip| at the resource scale factors supported by the |
56 // platform (eg MacOS) in addition to 1x. | 55 // current platform (eg MacOS) in addition to 1x. |
57 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in | 56 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in |
58 // |image| originate from. | 57 // |image| originate from. |
59 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several | 58 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several |
60 // icon URLs. | 59 // icon URLs. |
61 | 60 |
62 // Requests the favicon at |icon_url| of |icon_type| whose size most closely | 61 // Requests the favicon at |icon_url| of |icon_type| whose size most closely |
63 // matches |desired_size_in_dip|. If |desired_size_in_dip| is 0, the largest | 62 // matches |desired_size_in_dip|. If |desired_size_in_dip| is 0, the largest |
64 // favicon bitmap at |icon_url| is returned. |consumer| is notified when the | 63 // favicon bitmap at |icon_url| is returned. |consumer| is notified when the |
65 // bits have been fetched. |icon_url| is the URL of the icon itself, e.g. | 64 // bits have been fetched. |icon_url| is the URL of the icon itself, e.g. |
66 // <http://www.google.com/favicon.ico>. | 65 // <http://www.google.com/favicon.ico>. |
67 // Each of the three methods below differs in the format of the callback and | 66 // Each of the three methods below differs in the format of the callback and |
68 // the requested scale factors. All of the scale factors supported by the | 67 // the requested scales. All of the resource scale factors supported by the |
69 // current platform (eg MacOS) are requested for GetFaviconImage(). | 68 // current platform (eg MacOS) are requested for GetFaviconImage(). |
70 base::CancelableTaskTracker::TaskId GetFaviconImage( | 69 base::CancelableTaskTracker::TaskId GetFaviconImage( |
71 const GURL& icon_url, | 70 const GURL& icon_url, |
72 favicon_base::IconType icon_type, | 71 favicon_base::IconType icon_type, |
73 int desired_size_in_dip, | 72 int desired_size_in_dip, |
74 const favicon_base::FaviconImageCallback& callback, | 73 const favicon_base::FaviconImageCallback& callback, |
75 base::CancelableTaskTracker* tracker); | 74 base::CancelableTaskTracker* tracker); |
76 | 75 |
77 base::CancelableTaskTracker::TaskId GetRawFavicon( | 76 base::CancelableTaskTracker::TaskId GetRawFavicon( |
78 const GURL& icon_url, | 77 const GURL& icon_url, |
79 favicon_base::IconType icon_type, | 78 favicon_base::IconType icon_type, |
80 int desired_size_in_dip, | 79 int desired_size_in_dip, |
81 ui::ScaleFactor desired_scale_factor, | 80 float desired_favicon_scale, |
82 const favicon_base::FaviconRawBitmapCallback& callback, | 81 const favicon_base::FaviconRawBitmapCallback& callback, |
83 base::CancelableTaskTracker* tracker); | 82 base::CancelableTaskTracker* tracker); |
84 | 83 |
85 // The first argument for |callback| is the set of bitmaps for the passed in | 84 // The first argument for |callback| is the set of bitmaps for the passed in |
86 // URL and icon types whose pixel sizes best match the passed in | 85 // URL and icon types whose pixel sizes best match the passed in |
87 // |desired_size_in_dip| at the scale factors supported by the current | 86 // |desired_size_in_dip| at the resource scale factors supported by the |
88 // platform (eg MacOS) in addition to 1x. The vector has at most one result | 87 // current platform (eg MacOS) in addition to 1x. The vector has at most one |
89 // for each of the scale factors. There are less entries if a single result | 88 // result for each of the resource scale factors. There are less entries if a |
90 // is the best bitmap to use for several scale factors. | 89 // single/ result is the best bitmap to use for several resource scale |
| 90 // factors. |
91 base::CancelableTaskTracker::TaskId GetFavicon( | 91 base::CancelableTaskTracker::TaskId GetFavicon( |
92 const GURL& icon_url, | 92 const GURL& icon_url, |
93 favicon_base::IconType icon_type, | 93 favicon_base::IconType icon_type, |
94 int desired_size_in_dip, | 94 int desired_size_in_dip, |
95 const favicon_base::FaviconResultsCallback& callback, | 95 const favicon_base::FaviconResultsCallback& callback, |
96 base::CancelableTaskTracker* tracker); | 96 base::CancelableTaskTracker* tracker); |
97 | 97 |
98 // Set the favicon mappings to |page_url| for |icon_types| in the history | 98 // Set the favicon mappings to |page_url| for |icon_types| in the history |
99 // database. | 99 // database. |
100 // Sample |icon_urls|: | 100 // Sample |icon_urls|: |
101 // { ICON_URL1 -> TOUCH_ICON, known to the database, | 101 // { ICON_URL1 -> TOUCH_ICON, known to the database, |
102 // ICON_URL2 -> TOUCH_ICON, not known to the database, | 102 // ICON_URL2 -> TOUCH_ICON, not known to the database, |
103 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } | 103 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } |
104 // The new mappings are computed from |icon_urls| with these rules: | 104 // The new mappings are computed from |icon_urls| with these rules: |
105 // 1) Any urls in |icon_urls| which are not already known to the database are | 105 // 1) Any urls in |icon_urls| which are not already known to the database are |
106 // rejected. | 106 // rejected. |
107 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } | 107 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } |
108 // 2) If |icon_types| has multiple types, the mappings are only set for the | 108 // 2) If |icon_types| has multiple types, the mappings are only set for the |
109 // largest icon type. | 109 // largest icon type. |
110 // Sample new mappings to |page_url|: { ICON_URL3 } | 110 // Sample new mappings to |page_url|: { ICON_URL3 } |
111 // |icon_types| can only have multiple IconTypes if | 111 // |icon_types| can only have multiple IconTypes if |
112 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. | 112 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. |
113 // The favicon bitmaps which most closely match |desired_size_in_dip| | 113 // The favicon bitmaps which most closely match |desired_size_in_dip| |
114 // at the scale factors supported by the current platform (eg MacOS) in | 114 // at the reosurce scale factors supported by the current platform (eg MacOS) |
115 // addition to 1x from the favicons which were just mapped to |page_url| are | 115 // in addition to 1x from the favicons which were just mapped to |page_url| |
116 // returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is | 116 // are returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is |
117 // returned. | 117 // returned. |
118 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( | 118 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( |
119 const GURL& page_url, | 119 const GURL& page_url, |
120 const std::vector<GURL>& icon_urls, | 120 const std::vector<GURL>& icon_urls, |
121 int icon_types, | 121 int icon_types, |
122 int desired_size_in_dip, | 122 int desired_size_in_dip, |
123 const favicon_base::FaviconResultsCallback& callback, | 123 const favicon_base::FaviconResultsCallback& callback, |
124 base::CancelableTaskTracker* tracker); | 124 base::CancelableTaskTracker* tracker); |
125 | 125 |
126 // Requests the favicons of any of |icon_types| whose pixel sizes most | 126 // Requests the favicons of any of |icon_types| whose pixel sizes most |
127 // closely match |desired_size_in_dip| and desired scale factors for a web | 127 // closely match |desired_size_in_dip| and desired scale for a web |
128 // page URL. If |desired_size_in_dip| is 0, the largest favicon for the web | 128 // page URL. If |desired_size_in_dip| is 0, the largest favicon for the web |
129 // page URL is returned. |callback| is run when the bits have been fetched. | 129 // page URL is returned. |callback| is run when the bits have been fetched. |
130 // |icon_types| can be any combination of IconType value, but only one icon | 130 // |icon_types| can be any combination of IconType value, but only one icon |
131 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and | 131 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and |
132 // FAVICON. Each of the three methods below differs in the format of the | 132 // FAVICON. Each of the three methods below differs in the format of the |
133 // callback and the requested scale factors. All of the scale factors | 133 // callback and the requested scales. All of the resource scale factors |
134 // supported by the current platform (eg MacOS) are requested for | 134 // supported by the current platform (eg MacOS) are requested for |
135 // GetFaviconImageForPageURL(). | 135 // GetFaviconImageForPageURL(). |
136 // Note. |callback| is always run asynchronously. | 136 // Note. |callback| is always run asynchronously. |
137 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( | 137 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( |
138 const FaviconForPageURLParams& params, | 138 const FaviconForPageURLParams& params, |
139 const favicon_base::FaviconImageCallback& callback, | 139 const favicon_base::FaviconImageCallback& callback, |
140 base::CancelableTaskTracker* tracker); | 140 base::CancelableTaskTracker* tracker); |
141 | 141 |
142 base::CancelableTaskTracker::TaskId GetRawFaviconForPageURL( | 142 base::CancelableTaskTracker::TaskId GetRawFaviconForPageURL( |
143 const FaviconForPageURLParams& params, | 143 const FaviconForPageURLParams& params, |
144 ui::ScaleFactor desired_scale_factor, | 144 float desired_favicon_scale, |
145 const favicon_base::FaviconRawBitmapCallback& callback, | 145 const favicon_base::FaviconRawBitmapCallback& callback, |
146 base::CancelableTaskTracker* tracker); | 146 base::CancelableTaskTracker* tracker); |
147 | 147 |
148 // See HistoryService::GetLargestFaviconForPageURL(). | 148 // See HistoryService::GetLargestFaviconForPageURL(). |
149 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( | 149 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( |
150 Profile* profile, | 150 Profile* profile, |
151 const GURL& page_url, | 151 const GURL& page_url, |
152 const std::vector<int>& icon_types, | 152 const std::vector<int>& icon_types, |
153 int minimum_size_in_pixels, | 153 int minimum_size_in_pixels, |
154 const favicon_base::FaviconRawBitmapCallback& callback, | 154 const favicon_base::FaviconRawBitmapCallback& callback, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 void RunFaviconRawBitmapCallbackWithBitmapResults( | 246 void RunFaviconRawBitmapCallbackWithBitmapResults( |
247 const favicon_base::FaviconRawBitmapCallback& callback, | 247 const favicon_base::FaviconRawBitmapCallback& callback, |
248 int desired_size_in_pixel, | 248 int desired_size_in_pixel, |
249 const std::vector<favicon_base::FaviconRawBitmapResult>& | 249 const std::vector<favicon_base::FaviconRawBitmapResult>& |
250 favicon_bitmap_results); | 250 favicon_bitmap_results); |
251 | 251 |
252 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 252 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
253 }; | 253 }; |
254 | 254 |
255 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 255 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
OLD | NEW |