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
|
// 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 "chrome/browser/search_provider_logos/logo_service_factory.h"
#include "base/feature_list.h"
#include "base/functional/bind.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/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"
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() {
static base::NoDestructor<LogoServiceFactory> instance;
return instance.get();
}
LogoServiceFactory::LogoServiceFactory()
: ProfileKeyedServiceFactory(
"LogoService",
ProfileSelections::Builder()
.WithRegular(ProfileSelection::kOriginalOnly)
// TODO(crbug.com/40257657): Check if this service is needed in
// Guest mode.
.WithGuest(ProfileSelection::kOriginalOnly)
// TODO(crbug.com/41488885): Check if this service is needed for
// Ash Internals.
.WithAshInternals(ProfileSelection::kOriginalOnly)
.Build()) {
DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(TemplateURLServiceFactory::GetInstance());
}
LogoServiceFactory::~LogoServiceFactory() = default;
std::unique_ptr<KeyedService>
LogoServiceFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
DCHECK(!profile->IsOffTheRecord());
return std::make_unique<LogoServiceImpl>(
profile->GetPath().Append(kCachedLogoDirectory),
IdentityManagerFactory::GetForProfile(profile),
TemplateURLServiceFactory::GetForProfile(profile),
std::make_unique<ImageDecoderImpl>(),
profile->GetDefaultStoragePartition()
->GetURLLoaderFactoryForBrowserProcess(),
base::BindRepeating(&UseGrayLogo));
}
|