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

Side by Side Diff: components/ntp_tiles/icon_cacher_impl.cc

Issue 2888393002: [Icon cacher] Add metrics for downloading favicons for NTP Tiles (Closed)
Patch Set: Robert's comments Created 3 years, 7 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/ntp_tiles/icon_cacher_impl.h" 5 #include "components/ntp_tiles/icon_cacher_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/histogram_macros.h"
10 #include "components/favicon/core/favicon_service.h" 11 #include "components/favicon/core/favicon_service.h"
11 #include "components/favicon/core/favicon_util.h" 12 #include "components/favicon/core/favicon_util.h"
12 #include "components/favicon/core/large_icon_service.h" 13 #include "components/favicon/core/large_icon_service.h"
13 #include "components/favicon_base/fallback_icon_style.h" 14 #include "components/favicon_base/fallback_icon_style.h"
14 #include "components/favicon_base/favicon_types.h" 15 #include "components/favicon_base/favicon_types.h"
15 #include "components/favicon_base/favicon_util.h" 16 #include "components/favicon_base/favicon_util.h"
16 #include "components/image_fetcher/core/image_decoder.h" 17 #include "components/image_fetcher/core/image_decoder.h"
17 #include "components/image_fetcher/core/image_fetcher.h" 18 #include "components/image_fetcher/core/image_fetcher.h"
18 #include "net/traffic_annotation/network_traffic_annotation.h" 19 #include "net/traffic_annotation/network_traffic_annotation.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 129 }
129 130
130 void IconCacherImpl::OnPopularSitesFaviconDownloaded( 131 void IconCacherImpl::OnPopularSitesFaviconDownloaded(
131 PopularSites::Site site, 132 PopularSites::Site site,
132 std::unique_ptr<CancelableImageCallback> preliminary_callback, 133 std::unique_ptr<CancelableImageCallback> preliminary_callback,
133 const std::string& id, 134 const std::string& id,
134 const gfx::Image& fetched_image, 135 const gfx::Image& fetched_image,
135 const image_fetcher::RequestMetadata& metadata) { 136 const image_fetcher::RequestMetadata& metadata) {
136 if (fetched_image.IsEmpty()) { 137 if (fetched_image.IsEmpty()) {
137 FinishRequestAndNotifyIconAvailable(site.url, /*newly_available=*/false); 138 FinishRequestAndNotifyIconAvailable(site.url, /*newly_available=*/false);
139 UMA_HISTOGRAM_BOOLEAN("NewTabPage.TileFaviconFetchSuccess.Popular", false);
138 return; 140 return;
139 } 141 }
140 142
141 // Avoid invoking callback about preliminary icon to be triggered. The best 143 // Avoid invoking callback about preliminary icon to be triggered. The best
142 // possible icon has already been downloaded. 144 // possible icon has already been downloaded.
143 if (preliminary_callback) { 145 if (preliminary_callback) {
144 preliminary_callback->Cancel(); 146 preliminary_callback->Cancel();
145 } 147 }
146 SaveIconForSite(site, fetched_image); 148 SaveIconForSite(site, fetched_image);
147 FinishRequestAndNotifyIconAvailable(site.url, /*newly_available=*/true); 149 FinishRequestAndNotifyIconAvailable(site.url, /*newly_available=*/true);
150 UMA_HISTOGRAM_BOOLEAN("NewTabPage.TileFaviconFetchSuccess.Popular", true);
148 } 151 }
149 152
150 void IconCacherImpl::SaveAndNotifyDefaultIconForSite( 153 void IconCacherImpl::SaveAndNotifyDefaultIconForSite(
151 const PopularSites::Site& site, 154 const PopularSites::Site& site,
152 const base::Closure& preliminary_icon_available, 155 const base::Closure& preliminary_icon_available,
153 const gfx::Image& image) { 156 const gfx::Image& image) {
154 SaveIconForSite(site, image); 157 SaveIconForSite(site, image);
155 if (preliminary_icon_available) { 158 if (preliminary_icon_available) {
156 preliminary_icon_available.Run(); 159 preliminary_icon_available.Run();
157 } 160 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 if (!HasResultDefaultBackgroundColor(result)) { 212 if (!HasResultDefaultBackgroundColor(result)) {
210 // We should only fetch for default "gray" tiles so that we never overrite 213 // We should only fetch for default "gray" tiles so that we never overrite
211 // any favicon of any size. 214 // any favicon of any size.
212 FinishRequestAndNotifyIconAvailable(page_url, /*newly_available=*/false); 215 FinishRequestAndNotifyIconAvailable(page_url, /*newly_available=*/false);
213 return; 216 return;
214 } 217 }
215 218
216 large_icon_service_ 219 large_icon_service_
217 ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 220 ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
218 page_url, kTileIconMinSizePx, kTileIconDesiredSizePx, 221 page_url, kTileIconMinSizePx, kTileIconDesiredSizePx,
219 base::Bind(&IconCacherImpl::FinishRequestAndNotifyIconAvailable, 222 base::Bind(&IconCacherImpl::OnMostLikelyFaviconDownloaded,
220 weak_ptr_factory_.GetWeakPtr(), page_url)); 223 weak_ptr_factory_.GetWeakPtr(), page_url));
221 } 224 }
222 225
226 void IconCacherImpl::OnMostLikelyFaviconDownloaded(const GURL& request_url,
227 bool success) {
228 UMA_HISTOGRAM_BOOLEAN("NewTabPage.TileFaviconFetchSuccess.Server", success);
229 FinishRequestAndNotifyIconAvailable(request_url, success);
230 }
231
223 bool IconCacherImpl::StartRequest(const GURL& request_url, 232 bool IconCacherImpl::StartRequest(const GURL& request_url,
224 const base::Closure& icon_available) { 233 const base::Closure& icon_available) {
225 bool in_flight = in_flight_requests_.count(request_url) > 0; 234 bool in_flight = in_flight_requests_.count(request_url) > 0;
226 in_flight_requests_[request_url].push_back(icon_available); 235 in_flight_requests_[request_url].push_back(icon_available);
227 return !in_flight; 236 return !in_flight;
228 } 237 }
229 238
230 void IconCacherImpl::FinishRequestAndNotifyIconAvailable( 239 void IconCacherImpl::FinishRequestAndNotifyIconAvailable(
231 const GURL& request_url, 240 const GURL& request_url,
232 bool newly_available) { 241 bool newly_available) {
233 std::vector<base::Closure> callbacks = 242 std::vector<base::Closure> callbacks =
234 std::move(in_flight_requests_[request_url]); 243 std::move(in_flight_requests_[request_url]);
235 in_flight_requests_.erase(request_url); 244 in_flight_requests_.erase(request_url);
236 if (!newly_available) { 245 if (!newly_available) {
237 return; 246 return;
238 } 247 }
239 for (const base::Closure& callback : callbacks) { 248 for (const base::Closure& callback : callbacks) {
240 if (callback) { 249 if (callback) {
241 callback.Run(); 250 callback.Run();
242 } 251 }
243 } 252 }
244 } 253 }
245 254
246 } // namespace ntp_tiles 255 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/icon_cacher_impl.h ('k') | components/ntp_tiles/icon_cacher_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698