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

Side by Side Diff: chrome/browser/extensions/favicon_downloader.h

Issue 64853004: Use high resolution icons where possible for streamlined hosted app icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_experiment_create_app_from_page
Patch Set: add RenderViewImpl test to ensure FaviconTabHelper is not sent an empty vector Created 7 years 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 2013 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 CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_
6 #define CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_
7
8 #include <map>
9 #include <set>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "content/public/browser/web_contents_observer.h"
15
16 class SkBitmap;
17
18 namespace content {
19 struct FaviconURL;
20 }
21
22 namespace gfx {
23 class Size;
24 }
25
26 // Class to help download all favicons for a tab.
27 class FaviconDownloader : public content::WebContentsObserver {
28 public:
29 typedef std::map<GURL, std::vector<SkBitmap> > FaviconMap;
30 typedef base::Callback<void(
31 bool, /* success */
32 /* A map of icon urls to the bitmaps provided by that url. */
33 const FaviconMap&)>
34 FaviconDownloaderCallback;
35 // |extra_favicon_urls| allows callers to provide icon urls that aren't
36 // |provided by the renderer (e.g touch icons on non-android environments).
37 FaviconDownloader(content::WebContents* web_contents,
38 const std::vector<GURL>& extra_favicon_urls,
39 FaviconDownloaderCallback callback);
40 virtual ~FaviconDownloader();
41
42 void Start();
43
44 private:
45 friend class TestFaviconDownloader;
46
47 // Initiates a download of the image at |url| and returns the download id.
48 // This is overridden in testing.
49 virtual int DownloadImage(const GURL& url);
50
51 // Queries FaviconTabHelper for the page's current favicon URLs.
52 // This is overridden in testing.
53 virtual std::vector<content::FaviconURL> GetFaviconURLsFromWebContents();
54
55 // Fetches icons for the given urls.
56 // |callback| is run when all downloads complete.
benwells 2013/12/12 21:17:57 Nit: what |callback|? Update: Oh - the |callback_
calamity 2013/12/13 03:11:55 Done.
57 void FetchIcons(const std::vector<content::FaviconURL>& favicon_urls);
58 void FetchIcons(const std::vector<GURL>& urls);
59
60 // Icon download callback.
61 void DidDownloadFavicon(int id,
62 int http_status_code,
63 const GURL& image_url,
64 const std::vector<SkBitmap>& bitmaps,
65 const std::vector<gfx::Size>& original_bitmap_sizes);
66
67 // content::WebContentsObserver overrides:
68 virtual void DidNavigateMainFrame(
69 const content::LoadCommittedDetails& details,
70 const content::FrameNavigateParams& params) OVERRIDE;
71 virtual void DidUpdateFaviconURL(
72 int32 page_id,
73 const std::vector<content::FaviconURL>& candidates) OVERRIDE;
74
75 // Whether we have received favicons from the renderer.
76 // FaviconURLs are received from GetFaviconURLsFromWebContents() if available.
benwells 2013/12/12 21:17:57 Nit: I'd recommend just the first line of this com
calamity 2013/12/13 03:11:55 Done.
77 // Otherwise they are provided when WebContentsObserver::DidUpdateFaviconURL()
78 // is called.
79 bool got_favicon_urls_;
80
81 // URLs that aren't given by WebContentsObserver::DidUpdateFaviconURL() that
82 // should be used for this favicon. This is necessary in order to get touch
83 // icons on non-android environments.
84 std::vector<GURL> extra_favicon_urls_;
85
86 // The icons which were downloaded. Populated by FetchIcons().
87 FaviconMap favicon_map_;
88
89 // Request ids of in-progress requests.
90 std::set<int> in_progress_requests_;
91
92 // Urls for which a download has already been initiated. Used to prevent
93 // duplicate downloads of the same url.
94 std::set<GURL> processed_urls_;
95
96 // Callback to run on favicon download completion.
97 FaviconDownloaderCallback callback_;
98
99 base::WeakPtrFactory<FaviconDownloader> weak_ptr_factory_;
100
101 DISALLOW_COPY_AND_ASSIGN(FaviconDownloader);
102 };
103
104 #endif // CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/favicon_downloader.cc » ('j') | chrome/browser/extensions/favicon_downloader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698