Index: chrome/browser/favicon/favicon_downloader.h |
diff --git a/chrome/browser/favicon/favicon_downloader.h b/chrome/browser/favicon/favicon_downloader.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a1683b2a7d7e6d43553668efc7e794b26b6b8dd8 |
--- /dev/null |
+++ b/chrome/browser/favicon/favicon_downloader.h |
@@ -0,0 +1,98 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_FAVICON_FAVICON_DOWNLOADER_H_ |
+#define CHROME_BROWSER_FAVICON_FAVICON_DOWNLOADER_H_ |
+ |
+#include <set> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/memory/scoped_ptr.h" |
pkotwicz
2013/12/02 01:00:57
You do not need to include scoped_ptr.h
calamity
2013/12/03 05:52:15
Done.
|
+#include "base/memory/weak_ptr.h" |
+#include "content/public/browser/web_contents_observer.h" |
+ |
+class SkBitmap; |
+ |
+namespace content { |
+struct FaviconURL; |
+} |
+ |
+namespace gfx { |
+class Size; |
+} |
+ |
+// Class to help download the full-size favicons for a tab. |
pkotwicz
2013/12/02 01:00:57
Can you update the class description? The goal of
calamity
2013/12/03 05:52:15
Done.
|
+class FaviconDownloader : public content::WebContentsObserver { |
+ public: |
+ typedef std::map<GURL, std::vector<SkBitmap> > FaviconMap; |
+ typedef base::Callback<void( |
+ bool, /* success */ |
+ /* A map of icon urls to the bitmaps provided by that url. */ |
+ const FaviconMap&)> |
+ FaviconDownloaderCallback; |
+ |
+ FaviconDownloader(content::WebContents* web_contents, |
+ FaviconDownloaderCallback callback); |
pkotwicz
2013/12/02 01:00:57
Can the extra favicon URLs be passed into the cons
calamity
2013/12/03 05:52:15
Done.
|
+ virtual ~FaviconDownloader(); |
+ |
+ void AddExtraFaviconUrl(const GURL& url); |
+ |
+ void Start(); |
+ |
+ private: |
+ friend class TestFaviconDownloader; |
+ |
+ // Initiates a download of the image at |url| and returns the download id. |
+ // This is overridden in testing. |
+ virtual int DownloadImage(const GURL& url); |
+ |
+ // Populates |favicon_url_candidates_| if possible. |
+ // This is overridden in testing. |
pkotwicz
2013/12/02 01:00:57
How about: "Queries FaviconTabHelper for the page'
calamity
2013/12/03 05:52:15
Done.
|
+ virtual void PopulateFaviconURLsFromWebContents(); |
+ |
+ // Fetches icons for |favicon_url_candidates_| and |extra_favicon_urls_|. |
+ // |callback| is run when all downloads complete. |
+ void FetchIcons(); |
+ |
+ // Icon download callback. |
+ void DidDownloadFavicon(int id, |
+ int http_status_code, |
+ const GURL& image_url, |
+ const std::vector<SkBitmap>& bitmaps, |
+ const std::vector<gfx::Size>& original_bitmap_sizes); |
+ |
+ // content::WebContentsObserver overrides: |
+ virtual void DidNavigateMainFrame( |
+ const content::LoadCommittedDetails& details, |
+ const content::FrameNavigateParams& params) OVERRIDE; |
+ virtual void DidUpdateFaviconURL( |
+ int32 page_id, |
+ const std::vector<content::FaviconURL>& candidates) OVERRIDE; |
+ |
+ // FaviconURLs for the current web contents. |
+ // This is populated when PopulateFaviconURLsFromWebContents() is called if |
+ // available. Otherwise it is populated when |
+ // WebContentsObserver::DidUpdateFaviconURL() is called. |
+ const std::vector<content::FaviconURL>* favicon_url_candidates_; |
+ |
+ // URLs that aren't given by WebContentsObserver::DidUpdateFaviconURL() that |
+ // should be used for this favicon. |
+ std::vector<GURL> extra_favicon_urls_; |
+ |
+ // The current page's icons. Populated by FetchIcons(). |
+ FaviconMap favicon_map_; |
+ |
+ // Request ids of in-progress requests. |
+ std::set<int> in_progress_requests_; |
+ |
+ // Callback to run on favicon download completion. |
+ FaviconDownloaderCallback callback_; |
+ |
+ base::WeakPtrFactory<FaviconDownloader> weak_ptr_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FaviconDownloader); |
+}; |
+ |
+#endif // CHROME_BROWSER_FAVICON_FAVICON_DOWNLOADER_H_ |