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 // If there are any FAVICONs for the page at |page_url| in the local cache, it | |
| 146 // uses only the local cache and never requests the icon from any Google | |
| 147 // server. If there is no icon in the cache larger than | |
| 148 // |minimum_size_in_pixels|, the result is an empty image. Otherwise, the | |
| 149 // result is a favicon rescaled to |desired_size_in_pixel|. If there are | |
| 150 // multiple icons to choose from, the one with size closest to the desired one | |
| 151 // is used (always preferring larger than |desired_size_in_pixel| over smaller | |
| 152 // ones). | |
| 153 // | |
| 154 // If there are no FAVICONs for the page at |page_url|, the function downloads | |
| 155 // the favicon for the page at |page_url| with size |desired_size_in_pixel| | |
| 156 // from a Google server. Currently, only icons of FAVICON IconType and of | |
| 157 // sizes 16, 24, 32, 48, and 64 are supported. If you specify any different | |
| 158 // size < 64, the smallest larger size is fetched. If you set | |
| 159 // |desired_size_in_pixel| > 64, the 64px size is fetched. If the fetched size | |
| 160 // is not available, the largest available size is upscaled to the fetched | |
| 161 // size (by the Google server, at indexing time). If no icon is available for | |
| 162 // the given url and size, the callback is called with a result with an empty | |
| 163 // image. | |
| 164 // | |
| 165 // If the request is successful, it stores the resulting favicon in the cache | |
| 166 // for future use (possibly overwriting previous image in the cache for the | |
| 167 // given url). The fetched favicon is immediately marked as expired so that | |
| 168 // when the user visits |page_url| for the next time, the favicon is | |
| 169 // re-downloaded. | |
| 170 // | |
| 171 // The Google favicon server requires to specify a string |client_id| | |
| 172 // used to identify your use case. Please negotiate a quota for your | |
| 173 // |client_id| before making use of this function in production (see | |
| 174 // g3doc/social/favicon/); use an arbitrary string in development builds. Use | |
| 175 // |data_use_service_name| to count the fetches to your data use (or | |
| 176 // NOT_TAGGED if not interested). | |
| 177 base::CancelableTaskTracker::TaskId | |
| 178 GetRawFaviconForPageURLDownloadFromGoogleServerIfNeeded( | |
|
jkrcal
2016/12/09 13:57:44
Peter, in an offline discussion, you've suggested
pkotwicz
2016/12/09 19:46:30
The goal of this function is to get a single resol
jkrcal
2016/12/14 15:18:50
Okay, thanks. Will keep it as it is, rename it in
| |
| 179 const GURL& page_url, | |
| 180 int minimum_size_in_pixels, | |
| 181 int desired_size_in_pixels, | |
| 182 std::string client_id, | |
| 183 data_use_measurement::DataUseUserData::ServiceName data_use_service_name, | |
| 184 const favicon_base::FaviconImageCallback& callback, | |
| 185 base::CancelableTaskTracker* tracker); | |
| 186 | |
| 138 // Set the favicon mappings to |page_url| for |icon_types| in the history | 187 // Set the favicon mappings to |page_url| for |icon_types| in the history |
| 139 // database. | 188 // database. |
| 140 // Sample |icon_urls|: | 189 // Sample |icon_urls|: |
| 141 // { ICON_URL1 -> TOUCH_ICON, known to the database, | 190 // { ICON_URL1 -> TOUCH_ICON, known to the database, |
| 142 // ICON_URL2 -> TOUCH_ICON, not known to the database, | 191 // ICON_URL2 -> TOUCH_ICON, not known to the database, |
| 143 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } | 192 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } |
| 144 // The new mappings are computed from |icon_urls| with these rules: | 193 // 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 | 194 // 1) Any urls in |icon_urls| which are not already known to the database are |
| 146 // rejected. | 195 // rejected. |
| 147 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } | 196 // 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() | 286 // Intermediate callback for GetRawFavicon() and GetRawFaviconForPageURL() |
| 238 // so that history service can deal solely with FaviconResultsCallback. | 287 // so that history service can deal solely with FaviconResultsCallback. |
| 239 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs | 288 // Resizes favicon_base::FaviconRawBitmapResult if necessary and runs |
| 240 // |callback|. | 289 // |callback|. |
| 241 void RunFaviconRawBitmapCallbackWithBitmapResults( | 290 void RunFaviconRawBitmapCallbackWithBitmapResults( |
| 242 const favicon_base::FaviconRawBitmapCallback& callback, | 291 const favicon_base::FaviconRawBitmapCallback& callback, |
| 243 int desired_size_in_pixel, | 292 int desired_size_in_pixel, |
| 244 const std::vector<favicon_base::FaviconRawBitmapResult>& | 293 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 245 favicon_bitmap_results); | 294 favicon_bitmap_results); |
| 246 | 295 |
| 296 // Intermediate callback for | |
| 297 // GetRawFaviconForPageURLDownloadFromGoogleServerIfNeeded() so that the | |
| 298 // client code can deal solely with FaviconImageCallback. | |
| 299 void RunFaviconImageCallbackOrDownloadFromGoogleFaviconServer( | |
| 300 const GURL& page_url, | |
| 301 int minimum_size_in_pixels, | |
| 302 int desired_size_in_pixels, | |
| 303 std::string client_id, | |
| 304 data_use_measurement::DataUseUserData::ServiceName data_use_service_name, | |
| 305 const favicon_base::FaviconImageCallback& callback, | |
| 306 const std::vector<favicon_base::FaviconRawBitmapResult>& | |
| 307 favicon_bitmap_results); | |
| 308 | |
| 309 // Intermediate callback for | |
| 310 // RunFaviconImageCallbackOrDownloadFromGoogleFaviconServer() so that the | |
| 311 // client code can deal solely with FaviconImageCallback. | |
| 312 void StoreFaviconFromGoogleServiceAndRunFaviconImageCallback( | |
| 313 const favicon_base::FaviconImageCallback& callback, | |
| 314 const GURL& domain_url, | |
| 315 const std::string& icon_url, | |
| 316 const gfx::Image& image); | |
| 317 | |
| 247 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; | 318 base::hash_set<MissingFaviconURLHash> missing_favicon_urls_; |
| 248 std::unique_ptr<FaviconClient> favicon_client_; | 319 std::unique_ptr<FaviconClient> favicon_client_; |
| 249 history::HistoryService* history_service_; | 320 history::HistoryService* history_service_; |
| 321 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_; | |
|
pkotwicz
2016/12/09 19:46:30
Is the security team OK with decoding images from
jkrcal
2016/12/14 15:18:50
componentes/image_fetcher uses an isolated process
pkotwicz
2016/12/15 01:22:27
You are right. I see now :)
| |
| 250 | 322 |
| 251 DISALLOW_COPY_AND_ASSIGN(FaviconService); | 323 DISALLOW_COPY_AND_ASSIGN(FaviconService); |
| 252 }; | 324 }; |
| 253 | 325 |
| 254 } // namespace favicon | 326 } // namespace favicon |
| 255 | 327 |
| 256 #endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ | 328 #endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVICE_H_ |
| OLD | NEW |