blob: 1028f72b29b7153cdd64706eaa4bc3623de11b41 [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;
31} // namespace image_fetcher
32
33namespace ntp_tiles {
34
35class IconCacherImpl : public IconCacher {
36 public:
37 IconCacherImpl(favicon::FaviconService* favicon_service,
38 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
39 ~IconCacherImpl() override;
40
41 void StartFetch(PopularSites::Site site,
42 const base::Callback<void(bool)>& done) override;
43
44 private:
45 void OnGetFaviconImageForPageURLFinished(
46 PopularSites::Site site,
47 const base::Callback<void(bool)>& done,
48 const favicon_base::FaviconImageResult& result);
49
50 void OnFaviconDownloaded(PopularSites::Site site,
51 const base::Callback<void(bool)>& done,
52 const std::string& id,
53 const gfx::Image& fetched_image);
54
55 base::CancelableTaskTracker tracker_;
56 favicon::FaviconService* const favicon_service_;
57 std::unique_ptr<image_fetcher::ImageFetcher> const image_fetcher_;
58
59 DISALLOW_COPY_AND_ASSIGN(IconCacherImpl);
60};
61
62} // namespace ntp_tiles
63
64#endif // COMPONENTS_NTP_TILES_ICON_CACHER_IMPL_H_