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

Side by Side Diff: components/favicon/core/large_icon_service.cc

Issue 2804283003: [LargeIconService] Report size of the downloaded favicon to UMA (Closed)
Patch Set: Fix the unit-tests #2 Created 3 years, 8 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 | « no previous file | components/favicon/core/large_icon_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/favicon/core/large_icon_service.h" 5 #include "components/favicon/core/large_icon_service.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/metrics/histogram_macros.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/task_runner.h" 17 #include "base/task_runner.h"
17 #include "base/threading/sequenced_worker_pool.h" 18 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
19 #include "components/data_use_measurement/core/data_use_user_data.h" 20 #include "components/data_use_measurement/core/data_use_user_data.h"
20 #include "components/favicon/core/favicon_service.h" 21 #include "components/favicon/core/favicon_service.h"
21 #include "components/favicon_base/fallback_icon_style.h" 22 #include "components/favicon_base/fallback_icon_style.h"
22 #include "components/favicon_base/favicon_types.h" 23 #include "components/favicon_base/favicon_types.h"
23 #include "components/favicon_base/favicon_util.h" 24 #include "components/favicon_base/favicon_util.h"
24 #include "components/image_fetcher/core/request_metadata.h" 25 #include "components/image_fetcher/core/request_metadata.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 211
211 if (!bitmap_result_.isNull()) { 212 if (!bitmap_result_.isNull()) {
212 image_callback_.Run(favicon_base::LargeIconImageResult( 213 image_callback_.Run(favicon_base::LargeIconImageResult(
213 gfx::Image::CreateFrom1xBitmap(bitmap_result_))); 214 gfx::Image::CreateFrom1xBitmap(bitmap_result_)));
214 return; 215 return;
215 } 216 }
216 image_callback_.Run( 217 image_callback_.Run(
217 favicon_base::LargeIconImageResult(fallback_icon_style_.release())); 218 favicon_base::LargeIconImageResult(fallback_icon_style_.release()));
218 } 219 }
219 220
221 void ReportDownloadedSize(int size) {
222 UMA_HISTOGRAM_COUNTS_1000("Favicons.LargeIconService.DownloadedSize", size);
223 }
224
220 void OnFetchIconFromGoogleServerComplete( 225 void OnFetchIconFromGoogleServerComplete(
221 FaviconService* favicon_service, 226 FaviconService* favicon_service,
222 const GURL& page_url, 227 const GURL& page_url,
223 const base::Callback<void(bool success)>& callback, 228 const base::Callback<void(bool success)>& callback,
224 const std::string& server_request_url, 229 const std::string& server_request_url,
225 const gfx::Image& image, 230 const gfx::Image& image,
226 const image_fetcher::RequestMetadata& metadata) { 231 const image_fetcher::RequestMetadata& metadata) {
227 if (image.IsEmpty()) { 232 if (image.IsEmpty()) {
228 DLOG(WARNING) << "large icon server fetch empty " << server_request_url; 233 DLOG(WARNING) << "large icon server fetch empty " << server_request_url;
229 favicon_service->UnableToDownloadFavicon(GURL(server_request_url)); 234 favicon_service->UnableToDownloadFavicon(GURL(server_request_url));
230 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 235 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
231 base::Bind(callback, false)); 236 base::Bind(callback, false));
237 ReportDownloadedSize(0);
232 return; 238 return;
233 } 239 }
234 240
241 ReportDownloadedSize(image.Width());
242
235 // If given, use the original favicon URL from Content-Location http header. 243 // If given, use the original favicon URL from Content-Location http header.
236 // Otherwise, use the request URL as fallback. 244 // Otherwise, use the request URL as fallback.
237 std::string original_icon_url = metadata.content_location_header; 245 std::string original_icon_url = metadata.content_location_header;
238 if (original_icon_url.empty()) { 246 if (original_icon_url.empty()) {
239 original_icon_url = server_request_url; 247 original_icon_url = server_request_url;
240 } 248 }
241 249
242 // Write fetched icons to FaviconService's cache, but only if no icon was 250 // Write fetched icons to FaviconService's cache, but only if no icon was
243 // available (clients are encouraged to do this in advance, but meanwhile 251 // available (clients are encouraged to do this in advance, but meanwhile
244 // something else could've been written). By marking the icons initially 252 // something else could've been written). By marking the icons initially
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 // TODO(beaudoin): For now this is just a wrapper around 344 // TODO(beaudoin): For now this is just a wrapper around
337 // GetLargestRawFaviconForPageURL. Add the logic required to select the best 345 // GetLargestRawFaviconForPageURL. Add the logic required to select the best
338 // possible large icon. Also add logic to fetch-on-demand when the URL of 346 // possible large icon. Also add logic to fetch-on-demand when the URL of
339 // a large icon is known but its bitmap is not available. 347 // a large icon is known but its bitmap is not available.
340 return favicon_service_->GetLargestRawFaviconForPageURL( 348 return favicon_service_->GetLargestRawFaviconForPageURL(
341 page_url, large_icon_types_, min_source_size_in_pixel, 349 page_url, large_icon_types_, min_source_size_in_pixel,
342 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker); 350 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker);
343 } 351 }
344 352
345 } // namespace favicon 353 } // namespace favicon
OLDNEW
« no previous file with comments | « no previous file | components/favicon/core/large_icon_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698