Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_NTP_TILES_ICON_CACHER_H_ | |
| 6 #define COMPONENTS_NTP_TILES_ICON_CACHER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "base/task/cancelable_task_tracker.h" | |
| 13 #include "components/ntp_tiles/popular_sites.h" | |
| 14 | |
| 15 namespace favicon { | |
| 16 class FaviconService; | |
| 17 } // namespace favicon | |
| 18 | |
| 19 namespace favicon_base { | |
| 20 struct FaviconImageResult; | |
| 21 } // namespace favicon_base | |
| 22 | |
| 23 namespace gfx { | |
| 24 class Image; | |
| 25 } // namespace gfx | |
| 26 | |
| 27 namespace image_fetcher { | |
| 28 class ImageFetcher; | |
| 29 } // namespace image_fetcher | |
| 30 | |
| 31 namespace ntp_tiles { | |
| 32 | |
| 33 // Ensures that a Popular Sites icon is cached, downloading and saving it if | |
| 34 // not. | |
| 35 // | |
| 36 // Does not provide any way to get a fetched favicon; use the FaviconService for | |
| 37 // that. All this class does is guarantee that FaviconService will be able to | |
| 38 // get you an icon (if it exists). | |
| 39 class IconCacher { | |
| 40 public: | |
| 41 IconCacher(favicon::FaviconService* favicon_service, | |
| 42 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher); | |
| 43 ~IconCacher(); | |
| 44 | |
| 45 // Fetches the icon if necessary, then invokes |done| with true if it was | |
| 46 // newly fetched (false if it was already cached or could not be fetched). | |
| 47 void StartFetch(PopularSites::Site site, | |
| 48 const base::Callback<void(bool)>& done); | |
| 49 | |
| 50 private: | |
| 51 void OnGetFaviconImageForPageURLFinished( | |
| 52 PopularSites::Site site, | |
| 53 const base::Callback<void(bool)>& done, | |
| 54 const favicon_base::FaviconImageResult& result); | |
| 55 | |
| 56 void OnFaviconDownloaded(PopularSites::Site site, | |
| 57 const base::Callback<void(bool)>& done, | |
| 58 const std::string& id, | |
| 59 const gfx::Image& fetched_image); | |
| 60 | |
| 61 base::CancelableTaskTracker tracker_; | |
| 62 favicon::FaviconService* const favicon_service_; | |
| 63 std::unique_ptr<image_fetcher::ImageFetcher> const image_fetcher_; | |
| 64 }; | |
|
Bernhard Bauer
2016/10/13 13:20:09
DISALLOW_COPY_AND_ASSIGN
sfiera
2016/10/14 06:27:32
Done.
| |
| 65 | |
| 66 } // namespace ntp_tiles | |
| 67 | |
| 68 #endif // COMPONENTS_NTP_TILES_ICON_CACHER_H_ | |
| OLD | NEW |