OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 19 matching lines...) Expand all Loading... |
30 typedef base::Callback<void( | 30 typedef base::Callback<void( |
31 bool, /* success */ | 31 bool, /* success */ |
32 /* A map of icon urls to the bitmaps provided by that url. */ | 32 /* A map of icon urls to the bitmaps provided by that url. */ |
33 const FaviconMap&)> | 33 const FaviconMap&)> |
34 FaviconDownloaderCallback; | 34 FaviconDownloaderCallback; |
35 // |extra_favicon_urls| allows callers to provide icon urls that aren't | 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). | 36 // |provided by the renderer (e.g touch icons on non-android environments). |
37 FaviconDownloader(content::WebContents* web_contents, | 37 FaviconDownloader(content::WebContents* web_contents, |
38 const std::vector<GURL>& extra_favicon_urls, | 38 const std::vector<GURL>& extra_favicon_urls, |
39 FaviconDownloaderCallback callback); | 39 FaviconDownloaderCallback callback); |
40 virtual ~FaviconDownloader(); | 40 ~FaviconDownloader() override; |
41 | 41 |
42 void Start(); | 42 void Start(); |
43 | 43 |
44 private: | 44 private: |
45 friend class TestFaviconDownloader; | 45 friend class TestFaviconDownloader; |
46 | 46 |
47 // Initiates a download of the image at |url| and returns the download id. | 47 // Initiates a download of the image at |url| and returns the download id. |
48 // This is overridden in testing. | 48 // This is overridden in testing. |
49 virtual int DownloadImage(const GURL& url); | 49 virtual int DownloadImage(const GURL& url); |
50 | 50 |
51 // Queries FaviconTabHelper for the page's current favicon URLs. | 51 // Queries FaviconTabHelper for the page's current favicon URLs. |
52 // This is overridden in testing. | 52 // This is overridden in testing. |
53 virtual std::vector<content::FaviconURL> GetFaviconURLsFromWebContents(); | 53 virtual std::vector<content::FaviconURL> GetFaviconURLsFromWebContents(); |
54 | 54 |
55 // Fetches icons for the given urls. | 55 // Fetches icons for the given urls. |
56 // |callback_| is run when all downloads complete. | 56 // |callback_| is run when all downloads complete. |
57 void FetchIcons(const std::vector<content::FaviconURL>& favicon_urls); | 57 void FetchIcons(const std::vector<content::FaviconURL>& favicon_urls); |
58 void FetchIcons(const std::vector<GURL>& urls); | 58 void FetchIcons(const std::vector<GURL>& urls); |
59 | 59 |
60 // Icon download callback. | 60 // Icon download callback. |
61 void DidDownloadFavicon(int id, | 61 void DidDownloadFavicon(int id, |
62 int http_status_code, | 62 int http_status_code, |
63 const GURL& image_url, | 63 const GURL& image_url, |
64 const std::vector<SkBitmap>& bitmaps, | 64 const std::vector<SkBitmap>& bitmaps, |
65 const std::vector<gfx::Size>& original_bitmap_sizes); | 65 const std::vector<gfx::Size>& original_bitmap_sizes); |
66 | 66 |
67 // content::WebContentsObserver overrides: | 67 // content::WebContentsObserver overrides: |
68 virtual void DidNavigateMainFrame( | 68 void DidNavigateMainFrame( |
69 const content::LoadCommittedDetails& details, | 69 const content::LoadCommittedDetails& details, |
70 const content::FrameNavigateParams& params) override; | 70 const content::FrameNavigateParams& params) override; |
71 virtual void DidUpdateFaviconURL( | 71 void DidUpdateFaviconURL( |
72 const std::vector<content::FaviconURL>& candidates) override; | 72 const std::vector<content::FaviconURL>& candidates) override; |
73 | 73 |
74 // Whether we have received favicons from the renderer. | 74 // Whether we have received favicons from the renderer. |
75 bool got_favicon_urls_; | 75 bool got_favicon_urls_; |
76 | 76 |
77 // URLs that aren't given by WebContentsObserver::DidUpdateFaviconURL() that | 77 // URLs that aren't given by WebContentsObserver::DidUpdateFaviconURL() that |
78 // should be used for this favicon. This is necessary in order to get touch | 78 // should be used for this favicon. This is necessary in order to get touch |
79 // icons on non-android environments. | 79 // icons on non-android environments. |
80 std::vector<GURL> extra_favicon_urls_; | 80 std::vector<GURL> extra_favicon_urls_; |
81 | 81 |
82 // The icons which were downloaded. Populated by FetchIcons(). | 82 // The icons which were downloaded. Populated by FetchIcons(). |
83 FaviconMap favicon_map_; | 83 FaviconMap favicon_map_; |
84 | 84 |
85 // Request ids of in-progress requests. | 85 // Request ids of in-progress requests. |
86 std::set<int> in_progress_requests_; | 86 std::set<int> in_progress_requests_; |
87 | 87 |
88 // Urls for which a download has already been initiated. Used to prevent | 88 // Urls for which a download has already been initiated. Used to prevent |
89 // duplicate downloads of the same url. | 89 // duplicate downloads of the same url. |
90 std::set<GURL> processed_urls_; | 90 std::set<GURL> processed_urls_; |
91 | 91 |
92 // Callback to run on favicon download completion. | 92 // Callback to run on favicon download completion. |
93 FaviconDownloaderCallback callback_; | 93 FaviconDownloaderCallback callback_; |
94 | 94 |
95 base::WeakPtrFactory<FaviconDownloader> weak_ptr_factory_; | 95 base::WeakPtrFactory<FaviconDownloader> weak_ptr_factory_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(FaviconDownloader); | 97 DISALLOW_COPY_AND_ASSIGN(FaviconDownloader); |
98 }; | 98 }; |
99 | 99 |
100 #endif // CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_ | 100 #endif // CHROME_BROWSER_EXTENSIONS_FAVICON_DOWNLOADER_H_ |
OLD | NEW |