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

Side by Side Diff: chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.cc

Issue 10828127: Use hi-resolution favicon variants if available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: grrrrr Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h" 5 #include "chrome/browser/ui/views/ash/launcher/launcher_favicon_loader.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/favicon/favicon_util.h" 8 #include "chrome/browser/favicon/favicon_util.h"
9 #include "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller. h" 9 #include "chrome/browser/ui/views/ash/launcher/browser_launcher_item_controller. h"
10 #include "chrome/common/favicon_url.h" 10 #include "chrome/common/favicon_url.h"
(...skipping 25 matching lines...) Expand all
36 ~FaviconBitmapHandler() {} 36 ~FaviconBitmapHandler() {}
37 37
38 const SkBitmap& bitmap() const { return bitmap_; } 38 const SkBitmap& bitmap() const { return bitmap_; }
39 39
40 void OnUpdateFaviconURL(int32 page_id, 40 void OnUpdateFaviconURL(int32 page_id,
41 const std::vector<FaviconURL>& candidates); 41 const std::vector<FaviconURL>& candidates);
42 42
43 void OnDidDownloadFavicon(int id, 43 void OnDidDownloadFavicon(int id,
44 const GURL& image_url, 44 const GURL& image_url,
45 bool errored, 45 bool errored,
46 const SkBitmap& bitmap); 46 int requested_size,
47 const std::vector<SkBitmap>& bitmaps);
47 48
48 private: 49 private:
49 void DownloadFavicon(const GURL& image_url); 50 void DownloadFavicon(const GURL& image_url);
50 void AddFavicon(const GURL& image_url, const SkBitmap& new_bitmap); 51 void AddFavicon(const GURL& image_url, const SkBitmap& new_bitmap);
51 52
52 content::WebContents* web_contents_; 53 content::WebContents* web_contents_;
53 LauncherFaviconLoader::Delegate* delegate_; 54 LauncherFaviconLoader::Delegate* delegate_;
54 55
55 typedef std::set<GURL> UrlSet; 56 typedef std::set<GURL> UrlSet;
56 // Map of pending download urls. 57 // Map of pending download urls.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 106 }
106 } 107 }
107 108
108 void FaviconBitmapHandler::DownloadFavicon(const GURL& image_url) { 109 void FaviconBitmapHandler::DownloadFavicon(const GURL& image_url) {
109 int image_size = 0; // Request the full sized image. 110 int image_size = 0; // Request the full sized image.
110 pending_requests_.insert(image_url); 111 pending_requests_.insert(image_url);
111 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); 112 content::RenderViewHost* host = web_contents_->GetRenderViewHost();
112 FaviconUtil::DownloadFavicon(host, image_url, image_size); 113 FaviconUtil::DownloadFavicon(host, image_url, image_size);
113 } 114 }
114 115
115 void FaviconBitmapHandler::OnDidDownloadFavicon(int id, 116
116 const GURL& image_url, 117 void FaviconBitmapHandler::OnDidDownloadFavicon(
117 bool errored, 118 int id,
118 const SkBitmap& bitmap) { 119 const GURL& image_url,
120 bool errored,
121 int requested_size,
122 const std::vector<SkBitmap>& bitmaps) {
119 UrlSet::iterator iter = pending_requests_.find(image_url); 123 UrlSet::iterator iter = pending_requests_.find(image_url);
120 if (iter == pending_requests_.end()) { 124 if (iter == pending_requests_.end()) {
121 // Updates are received for all downloads; ignore unrequested urls. 125 // Updates are received for all downloads; ignore unrequested urls.
122 return; 126 return;
123 } 127 }
124 pending_requests_.erase(iter); 128 pending_requests_.erase(iter);
125 129
126 if (!errored) 130 // Favicon bitmaps are ordered by decreasing width.
127 AddFavicon(image_url, bitmap); 131 if (!errored && !bitmaps.empty())
132 AddFavicon(image_url, bitmaps[0]);
128 } 133 }
129 134
130 void FaviconBitmapHandler::AddFavicon(const GURL& image_url, 135 void FaviconBitmapHandler::AddFavicon(const GURL& image_url,
131 const SkBitmap& new_bitmap) { 136 const SkBitmap& new_bitmap) {
132 processed_requests_.insert(image_url); 137 processed_requests_.insert(image_url);
133 if (new_bitmap.height() > kMaxBitmapSize || 138 if (new_bitmap.height() > kMaxBitmapSize ||
134 new_bitmap.width() > kMaxBitmapSize) 139 new_bitmap.width() > kMaxBitmapSize)
135 return; 140 return;
136 if (new_bitmap.height() < ash::kLauncherPreferredSize) 141 if (new_bitmap.height() < ash::kLauncherPreferredSize)
137 return; 142 return;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 SkBitmap LauncherFaviconLoader::GetFavicon() const { 177 SkBitmap LauncherFaviconLoader::GetFavicon() const {
173 return favicon_handler_->bitmap(); 178 return favicon_handler_->bitmap();
174 } 179 }
175 180
176 void LauncherFaviconLoader::OnUpdateFaviconURL( 181 void LauncherFaviconLoader::OnUpdateFaviconURL(
177 int32 page_id, 182 int32 page_id,
178 const std::vector<FaviconURL>& candidates) { 183 const std::vector<FaviconURL>& candidates) {
179 favicon_handler_->OnUpdateFaviconURL(page_id, candidates); 184 favicon_handler_->OnUpdateFaviconURL(page_id, candidates);
180 } 185 }
181 186
182 void LauncherFaviconLoader::OnDidDownloadFavicon(int id, 187 void LauncherFaviconLoader::OnDidDownloadFavicon(
183 const GURL& image_url, 188 int id,
184 bool errored, 189 const GURL& image_url,
185 const SkBitmap& bitmap) { 190 bool errored,
186 favicon_handler_->OnDidDownloadFavicon(id, image_url, errored, bitmap); 191 int requested_size,
192 const std::vector<SkBitmap>& bitmaps) {
193 favicon_handler_->OnDidDownloadFavicon(
194 id, image_url, errored, requested_size, bitmaps);
187 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698