summaryrefslogtreecommitdiff
path: root/chromium/components/favicon
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-02-13 15:05:36 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-02-14 10:33:47 +0000
commite684a3455bcc29a6e3e66a004e352dea4e1141e7 (patch)
treed55b4003bde34d7d05f558f02cfd82b2a66a7aac /chromium/components/favicon
parent2b94bfe47ccb6c08047959d1c26e392919550e86 (diff)
downloadqtwebengine-chromium-e684a3455bcc29a6e3e66a004e352dea4e1141e7.tar.gz
BASELINE: Update Chromium to 72.0.3626.110 and Ninja to 1.9.0
Change-Id: Ic57220b00ecc929a893c91f5cc552f5d3e99e922 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/components/favicon')
-rw-r--r--chromium/components/favicon/core/BUILD.gn5
-rw-r--r--chromium/components/favicon/core/favicon_handler.cc63
-rw-r--r--chromium/components/favicon/core/favicon_handler.h3
-rw-r--r--chromium/components/favicon/core/favicon_handler_unittest.cc40
-rw-r--r--chromium/components/favicon/core/large_icon_service.h76
-rw-r--r--chromium/components/favicon/core/large_icon_service_impl.cc (renamed from chromium/components/favicon/core/large_icon_service.cc)41
-rw-r--r--chromium/components/favicon/core/large_icon_service_impl.h95
-rw-r--r--chromium/components/favicon/core/large_icon_service_impl_unittest.cc (renamed from chromium/components/favicon/core/large_icon_service_unittest.cc)32
-rw-r--r--chromium/components/favicon/ios/web_favicon_driver.mm2
9 files changed, 231 insertions, 126 deletions
diff --git a/chromium/components/favicon/core/BUILD.gn b/chromium/components/favicon/core/BUILD.gn
index 798ad7bce73..ee55c2eb0dd 100644
--- a/chromium/components/favicon/core/BUILD.gn
+++ b/chromium/components/favicon/core/BUILD.gn
@@ -26,8 +26,9 @@ static_library("core") {
"favicon_util.h",
"features.cc",
"features.h",
- "large_icon_service.cc",
"large_icon_service.h",
+ "large_icon_service_impl.cc",
+ "large_icon_service_impl.h",
]
deps = [
@@ -52,7 +53,7 @@ source_set("unit_tests") {
"fallback_url_util_unittest.cc",
"favicon_handler_unittest.cc",
"favicon_service_impl_unittest.cc",
- "large_icon_service_unittest.cc",
+ "large_icon_service_impl_unittest.cc",
]
deps = [
diff --git a/chromium/components/favicon/core/favicon_handler.cc b/chromium/components/favicon/core/favicon_handler.cc
index abf4cdc925e..ae2eecd8f89 100644
--- a/chromium/components/favicon/core/favicon_handler.cc
+++ b/chromium/components/favicon/core/favicon_handler.cc
@@ -121,16 +121,30 @@ bool FaviconURLEquals(const FaviconURL& lhs, const FaviconURL& rhs) {
FaviconHandler::FaviconCandidate
FaviconHandler::FaviconCandidate::FromFaviconURL(
const favicon::FaviconURL& favicon_url,
- const std::vector<int>& desired_pixel_sizes) {
+ const std::vector<int>& desired_pixel_sizes,
+ bool want_largest_icon) {
FaviconCandidate candidate;
candidate.icon_url = favicon_url.icon_url;
candidate.icon_type = favicon_url.icon_type;
- // TODO(crbug.com/705900): For candidates without explicit size information,
- // sizes could be inferred for the most common cases. Namely, .ico files tend
- // to contain the 16x16 bitmap, which would allow to improve the
- // prioritization on desktop.
- SelectFaviconFrameIndices(favicon_url.icon_sizes, desired_pixel_sizes,
- /*best_indices=*/nullptr, &candidate.score);
+
+ if (!favicon_url.icon_sizes.empty()) {
+ // For candidates with explicit size information, the score is computed
+ // based on similarity with |desired_pixel_sizes|.
+ SelectFaviconFrameIndices(favicon_url.icon_sizes, desired_pixel_sizes,
+ /*best_indices=*/nullptr, &candidate.score);
+ } else if (want_largest_icon) {
+ // If looking for largest icon (mobile), candidates without explicit size
+ // information are scored low because they are likely small.
+ candidate.score = 0.0f;
+ } else {
+ // If looking for small icons (desktop), candidates without explicit size
+ // information are scored highest, as high as candidates with an ideal
+ // explicit size information. This guarantees all candidates without
+ // explicit size information will be processed until an ideal candidate is
+ // found (if available).
+ candidate.score = 1.0f;
+ }
+
return candidate;
}
@@ -222,24 +236,19 @@ bool FaviconHandler::UpdateFaviconCandidate(
if (downloaded_favicon.candidate.score > best_favicon_.candidate.score)
best_favicon_ = downloaded_favicon;
- if (download_largest_icon_) {
- // The size of the downloaded icon may not match the declared size. It's
- // important to stop downloading if:
- // - current candidate is only candidate.
- // - next candidate has sizes attribute and it is not better than the best
- // one observed so far, which means any following candidate should also
- // be worse or equal too.
- // - next candidate doesn't have sizes attributes, which means further
- // candidates don't have sizes attribute either (because the score lowest
- // and hence get sorted last during prioritization). We stop immediately
- // to avoid downloading them all, although we don't have the certainty
- // that no better favicon is among them.
- return current_candidate_index_ + 1 >= final_candidates_->size() ||
- (*final_candidates_)[current_candidate_index_ + 1].score <=
- best_favicon_.candidate.score;
- } else {
- return best_favicon_.candidate.score == 1;
- }
+ // Stop downloading if the current candidate is the last candidate.
+ if (current_candidate_index_ + 1 >= final_candidates_->size())
+ return true;
+
+ // |next_candidate_score| is based on the sizes provided in the <link> tag,
+ // see FaviconCandidate::FromFaviconURL().
+ float next_candidate_score =
+ (*final_candidates_)[current_candidate_index_ + 1].score;
+
+ // Stop downloading if the next candidate is not better than the best one
+ // observed so far, which means any following candidate should also be worse
+ // or equal too.
+ return next_candidate_score <= best_favicon_.candidate.score;
}
void FaviconHandler::SetFavicon(const GURL& icon_url,
@@ -420,8 +429,8 @@ void FaviconHandler::OnGotFinalIconURLCandidates(
for (const FaviconURL& candidate : candidates) {
if (!candidate.icon_url.is_empty() &&
(icon_types_.count(candidate.icon_type) != 0)) {
- sorted_candidates.push_back(
- FaviconCandidate::FromFaviconURL(candidate, desired_pixel_sizes));
+ sorted_candidates.push_back(FaviconCandidate::FromFaviconURL(
+ candidate, desired_pixel_sizes, download_largest_icon_));
}
}
diff --git a/chromium/components/favicon/core/favicon_handler.h b/chromium/components/favicon/core/favicon_handler.h
index 6a8ff2f0aec..08373a522e9 100644
--- a/chromium/components/favicon/core/favicon_handler.h
+++ b/chromium/components/favicon/core/favicon_handler.h
@@ -168,7 +168,8 @@ class FaviconHandler {
// Builds a scored candidate by selecting the best bitmap sizes.
static FaviconCandidate FromFaviconURL(
const favicon::FaviconURL& favicon_url,
- const std::vector<int>& desired_pixel_sizes);
+ const std::vector<int>& desired_pixel_sizes,
+ bool want_largest_icon);
// Compare function used for std::stable_sort to sort in descending order.
static bool CompareScore(const FaviconCandidate& lhs,
diff --git a/chromium/components/favicon/core/favicon_handler_unittest.cc b/chromium/components/favicon/core/favicon_handler_unittest.cc
index 67ce9a4c979..18128fd4513 100644
--- a/chromium/components/favicon/core/favicon_handler_unittest.cc
+++ b/chromium/components/favicon/core/favicon_handler_unittest.cc
@@ -36,6 +36,7 @@ namespace favicon {
namespace {
using favicon_base::FaviconRawBitmapResult;
+using testing::_;
using testing::AnyNumber;
using testing::Assign;
using testing::Contains;
@@ -45,7 +46,7 @@ using testing::Invoke;
using testing::IsEmpty;
using testing::Not;
using testing::Return;
-using testing::_;
+using testing::SizeIs;
using IntVector = std::vector<int>;
using URLVector = std::vector<GURL>;
@@ -1405,6 +1406,43 @@ TEST_F(FaviconHandlerMultipleFaviconsTest, ChooseMinorUpsamplingOverHugeIcon) {
EXPECT_EQ(17, DownloadTillDoneIgnoringHistory(IntVector{17, 256}));
}
+// Test a page with multiple favicon candidates with explicit sizes information.
+// Only the best one should be downloaded.
+TEST_F(FaviconHandlerMultipleFaviconsTest,
+ StopsDownloadingWhenRemainingCandidatesWorse) {
+ RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP,
+ {
+ FaviconURL(kIconURL16x16, kFavicon,
+ SizeVector(1U, gfx::Size(16, 16))),
+ FaviconURL(kIconURL64x64, kFavicon,
+ SizeVector(1U, gfx::Size(64, 64))),
+ });
+
+ EXPECT_THAT(delegate_.downloads(), SizeIs(1));
+}
+
+TEST_F(FaviconHandlerMultipleFaviconsTest,
+ DownloadsAllIconsWithoutSizesAttributeIfNotWantsLargest) {
+ RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP,
+ {
+ FaviconURL(kIconURL16x16, kFavicon, kEmptySizes),
+ FaviconURL(kIconURL64x64, kFavicon, kEmptySizes),
+ });
+
+ EXPECT_THAT(delegate_.downloads(), SizeIs(2));
+}
+
+TEST_F(FaviconHandlerMultipleFaviconsTest,
+ DownloadsOnlyOneIconWithoutSizesAttributeIfWantsLargest) {
+ RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_LARGEST,
+ {
+ FaviconURL(kIconURL16x16, kFavicon, kEmptySizes),
+ FaviconURL(kIconURL64x64, kFavicon, kEmptySizes),
+ });
+
+ EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16));
+}
+
TEST_F(FaviconHandlerTest, Report404) {
const GURL k404IconURL("http://www.google.com/404.png");
diff --git a/chromium/components/favicon/core/large_icon_service.h b/chromium/components/favicon/core/large_icon_service.h
index 1d1a32cdb5c..230f06a7a70 100644
--- a/chromium/components/favicon/core/large_icon_service.h
+++ b/chromium/components/favicon/core/large_icon_service.h
@@ -6,37 +6,25 @@
#define COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_H_
#include <memory>
-#include <vector>
#include "base/macros.h"
-#include "base/memory/weak_ptr.h"
#include "base/task/cancelable_task_tracker.h"
#include "components/favicon_base/favicon_callback.h"
-#include "components/favicon_base/favicon_types.h"
-#include "components/image_fetcher/core/image_fetcher.h"
#include "components/keyed_service/core/keyed_service.h"
-#include "net/traffic_annotation/network_traffic_annotation.h"
-class GURL;
-
-namespace image_fetcher {
-class ImageFetcher;
+namespace net {
+struct NetworkTrafficAnnotationTag;
}
+class GURL;
+
namespace favicon {
-class FaviconService;
class FaviconServerFetcherParams;
-// The large icon service provides methods to access large icons. It relies on
-// the favicon service.
+// The large icon service provides methods to access large icons.
class LargeIconService : public KeyedService {
public:
- LargeIconService(
- FaviconService* favicon_service,
- std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
- ~LargeIconService() override;
-
// Requests the best large icon for the page at |page_url|.
// Case 1. An icon exists whose size is >= MAX(|min_source_size_in_pixel|,
// |desired_size_in_pixel|):
@@ -52,22 +40,22 @@ class LargeIconService : public KeyedService {
// - Returns the default fallback icon style.
// For cases 4 and 5, this function returns the style of the fallback icon
// instead of rendering an icon so clients can render the icon themselves.
- // TODO(jkrcal): Rename to GetLargeIconRawBitmapOrFallbackStyle.
- base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle(
+ // TODO(crbug.com/903617): Rename to GetLargeIconRawBitmapOrFallbackStyle.
+ virtual base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
const favicon_base::LargeIconCallback& callback,
- base::CancelableTaskTracker* tracker);
+ base::CancelableTaskTracker* tracker) = 0;
// Behaves the same as GetLargeIconOrFallbackStyle(), only returns the large
// icon (if available) decoded.
- base::CancelableTaskTracker::TaskId GetLargeIconImageOrFallbackStyle(
+ virtual base::CancelableTaskTracker::TaskId GetLargeIconImageOrFallbackStyle(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
const favicon_base::LargeIconImageCallback& callback,
- base::CancelableTaskTracker* tracker);
+ base::CancelableTaskTracker* tracker) = 0;
// Fetches the best large icon for the page at |page_url| from a Google
// favicon server and stores the result in the FaviconService database
@@ -91,13 +79,14 @@ class LargeIconService : public KeyedService {
// WARNING: This function will share the |page_url| with a Google server. This
// Can be used only for urls that are not privacy sensitive or for users that
// sync their history with Google servers.
- // TODO(jkrcal): It is not clear from the name of this function, that it
- // actually adds the icon to the local cache. Maybe "StoreLargeIcon..."?
- void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
+ // TODO(crbug.com/903826): It is not clear from the name of this function,
+ // that it actually adds the icon to the local cache. Maybe
+ // "StoreLargeIcon..."?
+ virtual void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
std::unique_ptr<FaviconServerFetcherParams> params,
bool may_page_url_be_private,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
- const favicon_base::GoogleFaviconServerCallback& callback);
+ const favicon_base::GoogleFaviconServerCallback& callback) = 0;
// Update the time that the icon at |icon_url| was requested. This should be
// called after obtaining the icon by GetLargeIcon*OrFallbackStyle() for any
@@ -105,41 +94,12 @@ class LargeIconService : public KeyedService {
// caller uses
// GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache()). This
// postpones the automatic eviction of the favicon from the database.
- void TouchIconFromGoogleServer(const GURL& icon_url);
+ virtual void TouchIconFromGoogleServer(const GURL& icon_url) = 0;
- // Extracts the organization-identifying domain from |url| which excludes
- // registrar portion (e.g. final ".com"). Used for logging UMA metrics.
- // Exposed publicly for testing.
- static std::string GetOrganizationNameForUma(const GURL& url);
+ protected:
+ LargeIconService(){};
private:
- base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyleImpl(
- const GURL& page_url,
- int min_source_size_in_pixel,
- int desired_size_in_pixel,
- const favicon_base::LargeIconCallback& raw_bitmap_callback,
- const favicon_base::LargeIconImageCallback& image_callback,
- base::CancelableTaskTracker* tracker);
-
- void OnCanSetOnDemandFaviconComplete(
- const GURL& server_request_url,
- const GURL& page_url,
- favicon_base::IconType icon_type,
- const net::NetworkTrafficAnnotationTag& traffic_annotation,
- const favicon_base::GoogleFaviconServerCallback& callback,
- bool can_set_on_demand_favicon);
-
- FaviconService* favicon_service_;
-
- // A pre-populated list of icon types to consider when looking for large
- // icons. This is an optimization over populating an icon type vector on each
- // request.
- std::vector<favicon_base::IconTypeSet> large_icon_types_;
-
- std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
-
- base::WeakPtrFactory<LargeIconService> weak_ptr_factory_;
-
DISALLOW_COPY_AND_ASSIGN(LargeIconService);
};
diff --git a/chromium/components/favicon/core/large_icon_service.cc b/chromium/components/favicon/core/large_icon_service_impl.cc
index 9c2d87836f1..2ebd9b695b5 100644
--- a/chromium/components/favicon/core/large_icon_service.cc
+++ b/chromium/components/favicon/core/large_icon_service_impl.cc
@@ -2,10 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/favicon/core/large_icon_service.h"
+#include "components/favicon/core/large_icon_service_impl.h"
#include <algorithm>
-#include <memory>
#include <string>
#include "base/bind.h"
@@ -13,7 +12,6 @@
#include "base/feature_list.h"
#include "base/location.h"
#include "base/logging.h"
-#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/singleton.h"
#include "base/metrics/field_trial_params.h"
@@ -27,7 +25,6 @@
#include "components/favicon/core/favicon_server_fetcher_params.h"
#include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/fallback_icon_style.h"
-#include "components/favicon_base/favicon_types.h"
#include "components/favicon_base/favicon_util.h"
#include "components/image_fetcher/core/request_metadata.h"
#include "net/base/network_change_notifier.h"
@@ -238,7 +235,7 @@ const DomainToOrganizationIdMap* DomainToOrganizationIdMap::GetInstance() {
int DomainToOrganizationIdMap::GetCanonicalOrganizationId(
const GURL& url) const {
- auto it = data_.find(LargeIconService::GetOrganizationNameForUma(url));
+ auto it = data_.find(LargeIconServiceImpl::GetOrganizationNameForUma(url));
return it == data_.end() ? kInvalidOrganizationId : it->second;
}
@@ -423,7 +420,8 @@ void OnFetchIconFromGoogleServerComplete(
DLOG(WARNING) << "large icon server fetch empty " << server_request_url;
favicon_service->UnableToDownloadFavicon(GURL(server_request_url));
callback.Run(
- metadata.http_response_code == net::URLFetcher::RESPONSE_CODE_INVALID
+ metadata.http_response_code ==
+ image_fetcher::RequestMetadata::RESPONSE_CODE_INVALID
? GoogleFaviconServerRequestStatus::FAILURE_CONNECTION_ERROR
: GoogleFaviconServerRequestStatus::FAILURE_HTTP_ERROR);
ReportDownloadedSize(0);
@@ -451,7 +449,7 @@ void OnFetchIconFromGoogleServerComplete(
} // namespace
-LargeIconService::LargeIconService(
+LargeIconServiceImpl::LargeIconServiceImpl(
FaviconService* favicon_service,
std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher)
: favicon_service_(favicon_service),
@@ -465,10 +463,10 @@ LargeIconService::LargeIconService(
// a DCHECK(image_fetcher_) here.
}
-LargeIconService::~LargeIconService() {}
+LargeIconServiceImpl::~LargeIconServiceImpl() {}
base::CancelableTaskTracker::TaskId
-LargeIconService::GetLargeIconOrFallbackStyle(
+LargeIconServiceImpl::GetLargeIconOrFallbackStyle(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
@@ -480,7 +478,7 @@ LargeIconService::GetLargeIconOrFallbackStyle(
}
base::CancelableTaskTracker::TaskId
-LargeIconService::GetLargeIconImageOrFallbackStyle(
+LargeIconServiceImpl::GetLargeIconImageOrFallbackStyle(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
@@ -491,7 +489,7 @@ LargeIconService::GetLargeIconImageOrFallbackStyle(
favicon_base::LargeIconCallback(), image_callback, tracker);
}
-void LargeIconService::
+void LargeIconServiceImpl::
GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
std::unique_ptr<FaviconServerFetcherParams> params,
bool may_page_url_be_private,
@@ -540,18 +538,18 @@ void LargeIconService::
favicon_service_->CanSetOnDemandFavicons(
params->page_url(), params->icon_type(),
- base::BindOnce(&LargeIconService::OnCanSetOnDemandFaviconComplete,
+ base::BindOnce(&LargeIconServiceImpl::OnCanSetOnDemandFaviconComplete,
weak_ptr_factory_.GetWeakPtr(), server_request_url,
params->page_url(), params->icon_type(),
traffic_annotation, callback));
}
-void LargeIconService::TouchIconFromGoogleServer(const GURL& icon_url) {
+void LargeIconServiceImpl::TouchIconFromGoogleServer(const GURL& icon_url) {
favicon_service_->TouchOnDemandFavicon(icon_url);
}
// static
-std::string LargeIconService::GetOrganizationNameForUma(const GURL& url) {
+std::string LargeIconServiceImpl::GetOrganizationNameForUma(const GURL& url) {
const size_t registry_length =
net::registry_controlled_domains::GetRegistryLength(
url, net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
@@ -561,7 +559,7 @@ std::string LargeIconService::GetOrganizationNameForUma(const GURL& url) {
url, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
if (registry_length == 0 || registry_length == std::string::npos ||
registry_length >= organization.size()) {
- return "";
+ return std::string();
}
// Strip final registry as well as the preceding dot.
@@ -570,7 +568,7 @@ std::string LargeIconService::GetOrganizationNameForUma(const GURL& url) {
}
base::CancelableTaskTracker::TaskId
-LargeIconService::GetLargeIconOrFallbackStyleImpl(
+LargeIconServiceImpl::GetLargeIconOrFallbackStyleImpl(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
@@ -587,16 +585,17 @@ LargeIconService::GetLargeIconOrFallbackStyleImpl(
int max_size_in_pixel =
std::max(desired_size_in_pixel, min_source_size_in_pixel);
// TODO(beaudoin): For now this is just a wrapper around
- // GetLargestRawFaviconForPageURL. Add the logic required to select the best
- // possible large icon. Also add logic to fetch-on-demand when the URL of
- // a large icon is known but its bitmap is not available.
+ // GetLargestRawFaviconForPageURL. Add the logic required to select the
+ // best possible large icon. Also add logic to fetch-on-demand when the
+ // URL of a large icon is known but its bitmap is not available.
return favicon_service_->GetLargestRawFaviconForPageURL(
page_url, large_icon_types_, max_size_in_pixel,
- base::Bind(&LargeIconWorker::OnIconLookupComplete, worker, page_url),
+ base::BindRepeating(&LargeIconWorker::OnIconLookupComplete, worker,
+ page_url),
tracker);
}
-void LargeIconService::OnCanSetOnDemandFaviconComplete(
+void LargeIconServiceImpl::OnCanSetOnDemandFaviconComplete(
const GURL& server_request_url,
const GURL& page_url,
favicon_base::IconType icon_type,
diff --git a/chromium/components/favicon/core/large_icon_service_impl.h b/chromium/components/favicon/core/large_icon_service_impl.h
new file mode 100644
index 00000000000..e9379ab0efb
--- /dev/null
+++ b/chromium/components/favicon/core/large_icon_service_impl.h
@@ -0,0 +1,95 @@
+// Copyright 2015 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_LARGE_ICON_SERVICE_IMPL_H_
+#define COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_IMPL_H_
+
+#include <memory>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "base/task/cancelable_task_tracker.h"
+#include "components/favicon/core/large_icon_service.h"
+#include "components/favicon_base/favicon_callback.h"
+#include "components/favicon_base/favicon_types.h"
+#include "components/image_fetcher/core/image_fetcher.h"
+
+class GURL;
+
+namespace net {
+struct NetworkTrafficAnnotationTag;
+}
+
+namespace favicon {
+
+class FaviconService;
+class FaviconServerFetcherParams;
+
+// Implementation class for LargeIconService.
+class LargeIconServiceImpl : public LargeIconService {
+ public:
+ LargeIconServiceImpl(
+ FaviconService* favicon_service,
+ std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
+ ~LargeIconServiceImpl() override;
+
+ // LargeIconService Implementation.
+ base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyle(
+ const GURL& page_url,
+ int min_source_size_in_pixel,
+ int desired_size_in_pixel,
+ const favicon_base::LargeIconCallback& callback,
+ base::CancelableTaskTracker* tracker) override;
+ base::CancelableTaskTracker::TaskId GetLargeIconImageOrFallbackStyle(
+ const GURL& page_url,
+ int min_source_size_in_pixel,
+ int desired_size_in_pixel,
+ const favicon_base::LargeIconImageCallback& callback,
+ base::CancelableTaskTracker* tracker) override;
+ void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
+ std::unique_ptr<FaviconServerFetcherParams> params,
+ bool may_page_url_be_private,
+ const net::NetworkTrafficAnnotationTag& traffic_annotation,
+ const favicon_base::GoogleFaviconServerCallback& callback) override;
+ void TouchIconFromGoogleServer(const GURL& icon_url) override;
+ // Extracts the organization-identifying domain from |url| which excludes
+ // registrar portion (e.g. final ".com"). Used for logging UMA metrics.
+ // Exposed publicly for testing.
+ static std::string GetOrganizationNameForUma(const GURL& url);
+
+ private:
+ base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyleImpl(
+ const GURL& page_url,
+ int min_source_size_in_pixel,
+ int desired_size_in_pixel,
+ const favicon_base::LargeIconCallback& raw_bitmap_callback,
+ const favicon_base::LargeIconImageCallback& image_callback,
+ base::CancelableTaskTracker* tracker);
+
+ void OnCanSetOnDemandFaviconComplete(
+ const GURL& server_request_url,
+ const GURL& page_url,
+ favicon_base::IconType icon_type,
+ const net::NetworkTrafficAnnotationTag& traffic_annotation,
+ const favicon_base::GoogleFaviconServerCallback& callback,
+ bool can_set_on_demand_favicon);
+
+ FaviconService* favicon_service_;
+
+ // A pre-populated list of icon types to consider when looking for large
+ // icons. This is an optimization over populating an icon type vector on each
+ // request.
+ std::vector<favicon_base::IconTypeSet> large_icon_types_;
+
+ std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
+
+ base::WeakPtrFactory<LargeIconServiceImpl> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(LargeIconServiceImpl);
+};
+
+} // namespace favicon
+
+#endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_IMPL_H_
diff --git a/chromium/components/favicon/core/large_icon_service_unittest.cc b/chromium/components/favicon/core/large_icon_service_impl_unittest.cc
index a45a41a3a1c..95b1e383d49 100644
--- a/chromium/components/favicon/core/large_icon_service_unittest.cc
+++ b/chromium/components/favicon/core/large_icon_service_impl_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/favicon/core/large_icon_service.h"
+#include "components/favicon/core/large_icon_service_impl.h"
#include <memory>
#include <string>
@@ -138,7 +138,7 @@ class LargeIconServiceTest : public testing::Test {
base::test::ScopedTaskEnvironment scoped_task_environment_;
NiceMock<MockImageFetcher>* mock_image_fetcher_;
testing::NiceMock<MockFaviconService> mock_favicon_service_;
- LargeIconService large_icon_service_;
+ LargeIconServiceImpl large_icon_service_;
base::HistogramTester histogram_tester_;
std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors>
scoped_set_supported_scale_factors_;
@@ -523,14 +523,15 @@ class LargeIconServiceGetterTest : public LargeIconServiceTest,
if (GetParam()) {
large_icon_service_.GetLargeIconOrFallbackStyle(
page_url, min_source_size_in_pixel, desired_size_in_pixel,
- base::Bind(&LargeIconServiceGetterTest::RawBitmapResultCallback,
- base::Unretained(this)),
+ base::BindRepeating(
+ &LargeIconServiceGetterTest::RawBitmapResultCallback,
+ base::Unretained(this)),
&cancelable_task_tracker_);
} else {
large_icon_service_.GetLargeIconImageOrFallbackStyle(
page_url, min_source_size_in_pixel, desired_size_in_pixel,
- base::Bind(&LargeIconServiceGetterTest::ImageResultCallback,
- base::Unretained(this)),
+ base::BindRepeating(&LargeIconServiceGetterTest::ImageResultCallback,
+ base::Unretained(this)),
&cancelable_task_tracker_);
}
scoped_task_environment_.RunUntilIdle();
@@ -759,18 +760,19 @@ INSTANTIATE_TEST_CASE_P(, // Empty instatiation name.
::testing::Values(false, true));
TEST(LargeIconServiceOrganizationNameTest, ShouldGetOrganizationNameForUma) {
- EXPECT_EQ("", LargeIconService::GetOrganizationNameForUma(GURL()));
- EXPECT_EQ("", LargeIconService::GetOrganizationNameForUma(GURL("http://")));
- EXPECT_EQ("", LargeIconService::GetOrganizationNameForUma(GURL("com")));
+ EXPECT_EQ("", LargeIconServiceImpl::GetOrganizationNameForUma(GURL()));
EXPECT_EQ("",
- LargeIconService::GetOrganizationNameForUma(GURL("http://com")));
- EXPECT_EQ("",
- LargeIconService::GetOrganizationNameForUma(GURL("http://google")));
- EXPECT_EQ("google", LargeIconService::GetOrganizationNameForUma(
+ LargeIconServiceImpl::GetOrganizationNameForUma(GURL("http://")));
+ EXPECT_EQ("", LargeIconServiceImpl::GetOrganizationNameForUma(GURL("com")));
+ EXPECT_EQ(
+ "", LargeIconServiceImpl::GetOrganizationNameForUma(GURL("http://com")));
+ EXPECT_EQ("", LargeIconServiceImpl::GetOrganizationNameForUma(
+ GURL("http://google")));
+ EXPECT_EQ("google", LargeIconServiceImpl::GetOrganizationNameForUma(
GURL("http://google.com")));
- EXPECT_EQ("google", LargeIconService::GetOrganizationNameForUma(
+ EXPECT_EQ("google", LargeIconServiceImpl::GetOrganizationNameForUma(
GURL("http://google.de")));
- EXPECT_EQ("google", LargeIconService::GetOrganizationNameForUma(
+ EXPECT_EQ("google", LargeIconServiceImpl::GetOrganizationNameForUma(
GURL("http://foo.google.com")));
}
diff --git a/chromium/components/favicon/ios/web_favicon_driver.mm b/chromium/components/favicon/ios/web_favicon_driver.mm
index f33ffa22b71..9e7a62b261c 100644
--- a/chromium/components/favicon/ios/web_favicon_driver.mm
+++ b/chromium/components/favicon/ios/web_favicon_driver.mm
@@ -60,7 +60,7 @@ bool WebFaviconDriver::FaviconIsValid() const {
GURL WebFaviconDriver::GetActiveURL() {
web::NavigationItem* item =
- web_state_->GetNavigationManager()->GetVisibleItem();
+ web_state_->GetNavigationManager()->GetLastCommittedItem();
return item ? item->GetURL() : GURL();
}