Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(774)

Side by Side Diff: components/ntp_tiles/icon_cacher.h

Issue 2388783004: Ensure PopularSite icon availability in ntp_tiles. (Closed)
Patch Set: Fix comments, variable names. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
Marc Treib 2016/10/12 09:11:28 2016
sfiera 2016/10/13 09:06:46 Done.
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 "base/callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "components/favicon/core/favicon_service.h"
11 #include "components/favicon/core/favicon_util.h"
12 #include "components/favicon_base/favicon_types.h"
13 #include "components/favicon_base/favicon_util.h"
14 #include "components/image_fetcher/image_fetcher.h"
15 #include "components/ntp_tiles/popular_sites.h"
16 #include "url/gurl.h"
17
18 namespace ntp_tiles {
19
20 // Ensures that a Popular Sites icon is cached, downloading and saving it if
21 // not.
22 //
23 // Does not provide any way to get a fetched favicon; use the FaviconService for
24 // that. All this class does is guarantee that FaviconService will be able to
25 // get you an icon (if it exists).
26 class IconCacher {
Marc Treib 2016/10/12 09:11:28 Hm, I'm not entirely happy with the name - caching
sfiera 2016/10/13 09:06:46 I don't like "Favicon" in the name, because that's
Marc Treib 2016/10/13 12:31:15 It'd be consistent with FaviconService, which also
27 public:
28 IconCacher(favicon::FaviconService* favicon_service,
29 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
Marc Treib 2016/10/12 09:11:28 #include <memory>
sfiera 2016/10/13 09:06:46 Done.
30 ~IconCacher();
31
32 // Fetches the icon if necessary, then invokes |done| with true if it was
33 // newly fetched (false if it was already cached or could not be fetched).
34 void StartFetch(PopularSites::Site site, base::Callback<void(bool)> done);
Marc Treib 2016/10/12 09:11:28 Pass the callback by const ref (to avoid some unne
sfiera 2016/10/13 09:06:45 Done.
35
36 private:
37 base::CancelableTaskTracker tracker_;
38 favicon::FaviconService* const favicon_service_;
39 std::unique_ptr<image_fetcher::ImageFetcher> const image_fetcher_;
40
41 base::WeakPtrFactory<IconCacher> weak_ptr_factory_;
Marc Treib 2016/10/12 09:11:28 Methods come before member variables
sfiera 2016/10/13 09:06:46 Done.
42
43 // Picks right icon URL and type based on presence of large_icon_url.
44 static favicon_base::IconType IconType(const PopularSites::Site& site);
45 static const GURL& IconURL(const PopularSites::Site& site);
Marc Treib 2016/10/12 09:11:28 Are these needed by tests? If not, you could move
sfiera 2016/10/13 09:06:46 Done.
46
47 void OnGetFaviconImageForPageURLFinished(
48 PopularSites::Site site,
49 base::Callback<void(bool)> done,
Marc Treib 2016/10/12 09:11:28 Also here: const ref
sfiera 2016/10/13 09:06:46 Done.
50 const favicon_base::FaviconImageResult& result);
51
52 void OnFaviconDownloaded(PopularSites::Site site,
53 base::Callback<void(bool)> done,
Marc Treib 2016/10/12 09:11:28 And here
sfiera 2016/10/13 09:06:46 Done.
54 const std::string& id,
55 const gfx::Image& fetched_image);
56 };
57
58 } // namespace ntp_tiles
59
60 #endif // COMPONENTS_NTP_TILES_ICON_CACHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698