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
|
// Copyright 2022 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/enterprise/chrome_browser_main_extra_parts_enterprise.h"
#include "components/enterprise/buildflags/buildflags.h"
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
#include "chrome/browser/enterprise/connectors/analysis/content_analysis_sdk_manager.h"
#include "chrome/browser/enterprise/connectors/connectors_service.h"
#endif // BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
namespace enterprise_util {
namespace {
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
// If a local agent has been configured for content analysis, this function
// connects to the agent immediately. Agents expect chrome to connect to them
// at some point during startup to determine if chrome is configuredcorrectly.
void MaybePrimeLocalContentAnalysisAgentConnection(Profile* profile) {
auto* connectors_service =
enterprise_connectors::ConnectorsServiceFactory::GetForBrowserContext(
profile);
constexpr enterprise_connectors::AnalysisConnector kConnectors[] = {
enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY,
enterprise_connectors::AnalysisConnector::FILE_DOWNLOADED,
enterprise_connectors::AnalysisConnector::FILE_ATTACHED,
enterprise_connectors::AnalysisConnector::PRINT,
};
for (auto connector : kConnectors) {
// While the connector service supports more than one config per connector,
// today only one is supported.
auto configs = connectors_service->GetAnalysisServiceConfigs(connector);
if (configs.size() < 1 || !configs[0]->local_path)
continue;
// Prime the SDK manager with the correct client.
enterprise_connectors::ContentAnalysisSdkManager::Get()->GetClient(
{configs[0]->local_path, configs[0]->user_specific});
}
}
#endif // BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
} // namespace
ChromeBrowserMainExtraPartsEnterprise::ChromeBrowserMainExtraPartsEnterprise() =
default;
ChromeBrowserMainExtraPartsEnterprise::
~ChromeBrowserMainExtraPartsEnterprise() = default;
void ChromeBrowserMainExtraPartsEnterprise::PostProfileInit(
Profile* profile,
bool is_initial_profile) {
#if BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
MaybePrimeLocalContentAnalysisAgentConnection(profile);
#endif // BUILDFLAG(ENTERPRISE_LOCAL_CONTENT_ANALYSIS)
}
} // namespace enterprise_util
|