Commit b9ee1080 authored by kristipark's avatar kristipark Committed by Commit Bot

Created params class for LargeIconService and added a desktop client

The params class sets default parameters for specific platforms, particularly desktop (which should not need to specify min size and desired size, and should store icons as IconType::kFavicon). Also added a separate Google Favicon Service client to be used on desktop. These will be used in the upcoming NTP redesign.

Bug: 837798
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib1a78c49a2518acffdc8f1f7c746a751377cfb45
Reviewed-on: https://chromium-review.googlesource.com/1031562Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Commit-Queue: Kristi Park <kristipark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556922}
parent e05b6555
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/favicon_service.h" #include "components/favicon/core/favicon_service.h"
#include "components/favicon/core/large_icon_service.h" #include "components/favicon/core/large_icon_service.h"
#include "components/favicon_base/favicon_types.h" #include "components/favicon_base/favicon_types.h"
...@@ -313,9 +314,10 @@ void PartnerBookmarksReader::OnGetFaviconFromCacheFinished( ...@@ -313,9 +314,10 @@ void PartnerBookmarksReader::OnGetFaviconFromCacheFinished(
})"); })");
GetLargeIconService() GetLargeIconService()
->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
page_url, kPartnerBookmarksMinimumFaviconSizePx, favicon::FaviconServerFetcherParams::CreateForMobile(
desired_favicon_size_px, false /* may_page_url_be_private */, page_url, kPartnerBookmarksMinimumFaviconSizePx,
traffic_annotation, desired_favicon_size_px),
false /* may_page_url_be_private */, traffic_annotation,
base::Bind(&PartnerBookmarksReader::OnGetFaviconFromServerFinished, base::Bind(&PartnerBookmarksReader::OnGetFaviconFromServerFinished,
base::Unretained(this), page_url, desired_favicon_size_px, base::Unretained(this), page_url, desired_favicon_size_px,
base::Passed(std::move(callback)))); base::Passed(std::move(callback))));
......
...@@ -14,6 +14,8 @@ static_library("core") { ...@@ -14,6 +14,8 @@ static_library("core") {
"favicon_driver_observer.h", "favicon_driver_observer.h",
"favicon_handler.cc", "favicon_handler.cc",
"favicon_handler.h", "favicon_handler.h",
"favicon_server_fetcher_params.cc",
"favicon_server_fetcher_params.h",
"favicon_service.cc", "favicon_service.cc",
"favicon_service.h", "favicon_service.h",
"favicon_service_impl.cc", "favicon_service_impl.cc",
......
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "components/favicon_base/favicon_util.h"
#include "ui/gfx/favicon_size.h"
namespace favicon {
namespace {
const char kClientParamDesktop[] = "client=chrome_desktop";
const char kClientParamMobile[] = "client=chrome";
float GetMaxDeviceScaleFactor() {
std::vector<float> favicon_scales = favicon_base::GetFaviconScales();
DCHECK(!favicon_scales.empty());
return favicon_scales.back();
}
} // namespace
std::unique_ptr<FaviconServerFetcherParams>
FaviconServerFetcherParams::CreateForDesktop(const GURL& page_url) {
return base::WrapUnique(new FaviconServerFetcherParams(
page_url, favicon_base::IconType::kFavicon,
std::ceil(gfx::kFaviconSize * GetMaxDeviceScaleFactor()), 0,
kClientParamDesktop));
}
std::unique_ptr<FaviconServerFetcherParams>
FaviconServerFetcherParams::CreateForMobile(const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel) {
return base::WrapUnique(new FaviconServerFetcherParams(
page_url, favicon_base::IconType::kTouchIcon, min_source_size_in_pixel,
desired_size_in_pixel, kClientParamMobile));
}
FaviconServerFetcherParams::FaviconServerFetcherParams(
const GURL& page_url,
favicon_base::IconType icon_type,
int min_source_size_in_pixel,
int desired_size_in_pixel,
const std::string& google_server_client_param)
: page_url_(page_url),
icon_type_(icon_type),
min_source_size_in_pixel_(min_source_size_in_pixel),
desired_size_in_pixel_(desired_size_in_pixel),
google_server_client_param_(google_server_client_param) {}
FaviconServerFetcherParams::~FaviconServerFetcherParams() = default;
} // namespace favicon
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_FAVICON_CORE_FAVICON_SERVER_FETCHER_PARAMS_H_
#define COMPONENTS_FAVICON_CORE_FAVICON_SERVER_FETCHER_PARAMS_H_
#include "components/favicon_base/favicon_util.h"
class GURL;
namespace favicon {
class FaviconServerFetcherParams {
public:
// Platform specific constructors that set default fetch parameters. Any
// platform not Android nor iOS is considered desktop.
static std::unique_ptr<FaviconServerFetcherParams> CreateForDesktop(
const GURL& page_url);
static std::unique_ptr<FaviconServerFetcherParams> CreateForMobile(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel);
~FaviconServerFetcherParams();
const GURL& page_url() const { return page_url_; };
favicon_base::IconType icon_type() const { return icon_type_; };
int min_source_size_in_pixel() const { return min_source_size_in_pixel_; };
int desired_size_in_pixel() const { return desired_size_in_pixel_; };
const std::string& google_server_client_param() const {
return google_server_client_param_;
};
private:
FaviconServerFetcherParams(const GURL& page_url,
favicon_base::IconType icon_type,
int min_source_size_in_pixel,
int desired_size_in_pixel,
const std::string& google_server_client_param);
const GURL& page_url_;
favicon_base::IconType icon_type_;
int min_source_size_in_pixel_;
int desired_size_in_pixel_;
std::string google_server_client_param_;
DISALLOW_COPY_AND_ASSIGN(FaviconServerFetcherParams);
};
} // namespace favicon
#endif // COMPONENTS_FAVICON_CORE_FAVICON_SERVER_FETCHER_PARAMS_H_
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "base/task_scheduler/post_task.h" #include "base/task_scheduler/post_task.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/data_use_measurement/core/data_use_user_data.h" #include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/favicon_service.h" #include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/fallback_icon_style.h" #include "components/favicon_base/fallback_icon_style.h"
#include "components/favicon_base/favicon_types.h" #include "components/favicon_base/favicon_types.h"
...@@ -52,6 +53,8 @@ const char kGoogleServerV2RequestFormat[] = ...@@ -52,6 +53,8 @@ const char kGoogleServerV2RequestFormat[] =
"size=%d&min_size=%d&max_size=%d&fallback_opts=TYPE,SIZE,URL&url=%s"; "size=%d&min_size=%d&max_size=%d&fallback_opts=TYPE,SIZE,URL&url=%s";
const char kGoogleServerV2RequestFormatParam[] = "request_format"; const char kGoogleServerV2RequestFormatParam[] = "request_format";
const char kClientParam[] = "client=chrome";
const char kCheckSeenParam[] = "check_seen=true&"; const char kCheckSeenParam[] = "check_seen=true&";
const int kGoogleServerV2EnforcedMinSizeInPixel = 16; const int kGoogleServerV2EnforcedMinSizeInPixel = 16;
...@@ -79,10 +82,12 @@ GURL TrimPageUrlForGoogleServer(const GURL& page_url) { ...@@ -79,10 +82,12 @@ GURL TrimPageUrlForGoogleServer(const GURL& page_url) {
return page_url.ReplaceComponents(replacements); return page_url.ReplaceComponents(replacements);
} }
GURL GetRequestUrlForGoogleServerV2(const GURL& page_url, GURL GetRequestUrlForGoogleServerV2(
int min_source_size_in_pixel, const GURL& page_url,
int desired_size_in_pixel, const std::string& google_server_client_param,
bool may_page_url_be_private) { int min_source_size_in_pixel,
int desired_size_in_pixel,
bool may_page_url_be_private) {
std::string url_format = base::GetFieldTrialParamValueByFeature( std::string url_format = base::GetFieldTrialParamValueByFeature(
kLargeIconServiceFetchingFeature, kGoogleServerV2RequestFormatParam); kLargeIconServiceFetchingFeature, kGoogleServerV2RequestFormatParam);
double desired_to_max_size_factor = base::GetFieldTrialParamByFeatureAsDouble( double desired_to_max_size_factor = base::GetFieldTrialParamByFeatureAsDouble(
...@@ -105,10 +110,13 @@ GURL GetRequestUrlForGoogleServerV2(const GURL& page_url, ...@@ -105,10 +110,13 @@ GURL GetRequestUrlForGoogleServerV2(const GURL& page_url,
static_cast<int>(desired_size_in_pixel * desired_to_max_size_factor); static_cast<int>(desired_size_in_pixel * desired_to_max_size_factor);
max_size_in_pixel = std::max(max_size_in_pixel, minimum_max_size_in_pixel); max_size_in_pixel = std::max(max_size_in_pixel, minimum_max_size_in_pixel);
return GURL(base::StringPrintf( std::string request_url = base::StringPrintf(
url_format.empty() ? kGoogleServerV2RequestFormat : url_format.c_str(), url_format.empty() ? kGoogleServerV2RequestFormat : url_format.c_str(),
may_page_url_be_private ? kCheckSeenParam : "", desired_size_in_pixel, may_page_url_be_private ? kCheckSeenParam : "", desired_size_in_pixel,
min_source_size_in_pixel, max_size_in_pixel, page_url.spec().c_str())); min_source_size_in_pixel, max_size_in_pixel, page_url.spec().c_str());
base::ReplaceFirstSubstringAfterOffset(
&request_url, 0, std::string(kClientParam), google_server_client_param);
return GURL(request_url);
} }
bool IsDbResultAdequate(const favicon_base::FaviconRawBitmapResult& db_result, bool IsDbResultAdequate(const favicon_base::FaviconRawBitmapResult& db_result,
...@@ -193,8 +201,8 @@ void ProcessIconOnBackgroundThread( ...@@ -193,8 +201,8 @@ void ProcessIconOnBackgroundThread(
void FinishServerRequestAsynchronously( void FinishServerRequestAsynchronously(
const favicon_base::GoogleFaviconServerCallback& callback, const favicon_base::GoogleFaviconServerCallback& callback,
favicon_base::GoogleFaviconServerRequestStatus status) { favicon_base::GoogleFaviconServerRequestStatus status) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::ThreadTaskRunnerHandle::Get()->PostTask(
base::Bind(callback, status)); FROM_HERE, base::BindOnce(callback, status));
} }
// Singleton map keyed by organization-identifying domain (excludes registrar // Singleton map keyed by organization-identifying domain (excludes registrar
...@@ -407,6 +415,7 @@ void OnSetOnDemandFaviconComplete( ...@@ -407,6 +415,7 @@ void OnSetOnDemandFaviconComplete(
void OnFetchIconFromGoogleServerComplete( void OnFetchIconFromGoogleServerComplete(
FaviconService* favicon_service, FaviconService* favicon_service,
const GURL& page_url, const GURL& page_url,
favicon_base::IconType icon_type,
const favicon_base::GoogleFaviconServerCallback& callback, const favicon_base::GoogleFaviconServerCallback& callback,
const std::string& server_request_url, const std::string& server_request_url,
const gfx::Image& image, const gfx::Image& image,
...@@ -437,8 +446,8 @@ void OnFetchIconFromGoogleServerComplete( ...@@ -437,8 +446,8 @@ void OnFetchIconFromGoogleServerComplete(
// expired (out-of-date), they will be refetched when we visit the original // expired (out-of-date), they will be refetched when we visit the original
// page any time in the future. // page any time in the future.
favicon_service->SetOnDemandFavicons( favicon_service->SetOnDemandFavicons(
page_url, GURL(original_icon_url), favicon_base::IconType::kTouchIcon, page_url, GURL(original_icon_url), icon_type, image,
image, base::Bind(&OnSetOnDemandFaviconComplete, callback)); base::BindOnce(&OnSetOnDemandFaviconComplete, callback));
} }
} // namespace } // namespace
...@@ -485,13 +494,11 @@ LargeIconService::GetLargeIconImageOrFallbackStyle( ...@@ -485,13 +494,11 @@ LargeIconService::GetLargeIconImageOrFallbackStyle(
void LargeIconService:: void LargeIconService::
GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
const GURL& page_url, std::unique_ptr<FaviconServerFetcherParams> params,
int min_source_size_in_pixel,
int desired_size_in_pixel,
bool may_page_url_be_private, bool may_page_url_be_private,
const net::NetworkTrafficAnnotationTag& traffic_annotation, const net::NetworkTrafficAnnotationTag& traffic_annotation,
const favicon_base::GoogleFaviconServerCallback& callback) { const favicon_base::GoogleFaviconServerCallback& callback) {
DCHECK_LE(0, min_source_size_in_pixel); DCHECK_LE(0, params->min_source_size_in_pixel());
if (net::NetworkChangeNotifier::IsOffline()) { if (net::NetworkChangeNotifier::IsOffline()) {
// By exiting early when offline, we avoid caching the failure and thus // By exiting early when offline, we avoid caching the failure and thus
...@@ -501,13 +508,13 @@ void LargeIconService:: ...@@ -501,13 +508,13 @@ void LargeIconService::
return; return;
} }
if (!page_url.is_valid()) { if (!params->page_url().is_valid()) {
FinishServerRequestAsynchronously( FinishServerRequestAsynchronously(
callback, GoogleFaviconServerRequestStatus::FAILURE_TARGET_URL_INVALID); callback, GoogleFaviconServerRequestStatus::FAILURE_TARGET_URL_INVALID);
return; return;
} }
const GURL trimmed_page_url = TrimPageUrlForGoogleServer(page_url); const GURL trimmed_page_url = TrimPageUrlForGoogleServer(params->page_url());
if (!trimmed_page_url.is_valid()) { if (!trimmed_page_url.is_valid()) {
FinishServerRequestAsynchronously( FinishServerRequestAsynchronously(
callback, GoogleFaviconServerRequestStatus::FAILURE_TARGET_URL_SKIPPED); callback, GoogleFaviconServerRequestStatus::FAILURE_TARGET_URL_SKIPPED);
...@@ -515,7 +522,8 @@ void LargeIconService:: ...@@ -515,7 +522,8 @@ void LargeIconService::
} }
const GURL server_request_url = GetRequestUrlForGoogleServerV2( const GURL server_request_url = GetRequestUrlForGoogleServerV2(
trimmed_page_url, min_source_size_in_pixel, desired_size_in_pixel, trimmed_page_url, params->google_server_client_param(),
params->min_source_size_in_pixel(), params->desired_size_in_pixel(),
may_page_url_be_private); may_page_url_be_private);
if (!server_request_url.is_valid()) { if (!server_request_url.is_valid()) {
FinishServerRequestAsynchronously( FinishServerRequestAsynchronously(
...@@ -532,10 +540,11 @@ void LargeIconService:: ...@@ -532,10 +540,11 @@ void LargeIconService::
} }
favicon_service_->CanSetOnDemandFavicons( favicon_service_->CanSetOnDemandFavicons(
page_url, favicon_base::IconType::kTouchIcon, params->page_url(), params->icon_type(),
base::BindOnce(&LargeIconService::OnCanSetOnDemandFaviconComplete, base::BindOnce(&LargeIconService::OnCanSetOnDemandFaviconComplete,
weak_ptr_factory_.GetWeakPtr(), server_request_url, weak_ptr_factory_.GetWeakPtr(), server_request_url,
page_url, traffic_annotation, callback)); params->page_url(), params->icon_type(),
traffic_annotation, callback));
} }
void LargeIconService::TouchIconFromGoogleServer(const GURL& icon_url) { void LargeIconService::TouchIconFromGoogleServer(const GURL& icon_url) {
...@@ -591,6 +600,7 @@ LargeIconService::GetLargeIconOrFallbackStyleImpl( ...@@ -591,6 +600,7 @@ LargeIconService::GetLargeIconOrFallbackStyleImpl(
void LargeIconService::OnCanSetOnDemandFaviconComplete( void LargeIconService::OnCanSetOnDemandFaviconComplete(
const GURL& server_request_url, const GURL& server_request_url,
const GURL& page_url, const GURL& page_url,
favicon_base::IconType icon_type,
const net::NetworkTrafficAnnotationTag& traffic_annotation, const net::NetworkTrafficAnnotationTag& traffic_annotation,
const favicon_base::GoogleFaviconServerCallback& callback, const favicon_base::GoogleFaviconServerCallback& callback,
bool can_set_on_demand_favicon) { bool can_set_on_demand_favicon) {
...@@ -603,8 +613,8 @@ void LargeIconService::OnCanSetOnDemandFaviconComplete( ...@@ -603,8 +613,8 @@ void LargeIconService::OnCanSetOnDemandFaviconComplete(
data_use_measurement::DataUseUserData::LARGE_ICON_SERVICE); data_use_measurement::DataUseUserData::LARGE_ICON_SERVICE);
image_fetcher_->FetchImage( image_fetcher_->FetchImage(
server_request_url.spec(), server_request_url, server_request_url.spec(), server_request_url,
base::BindRepeating(&OnFetchIconFromGoogleServerComplete, base::BindOnce(&OnFetchIconFromGoogleServerComplete, favicon_service_,
favicon_service_, page_url, callback), page_url, icon_type, callback),
traffic_annotation); traffic_annotation);
} }
......
...@@ -26,6 +26,7 @@ class ImageFetcher; ...@@ -26,6 +26,7 @@ class ImageFetcher;
namespace favicon { namespace favicon {
class FaviconService; class FaviconService;
class FaviconServerFetcherParams;
// The large icon service provides methods to access large icons. It relies on // The large icon service provides methods to access large icons. It relies on
// the favicon service. // the favicon service.
...@@ -93,9 +94,7 @@ class LargeIconService : public KeyedService { ...@@ -93,9 +94,7 @@ class LargeIconService : public KeyedService {
// TODO(jkrcal): It is not clear from the name of this function, that it // TODO(jkrcal): It is not clear from the name of this function, that it
// actually adds the icon to the local cache. Maybe "StoreLargeIcon..."? // actually adds the icon to the local cache. Maybe "StoreLargeIcon..."?
void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
const GURL& page_url, std::unique_ptr<FaviconServerFetcherParams> params,
int min_source_size_in_pixel,
int desired_size_in_pixel,
bool may_page_url_be_private, bool may_page_url_be_private,
const net::NetworkTrafficAnnotationTag& traffic_annotation, const net::NetworkTrafficAnnotationTag& traffic_annotation,
const favicon_base::GoogleFaviconServerCallback& callback); const favicon_base::GoogleFaviconServerCallback& callback);
...@@ -125,6 +124,7 @@ class LargeIconService : public KeyedService { ...@@ -125,6 +124,7 @@ class LargeIconService : public KeyedService {
void OnCanSetOnDemandFaviconComplete( void OnCanSetOnDemandFaviconComplete(
const GURL& server_request_url, const GURL& server_request_url,
const GURL& page_url, const GURL& page_url,
favicon_base::IconType icon_type,
const net::NetworkTrafficAnnotationTag& traffic_annotation, const net::NetworkTrafficAnnotationTag& traffic_annotation,
const favicon_base::GoogleFaviconServerCallback& callback, const favicon_base::GoogleFaviconServerCallback& callback,
bool can_set_on_demand_favicon); bool can_set_on_demand_favicon);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/favicon/core/favicon_client.h" #include "components/favicon/core/favicon_client.h"
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/test/mock_favicon_service.h" #include "components/favicon/core/test/mock_favicon_service.h"
#include "components/favicon_base/fallback_icon_style.h" #include "components/favicon_base/fallback_icon_style.h"
#include "components/favicon_base/favicon_types.h" #include "components/favicon_base/favicon_types.h"
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/base/layout.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
...@@ -125,7 +127,10 @@ class LargeIconServiceTest : public testing::Test { ...@@ -125,7 +127,10 @@ class LargeIconServiceTest : public testing::Test {
LargeIconServiceTest() LargeIconServiceTest()
: mock_image_fetcher_(new NiceMock<MockImageFetcher>()), : mock_image_fetcher_(new NiceMock<MockImageFetcher>()),
large_icon_service_(&mock_favicon_service_, large_icon_service_(&mock_favicon_service_,
base::WrapUnique(mock_image_fetcher_)) {} base::WrapUnique(mock_image_fetcher_)) {
scoped_set_supported_scale_factors_.reset(
new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_200P}));
}
~LargeIconServiceTest() override {} ~LargeIconServiceTest() override {}
...@@ -135,6 +140,8 @@ class LargeIconServiceTest : public testing::Test { ...@@ -135,6 +140,8 @@ class LargeIconServiceTest : public testing::Test {
testing::NiceMock<MockFaviconService> mock_favicon_service_; testing::NiceMock<MockFaviconService> mock_favicon_service_;
LargeIconService large_icon_service_; LargeIconService large_icon_service_;
base::HistogramTester histogram_tester_; base::HistogramTester histogram_tester_;
std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors>
scoped_set_supported_scale_factors_;
private: private:
DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest);
...@@ -164,9 +171,12 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { ...@@ -164,9 +171,12 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) {
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, EXPECT_CALL(callback,
Run(favicon_base::GoogleFaviconServerRequestStatus::SUCCESS)); Run(favicon_base::GoogleFaviconServerRequestStatus::SUCCESS));
...@@ -175,6 +185,42 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) { ...@@ -175,6 +185,42 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServer) {
"Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1); "Favicons.LargeIconService.DownloadedSize", 64, /*expected_count=*/1);
} }
TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerForDesktop) {
const GURL kExpectedServerUrl(
"https://t0.gstatic.com/faviconV2?client=chrome_desktop"
"&drop_404_icon=true&check_seen=true&size=32&min_size=32&max_size=256"
"&fallback_opts=TYPE,SIZE,URL&url=http://www.example.com/");
EXPECT_CALL(mock_favicon_service_, UnableToDownloadFavicon(_)).Times(0);
EXPECT_CALL(mock_favicon_service_,
CanSetOnDemandFavicons(GURL(kDummyUrl),
favicon_base::IconType::kFavicon, _))
.WillOnce(PostBoolReplyToArg2(true));
base::MockCallback<favicon_base::GoogleFaviconServerCallback> callback;
EXPECT_CALL(*mock_image_fetcher_,
FetchImageAndData_(_, kExpectedServerUrl, _, _, _))
.WillOnce(PostFetchReply(gfx::Image::CreateFrom1xBitmap(
CreateTestSkBitmap(32, 32, kTestColor))));
EXPECT_CALL(mock_favicon_service_,
SetOnDemandFavicons(GURL(kDummyUrl), kExpectedServerUrl,
favicon_base::IconType::kFavicon, _, _))
.WillOnce(PostBoolReplyToArg4(true));
large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
favicon::FaviconServerFetcherParams::CreateForDesktop(
GURL(kDummyUrl)),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback,
Run(favicon_base::GoogleFaviconServerRequestStatus::SUCCESS));
scoped_task_environment_.RunUntilIdle();
histogram_tester_.ExpectUniqueSample(
"Favicons.LargeIconService.DownloadedSize", 32, /*expected_count=*/1);
}
TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithCustomUrl) { TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithCustomUrl) {
variations::testing::VariationParamsManager variation_params( variations::testing::VariationParamsManager variation_params(
"LargeIconServiceFetching", "LargeIconServiceFetching",
...@@ -206,9 +252,12 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithCustomUrl) { ...@@ -206,9 +252,12 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithCustomUrl) {
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, EXPECT_CALL(callback,
Run(favicon_base::GoogleFaviconServerRequestStatus::SUCCESS)); Run(favicon_base::GoogleFaviconServerRequestStatus::SUCCESS));
...@@ -243,9 +292,12 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) { ...@@ -243,9 +292,12 @@ TEST_F(LargeIconServiceTest, ShouldGetFromGoogleServerWithOriginalUrl) {
base::MockCallback<favicon_base::GoogleFaviconServerCallback> callback; base::MockCallback<favicon_base::GoogleFaviconServerCallback> callback;
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, EXPECT_CALL(callback,
Run(favicon_base::GoogleFaviconServerRequestStatus::SUCCESS)); Run(favicon_base::GoogleFaviconServerRequestStatus::SUCCESS));
...@@ -274,9 +326,11 @@ TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) { ...@@ -274,9 +326,11 @@ TEST_F(LargeIconServiceTest, ShouldTrimQueryParametersForGoogleServer) {
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrlWithQuery), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyUrlWithQuery),
TRAFFIC_ANNOTATION_FOR_TESTS, /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
favicon_base::GoogleFaviconServerCallback()); favicon_base::GoogleFaviconServerCallback());
scoped_task_environment_.RunUntilIdle(); scoped_task_environment_.RunUntilIdle();
...@@ -298,9 +352,12 @@ TEST_F(LargeIconServiceTest, ShouldNotCheckOnPublicUrls) { ...@@ -298,9 +352,12 @@ TEST_F(LargeIconServiceTest, ShouldNotCheckOnPublicUrls) {
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/false, GURL(kDummyUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/false, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus:: EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus::
FAILURE_CONNECTION_ERROR)); FAILURE_CONNECTION_ERROR));
...@@ -316,9 +373,12 @@ TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidScheme) { ...@@ -316,9 +373,12 @@ TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidScheme) {
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyFtpUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyFtpUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus:: EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus::
FAILURE_TARGET_URL_SKIPPED)); FAILURE_TARGET_URL_SKIPPED));
...@@ -337,9 +397,12 @@ TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidURL) { ...@@ -337,9 +397,12 @@ TEST_F(LargeIconServiceTest, ShouldNotQueryGoogleServerIfInvalidURL) {
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyInvalidUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyInvalidUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus:: EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus::
FAILURE_TARGET_URL_INVALID)); FAILURE_TARGET_URL_INVALID));
...@@ -371,9 +434,12 @@ TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) { ...@@ -371,9 +434,12 @@ TEST_F(LargeIconServiceTest, ShouldReportUnavailableIfFetchFromServerFails) {
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus:: EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus::
FAILURE_CONNECTION_ERROR)); FAILURE_CONNECTION_ERROR));
...@@ -400,9 +466,12 @@ TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfUnavailable) { ...@@ -400,9 +466,12 @@ TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfUnavailable) {
base::MockCallback<favicon_base::GoogleFaviconServerCallback> callback; base::MockCallback<favicon_base::GoogleFaviconServerCallback> callback;
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus:: EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus::
FAILURE_HTTP_ERROR_CACHED)); FAILURE_HTTP_ERROR_CACHED));
...@@ -426,9 +495,12 @@ TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfCannotSet) { ...@@ -426,9 +495,12 @@ TEST_F(LargeIconServiceTest, ShouldNotGetFromGoogleServerIfCannotSet) {
base::MockCallback<favicon_base::GoogleFaviconServerCallback> callback; base::MockCallback<favicon_base::GoogleFaviconServerCallback> callback;
large_icon_service_ large_icon_service_
.GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( .GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
GURL(kDummyUrl), /*min_source_size_in_pixel=*/42, favicon::FaviconServerFetcherParams::CreateForMobile(
/*desired_size_in_pixel=*/61, /*may_page_url_be_private=*/true, GURL(kDummyUrl),
TRAFFIC_ANNOTATION_FOR_TESTS, callback.Get()); /*min_source_size_in_pixel=*/42,
/*desired_size_in_pixel=*/61),
/*may_page_url_be_private=*/true, TRAFFIC_ANNOTATION_FOR_TESTS,
callback.Get());
EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus:: EXPECT_CALL(callback, Run(favicon_base::GoogleFaviconServerRequestStatus::
FAILURE_ICON_EXISTS_IN_DB)); FAILURE_ICON_EXISTS_IN_DB));
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/default_clock.h" #include "base/time/default_clock.h"
#include "base/values.h" #include "base/values.h"
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/large_icon_service.h" #include "components/favicon/core/large_icon_service.h"
#include "components/favicon_base/fallback_icon_style.h" #include "components/favicon_base/fallback_icon_style.h"
#include "components/favicon_base/favicon_types.h" #include "components/favicon_base/favicon_types.h"
...@@ -295,7 +296,8 @@ void ContentSuggestionsService::OnGetFaviconFromCacheFinished( ...@@ -295,7 +296,8 @@ void ContentSuggestionsService::OnGetFaviconFromCacheFinished(
})"); })");
large_icon_service_ large_icon_service_
->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
publisher_url, minimum_size_in_pixel, desired_size_in_pixel, favicon::FaviconServerFetcherParams::CreateForMobile(
publisher_url, minimum_size_in_pixel, desired_size_in_pixel),
/*may_page_url_be_private=*/false, traffic_annotation, /*may_page_url_be_private=*/false, traffic_annotation,
base::Bind( base::Bind(
&ContentSuggestionsService::OnGetFaviconFromGoogleServerFinished, &ContentSuggestionsService::OnGetFaviconFromGoogleServerFinished,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/favicon_service.h" #include "components/favicon/core/favicon_service.h"
#include "components/favicon/core/favicon_util.h" #include "components/favicon/core/favicon_util.h"
#include "components/favicon/core/large_icon_service.h" #include "components/favicon/core/large_icon_service.h"
...@@ -264,9 +265,10 @@ void IconCacherImpl::OnGetLargeIconOrFallbackStyleFinished( ...@@ -264,9 +265,10 @@ void IconCacherImpl::OnGetLargeIconOrFallbackStyleFinished(
})"); })");
large_icon_service_ large_icon_service_
->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
page_url, favicon::FaviconServerFetcherParams::CreateForMobile(
GetMinimumFetchingSizeForChromeSuggestionsFaviconsFromServer(), page_url,
GetDesiredFetchingSizeForChromeSuggestionsFaviconsFromServer(), GetMinimumFetchingSizeForChromeSuggestionsFaviconsFromServer(),
GetDesiredFetchingSizeForChromeSuggestionsFaviconsFromServer()),
/*may_page_url_be_private=*/true, traffic_annotation, /*may_page_url_be_private=*/true, traffic_annotation,
base::Bind(&IconCacherImpl::OnMostLikelyFaviconDownloaded, base::Bind(&IconCacherImpl::OnMostLikelyFaviconDownloaded,
weak_ptr_factory_.GetWeakPtr(), page_url)); weak_ptr_factory_.GetWeakPtr(), page_url));
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/favicon/core/fallback_url_util.h" #include "components/favicon/core/fallback_url_util.h"
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/large_icon_service.h" #include "components/favicon/core/large_icon_service.h"
#include "components/favicon_base/fallback_icon_style.h" #include "components/favicon_base/fallback_icon_style.h"
#include "components/favicon_base/favicon_types.h" #include "components/favicon_base/favicon_types.h"
...@@ -757,7 +758,9 @@ using IntegerPair = std::pair<NSInteger, NSInteger>; ...@@ -757,7 +758,9 @@ using IntegerPair = std::pair<NSInteger, NSInteger>;
strongSelf.sharedState.faviconDownloadCount++; strongSelf.sharedState.faviconDownloadCount++;
IOSChromeLargeIconServiceFactory::GetForBrowserState(self.browserState) IOSChromeLargeIconServiceFactory::GetForBrowserState(self.browserState)
->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache( ->GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
node->url(), minFaviconSizeInPixel, desiredFaviconSizeInPixel, favicon::FaviconServerFetcherParams::CreateForMobile(
node->url(), minFaviconSizeInPixel,
desiredFaviconSizeInPixel),
/*may_page_url_be_private=*/true, kTrafficAnnotation, /*may_page_url_be_private=*/true, kTrafficAnnotation,
base::BindBlockArc(faviconLoadedFromServerBlock)); base::BindBlockArc(faviconLoadedFromServerBlock));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment