| 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 for URLs. |
| 35 struct FaviconForURLParams { |
| 36 FaviconForURLParams(Profile* profile, |
| 37 const GURL& page_url, |
| 38 int icon_types, |
| 39 int desired_size_in_dip, |
| 40 CancelableRequestConsumerBase* consumer) |
| 41 : profile(profile), |
| 42 page_url(page_url), |
| 43 icon_types(icon_types), |
| 44 desired_size_in_dip(desired_size_in_dip), |
| 45 consumer(consumer) { |
| 46 } |
| 47 |
| 48 Profile* profile; |
| 49 GURL page_url; |
| 50 int icon_types; |
| 51 int desired_size_in_dip; |
| 52 CancelableRequestConsumerBase* consumer; |
| 53 }; |
| 54 |
| 34 // Callback for GetFaviconImage() and GetFaviconImageForURL(). | 55 // Callback for GetFaviconImage() and GetFaviconImageForURL(). |
| 35 // |FaviconImageResult::image| is constructed from the bitmaps for the | 56 // |FaviconImageResult::image| is constructed from the bitmaps for the |
| 36 // passed in URL and icon types which most which closely match the passed in | 57 // 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 | 58 // |desired_size_in_dip| at the scale factors supported by the current |
| 38 // platform (eg MacOS). | 59 // platform (eg MacOS). |
| 39 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in | 60 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in |
| 40 // |image| originate from. | 61 // |image| originate from. |
| 41 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several | 62 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several |
| 42 // icon URLs. | 63 // icon URLs. |
| 43 typedef base::Callback<void(Handle, const history::FaviconImageResult&)> | 64 typedef base::Callback<void(Handle, const history::FaviconImageResult&)> |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 139 |
| 119 // Requests the favicons of any of |icon_types| whose pixel sizes most | 140 // 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 | 141 // 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. | 142 // 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 | 143 // |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 | 144 // 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 | 145 // 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 | 146 // callback and the requested scale factors. All of the scale factors |
| 126 // supported by the current platform (eg MacOS) are requested for | 147 // supported by the current platform (eg MacOS) are requested for |
| 127 // GetFaviconImageForURL(). | 148 // GetFaviconImageForURL(). |
| 128 Handle GetFaviconImageForURL(Profile* profile, | 149 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); | 150 const FaviconImageCallback& callback); |
| 134 | 151 |
| 135 Handle GetRawFaviconForURL(Profile* profile, | 152 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, | 153 ui::ScaleFactor desired_scale_factor, |
| 140 CancelableRequestConsumerBase* consumer, | |
| 141 const FaviconRawCallback& callback); | 154 const FaviconRawCallback& callback); |
| 142 | 155 |
| 143 Handle GetFaviconForURL( | 156 Handle GetFaviconForURL( |
| 144 Profile* profile, | 157 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, | 158 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 149 CancelableRequestConsumerBase* consumer, | |
| 150 const FaviconResultsCallback& callback); | 159 const FaviconResultsCallback& callback); |
| 151 | 160 |
| 152 // Requests the favicon for |favicon_id| which most closely matches | 161 // Requests the favicon for |favicon_id| which most closely matches |
| 153 // |desired_size_in_dip| and |desired_scale_factor|. The |consumer| is | 162 // |desired_size_in_dip| and |desired_scale_factor|. The |consumer| is |
| 154 // notified when the bits have been fetched. | 163 // notified when the bits have been fetched. |
| 155 Handle GetRawFaviconForID(history::FaviconID favicon_id, | 164 Handle GetRawFaviconForID(history::FaviconID favicon_id, |
| 156 int desired_size_in_dip, | 165 int desired_size_in_dip, |
| 157 ui::ScaleFactor desired_scale_factor, | 166 ui::ScaleFactor desired_scale_factor, |
| 158 CancelableRequestConsumerBase* consumer, | 167 CancelableRequestConsumerBase* consumer, |
| 159 const FaviconRawCallback& callback); | 168 const FaviconRawCallback& callback); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 182 | 191 |
| 183 private: | 192 private: |
| 184 HistoryService* history_service_; | 193 HistoryService* history_service_; |
| 185 | 194 |
| 186 // Helper to forward an empty result if we cannot get the history service. | 195 // Helper to forward an empty result if we cannot get the history service. |
| 187 void ForwardEmptyResultAsync(GetFaviconRequest* request); | 196 void ForwardEmptyResultAsync(GetFaviconRequest* request); |
| 188 | 197 |
| 189 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and | 198 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and |
| 190 // GetFaviconForURL(). | 199 // GetFaviconForURL(). |
| 191 Handle GetFaviconForURLImpl( | 200 Handle GetFaviconForURLImpl( |
| 192 Profile* profile, | 201 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, | 202 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 197 CancelableRequestConsumerBase* consumer, | |
| 198 GetFaviconRequest* request); | 203 GetFaviconRequest* request); |
| 199 | 204 |
| 200 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() | 205 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() |
| 201 // so that history service can deal solely with FaviconResultsCallback. | 206 // so that history service can deal solely with FaviconResultsCallback. |
| 202 // Builds history::FaviconImageResult from |favicon_bitmap_results| and runs | 207 // Builds history::FaviconImageResult from |favicon_bitmap_results| and runs |
| 203 // |callback|. | 208 // |callback|. |
| 204 void GetFaviconImageCallback( | 209 void GetFaviconImageCallback( |
| 205 int desired_size_in_dip, | 210 int desired_size_in_dip, |
| 206 FaviconImageCallback callback, | 211 FaviconImageCallback callback, |
| 207 Handle handle, | 212 Handle handle, |
| 208 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, | 213 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, |
| 209 history::IconURLSizesMap icon_url_sizes_map); | 214 history::IconURLSizesMap icon_url_sizes_map); |
| 210 | 215 |
| 211 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() | 216 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() |
| 212 // so that history service can deal solely with FaviconResultsCallback. | 217 // so that history service can deal solely with FaviconResultsCallback. |
| 213 // Resizes history::FaviconBitmapResult if necessary and runs |callback|. | 218 // Resizes history::FaviconBitmapResult if necessary and runs |callback|. |
| 214 void GetRawFaviconCallback( | 219 void GetRawFaviconCallback( |
| 215 int desired_size_in_dip, | 220 int desired_size_in_dip, |
| 216 ui::ScaleFactor desired_scale_factor, | 221 ui::ScaleFactor desired_scale_factor, |
| 217 FaviconRawCallback callback, | 222 FaviconRawCallback callback, |
| 218 Handle handle, | 223 Handle handle, |
| 219 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, | 224 std::vector<history::FaviconBitmapResult> favicon_bitmap_results, |
| 220 history::IconURLSizesMap icon_url_sizes_map); | 225 history::IconURLSizesMap icon_url_sizes_map); |
| 221 | 226 |
| 222 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 227 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 223 }; | 228 }; |
| 224 | 229 |
| 225 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 230 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
| OLD | NEW |