mastiz | 73693f1 | 2017-01-27 15:52:57 | [diff] [blame] | 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_IMPL_H_ |
| 6 | #define COMPONENTS_NTP_TILES_ICON_CACHER_IMPL_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "base/callback.h" |
| 12 | #include "base/memory/weak_ptr.h" |
| 13 | #include "base/task/cancelable_task_tracker.h" |
| 14 | #include "components/ntp_tiles/icon_cacher.h" |
| 15 | #include "components/ntp_tiles/popular_sites.h" |
| 16 | |
| 17 | namespace favicon { |
| 18 | class FaviconService; |
| 19 | } // namespace favicon |
| 20 | |
| 21 | namespace favicon_base { |
| 22 | struct FaviconImageResult; |
| 23 | } // namespace favicon_base |
| 24 | |
| 25 | namespace gfx { |
| 26 | class Image; |
| 27 | } // namespace gfx |
| 28 | |
| 29 | namespace image_fetcher { |
| 30 | class ImageFetcher; |
treib | 0a6cfc6 | 2017-03-20 13:10:30 | [diff] [blame^] | 31 | struct RequestMetadata; |
mastiz | 73693f1 | 2017-01-27 15:52:57 | [diff] [blame] | 32 | } // namespace image_fetcher |
| 33 | |
| 34 | namespace ntp_tiles { |
| 35 | |
| 36 | class IconCacherImpl : public IconCacher { |
| 37 | public: |
| 38 | IconCacherImpl(favicon::FaviconService* favicon_service, |
| 39 | std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher); |
| 40 | ~IconCacherImpl() override; |
| 41 | |
| 42 | void StartFetch(PopularSites::Site site, |
fhorschig | fed34be | 2017-03-02 23:16:09 | [diff] [blame] | 43 | const base::Closure& icon_available, |
| 44 | const base::Closure& preliminary_icon_available) override; |
mastiz | 73693f1 | 2017-01-27 15:52:57 | [diff] [blame] | 45 | |
| 46 | private: |
| 47 | void OnGetFaviconImageForPageURLFinished( |
| 48 | PopularSites::Site site, |
fhorschig | fed34be | 2017-03-02 23:16:09 | [diff] [blame] | 49 | const base::Closure& icon_available, |
| 50 | const base::Closure& preliminary_icon_available, |
mastiz | 73693f1 | 2017-01-27 15:52:57 | [diff] [blame] | 51 | const favicon_base::FaviconImageResult& result); |
| 52 | |
| 53 | void OnFaviconDownloaded(PopularSites::Site site, |
fhorschig | fed34be | 2017-03-02 23:16:09 | [diff] [blame] | 54 | const base::Closure& icon_available, |
mastiz | 73693f1 | 2017-01-27 15:52:57 | [diff] [blame] | 55 | const std::string& id, |
treib | 0a6cfc6 | 2017-03-20 13:10:30 | [diff] [blame^] | 56 | const gfx::Image& fetched_image, |
| 57 | const image_fetcher::RequestMetadata& metadata); |
mastiz | 73693f1 | 2017-01-27 15:52:57 | [diff] [blame] | 58 | |
fhorschig | fed34be | 2017-03-02 23:16:09 | [diff] [blame] | 59 | bool ProvideDefaultIcon(const PopularSites::Site& site); |
| 60 | void SaveIconForSite(const PopularSites::Site& site, const gfx::Image image); |
| 61 | |
mastiz | 73693f1 | 2017-01-27 15:52:57 | [diff] [blame] | 62 | base::CancelableTaskTracker tracker_; |
| 63 | favicon::FaviconService* const favicon_service_; |
| 64 | std::unique_ptr<image_fetcher::ImageFetcher> const image_fetcher_; |
| 65 | |
| 66 | DISALLOW_COPY_AND_ASSIGN(IconCacherImpl); |
| 67 | }; |
| 68 | |
| 69 | } // namespace ntp_tiles |
| 70 | |
| 71 | #endif // COMPONENTS_NTP_TILES_ICON_CACHER_IMPL_H_ |