Chromium Code Reviews| 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" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 // | 24 // |
| 25 // This service is thread safe. Each request callback is invoked in the | 25 // This service is thread safe. Each request callback is invoked in the |
| 26 // thread that made the request. | 26 // thread that made the request. |
| 27 class FaviconService : public CancelableRequestProvider, | 27 class FaviconService : public CancelableRequestProvider, |
| 28 public ProfileKeyedService { | 28 public ProfileKeyedService { |
| 29 public: | 29 public: |
| 30 explicit FaviconService(HistoryService* history_service); | 30 explicit FaviconService(HistoryService* history_service); |
| 31 | 31 |
| 32 virtual ~FaviconService(); | 32 virtual ~FaviconService(); |
| 33 | 33 |
| 34 // Auxiliary argument structure for requesting favicons. | |
|
James Hawkins
2012/09/05 22:02:58
Why is this necessary?
Leandro Graciá Gil
2012/09/05 22:04:28
I could remove this case and leave only the URL on
James Hawkins
2012/09/05 22:11:49
Yes, please remove. The FaviconForURLParams is a
| |
| 35 struct FaviconParams { | |
| 36 FaviconParams(const GURL& icon_url, | |
| 37 history::IconType icon_type, | |
| 38 int desired_size_in_dip, | |
| 39 CancelableRequestConsumerBase* consumer) | |
| 40 : icon_url(icon_url), | |
| 41 icon_type(icon_type), | |
| 42 desired_size_in_dip(desired_size_in_dip), | |
| 43 consumer(consumer) { | |
| 44 } | |
| 45 | |
| 46 GURL icon_url; | |
| 47 history::IconType icon_type; | |
| 48 int desired_size_in_dip; | |
| 49 CancelableRequestConsumerBase* consumer; | |
| 50 }; | |
| 51 | |
| 52 // Auxiliary argument structure for requesting favicons for URLs. | |
| 53 struct FaviconForURLParams { | |
| 54 FaviconForURLParams(Profile* profile, | |
| 55 const GURL& page_url, | |
| 56 int icon_types, | |
| 57 int desired_size_in_dip, | |
| 58 CancelableRequestConsumerBase* consumer) | |
| 59 : profile(profile), | |
| 60 page_url(page_url), | |
| 61 icon_types(icon_types), | |
| 62 desired_size_in_dip(desired_size_in_dip), | |
| 63 consumer(consumer) { | |
| 64 } | |
| 65 | |
| 66 Profile* profile; | |
| 67 GURL page_url; | |
| 68 int icon_types; | |
| 69 int desired_size_in_dip; | |
| 70 CancelableRequestConsumerBase* consumer; | |
| 71 }; | |
| 72 | |
| 34 // Callback for GetFaviconImage() and GetFaviconImageForURL(). | 73 // Callback for GetFaviconImage() and GetFaviconImageForURL(). |
| 35 // |FaviconImageResult::image| is constructed from the bitmaps for the | 74 // |FaviconImageResult::image| is constructed from the bitmaps for the |
| 36 // passed in URL and icon types which most which closely match the passed in | 75 // passed in URL and icon types which most which closely match the passed in |
| 37 // |desired_size_in_dip| at the scale factors supported by the current | 76 // |desired_size_in_dip| at the scale factors supported by the current |
| 38 // platform (eg MacOS). | 77 // platform (eg MacOS). |
| 39 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in | 78 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in |
| 40 // |image| originate from. | 79 // |image| originate from. |
| 41 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several | 80 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several |
| 42 // icon URLs. | 81 // icon URLs. |
| 43 typedef base::Callback<void(Handle, const history::FaviconImageResult&)> | 82 typedef base::Callback<void(Handle, const history::FaviconImageResult&)> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 | 117 |
| 79 typedef CancelableRequest<FaviconResultsCallback> GetFaviconRequest; | 118 typedef CancelableRequest<FaviconResultsCallback> GetFaviconRequest; |
| 80 | 119 |
| 81 // Requests the favicon at |icon_url| of |icon_type| whose size most closely | 120 // Requests the favicon at |icon_url| of |icon_type| whose size most closely |
| 82 // matches |desired_size_in_dip|. |consumer| is notified when the bits have | 121 // matches |desired_size_in_dip|. |consumer| is notified when the bits have |
| 83 // been fetched. |icon_url| is the URL of the icon itself, e.g. | 122 // been fetched. |icon_url| is the URL of the icon itself, e.g. |
| 84 // <http://www.google.com/favicon.ico>. | 123 // <http://www.google.com/favicon.ico>. |
| 85 // Each of the three methods below differs in the format of the callback and | 124 // Each of the three methods below differs in the format of the callback and |
| 86 // the requested scale factors. All of the scale factors supported by the | 125 // the requested scale factors. All of the scale factors supported by the |
| 87 // current platform (eg MacOS) are requested for GetFaviconImage(). | 126 // current platform (eg MacOS) are requested for GetFaviconImage(). |
| 88 Handle GetFaviconImage(const GURL& icon_url, | 127 Handle GetFaviconImage(const FaviconParams& params, |
| 89 history::IconType icon_type, | |
| 90 int desired_size_in_dip, | |
| 91 CancelableRequestConsumerBase* consumer, | |
| 92 const FaviconImageCallback& callback); | 128 const FaviconImageCallback& callback); |
| 93 | 129 |
| 94 Handle GetRawFavicon(const GURL& icon_url, | 130 Handle GetRawFavicon(const FaviconParams& params, |
| 95 history::IconType icon_type, | |
| 96 int desired_size_in_dip, | |
| 97 ui::ScaleFactor desired_scale_factor, | 131 ui::ScaleFactor desired_scale_factor, |
| 98 CancelableRequestConsumerBase* consumer, | |
| 99 const FaviconRawCallback& callback); | 132 const FaviconRawCallback& callback); |
| 100 | 133 |
| 101 Handle GetFavicon(const GURL& icon_url, | 134 Handle GetFavicon(const FaviconParams& params, |
| 102 history::IconType icon_type, | |
| 103 int desired_size_in_dip, | |
| 104 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 135 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 105 CancelableRequestConsumerBase* consumer, | |
| 106 const FaviconResultsCallback& callback); | 136 const FaviconResultsCallback& callback); |
| 107 | 137 |
| 108 // Fetches the |icon_type| of favicon at |icon_url|, sending the results to | 138 // Fetches the |icon_type| of favicon at |icon_url|, sending the results to |
| 109 // the given |callback|. If the favicon has previously been set via | 139 // the given |callback|. If the favicon has previously been set via |
| 110 // SetFavicon(), then the favicon URL for |page_url| and all redirects is set | 140 // SetFavicon(), then the favicon URL for |page_url| and all redirects is set |
| 111 // to |icon_url|. If the favicon has not been set, the database is not | 141 // to |icon_url|. If the favicon has not been set, the database is not |
| 112 // updated. | 142 // updated. |
| 113 Handle UpdateFaviconMappingAndFetch(const GURL& page_url, | 143 Handle UpdateFaviconMappingAndFetch(const GURL& page_url, |
| 114 const GURL& icon_url, | 144 const GURL& icon_url, |
| 115 history::IconType icon_type, | 145 history::IconType icon_type, |
| 116 CancelableRequestConsumerBase* consumer, | 146 CancelableRequestConsumerBase* consumer, |
| 117 const FaviconResultsCallback& callback); | 147 const FaviconResultsCallback& callback); |
| 118 | 148 |
| 119 // Requests the favicons of any of |icon_types| whose pixel sizes most | 149 // Requests the favicons of any of |icon_types| whose pixel sizes most |
| 120 // closely match |desired_size_in_dip| and desired scale factors for a web | 150 // closely match |desired_size_in_dip| and desired scale factors for a web |
| 121 // page URL. |consumer| is notified when the bits have been fetched. | 151 // page URL. |consumer| is notified when the bits have been fetched. |
| 122 // |icon_types| can be any combination of IconType value, but only one icon | 152 // |icon_types| can be any combination of IconType value, but only one icon |
| 123 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON | 153 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON |
| 124 // and FAVICON. Each of the three methods below differs in the format of the | 154 // and FAVICON. Each of the three methods below differs in the format of the |
| 125 // callback and the requested scale factors. All of the scale factors | 155 // callback and the requested scale factors. All of the scale factors |
| 126 // supported by the current platform (eg MacOS) are requested for | 156 // supported by the current platform (eg MacOS) are requested for |
| 127 // GetFaviconImageForURL(). | 157 // GetFaviconImageForURL(). |
| 128 Handle GetFaviconImageForURL(Profile* profile, | 158 Handle GetFaviconImageForURL(const FaviconForURLParams& params, |
| 129 const GURL& page_url, | |
| 130 int icon_types, | |
| 131 int desired_size_in_dip, | |
| 132 CancelableRequestConsumerBase* consumer, | |
| 133 const FaviconImageCallback& callback); | 159 const FaviconImageCallback& callback); |
| 134 | 160 |
| 135 Handle GetRawFaviconForURL(Profile* profile, | 161 Handle GetRawFaviconForURL(const FaviconForURLParams& params, |
| 136 const GURL& page_url, | |
| 137 int icon_types, | |
| 138 int desired_size_in_dip, | |
| 139 ui::ScaleFactor desired_scale_factor, | 162 ui::ScaleFactor desired_scale_factor, |
| 140 CancelableRequestConsumerBase* consumer, | |
| 141 const FaviconRawCallback& callback); | 163 const FaviconRawCallback& callback); |
| 142 | 164 |
| 143 Handle GetFaviconForURL( | 165 Handle GetFaviconForURL( |
| 144 Profile* profile, | 166 const FaviconForURLParams& params, |
| 145 const GURL& page_url, | |
| 146 int icon_types, | |
| 147 int desired_size_in_dip, | |
| 148 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 167 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 149 CancelableRequestConsumerBase* consumer, | |
| 150 const FaviconResultsCallback& callback); | 168 const FaviconResultsCallback& callback); |
| 151 | 169 |
| 152 // Requests the favicon for |favicon_id| which most closely matches | 170 // Requests the favicon for |favicon_id| which most closely matches |
| 153 // |desired_size_in_dip| and |desired_scale_factor|. The |consumer| is | 171 // |desired_size_in_dip| and |desired_scale_factor|. The |consumer| is |
| 154 // notified when the bits have been fetched. | 172 // notified when the bits have been fetched. |
| 155 Handle GetRawFaviconForID(history::FaviconID favicon_id, | 173 Handle GetRawFaviconForID(history::FaviconID favicon_id, |
| 156 int desired_size_in_dip, | 174 int desired_size_in_dip, |
| 157 ui::ScaleFactor desired_scale_factor, | 175 ui::ScaleFactor desired_scale_factor, |
| 158 CancelableRequestConsumerBase* consumer, | 176 CancelableRequestConsumerBase* consumer, |
| 159 const FaviconRawCallback& callback); | 177 const FaviconRawCallback& callback); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 182 | 200 |
| 183 private: | 201 private: |
| 184 HistoryService* history_service_; | 202 HistoryService* history_service_; |
| 185 | 203 |
| 186 // Helper to forward an empty result if we cannot get the history service. | 204 // Helper to forward an empty result if we cannot get the history service. |
| 187 void ForwardEmptyResultAsync(GetFaviconRequest* request); | 205 void ForwardEmptyResultAsync(GetFaviconRequest* request); |
| 188 | 206 |
| 189 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and | 207 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and |
| 190 // GetFaviconForURL(). | 208 // GetFaviconForURL(). |
| 191 Handle GetFaviconForURLImpl( | 209 Handle GetFaviconForURLImpl( |
| 192 Profile* profile, | 210 const FaviconForURLParams& params, |
| 193 const GURL& page_url, | |
| 194 int icon_types, | |
| 195 int desired_size_in_dip, | |
| 196 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 211 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 197 CancelableRequestConsumerBase* consumer, | |
| 198 GetFaviconRequest* request); | 212 GetFaviconRequest* request); |
| 199 | 213 |
| 200 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() | 214 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() |
| 201 // so that history service can deal solely with FaviconResultsCallback. | 215 // so that history service can deal solely with FaviconResultsCallback. |
| 202 // Builds history::FaviconImageResult from |favicon_bitmap_results| and runs | 216 // Builds history::FaviconImageResult from |favicon_bitmap_results| and runs |
| 203 // |callback|. | 217 // |callback|. |
| 204 void GetFaviconImageCallback( | 218 void GetFaviconImageCallback( |
| 205 int desired_size_in_dip, | 219 int desired_size_in_dip, |
| 206 FaviconImageCallback callback, | 220 FaviconImageCallback callback, |
| 207 Handle handle, | 221 Handle handle, |
| 208 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, | 222 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, |
| 209 history::IconURLSizesMap icon_url_sizes_map); | 223 history::IconURLSizesMap icon_url_sizes_map); |
| 210 | 224 |
| 211 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() | 225 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() |
| 212 // so that history service can deal solely with FaviconResultsCallback. | 226 // so that history service can deal solely with FaviconResultsCallback. |
| 213 // Resizes history::FaviconBitmapResult if necessary and runs |callback|. | 227 // Resizes history::FaviconBitmapResult if necessary and runs |callback|. |
| 214 void GetRawFaviconCallback( | 228 void GetRawFaviconCallback( |
| 215 int desired_size_in_dip, | 229 int desired_size_in_dip, |
| 216 ui::ScaleFactor desired_scale_factor, | 230 ui::ScaleFactor desired_scale_factor, |
| 217 FaviconRawCallback callback, | 231 FaviconRawCallback callback, |
| 218 Handle handle, | 232 Handle handle, |
| 219 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, | 233 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, |
| 220 history::IconURLSizesMap icon_url_sizes_map); | 234 history::IconURLSizesMap icon_url_sizes_map); |
| 221 | 235 |
| 222 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 236 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 223 }; | 237 }; |
| 224 | 238 |
| 225 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 239 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
| OLD | NEW |