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

Side by Side Diff: chrome/browser/extensions/favicon_downloader.cc

Issue 2662443005: Convert FaviconDownloader to use the new navigation callbacks. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « chrome/browser/extensions/favicon_downloader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/favicon_downloader.h" 5 #include "chrome/browser/extensions/favicon_downloader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "components/favicon/content/content_favicon_driver.h" 8 #include "components/favicon/content/content_favicon_driver.h"
9 #include "content/public/browser/navigation_handle.h"
9 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
10 #include "content/public/common/favicon_url.h" 11 #include "content/public/common/favicon_url.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 12 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
13 14
14 FaviconDownloader::FaviconDownloader( 15 FaviconDownloader::FaviconDownloader(
15 content::WebContents* web_contents, 16 content::WebContents* web_contents,
16 const std::vector<GURL>& extra_favicon_urls, 17 const std::vector<GURL>& extra_favicon_urls,
17 FaviconDownloaderCallback callback) 18 FaviconDownloaderCallback callback)
18 : content::WebContentsObserver(web_contents), 19 : content::WebContentsObserver(web_contents),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if (in_progress_requests_.empty() && !need_favicon_urls_) 94 if (in_progress_requests_.empty() && !need_favicon_urls_)
94 callback_.Run(true, favicon_map_); 95 callback_.Run(true, favicon_map_);
95 } 96 }
96 97
97 void FaviconDownloader::DidDownloadFavicon( 98 void FaviconDownloader::DidDownloadFavicon(
98 int id, 99 int id,
99 int http_status_code, 100 int http_status_code,
100 const GURL& image_url, 101 const GURL& image_url,
101 const std::vector<SkBitmap>& bitmaps, 102 const std::vector<SkBitmap>& bitmaps,
102 const std::vector<gfx::Size>& original_bitmap_sizes) { 103 const std::vector<gfx::Size>& original_bitmap_sizes) {
103 // Request may have been canceled by DidNavigateMainFrame(). 104 // Request may have been canceled by DidFinishNavigation().
104 if (in_progress_requests_.erase(id) == 0) 105 if (in_progress_requests_.erase(id) == 0)
105 return; 106 return;
106 107
107 favicon_map_[image_url] = bitmaps; 108 favicon_map_[image_url] = bitmaps;
108 109
109 // Once all requests have been resolved, perform post-download tasks. 110 // Once all requests have been resolved, perform post-download tasks.
110 if (in_progress_requests_.empty() && !need_favicon_urls_) 111 if (in_progress_requests_.empty() && !need_favicon_urls_)
111 callback_.Run(true, favicon_map_); 112 callback_.Run(true, favicon_map_);
112 } 113 }
113 114
114 // content::WebContentsObserver overrides: 115 // content::WebContentsObserver overrides:
115 void FaviconDownloader::DidNavigateMainFrame( 116 void FaviconDownloader::DidFinishNavigation(
116 const content::LoadCommittedDetails& details, 117 content::NavigationHandle* navigation_handle) {
117 const content::FrameNavigateParams& params) { 118 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted())
Devlin 2017/01/27 21:51:51 I realize that this is the conversion that would l
jam 2017/01/27 23:04:25 DidStartNavigation might not commit though, i.e. b
Devlin 2017/01/28 02:24:23 Interesting, okay. And there's no way to know tha
jam 2017/01/28 04:35:00 Right, at the start is before the network request
119 return;
120
118 // Clear all pending requests. 121 // Clear all pending requests.
119 in_progress_requests_.clear(); 122 in_progress_requests_.clear();
120 favicon_map_.clear(); 123 favicon_map_.clear();
121 callback_.Run(false, favicon_map_); 124 callback_.Run(false, favicon_map_);
122 } 125 }
123 126
124 void FaviconDownloader::DidUpdateFaviconURL( 127 void FaviconDownloader::DidUpdateFaviconURL(
125 const std::vector<content::FaviconURL>& candidates) { 128 const std::vector<content::FaviconURL>& candidates) {
126 // Only consider the first candidates we are given. This prevents pages that 129 // Only consider the first candidates we are given. This prevents pages that
127 // change their favicon from spamming us. 130 // change their favicon from spamming us.
128 if (!need_favicon_urls_) 131 if (!need_favicon_urls_)
129 return; 132 return;
130 133
131 need_favicon_urls_ = false; 134 need_favicon_urls_ = false;
132 FetchIcons(candidates); 135 FetchIcons(candidates);
133 } 136 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/favicon_downloader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698