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

Side by Side 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: 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 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/ash/launcher/launcher_favicon_loader.h" 5 #include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/favicon/favicon_download_helper.h"
9 #include "chrome/browser/favicon/favicon_download_helper_delegate.h"
10 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h" 8 #include "chrome/browser/ui/ash/launcher/browser_launcher_item_controller.h"
11 #include "chrome/common/favicon_url.h" 9 #include "content/public/browser/favicon_download_delegate.h"
12 #include "chrome/common/icon_messages.h"
13 #include "content/public/browser/render_view_host.h" 10 #include "content/public/browser/render_view_host.h"
14 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_delegate.h" 12 #include "content/public/common/favicon_url.h"
16 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
17 #include "third_party/skia/include/core/SkBitmap.h" 14 #include "third_party/skia/include/core/SkBitmap.h"
18 15
16 using content::FaviconURL;
17
18 using content::FaviconURL;
19
19 namespace internal { 20 namespace internal {
20 21
21 const int kMaxBitmapSize = 256; 22 const int kMaxBitmapSize = 256;
22 23
23 //////////////////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////////////////
24 // FaviconBitmapHandler fetchs all bitmaps with the 'icon' (or 'shortcut icon') 25 // FaviconBitmapHandler fetchs all bitmaps with the 'icon' (or 'shortcut icon')
25 // link tag, storing the one that best matches ash::kLauncherPreferredSize. 26 // link tag, storing the one that best matches ash::kLauncherPreferredSize.
26 // These icon bitmaps are not resized and are not cached beyond the lifetime 27 // These icon bitmaps are not resized and are not cached beyond the lifetime
27 // of the class. Bitmaps larger than kMaxBitmapSize are ignored. 28 // of the class. Bitmaps larger than kMaxBitmapSize are ignored.
28 29
29 class FaviconBitmapHandler : public FaviconDownloadHelperDelegate { 30 class FaviconBitmapHandler : public content::FaviconDownloadDelegate {
30 public: 31 public:
31 FaviconBitmapHandler(content::WebContents* web_contents, 32 FaviconBitmapHandler(content::WebContents* web_contents,
32 LauncherFaviconLoader::Delegate* delegate) 33 LauncherFaviconLoader::Delegate* delegate)
33 : delegate_(delegate) { 34 : delegate_(delegate),
34 download_helper_.reset(new FaviconDownloadHelper(web_contents, this)); 35 web_contents_(web_contents) {
36 web_contents->RegisterFaviconDelegate(this);
35 } 37 }
36 38
37 ~FaviconBitmapHandler() {} 39 ~FaviconBitmapHandler() {}
38 40
39 const SkBitmap& bitmap() const { return bitmap_; } 41 const SkBitmap& bitmap() const { return bitmap_; }
40 42
41 bool HasPendingDownloads() const; 43 bool HasPendingDownloads() const;
42 44
43 // FaviconDownloadHelperDelegate methods 45 // FaviconDownloadDelegate methods
44 virtual void OnUpdateFaviconURL( 46 virtual void UpdateFaviconURL(
45 int32 page_id, 47 int32 page_id,
46 const std::vector<FaviconURL>& candidates) OVERRIDE; 48 const std::vector<FaviconURL>& candidates) OVERRIDE;
47 49
48 virtual void OnDidDownloadFavicon( 50 virtual void DidDownloadFavicon(
49 int id, 51 int id,
50 const GURL& image_url, 52 const GURL& image_url,
51 bool errored, 53 bool errored,
52 int requested_size, 54 int requested_size,
53 const std::vector<SkBitmap>& bitmaps) OVERRIDE; 55 const std::vector<SkBitmap>& bitmaps) OVERRIDE;
54 56
55 private: 57 private:
56 void DownloadFavicon(const GURL& image_url); 58 void DownloadFavicon(const GURL& image_url);
57 void AddFavicon(const GURL& image_url, const SkBitmap& new_bitmap); 59 void AddFavicon(const GURL& image_url, const SkBitmap& new_bitmap);
58 60
59 LauncherFaviconLoader::Delegate* delegate_; 61 LauncherFaviconLoader::Delegate* delegate_;
60 62
61 scoped_ptr<FaviconDownloadHelper> download_helper_; 63 content::WebContents* web_contents_;
62 64
63 typedef std::set<GURL> UrlSet; 65 typedef std::set<GURL> UrlSet;
64 // Map of pending download urls. 66 // Map of pending download urls.
65 UrlSet pending_requests_; 67 UrlSet pending_requests_;
66 // Map of processed urls. 68 // Map of processed urls.
67 UrlSet processed_requests_; 69 UrlSet processed_requests_;
68 // Current bitmap and source url. 70 // Current bitmap and source url.
69 SkBitmap bitmap_; 71 SkBitmap bitmap_;
70 GURL bitmap_url_; 72 GURL bitmap_url_;
71 73
72 DISALLOW_COPY_AND_ASSIGN(FaviconBitmapHandler); 74 DISALLOW_COPY_AND_ASSIGN(FaviconBitmapHandler);
73 }; 75 };
74 76
75 void FaviconBitmapHandler::OnUpdateFaviconURL( 77 void FaviconBitmapHandler::UpdateFaviconURL(
76 int32 page_id, 78 int32 page_id,
77 const std::vector<FaviconURL>& candidates) { 79 const std::vector<FaviconURL>& candidates) {
78 // This function receives a complete list of faviocn urls for the page. 80 // This function receives a complete list of faviocn urls for the page.
79 // It may get called multiple times with the same list, and will also get 81 // It may get called multiple times with the same list, and will also get
80 // called any time an item is added or removed. As such, we track processed 82 // called any time an item is added or removed. As such, we track processed
81 // and pending urls, but only until they are removed from the list. 83 // and pending urls, but only until they are removed from the list.
82 UrlSet new_pending, new_processed; 84 UrlSet new_pending, new_processed;
83 // Create a map of valid favicon urls. 85 // Create a map of valid favicon urls.
84 std::set<GURL> urls; 86 std::set<GURL> urls;
85 for (std::vector<FaviconURL>::const_iterator iter = candidates.begin(); 87 for (std::vector<FaviconURL>::const_iterator iter = candidates.begin();
(...skipping 17 matching lines...) Expand all
103 bitmap_.reset(); 105 bitmap_.reset();
104 } 106 }
105 // Request any new urls. 107 // Request any new urls.
106 for (std::set<GURL>::iterator iter = urls.begin(); 108 for (std::set<GURL>::iterator iter = urls.begin();
107 iter != urls.end(); ++iter) { 109 iter != urls.end(); ++iter) {
108 if (processed_requests_.find(*iter) != processed_requests_.end()) 110 if (processed_requests_.find(*iter) != processed_requests_.end())
109 continue; // Skip already processed downloads. 111 continue; // Skip already processed downloads.
110 if (pending_requests_.find(*iter) != pending_requests_.end()) 112 if (pending_requests_.find(*iter) != pending_requests_.end())
111 continue; // Skip already pending downloads. 113 continue; // Skip already pending downloads.
112 pending_requests_.insert(*iter); 114 pending_requests_.insert(*iter);
113 download_helper_->DownloadFavicon(*iter, 0); 115 web_contents_->DownloadFavicon(*iter, 0);
114 } 116 }
115 } 117 }
116 118
117 void FaviconBitmapHandler::OnDidDownloadFavicon( 119 void FaviconBitmapHandler::DidDownloadFavicon(
118 int id, 120 int id,
119 const GURL& image_url, 121 const GURL& image_url,
120 bool errored, 122 bool errored,
121 int requested_size, 123 int requested_size,
122 const std::vector<SkBitmap>& bitmaps) { 124 const std::vector<SkBitmap>& bitmaps) {
123 UrlSet::iterator iter = pending_requests_.find(image_url); 125 UrlSet::iterator iter = pending_requests_.find(image_url);
124 if (iter == pending_requests_.end()) { 126 if (iter == pending_requests_.end()) {
125 // Updates are received for all downloads; ignore unrequested urls. 127 // Updates are received for all downloads; ignore unrequested urls.
126 return; 128 return;
127 } 129 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 LauncherFaviconLoader::~LauncherFaviconLoader() { 170 LauncherFaviconLoader::~LauncherFaviconLoader() {
169 } 171 }
170 172
171 SkBitmap LauncherFaviconLoader::GetFavicon() const { 173 SkBitmap LauncherFaviconLoader::GetFavicon() const {
172 return favicon_handler_->bitmap(); 174 return favicon_handler_->bitmap();
173 } 175 }
174 176
175 bool LauncherFaviconLoader::HasPendingDownloads() const { 177 bool LauncherFaviconLoader::HasPendingDownloads() const {
176 return favicon_handler_->HasPendingDownloads(); 178 return favicon_handler_->HasPendingDownloads();
177 } 179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698