#include "chrome/browser/enterprise/data_controls/dlp_reporting_manager.h"
#include <memory>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "build/chromeos_buildflags.h"
#include "components/enterprise/data_controls/core/browser/dlp_histogram_helper.h"
#include "components/enterprise/data_controls/core/browser/dlp_policy_event.pb.h"
#include "components/reporting/client/report_queue.h"
#include "components/reporting/client/report_queue_configuration.h"
#include "components/reporting/client/report_queue_factory.h"
#include "components/reporting/proto/synced/record_constants.pb.h"
#include "components/reporting/util/status.h"
#include "content/public/common/content_constants.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chromeos/startup/browser_params_proxy.h"
#endif
namespace data_controls {
DlpPolicyEvent_Mode RuleLevel2DlpEventMode(
Rule::Level level) { … }
DlpPolicyEvent_Restriction RuleRestriction2DlpEventRestriction(
Rule::Restriction restriction) { … }
Rule::Restriction DlpEventRestriction2RuleRestriction(
DlpPolicyEvent_Restriction restriction) { … }
DlpPolicyEvent_UserType GetCurrentUserType() { … }
std::unique_ptr<DlpPolicyEventBuilder> DlpPolicyEventBuilder::Event(
const std::string& src_url,
const std::string& rule_name,
const std::string& rule_id,
Rule::Restriction restriction,
Rule::Level level) { … }
std::unique_ptr<DlpPolicyEventBuilder>
DlpPolicyEventBuilder::WarningProceededEvent(const std::string& src_url,
const std::string& rule_name,
const std::string& rule_id,
Rule::Restriction restriction) { … }
DlpPolicyEventBuilder::DlpPolicyEventBuilder() { … }
void DlpPolicyEventBuilder::SetDestinationUrl(const std::string& dst_url) { … }
#if BUILDFLAG(IS_CHROMEOS)
void DlpPolicyEventBuilder::SetDestinationComponent(
Component dst_component) {
DlpPolicyEventDestination* event_destination = new DlpPolicyEventDestination;
switch (dst_component) {
case (Component::kArc):
event_destination->set_component(DlpPolicyEventDestination_Component_ARC);
break;
case (Component::kCrostini):
event_destination->set_component(
DlpPolicyEventDestination_Component_CROSTINI);
break;
case (Component::kPluginVm):
event_destination->set_component(
DlpPolicyEventDestination_Component_PLUGIN_VM);
break;
case (Component::kUsb):
event_destination->set_component(DlpPolicyEventDestination_Component_USB);
break;
case (Component::kDrive):
event_destination->set_component(
DlpPolicyEventDestination_Component_DRIVE);
break;
case (Component::kOneDrive):
event_destination->set_component(
DlpPolicyEventDestination_Component_ONEDRIVE);
break;
case (Component::kUnknownComponent):
event_destination->set_component(
DlpPolicyEventDestination_Component_UNDEFINED_COMPONENT);
break;
}
event.set_allocated_destination(event_destination);
}
#endif
void DlpPolicyEventBuilder::SetContentName(const std::string& content_name) { … }
DlpPolicyEvent DlpPolicyEventBuilder::Create() { … }
void DlpPolicyEventBuilder::SetSourceUrl(const std::string& src_url) { … }
void DlpPolicyEventBuilder::SetRestriction(
Rule::Restriction restriction) { … }
DlpPolicyEvent CreateDlpPolicyEvent(const std::string& src_url,
Rule::Restriction restriction,
const std::string& rule_name,
const std::string& rule_id,
Rule::Level level) { … }
DlpPolicyEvent CreateDlpPolicyEvent(const std::string& src_url,
const std::string& dst_url,
Rule::Restriction restriction,
const std::string& rule_name,
const std::string& rule_id,
Rule::Level level) { … }
#if BUILDFLAG(IS_CHROMEOS)
DlpPolicyEvent CreateDlpPolicyEvent(const std::string& src_url,
Component dst_component,
Rule::Restriction restriction,
const std::string& rule_name,
const std::string& rule_id,
Rule::Level level) {
auto event_builder = DlpPolicyEventBuilder::Event(src_url, rule_name, rule_id,
restriction, level);
event_builder->SetDestinationComponent(dst_component);
return event_builder->Create();
}
#endif
DlpReportingManager::DlpReportingManager()
: … { … }
DlpReportingManager::~DlpReportingManager() = default;
void DlpReportingManager::SetReportQueueForTest(
std::unique_ptr<::reporting::ReportQueue, base::OnTaskRunnerDeleter>
report_queue) { … }
void DlpReportingManager::ReportEvent(const std::string& src_url,
Rule::Restriction restriction,
Rule::Level level,
const std::string& rule_name,
const std::string& rule_id) { … }
void DlpReportingManager::ReportEvent(const std::string& src_url,
const std::string& dst_url,
Rule::Restriction restriction,
Rule::Level level,
const std::string& rule_name,
const std::string& rule_id) { … }
#if BUILDFLAG(IS_CHROMEOS)
void DlpReportingManager::ReportEvent(const std::string& src_url,
const Component dst_component,
Rule::Restriction restriction,
Rule::Level level,
const std::string& rule_name,
const std::string& rule_id) {
auto event = CreateDlpPolicyEvent(src_url, dst_component, restriction,
rule_name, rule_id, level);
ReportEvent(std::move(event));
}
#endif
void DlpReportingManager::OnEventEnqueued(reporting::Status status) { … }
void DlpReportingManager::ReportEvent(DlpPolicyEvent event) { … }
void DlpReportingManager::AddObserver(Observer* observer) { … }
void DlpReportingManager::RemoveObserver(Observer* observer) { … }
}