#include "components/search_provider_logos/logo_service_impl.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/time/default_clock.h"
#include "build/build_config.h"
#include "components/image_fetcher/core/image_decoder.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_provider_logos/fixed_logo_api.h"
#include "components/search_provider_logos/google_logo_api.h"
#include "components/search_provider_logos/logo_cache.h"
#include "components/search_provider_logos/logo_observer.h"
#include "components/search_provider_logos/switches.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "ui/gfx/image/image.h"
namespace search_provider_logos {
namespace {
const int64_t kMaxDownloadBytes = …;
const int kDecodeLogoTimeoutSeconds = …;
class ImageDecodedHandlerWithTimeout { … };
void ObserverOnLogoAvailable(LogoObserver* observer,
bool from_cache,
LogoCallbackReason type,
const std::optional<Logo>& logo) { … }
void RunCallbacksWithDisabled(LogoCallbacks callbacks) { … }
bool IsLogoOkToShow(const LogoMetadata& metadata, base::Time now) { … }
std::unique_ptr<EncodedLogo> GetLogoFromCacheOnFileThread(LogoCache* logo_cache,
const GURL& logo_url,
base::Time now) { … }
void NotifyAndClear(std::vector<EncodedLogoCallback>* encoded_callbacks,
std::vector<LogoCallback>* decoded_callbacks,
LogoCallbackReason type,
const EncodedLogo* encoded_logo,
const Logo* decoded_logo) { … }
}
LogoServiceImpl::LogoServiceImpl(
const base::FilePath& cache_directory,
signin::IdentityManager* identity_manager,
TemplateURLService* template_url_service,
std::unique_ptr<image_fetcher::ImageDecoder> image_decoder,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
base::RepeatingCallback<bool()> want_gray_logo_getter)
: … { … }
LogoServiceImpl::~LogoServiceImpl() = default;
void LogoServiceImpl::Shutdown() { … }
void LogoServiceImpl::GetLogo(search_provider_logos::LogoObserver* observer) { … }
void LogoServiceImpl::GetLogo(LogoCallbacks callbacks, bool for_webui_ntp) { … }
void LogoServiceImpl::SetLogoCacheForTests(std::unique_ptr<LogoCache> cache) { … }
void LogoServiceImpl::SetClockForTests(base::Clock* clock) { … }
void LogoServiceImpl::SetServerAPI(
const GURL& logo_url,
const ParseLogoResponse& parse_logo_response_func,
const AppendQueryparamsToLogoURL& append_queryparams_func) { … }
void LogoServiceImpl::ClearCachedLogo() { … }
void LogoServiceImpl::ReturnToIdle(int outcome) { … }
void LogoServiceImpl::OnCachedLogoRead(
std::unique_ptr<EncodedLogo> cached_logo) { … }
void LogoServiceImpl::SetCachedLogo(std::unique_ptr<EncodedLogo> logo) { … }
void LogoServiceImpl::SetCachedMetadata(const LogoMetadata& metadata) { … }
void LogoServiceImpl::OnLightCachedImageDecoded(
std::unique_ptr<EncodedLogo> cached_logo,
const SkBitmap& image) { … }
void LogoServiceImpl::OnCachedLogoAvailable(
std::unique_ptr<EncodedLogo> encoded_logo,
const SkBitmap& image,
const SkBitmap& dark_image) { … }
void LogoServiceImpl::FetchLogo() { … }
void LogoServiceImpl::OnFreshLogoParsed(bool* parsing_failed,
bool from_http_cache,
std::unique_ptr<EncodedLogo> logo) { … }
void LogoServiceImpl::OnLightFreshImageDecoded(
std::unique_ptr<EncodedLogo> logo,
bool download_failed,
bool parsing_failed,
bool from_http_cache,
const SkBitmap& image) { … }
void LogoServiceImpl::OnFreshLogoAvailable(
std::unique_ptr<EncodedLogo> encoded_logo,
bool download_failed,
bool parsing_failed,
bool from_http_cache,
const SkBitmap& image,
const SkBitmap& dark_image) { … }
void LogoServiceImpl::OnURLLoadComplete(const network::SimpleURLLoader* source,
std::unique_ptr<std::string> body) { … }
void LogoServiceImpl::OnAccountsInCookieUpdated(
const signin::AccountsInCookieJarInfo&,
const GoogleServiceAuthError&) { … }
}