#include "components/manta/manta_service.h"
#include <memory>
#include "base/containers/contains.h"
#include "base/containers/fixed_flat_set.h"
#include "base/memory/scoped_refptr.h"
#include "build/chromeos_buildflags.h"
#include "components/account_id/account_id.h"
#include "components/manta/anchovy/anchovy_provider.h"
#include "components/manta/provider_params.h"
#include "components/manta/sparky/system_info_delegate.h"
#include "components/signin/public/identity_manager/account_capabilities.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/tribool.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/constants/chromeos_features.h"
#include "components/manta/mahi_provider.h"
#include "components/manta/orca_provider.h"
#include "components/manta/snapper_provider.h"
#include "components/manta/sparky/sparky_provider.h"
#endif
namespace manta {
namespace {
FeatureSupportStatus ConvertToMantaFeatureSupportStatus(signin::Tribool value) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
constexpr auto kAllowedLanguagesForAddingLocaleToRequest =
base::MakeFixedFlatSet<std::string_view>({"de", "en", "en-GB", "fr", "ja"});
bool ShouldIncludeLocaleInRequest(std::string_view locale) {
return chromeos::features::IsOrcaUseL10nStringsEnabled() ||
(chromeos::features::IsOrcaInternationalizeEnabled() &&
base::Contains(kAllowedLanguagesForAddingLocaleToRequest, locale));
}
#endif
}
MantaService::MantaService(
scoped_refptr<network::SharedURLLoaderFactory> shared_url_loader_factory,
signin::IdentityManager* identity_manager,
bool is_demo_mode,
bool is_otr_profile,
const std::string& chrome_version,
const version_info::Channel chrome_channel,
const std::string& locale)
: … { … }
MantaService::~MantaService() = default;
FeatureSupportStatus MantaService::SupportsOrca() { … }
FeatureSupportStatus
MantaService::CanAccessMantaFeaturesWithoutMinorRestrictions() { … }
std::unique_ptr<AnchovyProvider> MantaService::CreateAnchovyProvider() { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::unique_ptr<OrcaProvider> MantaService::CreateOrcaProvider() {
if (!identity_manager_) {
return nullptr;
}
const ProviderParams provider_params = {
is_demo_mode_, chrome_version_, chrome_channel_,
ShouldIncludeLocaleInRequest(locale_) ? locale_ : std::string()};
return std::make_unique<OrcaProvider>(shared_url_loader_factory_,
identity_manager_, provider_params);
}
std::unique_ptr<SnapperProvider> MantaService::CreateSnapperProvider() {
if (!identity_manager_) {
return nullptr;
}
const ProviderParams provider_params = {is_demo_mode_,
chrome_version_, chrome_channel_};
return std::make_unique<SnapperProvider>(shared_url_loader_factory_,
identity_manager_, provider_params);
}
std::unique_ptr<MahiProvider> MantaService::CreateMahiProvider() {
if (!identity_manager_) {
return nullptr;
}
const ProviderParams provider_params = {is_demo_mode_,
chrome_version_, chrome_channel_};
return std::make_unique<MahiProvider>(shared_url_loader_factory_,
identity_manager_, provider_params);
}
std::unique_ptr<SparkyProvider> MantaService::CreateSparkyProvider(
std::unique_ptr<SparkyDelegate> sparky_delegate,
std::unique_ptr<SystemInfoDelegate> system_info_delegate) {
if (!identity_manager_ || !sparky_delegate || !system_info_delegate) {
return nullptr;
}
const ProviderParams provider_params = {is_demo_mode_,
chrome_version_, chrome_channel_};
return std::make_unique<SparkyProvider>(
shared_url_loader_factory_, identity_manager_, provider_params,
std::move(sparky_delegate), std::move(system_info_delegate));
}
#endif
void MantaService::Shutdown() { … }
}