chromium/components/search_provider_logos/logo_service_impl.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 =;

// Implements a callback for image_fetcher::ImageDecoder. If Run() is called on
// a callback returned by GetCallback() within 30 seconds, forwards the decoded
// image to the wrapped callback. If not, sends an empty image to the wrapped
// callback instead. Either way, deletes the object and prevents further calls.
//
// TODO(sfiera): find a more idiomatic way of setting a deadline on the
// callback. This is implemented as a self-deleting object in part because it
// needed to when it used to be a delegate and in part because I couldn't figure
// out a better way, now that it isn't.
class ImageDecodedHandlerWithTimeout {};

void ObserverOnLogoAvailable(LogoObserver* observer,
                             bool from_cache,
                             LogoCallbackReason type,
                             const std::optional<Logo>& logo) {}

void RunCallbacksWithDisabled(LogoCallbacks callbacks) {}

// Returns whether the metadata for the cached logo indicates that the logo is
// OK to show, i.e. it's not expired or it's allowed to be shown temporarily
// after expiration.
bool IsLogoOkToShow(const LogoMetadata& metadata, base::Time now) {}

// Reads the logo from the cache and returns it. Returns NULL if the cache is
// empty, corrupt, expired, or doesn't apply to the current logo URL.
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) {}

}  // namespace

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&) {}

}  // namespace search_provider_logos