blob: 5cd1ee7209a26c0e127c817a0345c892795223eb [file] [log] [blame]
mastiz73693f12017-01-27 15:52:571// 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
17namespace favicon {
18class FaviconService;
19} // namespace favicon
20
21namespace favicon_base {
22struct FaviconImageResult;
23} // namespace favicon_base
24
25namespace gfx {
26class Image;
27} // namespace gfx
28
29namespace image_fetcher {
30class ImageFetcher;
treib0a6cfc62017-03-20 13:10:3031struct RequestMetadata;
mastiz73693f12017-01-27 15:52:5732} // namespace image_fetcher
33
34namespace ntp_tiles {
35
36class 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,
fhorschigfed34be2017-03-02 23:16:0943 const base::Closure& icon_available,
44 const base::Closure& preliminary_icon_available) override;
mastiz73693f12017-01-27 15:52:5745
46 private:
47 void OnGetFaviconImageForPageURLFinished(
48 PopularSites::Site site,
fhorschigfed34be2017-03-02 23:16:0949 const base::Closure& icon_available,
50 const base::Closure& preliminary_icon_available,
mastiz73693f12017-01-27 15:52:5751 const favicon_base::FaviconImageResult& result);
52
53 void OnFaviconDownloaded(PopularSites::Site site,
fhorschigfed34be2017-03-02 23:16:0954 const base::Closure& icon_available,
mastiz73693f12017-01-27 15:52:5755 const std::string& id,
treib0a6cfc62017-03-20 13:10:3056 const gfx::Image& fetched_image,
57 const image_fetcher::RequestMetadata& metadata);
mastiz73693f12017-01-27 15:52:5758
fhorschigfed34be2017-03-02 23:16:0959 bool ProvideDefaultIcon(const PopularSites::Site& site);
60 void SaveIconForSite(const PopularSites::Site& site, const gfx::Image image);
61
mastiz73693f12017-01-27 15:52:5762 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_