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

Unified Diff: chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc

Issue 11411180: move favicon download code from chrome/ into content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WebContentsObserver and callback Created 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
diff --git a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
index 468d7daba9dd727a85d8d8e3aa9741a14bd5dd9e..9054a91c5024927a329b53e58b1f56f54d66ee22 100644
--- a/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
+++ b/chrome/browser/ui/ash/launcher/launcher_favicon_loader.cc
@@ -5,17 +5,16 @@
#include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
#include "base/logging.h"
-#include "chrome/browser/favicon/favicon_download_helper.h"
-#include "chrome/browser/favicon/favicon_download_helper_delegate.h"
#include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
-#include "chrome/common/favicon_url.h"
-#include "chrome/common/icon_messages.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/common/favicon_url.h"
jam 2012/12/03 21:59:39 nit: this is in the header, so don't add it here a
Cait (Slow) 2012/12/04 20:57:35 Done.
#include "googleurl/src/gurl.h"
#include "third_party/skia/include/core/SkBitmap.h"
+using content::FaviconURL;
+
namespace internal {
const int kMaxBitmapSize = 256;
@@ -26,12 +25,13 @@ const int kMaxBitmapSize = 256;
// These icon bitmaps are not resized and are not cached beyond the lifetime
// of the class. Bitmaps larger than kMaxBitmapSize are ignored.
-class FaviconBitmapHandler : public FaviconDownloadHelperDelegate {
+class FaviconBitmapHandler : public content::WebContentsObserver {
public:
FaviconBitmapHandler(content::WebContents* web_contents,
LauncherFaviconLoader::Delegate* delegate)
- : delegate_(delegate) {
- download_helper_.reset(new FaviconDownloadHelper(web_contents, this));
+ : content::WebContentsObserver(web_contents),
+ delegate_(delegate),
+ web_contents_(web_contents) {
}
~FaviconBitmapHandler() {}
@@ -40,25 +40,24 @@ class FaviconBitmapHandler : public FaviconDownloadHelperDelegate {
bool HasPendingDownloads() const;
- // FaviconDownloadHelperDelegate methods
- virtual void OnUpdateFaviconURL(
+ // content::WebContentObserver implementation.
+ virtual void DidUpdateFaviconURL(
int32 page_id,
const std::vector<FaviconURL>& candidates) OVERRIDE;
- virtual void OnDidDownloadFavicon(
- int id,
- const GURL& image_url,
- bool errored,
- int requested_size,
- const std::vector<SkBitmap>& bitmaps) OVERRIDE;
-
private:
- void DownloadFavicon(const GURL& image_url);
+ void DidDownloadFavicon(
+ int id,
+ const GURL& image_url,
+ bool errored,
+ int requested_size,
+ const std::vector<SkBitmap>& bitmaps);
+
void AddFavicon(const GURL& image_url, const SkBitmap& new_bitmap);
LauncherFaviconLoader::Delegate* delegate_;
- scoped_ptr<FaviconDownloadHelper> download_helper_;
+ content::WebContents* web_contents_;
typedef std::set<GURL> UrlSet;
// Map of pending download urls.
@@ -72,7 +71,7 @@ class FaviconBitmapHandler : public FaviconDownloadHelperDelegate {
DISALLOW_COPY_AND_ASSIGN(FaviconBitmapHandler);
};
-void FaviconBitmapHandler::OnUpdateFaviconURL(
+void FaviconBitmapHandler::DidUpdateFaviconURL(
int32 page_id,
const std::vector<FaviconURL>& candidates) {
// This function receives a complete list of faviocn urls for the page.
@@ -110,11 +109,17 @@ void FaviconBitmapHandler::OnUpdateFaviconURL(
if (pending_requests_.find(*iter) != pending_requests_.end())
continue; // Skip already pending downloads.
pending_requests_.insert(*iter);
- download_helper_->DownloadFavicon(*iter, 0);
+ web_contents_->DownloadFavicon(*iter, 0,
+ base::Bind(&FaviconBitmapHandler::DidDownloadFavicon,
+ base::Unretained(this)));
jam 2012/12/03 21:59:39 ditto re lifetime
}
}
-void FaviconBitmapHandler::OnDidDownloadFavicon(
+bool FaviconBitmapHandler::HasPendingDownloads() const {
+ return !pending_requests_.empty();
+}
+
+void FaviconBitmapHandler::DidDownloadFavicon(
int id,
const GURL& image_url,
bool errored,
@@ -132,10 +137,6 @@ void FaviconBitmapHandler::OnDidDownloadFavicon(
AddFavicon(image_url, bitmaps[0]);
}
-bool FaviconBitmapHandler::HasPendingDownloads() const {
- return !pending_requests_.empty();
-}
-
void FaviconBitmapHandler::AddFavicon(const GURL& image_url,
const SkBitmap& new_bitmap) {
processed_requests_.insert(image_url);

Powered by Google App Engine
This is Rietveld 408576698