#include "chrome/browser/enterprise/connectors/connectors_service.h"
#include <memory>
#include "base/check_op.h"
#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/connectors/common.h"
#include "chrome/browser/enterprise/connectors/connectors_manager.h"
#include "chrome/browser/enterprise/connectors/reporting/realtime_reporting_client_factory.h"
#include "chrome/browser/enterprise/util/affiliation.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/policy/dm_token_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/reporting_util.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/managed_ui.h"
#include "components/embedder_support/user_agent_utils.h"
#include "components/enterprise/browser/controller/browser_dm_token_storage.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/enterprise/common/proto/connectors.pb.h"
#include "components/enterprise/connectors/core/connectors_prefs.h"
#include "components/enterprise/connectors/core/service_provider_config.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/policy/core/common/cloud/cloud_policy_store.h"
#include "components/policy/core/common/cloud/cloud_policy_util.h"
#include "components/policy/core/common/cloud/dm_token.h"
#include "components/policy/core/common/cloud/machine_level_user_cloud_policy_manager.h"
#include "components/policy/core/common/cloud/machine_level_user_cloud_policy_store.h"
#include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
#include "components/policy/core/common/policy_types.h"
#include "components/signin/public/base/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/user_prefs/user_prefs.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browser_context.h"
#include "content/public/common/url_constants.h"
#include "device_management_backend.pb.h"
#include "google_apis/gaia/gaia_auth_util.h"
#if BUILDFLAG(ENTERPRISE_CONTENT_ANALYSIS)
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "extensions/browser/extension_registry_factory.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/components/mgs/managed_guest_session_utils.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/policy/core/user_cloud_policy_manager_ash.h"
#include "chrome/browser/ash/settings/device_settings_service.h"
#include "chromeos/ash/components/browser_context_helper/browser_context_helper.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "extensions/common/constants.h"
#else
#include "components/policy/core/common/cloud/profile_cloud_policy_manager.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/startup/browser_params_proxy.h"
#include "components/policy/core/common/policy_loader_lacros.h"
#endif
namespace enterprise_connectors {
namespace {
void PopulateBrowserMetadata(bool include_device_info,
ClientMetadata::Browser* browser_proto) { … }
std::string GetClientId(Profile* profile) { … }
void PopulateDeviceMetadata(const ReportingSettings& reporting_settings,
Profile* profile,
ClientMetadata::Device* device_proto) { … }
bool IsURLExemptFromAnalysis(const GURL& url) { … }
#if BUILDFLAG(IS_CHROMEOS)
std::optional<std::string> GetDeviceDMToken() {
#if BUILDFLAG(IS_CHROMEOS_LACROS)
const chromeos::BrowserParamsProxy* init_params =
chromeos::BrowserParamsProxy::Get();
if (init_params->DeviceProperties()) {
return init_params->DeviceProperties()->device_dm_token;
}
return std::nullopt;
#else
const enterprise_management::PolicyData* policy_data =
ash::DeviceSettingsService::Get()->policy_data();
if (policy_data && policy_data->has_request_token())
return policy_data->request_token();
return std::nullopt;
#endif
}
#endif
bool IsManagedGuestSession() { … }
}
BASE_FEATURE(…);
ConnectorsService::ConnectorsService(content::BrowserContext* context,
std::unique_ptr<ConnectorsManager> manager)
: … { … }
ConnectorsService::~ConnectorsService() = default;
std::unique_ptr<ClientMetadata> ConnectorsService::GetBasicClientMetadata(
Profile* profile) { … }
std::optional<ReportingSettings> ConnectorsService::GetReportingSettings(
ReportingConnector connector) { … }
std::optional<AnalysisSettings> ConnectorsService::GetAnalysisSettings(
const GURL& url,
AnalysisConnector connector) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
std::optional<AnalysisSettings> ConnectorsService::GetAnalysisSettings(
const storage::FileSystemURL& source_url,
const storage::FileSystemURL& destination_url,
AnalysisConnector connector) {
DCHECK_EQ(connector, AnalysisConnector::FILE_TRANSFER);
if (!ConnectorsEnabled())
return std::nullopt;
return GetCommonAnalysisSettings(
connectors_manager_->GetAnalysisSettings(context_, source_url,
destination_url, connector),
connector);
}
#endif
std::optional<AnalysisSettings> ConnectorsService::GetCommonAnalysisSettings(
std::optional<AnalysisSettings> settings,
AnalysisConnector connector) { … }
bool ConnectorsService::IsConnectorEnabled(AnalysisConnector connector) const { … }
bool ConnectorsService::IsConnectorEnabled(ReportingConnector connector) const { … }
std::vector<std::string> ConnectorsService::GetReportingServiceProviderNames(
ReportingConnector connector) { … }
std::vector<const AnalysisConfig*> ConnectorsService::GetAnalysisServiceConfigs(
AnalysisConnector connector) { … }
bool ConnectorsService::DelayUntilVerdict(AnalysisConnector connector) { … }
std::optional<std::u16string> ConnectorsService::GetCustomMessage(
AnalysisConnector connector,
const std::string& tag) { … }
std::optional<GURL> ConnectorsService::GetLearnMoreUrl(
AnalysisConnector connector,
const std::string& tag) { … }
bool ConnectorsService::GetBypassJustificationRequired(
AnalysisConnector connector,
const std::string& tag) { … }
bool ConnectorsService::HasExtraUiToDisplay(AnalysisConnector connector,
const std::string& tag) { … }
std::vector<std::string> ConnectorsService::GetAnalysisServiceProviderNames(
AnalysisConnector connector) { … }
std::string ConnectorsService::GetManagementDomain() { … }
std::string ConnectorsService::GetRealTimeUrlCheckIdentifier() const { … }
ConnectorsManager* ConnectorsService::ConnectorsManagerForTesting() { … }
void ConnectorsService::ObserveTelemetryReporting(
base::RepeatingCallback<void()> callback) { … }
std::optional<ConnectorsService::DmToken> ConnectorsService::GetDmToken(
const char* scope_pref) const { … }
std::optional<std::string> ConnectorsService::GetBrowserDmToken() const { … }
#if !BUILDFLAG(IS_CHROMEOS_ASH)
std::optional<std::string> ConnectorsService::GetProfileDmToken() const { … }
#endif
policy::PolicyScope ConnectorsService::GetPolicyScope(
const char* scope_pref) const { … }
bool ConnectorsService::ConnectorsEnabled() const { … }
PrefService* ConnectorsService::GetPrefs() { … }
const PrefService* ConnectorsService::GetPrefs() const { … }
std::unique_ptr<ClientMetadata> ConnectorsService::BuildClientMetadata(
bool is_cloud) { … }
ConnectorsServiceFactory* ConnectorsServiceFactory::GetInstance() { … }
ConnectorsService* ConnectorsServiceFactory::GetForBrowserContext(
content::BrowserContext* context) { … }
ConnectorsServiceFactory::ConnectorsServiceFactory()
: … { … }
ConnectorsServiceFactory::~ConnectorsServiceFactory() = default;
KeyedService* ConnectorsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { … }
content::BrowserContext* ConnectorsServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const { … }
}