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 COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ | 5 #ifndef COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ |
| 6 #define COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ | 6 #define COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 14 #include "base/containers/hash_tables.h" | 15 #include "base/containers/hash_tables.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/task/cancelable_task_tracker.h" | 18 #include "base/task/cancelable_task_tracker.h" |
| 19 #include "components/data_use_measurement/core/data_use_user_data.h" | |
| 18 #include "components/favicon_base/favicon_callback.h" | 20 #include "components/favicon_base/favicon_callback.h" |
| 19 #include "components/favicon_base/favicon_types.h" | 21 #include "components/favicon_base/favicon_types.h" |
| 20 #include "components/favicon_base/favicon_usage_data.h" | 22 #include "components/favicon_base/favicon_usage_data.h" |
| 21 #include "components/keyed_service/core/keyed_service.h" | 23 #include "components/keyed_service/core/keyed_service.h" |
| 22 | 24 |
| 23 class GURL; | 25 class GURL; |
| 24 | 26 |
| 25 namespace history { | 27 namespace history { |
| 26 class HistoryService; | 28 class HistoryService; |
| 27 } | 29 } |
| 28 | 30 |
| 31 namespace image_fetcher { | |
| 32 class ImageFetcher; | |
| 33 } | |
| 34 | |
| 29 namespace favicon { | 35 namespace favicon { |
| 30 | 36 |
| 31 class FaviconClient; | 37 class FaviconClient; |
| 32 | 38 |
| 33 // The favicon service provides methods to access favicons. It calls the history | 39 // The favicon service provides methods to access favicons. It calls the history |
| 34 // backend behind the scenes. The callbacks are run asynchronously, even in the | 40 // backend behind the scenes. The callbacks are run asynchronously, even in the |
| 35 // case of an error. | 41 // case of an error. |
| 36 class FaviconService : public KeyedService { | 42 class FaviconService : public KeyedService { |
| 37 public: | 43 public: |
| 38 // The FaviconClient must outlive the constructed FaviconService. | 44 // The FaviconClient must outlive the constructed FaviconService. |
| 39 FaviconService(std::unique_ptr<FaviconClient> favicon_client, | 45 FaviconService(std::unique_ptr<FaviconClient> favicon_client, |
| 40 history::HistoryService* history_service); | 46 history::HistoryService* history_service, |
| 47 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher); | |
| 41 | 48 |
| 42 ~FaviconService() override; | 49 ~FaviconService() override; |
| 43 | 50 |
| 44 // We usually pass parameters with pointer to avoid copy. This function is a | 51 // We usually pass parameters with pointer to avoid copy. This function is a |
| 45 // helper to run FaviconResultsCallback with pointer parameters. | 52 // helper to run FaviconResultsCallback with pointer parameters. |
| 46 static void FaviconResultsCallbackRunner( | 53 static void FaviconResultsCallbackRunner( |
| 47 const favicon_base::FaviconResultsCallback& callback, | 54 const favicon_base::FaviconResultsCallback& callback, |
| 48 const std::vector<favicon_base::FaviconRawBitmapResult>* results); | 55 const std::vector<favicon_base::FaviconRawBitmapResult>* results); |
| 49 | 56 |
| 50 ////////////////////////////////////////////////////////////////////////////// | 57 ////////////////////////////////////////////////////////////////////////////// |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 const favicon_base::FaviconRawBitmapCallback& callback, | 135 const favicon_base::FaviconRawBitmapCallback& callback, |
| 129 base::CancelableTaskTracker* tracker); | 136 base::CancelableTaskTracker* tracker); |
| 130 | 137 |
| 131 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( | 138 base::CancelableTaskTracker::TaskId GetFaviconForPageURL( |
| 132 const GURL& page_url, | 139 const GURL& page_url, |
| 133 int icon_types, | 140 int icon_types, |
| 134 int desired_size_in_dip, | 141 int desired_size_in_dip, |
| 135 const favicon_base::FaviconResultsCallback& callback, | 142 const favicon_base::FaviconResultsCallback& callback, |
| 136 base::CancelableTaskTracker* tracker); | 143 base::CancelableTaskTracker* tracker); |
| 137 | 144 |
| 145 // Downloads the favicon for the page at |page_url| with size | |
| 146 // |desired_size_in_pixel| from a Google server. Currently, only sizes 16, 24, | |
| 147 // 32, 48, and 64 are supported and only FAVICON IconType is supported. If you | |
|
stkhapugin
2016/09/28 16:12:18
I know this may not be the best place to ask, but
jkrcal
2016/12/09 13:57:44
Having another function for fetching larger APPLE_
| |
| 148 // specify any different size < 64, the smallest larger size is fetched. If | |
| 149 // you set |desired_size_in_pixel| > 64, the 64px size is fetched. If the | |
| 150 // fetched size is not available, the largest available size is upscaled to | |
| 151 // the fetched size (by the Google server, at indexing time). If no icon is | |
| 152 // available for the given url and size, the callback is called with a result | |
| 153 // with an empty image. | |
| 154 // | |
| 155 // This function does not check the local cache, it always directly calls the | |
| 156 // server. However, if the request is successful, it stores the resulting | |
| 157 // favicon in the cache for future use (possibly overwriting previous image in | |
| 158 // the cache for the given url). The fetched favicon is immediately marked as | |
| 159 // expired so that when the user visits |page_url| for the next time, the | |
| 160 // favicon is re-downloaded. | |
| 161 // | |
| 162 // The Google favicon server requires to specify a string |client_id| | |
| 163 // used to identify your use case. Please negotiate a quota for your | |
| 164 // |client_id| before making use of this function in production (see | |
| 165 // g3doc/social/favicon/); use an arbitrary string in development builds. Use | |
| 166 // |data_use_service_name| to count the fetches to your data use (or | |
| 167 // NOT_TAGGED if not interested). | |
| 168 void DownloadFromGoogleServerFaviconImageForPageURL( | |
|
stkhapugin
2016/09/28 16:12:18
It looks like every other async call here returns
jkrcal
2016/12/09 13:57:44
Done.
| |
| 169 const GURL& page_url, | |
| 170 int desired_size_in_pixel, | |
| 171 std::string client_id, | |
| 172 data_use_measurement::DataUseUserData::ServiceName data_use_service_name, | |
| 173 const favicon_base::FaviconImageCallback& callback); | |
| 174 | |
| 138 // Set the favicon mappings to |page_url| for |icon_types| in the history | 175 // Set the favicon mappings to |page_url| for |icon_types| in the history |
| 139 // database. | 176 // database. |
| 140 // Sample |icon_urls|: | 177 // Sample |icon_urls|: |
| 141 // { ICON_URL1 -> TOUCH_ICON, known to the database, | 178 // { ICON_URL1 -> TOUCH_ICON, known to the database, |
| 142 // ICON_URL2 -> TOUCH_ICON, not known to the database, | 179 // ICON_URL2 -> TOUCH_ICON, not known to the database, |
| 143 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } | 180 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } |
| 144 // The new mappings are computed from |icon_urls| with these rules: | 181 // The new mappings are computed from |icon_urls| with these rules: |
| 145 // 1) Any urls in |icon_urls| which are not already known to the database are | 182 // 1) Any urls in |icon_urls| which are not already known to the database are |
| 146 // rejected. | 183 // rejected. |
| 147 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } | 184 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() | 274 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() |
| 238 // so that history service can deal solely with FaviconResultsCallback. | 275 // so that history service can deal solely with FaviconResultsCallback. |
| 239 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs | 276 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs |
| 240 // |callback|. | 277 // |callback|. |
| 241 void RunFaviconRawBitmapCallbackWithBitmapResults( | 278 void RunFaviconRawBitmapCallbackWithBitmapResults( |
| 242 const favicon_base::FaviconRawBitmapCallback& callback, | 279 const favicon_base::FaviconRawBitmapCallback& callback, |
| 243 int desired_size_in_pixel, | 280 int desired_size_in_pixel, |
| 244 const std::vector<favicon_base::FaviconRawBitmapResult>& | 281 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 245 favicon_bitmap_results); | 282 favicon_bitmap_results); |
| 246 | 283 |
| 284 // Intermediate callback for DownloadFromGoogleServerFaviconImageForPageURL() | |
| 285 // so that the client code can deal solely with FaviconImageCallback. | |
| 286 void StoreFaviconFromGoogleServiceAndRunFaviconImageCallback( | |
| 287 const favicon_base::FaviconImageCallback& callback, | |
| 288 const GURL& domain_url, | |
| 289 const std::string& icon_url, | |
| 290 const gfx::Image& image); | |
| 291 | |
| 247 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; | 292 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; |
| 248 std::unique_ptr<FaviconClient> favicon_client_; | 293 std::unique_ptr<FaviconClient> favicon_client_; |
| 249 history::HistoryService* history_service_; | 294 history::HistoryService* history_service_; |
| 295 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | |
| 250 | 296 |
| 251 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 297 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 252 }; | 298 }; |
| 253 | 299 |
| 254 } // namespace favicon | 300 } // namespace favicon |
| 255 | 301 |
| 256 #endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ | 302 #endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ |
| OLD | NEW |