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

Side by Side Diff: chrome/browser/favicon/favicon_download_helper.cc

Issue 11411180: move favicon download code from chrome/ into content/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix order 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/favicon/favicon_download_helper.h"
6
7 #include "chrome/browser/favicon/favicon_download_helper_delegate.h"
8 #include "chrome/common/icon_messages.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_delegate.h"
12
13 using content::WebContents;
14
15 namespace {
16 static int StartDownload(content::RenderViewHost* rvh,
17 const GURL& url,
18 int image_size) {
19 static int id = 0;
20 rvh->Send(new IconMsg_DownloadFavicon(rvh->GetRoutingID(), ++id, url,
21 image_size));
22 return id;
23 }
24 } // namespace.
25
26 FaviconDownloadHelper::FaviconDownloadHelper(
27 WebContents* web_contents,
28 FaviconDownloadHelperDelegate* delegate)
29 : content::WebContentsObserver(web_contents),
30 delegate_(delegate) {
31 DCHECK(delegate_);
32 }
33
34 FaviconDownloadHelper::~FaviconDownloadHelper() {
35 }
36
37 int FaviconDownloadHelper::DownloadFavicon(const GURL& url, int image_size) {
38 content::RenderViewHost* host = web_contents()->GetRenderViewHost();
39 int id = StartDownload(host, url, image_size);
40 DownloadIdList::iterator i =
41 std::find(download_ids_.begin(), download_ids_.end(), id);
42 DCHECK(i == download_ids_.end());
43 download_ids_.insert(id);
44 return id;
45 }
46
47 bool FaviconDownloadHelper::OnMessageReceived(const IPC::Message& message) {
48 bool message_handled = false; // Allow other handlers to receive these.
49 IPC_BEGIN_MESSAGE_MAP(FaviconDownloadHelper, message)
50 IPC_MESSAGE_HANDLER(IconHostMsg_DidDownloadFavicon, OnDidDownloadFavicon)
51 IPC_MESSAGE_HANDLER(IconHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
52 IPC_MESSAGE_UNHANDLED(message_handled = false)
53 IPC_END_MESSAGE_MAP()
54 return message_handled;
55 }
56
57 void FaviconDownloadHelper::OnDidDownloadFavicon(
58 int id,
59 const GURL& image_url,
60 bool errored,
61 int requested_size,
62 const std::vector<SkBitmap>& bitmaps) {
63 DownloadIdList::iterator i =
64 std::find(download_ids_.begin(), download_ids_.end(), id);
65 if (i == download_ids_.end()) {
66 // Currently WebContents notifies us of ANY downloads so that it is
67 // possible to get here.
68 return;
69 }
70 delegate_->OnDidDownloadFavicon(
71 id, image_url, errored, requested_size, bitmaps);
72 download_ids_.erase(i);
73 }
74
75 void FaviconDownloadHelper::OnUpdateFaviconURL(
76 int32 page_id,
77 const std::vector<FaviconURL>& candidates) {
78 delegate_->OnUpdateFaviconURL(page_id, candidates);
79 }
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_download_helper.h ('k') | chrome/browser/favicon/favicon_download_helper_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698