blob: 36733cdca27c499cdc29059facbf098718dcf6cd [file] [log] [blame]
// Copyright 2017 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 "chrome/browser/search_provider_logos/logo_service_factory.h"
#include "base/bind.h"
#include "base/feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/image_fetcher/image_decoder_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/search_provider_logos/logo_service.h"
#include "components/search_provider_logos/logo_service_impl.h"
#include "content/public/browser/storage_partition.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if defined(OS_ANDROID)
#include "chrome/browser/android/feature_utilities.h"
#endif
using search_provider_logos::LogoService;
using search_provider_logos::LogoServiceImpl;
namespace {
constexpr base::FilePath::CharType kCachedLogoDirectory[] =
FILE_PATH_LITERAL("Search Logos");
bool UseGrayLogo() {
return false;
}
} // namespace
// static
LogoService* LogoServiceFactory::GetForProfile(Profile* profile) {
return static_cast<LogoService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
LogoServiceFactory* LogoServiceFactory::GetInstance() {
return base::Singleton<LogoServiceFactory>::get();
}
LogoServiceFactory::LogoServiceFactory()
: BrowserContextKeyedServiceFactory(
"LogoService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(TemplateURLServiceFactory::GetInstance());
}
LogoServiceFactory::~LogoServiceFactory() = default;
KeyedService* LogoServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
DCHECK(!profile->IsOffTheRecord());
return new LogoServiceImpl(
profile->GetPath().Append(kCachedLogoDirectory),
IdentityManagerFactory::GetForProfile(profile),
TemplateURLServiceFactory::GetForProfile(profile),
std::make_unique<ImageDecoderImpl>(),
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetURLLoaderFactoryForBrowserProcess(),
base::BindRepeating(&UseGrayLogo));
}