| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // 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 |
| 25 // backend behind the scenes. | 25 // backend behind the scenes. |
| 26 class FaviconService : public KeyedService { | 26 class FaviconService : public KeyedService { |
| 27 public: | 27 public: |
| 28 explicit FaviconService(Profile* profile); | 28 explicit FaviconService(Profile* profile); |
| 29 | 29 |
| 30 virtual ~FaviconService(); | 30 virtual ~FaviconService(); |
| 31 | 31 |
| 32 // Auxiliary argument structure for requesting favicons for URLs. | 32 // Auxiliary argument structure for requesting favicons for URLs. |
| 33 struct FaviconForURLParams { | 33 struct FaviconForPageURLParams { |
| 34 FaviconForURLParams(const GURL& page_url, | 34 FaviconForPageURLParams(const GURL& page_url, |
| 35 int icon_types, | 35 int icon_types, |
| 36 int desired_size_in_dip) | 36 int desired_size_in_dip) |
| 37 : page_url(page_url), | 37 : page_url(page_url), |
| 38 icon_types(icon_types), | 38 icon_types(icon_types), |
| 39 desired_size_in_dip(desired_size_in_dip) {} | 39 desired_size_in_dip(desired_size_in_dip) {} |
| 40 | 40 |
| 41 GURL page_url; | 41 GURL page_url; |
| 42 int icon_types; | 42 int icon_types; |
| 43 int desired_size_in_dip; | 43 int desired_size_in_dip; |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 // 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 |
| 47 // helper to run FaviconResultsCallback with pointer parameters. | 47 // helper to run FaviconResultsCallback with pointer parameters. |
| 48 static void FaviconResultsCallbackRunner( | 48 static void FaviconResultsCallbackRunner( |
| 49 const favicon_base::FaviconResultsCallback& callback, | 49 const favicon_base::FaviconResultsCallback& callback, |
| 50 const std::vector<favicon_base::FaviconBitmapResult>* results); | 50 const std::vector<favicon_base::FaviconRawBitmapResult>* results); |
| 51 | 51 |
| 52 // The first argument of |callback| is a |const FaviconImageResult&|. Of which | 52 // The first argument of |callback| is a |const FaviconImageResult&|. Of which |
| 53 // |FaviconImageResult::image| is constructed from the bitmaps for the | 53 // |FaviconImageResult::image| is constructed from the bitmaps for the |
| 54 // passed in URL and icon types which most which closely match the passed in | 54 // passed in URL and icon types which most which closely match the passed in |
| 55 // |desired_size_in_dip| at the scale factors supported by the current | 55 // |desired_size_in_dip| at the scale factors supported by the current |
| 56 // platform (eg MacOS) in addition to 1x. | 56 // platform (eg MacOS) in addition to 1x. |
| 57 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in | 57 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in |
| 58 // |image| originate from. | 58 // |image| originate from. |
| 59 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several | 59 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several |
| 60 // icon URLs. | 60 // icon URLs. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 72 favicon_base::IconType icon_type, | 72 favicon_base::IconType icon_type, |
| 73 int desired_size_in_dip, | 73 int desired_size_in_dip, |
| 74 const favicon_base::FaviconImageCallback& callback, | 74 const favicon_base::FaviconImageCallback& callback, |
| 75 base::CancelableTaskTracker* tracker); | 75 base::CancelableTaskTracker* tracker); |
| 76 | 76 |
| 77 base::CancelableTaskTracker::TaskId GetRawFavicon( | 77 base::CancelableTaskTracker::TaskId GetRawFavicon( |
| 78 const GURL& icon_url, | 78 const GURL& icon_url, |
| 79 favicon_base::IconType icon_type, | 79 favicon_base::IconType icon_type, |
| 80 int desired_size_in_dip, | 80 int desired_size_in_dip, |
| 81 ui::ScaleFactor desired_scale_factor, | 81 ui::ScaleFactor desired_scale_factor, |
| 82 const favicon_base::FaviconRawCallback& callback, | 82 const favicon_base::FaviconRawBitmapCallback& callback, |
| 83 base::CancelableTaskTracker* tracker); | 83 base::CancelableTaskTracker* tracker); |
| 84 | 84 |
| 85 // The first argument for |callback| is the set of bitmaps for the passed in | 85 // 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 | 86 // 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 | 87 // |desired_size_in_dip| at the scale factors supported by the current |
| 88 // platform (eg MacOS) in addition to 1x. The vector has at most one result | 88 // platform (eg MacOS) in addition to 1x. The vector has at most one result |
| 89 // for each of the scale factors. There are less entries if a single result | 89 // for each of the scale factors. There are less entries if a single result |
| 90 // is the best bitmap to use for several scale factors. | 90 // is the best bitmap to use for several scale factors. |
| 91 base::CancelableTaskTracker::TaskId GetFavicon( | 91 base::CancelableTaskTracker::TaskId GetFavicon( |
| 92 const GURL& icon_url, | 92 const GURL& icon_url, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 factors 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 scale factors. All of the 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 // GetFaviconImageForURL(). | 135 // GetFaviconImageForPageURL(). |
| 136 // Note. |callback| is always run asynchronously. | 136 // Note. |callback| is always run asynchronously. |
| 137 base::CancelableTaskTracker::TaskId GetFaviconImageForURL( | 137 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( |
| 138 const FaviconForURLParams& 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 GetRawFaviconForURL( | 142 base::CancelableTaskTracker::TaskId GetRawFaviconForPageURL( |
| 143 const FaviconForURLParams& params, | 143 const FaviconForPageURLParams& params, |
| 144 ui::ScaleFactor desired_scale_factor, | 144 ui::ScaleFactor desired_scale_factor, |
| 145 const favicon_base::FaviconRawCallback& callback, | 145 const favicon_base::FaviconRawBitmapCallback& callback, |
| 146 base::CancelableTaskTracker* tracker); | 146 base::CancelableTaskTracker* tracker); |
| 147 | 147 |
| 148 // See HistoryService::GetLargestFaviconForURL(). | 148 // See HistoryService::GetLargestFaviconForPageURL(). |
| 149 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForURL( | 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::FaviconRawCallback& callback, | 154 const favicon_base::FaviconRawBitmapCallback& callback, |
| 155 base::CancelableTaskTracker* tracker); | 155 base::CancelableTaskTracker* tracker); |
| 156 | 156 |
| 157 base::CancelableTaskTracker::TaskId GetFaviconForURL( | 157 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( |
| 158 const FaviconForURLParams& params, | 158 const FaviconForPageURLParams& params, |
| 159 const favicon_base::FaviconResultsCallback& callback, | 159 const favicon_base::FaviconResultsCallback& callback, |
| 160 base::CancelableTaskTracker* tracker); | 160 base::CancelableTaskTracker* tracker); |
| 161 | 161 |
| 162 // Used to request a bitmap for the favicon with |favicon_id| which is not | 162 // Used to request a bitmap for the favicon with |favicon_id| which is not |
| 163 // resized from the size it is stored at in the database. If there are | 163 // resized from the size it is stored at in the database. If there are |
| 164 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is | 164 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is |
| 165 // returned. | 165 // returned. |
| 166 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( | 166 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( |
| 167 favicon_base::FaviconID favicon_id, | 167 favicon_base::FaviconID favicon_id, |
| 168 const favicon_base::FaviconRawCallback& callback, | 168 const favicon_base::FaviconRawBitmapCallback& callback, |
| 169 base::CancelableTaskTracker* tracker); | 169 base::CancelableTaskTracker* tracker); |
| 170 | 170 |
| 171 // Marks all types of favicon for the page as being out of date. | 171 // Marks all types of favicon for the page as being out of date. |
| 172 void SetFaviconOutOfDateForPage(const GURL& page_url); | 172 void SetFaviconOutOfDateForPage(const GURL& page_url); |
| 173 | 173 |
| 174 // Clones all icons from an existing page. This associates the icons from | 174 // Clones all icons from an existing page. This associates the icons from |
| 175 // |old_page_url| with |new_page_url|, provided |new_page_url| has no | 175 // |old_page_url| with |new_page_url|, provided |new_page_url| has no |
| 176 // recorded associations to any other icons. | 176 // recorded associations to any other icons. |
| 177 // Needed if you want to declare favicons (tentatively) in advance, before a | 177 // Needed if you want to declare favicons (tentatively) in advance, before a |
| 178 // page is ever visited. | 178 // page is ever visited. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 void UnableToDownloadFavicon(const GURL& icon_url); | 214 void UnableToDownloadFavicon(const GURL& icon_url); |
| 215 bool WasUnableToDownloadFavicon(const GURL& icon_url) const; | 215 bool WasUnableToDownloadFavicon(const GURL& icon_url) const; |
| 216 void ClearUnableToDownloadFavicons(); | 216 void ClearUnableToDownloadFavicons(); |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 typedef uint32 MissingFaviconURLHash; | 219 typedef uint32 MissingFaviconURLHash; |
| 220 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; | 220 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; |
| 221 HistoryService* history_service_; | 221 HistoryService* history_service_; |
| 222 Profile* profile_; | 222 Profile* profile_; |
| 223 | 223 |
| 224 // Helper function for GetFaviconImageForURL(), GetRawFaviconForURL() and | 224 // Helper function for GetFaviconImageForPageURL(), GetRawFaviconForPageURL() |
| 225 // GetFaviconForURL(). | 225 // and GetFaviconForPageURL(). |
| 226 base::CancelableTaskTracker::TaskId GetFaviconForURLImpl( | 226 base::CancelableTaskTracker::TaskId GetFaviconForPageURLImpl( |
| 227 const FaviconForURLParams& params, | 227 const FaviconForPageURLParams& params, |
| 228 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 228 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 229 const favicon_base::FaviconResultsCallback& callback, | 229 const favicon_base::FaviconResultsCallback& callback, |
| 230 base::CancelableTaskTracker* tracker); | 230 base::CancelableTaskTracker* tracker); |
| 231 | 231 |
| 232 // Intermediate callback for GetFaviconImage() and GetFaviconImageForURL() | 232 // Intermediate callback for GetFaviconImage() and GetFaviconImageForPageURL() |
| 233 // so that history service can deal solely with FaviconResultsCallback. | 233 // so that history service can deal solely with FaviconResultsCallback. |
| 234 // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and | 234 // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and |
| 235 // runs | 235 // runs |callback|. |
| 236 // |callback|. | |
| 237 void RunFaviconImageCallbackWithBitmapResults( | 236 void RunFaviconImageCallbackWithBitmapResults( |
| 238 const favicon_base::FaviconImageCallback& callback, | 237 const favicon_base::FaviconImageCallback& callback, |
| 239 int desired_size_in_dip, | 238 int desired_size_in_dip, |
| 240 const std::vector<favicon_base::FaviconBitmapResult>& | 239 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 241 favicon_bitmap_results); | 240 favicon_bitmap_results); |
| 242 | 241 |
| 243 // Intermediate callback for GetRawFavicon() and GetRawFaviconForURL() | 242 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() |
| 244 // so that history service can deal solely with FaviconResultsCallback. | 243 // so that history service can deal solely with FaviconResultsCallback. |
| 245 // Resizes favicon_base::FaviconBitmapResult if necessary and runs |callback|. | 244 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs |
| 246 void RunFaviconRawCallbackWithBitmapResults( | 245 // |callback|. |
| 247 const favicon_base::FaviconRawCallback& callback, | 246 void RunFaviconRawBitmapCallbackWithBitmapResults( |
| 247 const favicon_base::FaviconRawBitmapCallback& callback, |
| 248 int desired_size_in_dip, | 248 int desired_size_in_dip, |
| 249 ui::ScaleFactor desired_scale_factor, | 249 ui::ScaleFactor desired_scale_factor, |
| 250 const std::vector<favicon_base::FaviconBitmapResult>& | 250 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 251 favicon_bitmap_results); | 251 favicon_bitmap_results); |
| 252 | 252 |
| 253 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 253 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 254 }; | 254 }; |
| 255 | 255 |
| 256 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 256 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
| OLD | NEW |