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

Side by Side Diff: chrome/browser/favicon/favicon_service.h

Issue 291643002: Move favicon callbacks to favicon_base (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android unittest Created 6 years, 7 months 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
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 #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_types.h" 15 #include "components/favicon_base/favicon_types.h"
15 #include "components/keyed_service/core/keyed_service.h" 16 #include "components/keyed_service/core/keyed_service.h"
16 #include "ui/base/layout.h" 17 #include "ui/base/layout.h"
17 18
18 class GURL; 19 class GURL;
19 class HistoryService; 20 class HistoryService;
20 struct ImportedFaviconUsage; 21 struct ImportedFaviconUsage;
21 class Profile; 22 class Profile;
22 23
23 namespace chrome {
24 struct FaviconImageResult;
25 }
26
27 // The favicon service provides methods to access favicons. It calls the history 24 // The favicon service provides methods to access favicons. It calls the history
28 // backend behind the scenes. 25 // backend behind the scenes.
29 class FaviconService : public KeyedService { 26 class FaviconService : public KeyedService {
30 public: 27 public:
31 explicit FaviconService(Profile* profile); 28 explicit FaviconService(Profile* profile);
32 29
33 virtual ~FaviconService(); 30 virtual ~FaviconService();
34 31
35 // Auxiliary argument structure for requesting favicons for URLs. 32 // Auxiliary argument structure for requesting favicons for URLs.
36 struct FaviconForURLParams { 33 struct FaviconForURLParams {
37 FaviconForURLParams(const GURL& page_url, 34 FaviconForURLParams(const GURL& page_url,
38 int icon_types, 35 int icon_types,
39 int desired_size_in_dip) 36 int desired_size_in_dip)
40 : page_url(page_url), 37 : page_url(page_url),
41 icon_types(icon_types), 38 icon_types(icon_types),
42 desired_size_in_dip(desired_size_in_dip) {} 39 desired_size_in_dip(desired_size_in_dip) {}
43 40
44 GURL page_url; 41 GURL page_url;
45 int icon_types; 42 int icon_types;
46 int desired_size_in_dip; 43 int desired_size_in_dip;
47 }; 44 };
48 45
49 // Callback for GetFaviconImage() and GetFaviconImageForURL().
50 // |FaviconImageResult::image| is constructed from the bitmaps for the
sdefresne 2014/05/19 14:36:39 This comment describe the GetFaviconImage & GetFav
Jiang Jiang 2014/05/19 15:56:41 Done.
51 // passed in URL and icon types which most which closely match the passed in
52 // |desired_size_in_dip| at the scale factors supported by the current
53 // platform (eg MacOS) in addition to 1x.
54 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in
55 // |image| originate from.
56 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several
57 // icon URLs.
58 typedef base::Callback<void(const favicon_base::FaviconImageResult&)>
59 FaviconImageCallback;
60
61 // Callback for GetRawFavicon(), GetRawFaviconForURL() and
62 // GetLargestRawFavicon().
63 // See function for details on value.
64 typedef base::Callback<void(const favicon_base::FaviconBitmapResult&)>
65 FaviconRawCallback;
66
67 // Callback for GetFavicon() and GetFaviconForURL().
68 //
69 // The first argument is the set of bitmaps for the passed in URL and
sdefresne 2014/05/19 14:36:39 This comment describe the GetFavicon & GetFaviconF
Jiang Jiang 2014/05/19 15:56:41 Done.
70 // icon types whose pixel sizes best match the passed in
71 // |desired_size_in_dip| at the scale factors supported by the current
72 // platform (eg MacOS) in addition to 1x. The vector has at most one result
73 // for each of the scale factors. There are less entries if a single result
74 // is the best bitmap to use for several scale factors.
75 typedef base::Callback<void(const std::vector<
76 favicon_base::FaviconBitmapResult>&)> FaviconResultsCallback;
77
78 // We usually pass parameters with pointer to avoid copy. This function is a 46 // We usually pass parameters with pointer to avoid copy. This function is a
79 // helper to run FaviconResultsCallback with pointer parameters. 47 // helper to run FaviconResultsCallback with pointer parameters.
80 static void FaviconResultsCallbackRunner( 48 static void FaviconResultsCallbackRunner(
81 const FaviconResultsCallback& callback, 49 const favicon_base::FaviconResultsCallback& callback,
82 const std::vector<favicon_base::FaviconBitmapResult>* results); 50 const std::vector<favicon_base::FaviconBitmapResult>* results);
83 51
84 // Requests the favicon at |icon_url| of |icon_type| whose size most closely 52 // Requests the favicon at |icon_url| of |icon_type| whose size most closely
85 // matches |desired_size_in_dip|. If |desired_size_in_dip| is 0, the largest 53 // matches |desired_size_in_dip|. If |desired_size_in_dip| is 0, the largest
86 // favicon bitmap at |icon_url| is returned. |consumer| is notified when the 54 // favicon bitmap at |icon_url| is returned. |consumer| is notified when the
87 // bits have been fetched. |icon_url| is the URL of the icon itself, e.g. 55 // bits have been fetched. |icon_url| is the URL of the icon itself, e.g.
88 // <http://www.google.com/favicon.ico>. 56 // <http://www.google.com/favicon.ico>.
89 // Each of the three methods below differs in the format of the callback and 57 // Each of the three methods below differs in the format of the callback and
90 // the requested scale factors. All of the scale factors supported by the 58 // the requested scale factors. All of the scale factors supported by the
91 // current platform (eg MacOS) are requested for GetFaviconImage(). 59 // current platform (eg MacOS) are requested for GetFaviconImage().
92 base::CancelableTaskTracker::TaskId GetFaviconImage( 60 base::CancelableTaskTracker::TaskId GetFaviconImage(
93 const GURL& icon_url, 61 const GURL& icon_url,
94 favicon_base::IconType icon_type, 62 favicon_base::IconType icon_type,
95 int desired_size_in_dip, 63 int desired_size_in_dip,
96 const FaviconImageCallback& callback, 64 const favicon_base::FaviconImageCallback& callback,
97 base::CancelableTaskTracker* tracker); 65 base::CancelableTaskTracker* tracker);
98 66
99 base::CancelableTaskTracker::TaskId GetRawFavicon( 67 base::CancelableTaskTracker::TaskId GetRawFavicon(
100 const GURL& icon_url, 68 const GURL& icon_url,
101 favicon_base::IconType icon_type, 69 favicon_base::IconType icon_type,
102 int desired_size_in_dip, 70 int desired_size_in_dip,
103 ui::ScaleFactor desired_scale_factor, 71 ui::ScaleFactor desired_scale_factor,
104 const FaviconRawCallback& callback, 72 const favicon_base::FaviconRawCallback& callback,
105 base::CancelableTaskTracker* tracker); 73 base::CancelableTaskTracker* tracker);
106 74
107 base::CancelableTaskTracker::TaskId GetFavicon( 75 base::CancelableTaskTracker::TaskId GetFavicon(
108 const GURL& icon_url, 76 const GURL& icon_url,
109 favicon_base::IconType icon_type, 77 favicon_base::IconType icon_type,
110 int desired_size_in_dip, 78 int desired_size_in_dip,
111 const FaviconResultsCallback& callback, 79 const favicon_base::FaviconResultsCallback& callback,
112 base::CancelableTaskTracker* tracker); 80 base::CancelableTaskTracker* tracker);
113 81
114 // Set the favicon mappings to |page_url| for |icon_types| in the history 82 // Set the favicon mappings to |page_url| for |icon_types| in the history
115 // database. 83 // database.
116 // Sample |icon_urls|: 84 // Sample |icon_urls|:
117 // { ICON_URL1 -> TOUCH_ICON, known to the database, 85 // { ICON_URL1 -> TOUCH_ICON, known to the database,
118 // ICON_URL2 -> TOUCH_ICON, not known to the database, 86 // ICON_URL2 -> TOUCH_ICON, not known to the database,
119 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } 87 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database }
120 // The new mappings are computed from |icon_urls| with these rules: 88 // The new mappings are computed from |icon_urls| with these rules:
121 // 1) Any urls in |icon_urls| which are not already known to the database are 89 // 1) Any urls in |icon_urls| which are not already known to the database are
122 // rejected. 90 // rejected.
123 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } 91 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 }
124 // 2) If |icon_types| has multiple types, the mappings are only set for the 92 // 2) If |icon_types| has multiple types, the mappings are only set for the
125 // largest icon type. 93 // largest icon type.
126 // Sample new mappings to |page_url|: { ICON_URL3 } 94 // Sample new mappings to |page_url|: { ICON_URL3 }
127 // |icon_types| can only have multiple IconTypes if 95 // |icon_types| can only have multiple IconTypes if
128 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. 96 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON.
129 // The favicon bitmaps which most closely match |desired_size_in_dip| 97 // The favicon bitmaps which most closely match |desired_size_in_dip|
130 // at the scale factors supported by the current platform (eg MacOS) in 98 // at the scale factors supported by the current platform (eg MacOS) in
131 // addition to 1x from the favicons which were just mapped to |page_url| are 99 // addition to 1x from the favicons which were just mapped to |page_url| are
132 // returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is 100 // returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is
133 // returned. 101 // returned.
134 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( 102 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch(
135 const GURL& page_url, 103 const GURL& page_url,
136 const std::vector<GURL>& icon_urls, 104 const std::vector<GURL>& icon_urls,
137 int icon_types, 105 int icon_types,
138 int desired_size_in_dip, 106 int desired_size_in_dip,
139 const FaviconResultsCallback& callback, 107 const favicon_base::FaviconResultsCallback& callback,
140 base::CancelableTaskTracker* tracker); 108 base::CancelableTaskTracker* tracker);
141 109
142 // Requests the favicons of any of |icon_types| whose pixel sizes most 110 // Requests the favicons of any of |icon_types| whose pixel sizes most
143 // closely match |desired_size_in_dip| and desired scale factors for a web 111 // closely match |desired_size_in_dip| and desired scale factors for a web
144 // page URL. If |desired_size_in_dip| is 0, the largest favicon for the web 112 // page URL. If |desired_size_in_dip| is 0, the largest favicon for the web
145 // page URL is returned. |callback| is run when the bits have been fetched. 113 // page URL is returned. |callback| is run when the bits have been fetched.
146 // |icon_types| can be any combination of IconType value, but only one icon 114 // |icon_types| can be any combination of IconType value, but only one icon
147 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and 115 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON and
148 // FAVICON. Each of the three methods below differs in the format of the 116 // FAVICON. Each of the three methods below differs in the format of the
149 // callback and the requested scale factors. All of the scale factors 117 // callback and the requested scale factors. All of the scale factors
150 // supported by the current platform (eg MacOS) are requested for 118 // supported by the current platform (eg MacOS) are requested for
151 // GetFaviconImageForURL(). 119 // GetFaviconImageForURL().
152 // Note. |callback| is always run asynchronously. 120 // Note. |callback| is always run asynchronously.
153 base::CancelableTaskTracker::TaskId GetFaviconImageForURL( 121 base::CancelableTaskTracker::TaskId GetFaviconImageForURL(
154 const FaviconForURLParams& params, 122 const FaviconForURLParams& params,
155 const FaviconImageCallback& callback, 123 const favicon_base::FaviconImageCallback& callback,
156 base::CancelableTaskTracker* tracker); 124 base::CancelableTaskTracker* tracker);
157 125
158 base::CancelableTaskTracker::TaskId GetRawFaviconForURL( 126 base::CancelableTaskTracker::TaskId GetRawFaviconForURL(
159 const FaviconForURLParams& params, 127 const FaviconForURLParams& params,
160 ui::ScaleFactor desired_scale_factor, 128 ui::ScaleFactor desired_scale_factor,
161 const FaviconRawCallback& callback, 129 const favicon_base::FaviconRawCallback& callback,
162 base::CancelableTaskTracker* tracker); 130 base::CancelableTaskTracker* tracker);
163 131
164 // See HistoryService::GetLargestFaviconForURL(). 132 // See HistoryService::GetLargestFaviconForURL().
165 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForURL( 133 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForURL(
166 Profile* profile, 134 Profile* profile,
167 const GURL& page_url, 135 const GURL& page_url,
168 const std::vector<int>& icon_types, 136 const std::vector<int>& icon_types,
169 int minimum_size_in_pixels, 137 int minimum_size_in_pixels,
170 const FaviconRawCallback& callback, 138 const favicon_base::FaviconRawCallback& callback,
171 base::CancelableTaskTracker* tracker); 139 base::CancelableTaskTracker* tracker);
172 140
173 base::CancelableTaskTracker::TaskId GetFaviconForURL( 141 base::CancelableTaskTracker::TaskId GetFaviconForURL(
174 const FaviconForURLParams& params, 142 const FaviconForURLParams& params,
175 const FaviconResultsCallback& callback, 143 const favicon_base::FaviconResultsCallback& callback,
176 base::CancelableTaskTracker* tracker); 144 base::CancelableTaskTracker* tracker);
177 145
178 // Used to request a bitmap for the favicon with |favicon_id| which is not 146 // Used to request a bitmap for the favicon with |favicon_id| which is not
179 // resized from the size it is stored at in the database. If there are 147 // resized from the size it is stored at in the database. If there are
180 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is 148 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is
181 // returned. 149 // returned.
182 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( 150 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID(
183 favicon_base::FaviconID favicon_id, 151 favicon_base::FaviconID favicon_id,
184 const FaviconRawCallback& callback, 152 const favicon_base::FaviconRawCallback& callback,
185 base::CancelableTaskTracker* tracker); 153 base::CancelableTaskTracker* tracker);
186 154
187 // Marks all types of favicon for the page as being out of date. 155 // Marks all types of favicon for the page as being out of date.
188 void SetFaviconOutOfDateForPage(const GURL& page_url); 156 void SetFaviconOutOfDateForPage(const GURL& page_url);
189 157
190 // Clones all icons from an existing page. This associates the icons from 158 // Clones all icons from an existing page. This associates the icons from
191 // |old_page_url| with |new_page_url|, provided |new_page_url| has no 159 // |old_page_url| with |new_page_url|, provided |new_page_url| has no
192 // recorded associations to any other icons. 160 // recorded associations to any other icons.
193 // Needed if you want to declare favicons (tentatively) in advance, before a 161 // Needed if you want to declare favicons (tentatively) in advance, before a
194 // page is ever visited. 162 // page is ever visited.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 typedef uint32 MissingFaviconURLHash; 203 typedef uint32 MissingFaviconURLHash;
236 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; 204 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_;
237 HistoryService* history_service_; 205 HistoryService* history_service_;
238 Profile* profile_; 206 Profile* profile_;
239 207
240 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and 208 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and
241 // GetFaviconForURL(). 209 // GetFaviconForURL().
242 base::CancelableTaskTracker::TaskId GetFaviconForURLImpl( 210 base::CancelableTaskTracker::TaskId GetFaviconForURLImpl(
243 const FaviconForURLParams& params, 211 const FaviconForURLParams& params,
244 const std::vector<ui::ScaleFactor>& desired_scale_factors, 212 const std::vector<ui::ScaleFactor>& desired_scale_factors,
245 const FaviconResultsCallback& callback, 213 const favicon_base::FaviconResultsCallback& callback,
246 base::CancelableTaskTracker* tracker); 214 base::CancelableTaskTracker* tracker);
247 215
248 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() 216 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL()
249 // so that history service can deal solely with FaviconResultsCallback. 217 // so that history service can deal solely with FaviconResultsCallback.
250 // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and 218 // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and
251 // runs 219 // runs
252 // |callback|. 220 // |callback|.
253 void RunFaviconImageCallbackWithBitmapResults( 221 void RunFaviconImageCallbackWithBitmapResults(
254 const FaviconImageCallback& callback, 222 const favicon_base::FaviconImageCallback& callback,
255 int desired_size_in_dip, 223 int desired_size_in_dip,
256 const std::vector<favicon_base::FaviconBitmapResult>& 224 const std::vector<favicon_base::FaviconBitmapResult>&
257 favicon_bitmap_results); 225 favicon_bitmap_results);
258 226
259 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() 227 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL()
260 // so that history service can deal solely with FaviconResultsCallback. 228 // so that history service can deal solely with FaviconResultsCallback.
261 // Resizes favicon_base::FaviconBitmapResult if necessary and runs |callback|. 229 // Resizes favicon_base::FaviconBitmapResult if necessary and runs |callback|.
262 void RunFaviconRawCallbackWithBitmapResults( 230 void RunFaviconRawCallbackWithBitmapResults(
263 const FaviconRawCallback& callback, 231 const favicon_base::FaviconRawCallback& callback,
264 int desired_size_in_dip, 232 int desired_size_in_dip,
265 ui::ScaleFactor desired_scale_factor, 233 ui::ScaleFactor desired_scale_factor,
266 const std::vector<favicon_base::FaviconBitmapResult>& 234 const std::vector<favicon_base::FaviconBitmapResult>&
267 favicon_bitmap_results); 235 favicon_bitmap_results);
268 236
269 DISALLOW_COPY_AND_ASSIGN(FaviconService); 237 DISALLOW_COPY_AND_ASSIGN(FaviconService);
270 }; 238 };
271 239
272 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ 240 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698