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 10 matching lines...) Expand all Loading... | |
| 21 class Profile; | 21 class Profile; |
| 22 | 22 |
| 23 // 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 |
| 24 // backend behind the scenes. | 24 // backend behind the scenes. |
| 25 class FaviconService : public KeyedService { | 25 class FaviconService : public KeyedService { |
| 26 public: | 26 public: |
| 27 explicit FaviconService(Profile* profile); | 27 explicit FaviconService(Profile* profile); |
| 28 | 28 |
| 29 virtual ~FaviconService(); | 29 virtual ~FaviconService(); |
| 30 | 30 |
| 31 // Auxiliary argument structure for requesting favicons for URLs. | |
| 32 struct FaviconForPageURLParams { | |
| 33 FaviconForPageURLParams(const GURL& page_url, | |
| 34 int icon_types, | |
| 35 int desired_size_in_dip) | |
| 36 : page_url(page_url), | |
| 37 icon_types(icon_types), | |
| 38 desired_size_in_dip(desired_size_in_dip) {} | |
| 39 | |
| 40 GURL page_url; | |
| 41 int icon_types; | |
| 42 int desired_size_in_dip; | |
| 43 }; | |
| 44 | |
| 45 // We usually pass parameters with pointer to avoid copy. This function is a | 31 // We usually pass parameters with pointer to avoid copy. This function is a |
| 46 // helper to run FaviconResultsCallback with pointer parameters. | 32 // helper to run FaviconResultsCallback with pointer parameters. |
| 47 static void FaviconResultsCallbackRunner( | 33 static void FaviconResultsCallbackRunner( |
| 48 const favicon_base::FaviconResultsCallback& callback, | 34 const favicon_base::FaviconResultsCallback& callback, |
| 49 const std::vector<favicon_base::FaviconRawBitmapResult>* results); | 35 const std::vector<favicon_base::FaviconRawBitmapResult>* results); |
| 50 | 36 |
| 51 // The first argument of |callback| is a |const FaviconImageResult&|. Of which | 37 ////////////////////////////////////////////////////////////////////////////// |
| 52 // |FaviconImageResult::image| is constructed from the bitmaps for the | 38 // Methods to request favicon bitmaps from the history backend for |icon_url|. |
| 53 // passed in URL and icon types which most wich closely match the passed in | 39 // |icon_url| is the URL of the icon itself. |
| 54 // |desired_size_in_dip| at the resource scale factors supported by the | 40 // (e.g. <http://www.google.com/favicon.ico>) |
| 55 // current platform (eg MacOS) in addition to 1x. | 41 // |callback| is run when the favicon has been fetched. It is always run |
|
sky
2014/07/10 00:03:39
Move |callback| documentation to class description
| |
| 56 // |FaviconImageResult::icon_url| is the favicon that the favicon bitmaps in | 42 // asynchronously, even in the case of an error. |
| 57 // |image| originate from. | |
| 58 // TODO(pkotwicz): Enable constructing |image| from bitmaps from several | |
| 59 // icon URLs. | |
| 60 | 43 |
| 61 // Requests the favicon at |icon_url| of |icon_type| whose size most closely | 44 // Requests the favicon at |icon_url| of type favicon_base::FAVICON and of |
| 62 // matches |desired_size_in_dip|. If |desired_size_in_dip| is 0, the largest | 45 // size gfx::kFaviconSize. The returned gfx::Image is populated with |
| 63 // favicon bitmap at |icon_url| is returned. |consumer| is notified when the | 46 // representations for all of the scale factors supported by the platform |
| 64 // bits have been fetched. |icon_url| is the URL of the icon itself, e.g. | 47 // (e.g. MacOS). If data is unavailable for some or all of the scale factors, |
| 65 // <http://www.google.com/favicon.ico>. | 48 // the bitmaps with the best matching sizes are resized. |
| 66 // Each of the three methods below differs in the format of the callback and | |
| 67 // the requested scales. All of the resource scale factors supported by the | |
| 68 // current platform (eg MacOS) are requested for GetFaviconImage(). | |
| 69 base::CancelableTaskTracker::TaskId GetFaviconImage( | 49 base::CancelableTaskTracker::TaskId GetFaviconImage( |
| 70 const GURL& icon_url, | 50 const GURL& icon_url, |
| 71 favicon_base::IconType icon_type, | |
| 72 int desired_size_in_dip, | |
| 73 const favicon_base::FaviconImageCallback& callback, | 51 const favicon_base::FaviconImageCallback& callback, |
| 74 base::CancelableTaskTracker* tracker); | 52 base::CancelableTaskTracker* tracker); |
| 75 | 53 |
| 54 // Requests the favicon at |icon_url| of |icon_type| of size | |
| 55 // |desired_size_in_pixel|. If there is no favicon of size | |
| 56 // |desired_size_in_pixel|, the favicon bitmap which best matches | |
| 57 // |desired_size_in_pixel| is resized. If |desired_size_in_pixel| is 0, | |
| 58 // the largest favicon bitmap is returned. | |
| 76 base::CancelableTaskTracker::TaskId GetRawFavicon( | 59 base::CancelableTaskTracker::TaskId GetRawFavicon( |
| 77 const GURL& icon_url, | 60 const GURL& icon_url, |
| 78 favicon_base::IconType icon_type, | 61 favicon_base::IconType icon_type, |
| 79 int desired_size_in_dip, | 62 int desired_size_in_pixel, |
| 80 float desired_favicon_scale, | |
| 81 const favicon_base::FaviconRawBitmapCallback& callback, | 63 const favicon_base::FaviconRawBitmapCallback& callback, |
| 82 base::CancelableTaskTracker* tracker); | 64 base::CancelableTaskTracker* tracker); |
| 83 | 65 |
| 84 // The first argument for |callback| is the set of bitmaps for the passed in | 66 // The first argument for |callback| is the set of bitmaps for the passed in |
| 85 // URL and icon types whose pixel sizes best match the passed in | 67 // URL and icon types whose pixel sizes best match the passed in |
| 86 // |desired_size_in_dip| at the resource scale factors supported by the | 68 // |desired_size_in_dip| at the resource scale factors supported by the |
| 87 // current platform (eg MacOS) in addition to 1x. The vector has at most one | 69 // current platform (eg MacOS) in addition to 1x. The vector has at most one |
| 88 // result for each of the resource scale factors. There are less entries if a | 70 // result for each of the resource scale factors. There are less entries if a |
| 89 // single/ result is the best bitmap to use for several resource scale | 71 // single/ result is the best bitmap to use for several resource scale |
| 90 // factors. | 72 // factors. |
| 91 base::CancelableTaskTracker::TaskId GetFavicon( | 73 base::CancelableTaskTracker::TaskId GetFavicon( |
| 92 const GURL& icon_url, | 74 const GURL& icon_url, |
| 93 favicon_base::IconType icon_type, | 75 favicon_base::IconType icon_type, |
| 94 int desired_size_in_dip, | 76 int desired_size_in_dip, |
| 95 const favicon_base::FaviconResultsCallback& callback, | 77 const favicon_base::FaviconResultsCallback& callback, |
| 96 base::CancelableTaskTracker* tracker); | 78 base::CancelableTaskTracker* tracker); |
| 97 | 79 |
| 80 ////////////////////////////////////////////////////////////////////////////// | |
| 81 // Methods to request favicon bitmaps from the history backend for |page_url|. | |
| 82 // |page_url| is the web page the favicon is associated with. | |
| 83 // (e.g. <http://www.google.com>) | |
| 84 // |callback| is run when the favicon has been fetched. It is always run | |
| 85 // asynchronously, even in the case of an error. | |
| 86 | |
| 87 // Requests the favicon for the page at |page_url| of type | |
| 88 // favicon_base::FAVICON and of size gfx::kFaviconSize. The returned | |
| 89 // gfx::Image is populated with representations for all of the scale factors | |
| 90 // supported by the platform (e.g. MacOS). If data is unavailable for some or | |
| 91 // all of the scale factors, the bitmaps with the best matching sizes are | |
| 92 // resized. | |
| 93 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( | |
| 94 const GURL& page_url, | |
| 95 const favicon_base::FaviconImageCallback& callback, | |
| 96 base::CancelableTaskTracker* tracker); | |
| 97 | |
| 98 // Requests the favicon for the page at |page_url| with one of |icon_types| | |
| 99 // and with |desired_size_in_pixel|. |icon_types| can be any combination of | |
| 100 // IconTypes. If favicon bitmaps for several IconTypes are available, the | |
| 101 // favicon bitmap is chosen in the priority of TOUCH_PRECOMPOSED_ICON, | |
| 102 // TOUCH_ICON and FAVICON. If there is no favicon bitmap of size | |
| 103 // |desired_size_in_pixel|, the favicon bitmap which best matches | |
| 104 // |desired_size_in_pixel| is resized. If |desired_size_in_pixel| is 0, | |
| 105 // the largest favicon bitmap is returned. Results with a higher priority | |
| 106 // IconType are preferred over an exact match of the favicon bitmap size. | |
| 107 base::CancelableTaskTracker::TaskId GetRawFaviconForPageURL( | |
| 108 const GURL& page_url, | |
| 109 int icon_types, | |
| 110 int desired_size_in_pixel, | |
| 111 const favicon_base::FaviconRawBitmapCallback& callback, | |
| 112 base::CancelableTaskTracker* tracker); | |
| 113 | |
| 114 // See HistoryService::GetLargestFaviconForPageURL(). | |
| 115 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( | |
| 116 const GURL& page_url, | |
| 117 const std::vector<int>& icon_types, | |
| 118 int minimum_size_in_pixels, | |
| 119 const favicon_base::FaviconRawBitmapCallback& callback, | |
| 120 base::CancelableTaskTracker* tracker); | |
| 121 | |
| 122 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( | |
| 123 const GURL& page_url, | |
| 124 int icon_types, | |
| 125 int desired_size_in_dip, | |
| 126 const favicon_base::FaviconResultsCallback& callback, | |
| 127 base::CancelableTaskTracker* tracker); | |
| 128 | |
| 98 // Set the favicon mappings to |page_url| for |icon_types| in the history | 129 // Set the favicon mappings to |page_url| for |icon_types| in the history |
| 99 // database. | 130 // database. |
| 100 // Sample |icon_urls|: | 131 // Sample |icon_urls|: |
| 101 // { ICON_URL1 -> TOUCH_ICON, known to the database, | 132 // { ICON_URL1 -> TOUCH_ICON, known to the database, |
| 102 // ICON_URL2 -> TOUCH_ICON, not known to the database, | 133 // ICON_URL2 -> TOUCH_ICON, not known to the database, |
| 103 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } | 134 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } |
| 104 // The new mappings are computed from |icon_urls| with these rules: | 135 // 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 | 136 // 1) Any urls in |icon_urls| which are not already known to the database are |
| 106 // rejected. | 137 // rejected. |
| 107 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } | 138 // 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 | 139 // 2) If |icon_types| has multiple types, the mappings are only set for the |
| 109 // largest icon type. | 140 // largest icon type. |
| 110 // Sample new mappings to |page_url|: { ICON_URL3 } | 141 // Sample new mappings to |page_url|: { ICON_URL3 } |
| 111 // |icon_types| can only have multiple IconTypes if | 142 // |icon_types| can only have multiple IconTypes if |
| 112 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. | 143 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. |
| 113 // The favicon bitmaps which most closely match |desired_size_in_dip| | 144 // The favicon bitmaps which most closely match |desired_size_in_dip| |
| 114 // at the reosurce scale factors supported by the current platform (eg MacOS) | 145 // at the reosurce scale factors supported by the current platform (eg MacOS) |
| 115 // in addition to 1x from the favicons which were just mapped to |page_url| | 146 // in addition to 1x from the favicons which were just mapped to |page_url| |
| 116 // are returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is | 147 // are returned. If |desired_size_in_dip| is 0, the largest favicon bitmap is |
| 117 // returned. | 148 // returned. |
| 118 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( | 149 base::CancelableTaskTracker::TaskId UpdateFaviconMappingsAndFetch( |
| 119 const GURL& page_url, | 150 const GURL& page_url, |
| 120 const std::vector<GURL>& icon_urls, | 151 const std::vector<GURL>& icon_urls, |
| 121 int icon_types, | 152 int icon_types, |
| 122 int desired_size_in_dip, | 153 int desired_size_in_dip, |
| 123 const favicon_base::FaviconResultsCallback& callback, | 154 const favicon_base::FaviconResultsCallback& callback, |
| 124 base::CancelableTaskTracker* tracker); | 155 base::CancelableTaskTracker* tracker); |
| 125 | 156 |
| 126 // Requests the favicons of any of |icon_types| whose pixel sizes most | |
| 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 | |
| 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 | |
| 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 | |
| 133 // callback and the requested scales. All of the resource scale factors | |
| 134 // supported by the current platform (eg MacOS) are requested for | |
| 135 // GetFaviconImageForPageURL(). | |
| 136 // Note. |callback| is always run asynchronously. | |
| 137 base::CancelableTaskTracker::TaskId GetFaviconImageForPageURL( | |
| 138 const FaviconForPageURLParams& params, | |
| 139 const favicon_base::FaviconImageCallback& callback, | |
| 140 base::CancelableTaskTracker* tracker); | |
| 141 | |
| 142 base::CancelableTaskTracker::TaskId GetRawFaviconForPageURL( | |
| 143 const FaviconForPageURLParams& params, | |
| 144 float desired_favicon_scale, | |
| 145 const favicon_base::FaviconRawBitmapCallback& callback, | |
| 146 base::CancelableTaskTracker* tracker); | |
| 147 | |
| 148 // See HistoryService::GetLargestFaviconForPageURL(). | |
| 149 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForPageURL( | |
| 150 const GURL& page_url, | |
| 151 const std::vector<int>& icon_types, | |
| 152 int minimum_size_in_pixels, | |
| 153 const favicon_base::FaviconRawBitmapCallback& callback, | |
| 154 base::CancelableTaskTracker* tracker); | |
| 155 | |
| 156 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( | |
| 157 const FaviconForPageURLParams& params, | |
| 158 const favicon_base::FaviconResultsCallback& callback, | |
| 159 base::CancelableTaskTracker* tracker); | |
| 160 | |
| 161 // Used to request a bitmap for the favicon with |favicon_id| which is not | 157 // Used to request a bitmap for the favicon with |favicon_id| which is not |
| 162 // resized from the size it is stored at in the database. If there are | 158 // resized from the size it is stored at in the database. If there are |
| 163 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is | 159 // multiple favicon bitmaps for |favicon_id|, the largest favicon bitmap is |
| 164 // returned. | 160 // returned. |
| 165 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( | 161 base::CancelableTaskTracker::TaskId GetLargestRawFaviconForID( |
| 166 favicon_base::FaviconID favicon_id, | 162 favicon_base::FaviconID favicon_id, |
| 167 const favicon_base::FaviconRawBitmapCallback& callback, | 163 const favicon_base::FaviconRawBitmapCallback& callback, |
| 168 base::CancelableTaskTracker* tracker); | 164 base::CancelableTaskTracker* tracker); |
| 169 | 165 |
| 170 // Marks all types of favicon for the page as being out of date. | 166 // Marks all types of favicon for the page as being out of date. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 212 |
| 217 private: | 213 private: |
| 218 typedef uint32 MissingFaviconURLHash; | 214 typedef uint32 MissingFaviconURLHash; |
| 219 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; | 215 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; |
| 220 HistoryService* history_service_; | 216 HistoryService* history_service_; |
| 221 Profile* profile_; | 217 Profile* profile_; |
| 222 | 218 |
| 223 // Helper function for GetFaviconImageForPageURL(), GetRawFaviconForPageURL() | 219 // Helper function for GetFaviconImageForPageURL(), GetRawFaviconForPageURL() |
| 224 // and GetFaviconForPageURL(). | 220 // and GetFaviconForPageURL(). |
| 225 base::CancelableTaskTracker::TaskId GetFaviconForPageURLImpl( | 221 base::CancelableTaskTracker::TaskId GetFaviconForPageURLImpl( |
| 226 const FaviconForPageURLParams& params, | 222 const GURL& page_url, |
| 223 int icon_types, | |
| 227 const std::vector<int>& desired_sizes_in_pixel, | 224 const std::vector<int>& desired_sizes_in_pixel, |
| 228 const favicon_base::FaviconResultsCallback& callback, | 225 const favicon_base::FaviconResultsCallback& callback, |
| 229 base::CancelableTaskTracker* tracker); | 226 base::CancelableTaskTracker* tracker); |
| 230 | 227 |
| 231 // Intermediate callback for GetFaviconImage() and GetFaviconImageForPageURL() | 228 // Intermediate callback for GetFaviconImage() and GetFaviconImageForPageURL() |
| 232 // so that history service can deal solely with FaviconResultsCallback. | 229 // so that history service can deal solely with FaviconResultsCallback. |
| 233 // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and | 230 // Builds favicon_base::FaviconImageResult from |favicon_bitmap_results| and |
| 234 // runs |callback|. | 231 // runs |callback|. |
| 235 void RunFaviconImageCallbackWithBitmapResults( | 232 void RunFaviconImageCallbackWithBitmapResults( |
| 236 const favicon_base::FaviconImageCallback& callback, | 233 const favicon_base::FaviconImageCallback& callback, |
| 237 int desired_size_in_dip, | 234 int desired_size_in_dip, |
| 238 const std::vector<favicon_base::FaviconRawBitmapResult>& | 235 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 239 favicon_bitmap_results); | 236 favicon_bitmap_results); |
| 240 | 237 |
| 241 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() | 238 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() |
| 242 // so that history service can deal solely with FaviconResultsCallback. | 239 // so that history service can deal solely with FaviconResultsCallback. |
| 243 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs | 240 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs |
| 244 // |callback|. | 241 // |callback|. |
| 245 void RunFaviconRawBitmapCallbackWithBitmapResults( | 242 void RunFaviconRawBitmapCallbackWithBitmapResults( |
| 246 const favicon_base::FaviconRawBitmapCallback& callback, | 243 const favicon_base::FaviconRawBitmapCallback& callback, |
| 247 int desired_size_in_pixel, | 244 int desired_size_in_pixel, |
| 248 const std::vector<favicon_base::FaviconRawBitmapResult>& | 245 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 249 favicon_bitmap_results); | 246 favicon_bitmap_results); |
| 250 | 247 |
| 251 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 248 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 252 }; | 249 }; |
| 253 | 250 |
| 254 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ | 251 #endif // CHROME_BROWSER_FAVICON_FAVICON_SERVICE_H_ |
| OLD | NEW |