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

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

Issue 2896803002: [LargeIconService] Make check_seen param optional for fetching (Closed)
Patch Set: Fix compilation 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 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/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 22 matching lines...) Expand all
33 namespace favicon { 33 namespace favicon {
34 namespace { 34 namespace {
35 35
36 // This feature is only used for accessing field trial parameters, not for 36 // This feature is only used for accessing field trial parameters, not for
37 // switching on/off the code. 37 // switching on/off the code.
38 const base::Feature kLargeIconServiceFetchingFeature{ 38 const base::Feature kLargeIconServiceFetchingFeature{
39 "LargeIconServiceFetching", base::FEATURE_ENABLED_BY_DEFAULT}; 39 "LargeIconServiceFetching", base::FEATURE_ENABLED_BY_DEFAULT};
40 40
41 const char kGoogleServerV2RequestFormat[] = 41 const char kGoogleServerV2RequestFormat[] =
42 "https://t0.gstatic.com/faviconV2?" 42 "https://t0.gstatic.com/faviconV2?"
43 "client=chrome&drop_404_icon=true&check_seen=true&" 43 "client=chrome&drop_404_icon=true&%s"
44 "size=%d&min_size=%d&max_size=%d&fallback_opts=TYPE,SIZE,URL&url=%s"; 44 "size=%d&min_size=%d&max_size=%d&fallback_opts=TYPE,SIZE,URL&url=%s";
45 const char kGoogleServerV2RequestFormatParam[] = "request_format"; 45 const char kGoogleServerV2RequestFormatParam[] = "request_format";
46 46
47 const char kCheckSeenParam[] = "check_seen=true&";
pkotwicz 2017/05/24 05:02:25 Random question: Does "check_seen=false" work?
jkrcal 2017/05/24 08:54:48 Yes. Any non-"true" value of check_seen is equival
48
47 const int kGoogleServerV2EnforcedMinSizeInPixel = 32; 49 const int kGoogleServerV2EnforcedMinSizeInPixel = 32;
48 const char kGoogleServerV2EnforcedMinSizeInPixelParam[] = 50 const char kGoogleServerV2EnforcedMinSizeInPixelParam[] =
49 "enforced_min_size_in_pixel"; 51 "enforced_min_size_in_pixel";
50 52
51 const double kGoogleServerV2DesiredToMaxSizeFactor = 2.0; 53 const double kGoogleServerV2DesiredToMaxSizeFactor = 2.0;
52 const char kGoogleServerV2DesiredToMaxSizeFactorParam[] = 54 const char kGoogleServerV2DesiredToMaxSizeFactorParam[] =
53 "desired_to_max_size_factor"; 55 "desired_to_max_size_factor";
54 56
55 GURL TrimPageUrlForGoogleServer(const GURL& page_url) { 57 GURL TrimPageUrlForGoogleServer(const GURL& page_url) {
56 if (!page_url.SchemeIsHTTPOrHTTPS() || page_url.HostIsIPAddress()) 58 if (!page_url.SchemeIsHTTPOrHTTPS() || page_url.HostIsIPAddress())
57 return GURL(); 59 return GURL();
58 60
59 url::Replacements<char> replacements; 61 url::Replacements<char> replacements;
60 replacements.ClearUsername(); 62 replacements.ClearUsername();
61 replacements.ClearPassword(); 63 replacements.ClearPassword();
62 replacements.ClearQuery(); 64 replacements.ClearQuery();
63 replacements.ClearRef(); 65 replacements.ClearRef();
64 return page_url.ReplaceComponents(replacements); 66 return page_url.ReplaceComponents(replacements);
65 } 67 }
66 68
67 GURL GetRequestUrlForGoogleServerV2(const GURL& page_url, 69 GURL GetRequestUrlForGoogleServerV2(const GURL& page_url,
68 int min_source_size_in_pixel, 70 int min_source_size_in_pixel,
69 int desired_size_in_pixel) { 71 int desired_size_in_pixel,
72 bool may_page_url_be_private) {
70 std::string url_format = base::GetFieldTrialParamValueByFeature( 73 std::string url_format = base::GetFieldTrialParamValueByFeature(
71 kLargeIconServiceFetchingFeature, kGoogleServerV2RequestFormatParam); 74 kLargeIconServiceFetchingFeature, kGoogleServerV2RequestFormatParam);
72 double desired_to_max_size_factor = base::GetFieldTrialParamByFeatureAsDouble( 75 double desired_to_max_size_factor = base::GetFieldTrialParamByFeatureAsDouble(
73 kLargeIconServiceFetchingFeature, 76 kLargeIconServiceFetchingFeature,
74 kGoogleServerV2DesiredToMaxSizeFactorParam, 77 kGoogleServerV2DesiredToMaxSizeFactorParam,
75 kGoogleServerV2DesiredToMaxSizeFactor); 78 kGoogleServerV2DesiredToMaxSizeFactor);
76 79
77 min_source_size_in_pixel = std::max( 80 min_source_size_in_pixel = std::max(
78 min_source_size_in_pixel, base::GetFieldTrialParamByFeatureAsInt( 81 min_source_size_in_pixel, base::GetFieldTrialParamByFeatureAsInt(
79 kLargeIconServiceFetchingFeature, 82 kLargeIconServiceFetchingFeature,
80 kGoogleServerV2EnforcedMinSizeInPixelParam, 83 kGoogleServerV2EnforcedMinSizeInPixelParam,
81 kGoogleServerV2EnforcedMinSizeInPixel)); 84 kGoogleServerV2EnforcedMinSizeInPixel));
82 desired_size_in_pixel = 85 desired_size_in_pixel =
83 std::max(desired_size_in_pixel, min_source_size_in_pixel); 86 std::max(desired_size_in_pixel, min_source_size_in_pixel);
84 int max_size_in_pixel = 87 int max_size_in_pixel =
85 static_cast<int>(desired_size_in_pixel * desired_to_max_size_factor); 88 static_cast<int>(desired_size_in_pixel * desired_to_max_size_factor);
86 89
87 return GURL(base::StringPrintf( 90 return GURL(base::StringPrintf(
88 url_format.empty() ? kGoogleServerV2RequestFormat : url_format.c_str(), 91 url_format.empty() ? kGoogleServerV2RequestFormat : url_format.c_str(),
89 desired_size_in_pixel, min_source_size_in_pixel, max_size_in_pixel, 92 may_page_url_be_private ? kCheckSeenParam : "", desired_size_in_pixel,
90 page_url.spec().c_str())); 93 min_source_size_in_pixel, max_size_in_pixel, page_url.spec().c_str()));
91 } 94 }
92 95
93 bool IsDbResultAdequate(const favicon_base::FaviconRawBitmapResult& db_result, 96 bool IsDbResultAdequate(const favicon_base::FaviconRawBitmapResult& db_result,
94 int min_source_size) { 97 int min_source_size) {
95 return db_result.is_valid() && 98 return db_result.is_valid() &&
96 db_result.pixel_size.width() == db_result.pixel_size.height() && 99 db_result.pixel_size.width() == db_result.pixel_size.height() &&
97 db_result.pixel_size.width() >= min_source_size; 100 db_result.pixel_size.width() >= min_source_size;
98 } 101 }
99 102
100 // Wraps the PNG data in |db_result| in a gfx::Image. If |desired_size| is not 103 // Wraps the PNG data in |db_result| in a gfx::Image. If |desired_size| is not
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 return GetLargeIconOrFallbackStyleImpl( 341 return GetLargeIconOrFallbackStyleImpl(
339 page_url, min_source_size_in_pixel, desired_size_in_pixel, 342 page_url, min_source_size_in_pixel, desired_size_in_pixel,
340 favicon_base::LargeIconCallback(), image_callback, tracker); 343 favicon_base::LargeIconCallback(), image_callback, tracker);
341 } 344 }
342 345
343 void LargeIconService:: 346 void LargeIconService::
344 GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( 347 GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
345 const GURL& page_url, 348 const GURL& page_url,
346 int min_source_size_in_pixel, 349 int min_source_size_in_pixel,
347 int desired_size_in_pixel, 350 int desired_size_in_pixel,
351 bool may_page_url_be_private,
348 const base::Callback<void(bool success)>& callback) { 352 const base::Callback<void(bool success)>& callback) {
349 DCHECK_LE(0, min_source_size_in_pixel); 353 DCHECK_LE(0, min_source_size_in_pixel);
350 354
351 const GURL trimmed_page_url = TrimPageUrlForGoogleServer(page_url); 355 const GURL trimmed_page_url = TrimPageUrlForGoogleServer(page_url);
352 const GURL server_request_url = GetRequestUrlForGoogleServerV2( 356 const GURL server_request_url = GetRequestUrlForGoogleServerV2(
353 trimmed_page_url, min_source_size_in_pixel, desired_size_in_pixel); 357 trimmed_page_url, min_source_size_in_pixel, desired_size_in_pixel,
358 may_page_url_be_private);
354 359
355 // Do not download if the URL is invalid after trimming, or there is a 360 // Do not download if the URL is invalid after trimming, or there is a
356 // previous cache miss recorded for |server_request_url|. 361 // previous cache miss recorded for |server_request_url|.
357 if (!server_request_url.is_valid() || !trimmed_page_url.is_valid() || 362 if (!server_request_url.is_valid() || !trimmed_page_url.is_valid() ||
358 !image_fetcher_ || 363 !image_fetcher_ ||
359 favicon_service_->WasUnableToDownloadFavicon(server_request_url)) { 364 favicon_service_->WasUnableToDownloadFavicon(server_request_url)) {
360 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 365 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
361 base::Bind(callback, false)); 366 base::Bind(callback, false));
362 return; 367 return;
363 } 368 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // TODO(beaudoin): For now this is just a wrapper around 417 // TODO(beaudoin): For now this is just a wrapper around
413 // GetLargestRawFaviconForPageURL. Add the logic required to select the best 418 // GetLargestRawFaviconForPageURL. Add the logic required to select the best
414 // possible large icon. Also add logic to fetch-on-demand when the URL of 419 // possible large icon. Also add logic to fetch-on-demand when the URL of
415 // a large icon is known but its bitmap is not available. 420 // a large icon is known but its bitmap is not available.
416 return favicon_service_->GetLargestRawFaviconForPageURL( 421 return favicon_service_->GetLargestRawFaviconForPageURL(
417 page_url, large_icon_types_, min_source_size_in_pixel, 422 page_url, large_icon_types_, min_source_size_in_pixel,
418 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker); 423 base::Bind(&LargeIconWorker::OnIconLookupComplete, worker), tracker);
419 } 424 }
420 425
421 } // namespace favicon 426 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698