1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
// Copyright 2015 The Chromium Authors
// 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 <optional>
#include "base/memory/raw_ptr.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;
// Implementation class for LargeIconService.
class LargeIconServiceImpl : public LargeIconService {
public:
LargeIconServiceImpl(
FaviconService* favicon_service,
std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher,
int desired_size_in_dip_for_server_requests,
favicon_base::IconType icon_type_for_server_requests,
const std::string& google_server_client_param);
LargeIconServiceImpl(const LargeIconServiceImpl&) = delete;
LargeIconServiceImpl& operator=(const LargeIconServiceImpl&) = delete;
~LargeIconServiceImpl() override;
// LargeIconService Implementation.
base::CancelableTaskTracker::TaskId
GetLargeIconRawBitmapOrFallbackStyleForPageUrl(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker* tracker) override;
base::CancelableTaskTracker::TaskId
GetLargeIconImageOrFallbackStyleForPageUrl(
const GURL& page_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
favicon_base::LargeIconImageCallback callback,
base::CancelableTaskTracker* tracker) override;
base::CancelableTaskTracker::TaskId GetLargeIconRawBitmapForPageUrl(
const GURL& page_url,
int min_source_size_in_pixel,
std::optional<int> size_in_pixel_to_resize_to,
NoBigEnoughIconBehavior no_big_enough_icon_behavior,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker* tracker) override;
base::CancelableTaskTracker::TaskId
GetLargeIconRawBitmapOrFallbackStyleForIconUrl(
const GURL& icon_url,
int min_source_size_in_pixel,
int desired_size_in_pixel,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker* tracker) override;
base::CancelableTaskTracker::TaskId GetIconRawBitmapOrFallbackStyleForPageUrl(
const GURL& page_url,
int desired_size_in_pixel,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker* tracker) override;
void GetLargeIconOrFallbackStyleFromGoogleServerSkippingLocalCache(
const GURL& page_url,
bool should_trim_page_url_path,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
favicon_base::GoogleFaviconServerCallback callback) override;
void GetLargeIconFromCacheFallbackToGoogleServer(
const GURL& page_url,
StandardIconSize min_source_size,
std::optional<StandardIconSize> size_to_resize_to,
NoBigEnoughIconBehavior no_big_enough_icon_behavior,
bool should_trim_page_url_path,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker* tracker) override;
void TouchIconFromGoogleServer(const GURL& icon_url) override;
// Overrides the URL of the Google favicon server to send requests to for
// testing.
void SetServerUrlForTesting(const GURL& server_url_for_testing);
private:
base::CancelableTaskTracker::TaskId GetLargeIconOrFallbackStyleImpl(
const GURL& page_url,
int min_source_size_in_pixel,
std::optional<int> size_in_pixel_to_resize_to,
NoBigEnoughIconBehavior no_big_enough_icon_behavior,
favicon_base::LargeIconCallback raw_bitmap_callback,
favicon_base::LargeIconImageCallback image_callback,
base::CancelableTaskTracker* tracker);
void OnCanSetOnDemandFaviconComplete(
const GURL& server_request_url,
const GURL& page_url,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
favicon_base::GoogleFaviconServerCallback callback,
bool can_set_on_demand_favicon);
// Called back when the requested icon is returned from the local favicon
// database. The result might be empty if the local database doesn't contain
// the requested icon. The request is done by
// `GetLargeIconFromCacheFallbackToGoogleServer()`.
void OnIconFetchedFromCache(
const GURL& page_url,
int min_source_size_in_pixel,
std::optional<int> size_in_pixel_to_resize_to,
NoBigEnoughIconBehavior no_big_enough_icon_behavior,
bool should_trim_page_url_path,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker* tracker,
const favicon_base::LargeIconResult& icon_result);
// Called back when the requested icon is returned from the Google favicon
// service. The request is done by
// `GetLargeIconFromCacheFallbackToGoogleServer()`.
void OnIconFetchedFromServer(
const GURL& page_url,
int min_source_size_in_pixel,
std::optional<int> size_in_pixel_to_resize_to,
favicon_base::LargeIconCallback callback,
base::CancelableTaskTracker::IsCanceledCallback
was_task_canceled_callback,
MayBeDangling<base::CancelableTaskTracker> tracker,
favicon_base::GoogleFaviconServerRequestStatus status);
const raw_ptr<FaviconService> favicon_service_;
const std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
const int desired_size_in_pixel_for_server_requests_;
const favicon_base::IconType icon_type_for_server_requests_;
const std::string google_server_client_param_;
// URL of the Google favicon server (overridable by tests).
GURL server_url_;
base::WeakPtrFactory<LargeIconServiceImpl> weak_ptr_factory_{this};
};
} // namespace favicon
#endif // COMPONENTS_FAVICON_CORE_LARGE_ICON_SERVICE_IMPL_H_
|