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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/enterprise/browser/reporting/profile_report_generator.h"
#include <utility>
#include "base/check_is_test.h"
#include "base/files/file_path.h"
#include "base/notreached.h"
#include "components/enterprise/browser/reporting/policy_info.h"
#include "components/enterprise/browser/reporting/report_type.h"
#include "components/enterprise/browser/reporting/report_util.h"
#include "components/enterprise/browser/reporting/reporting_delegate_factory.h"
#include "components/policy/core/browser/policy_conversions.h"
#include "profile_report_generator.h"
namespace em = enterprise_management;
namespace enterprise_reporting {
ProfileReportGenerator::ProfileReportGenerator(
ReportingDelegateFactory* delegate_factory)
: delegate_(delegate_factory->GetProfileReportGeneratorDelegate()) {}
ProfileReportGenerator::~ProfileReportGenerator() = default;
void ProfileReportGenerator::set_extensions_enabled(bool enabled) {
extensions_enabled_ = enabled;
}
void ProfileReportGenerator::set_policies_enabled(bool enabled) {
policies_enabled_ = enabled;
}
void ProfileReportGenerator::set_is_machine_scope(bool is_machine) {
is_machine_scope_ = is_machine;
}
void ProfileReportGenerator::SetExtensionsEnabledCallback(
ExtensionsEnabledCallback callback) {
extensions_enabled_callback_ = std::move(callback);
}
void ProfileReportGenerator::MaybeGenerate(
const base::FilePath& path,
ReportType report_type,
base::OnceCallback<void(std::unique_ptr<em::ChromeUserProfileInfo>)>
callback) {
if (!delegate_->Init(path)) {
std::move(callback).Run(nullptr);
return;
}
report_ = std::make_unique<em::ChromeUserProfileInfo>();
switch (report_type) {
// TODO(crbug.com/330336666): Rename report type `kFull` to `kBrowser`.
case ReportType::kFull:
report_->set_id(path.AsUTF8Unsafe());
break;
case ReportType::kProfileReport:
report_->set_id(ObfuscateFilePath(path.AsUTF8Unsafe()));
break;
case ReportType::kBrowserVersion:
NOTREACHED();
}
report_->set_is_detail_available(true);
delegate_->GetSigninUserInfo(report_.get());
delegate_->GetProfileName(report_.get());
#if !BUILDFLAG(IS_CHROMEOS)
delegate_->GetAffiliationInfo(report_.get());
#endif
if (extensions_enabled_ &&
(!extensions_enabled_callback_ || extensions_enabled_callback_.Run())) {
delegate_->GetExtensionInfo(report_.get());
}
if (is_machine_scope_) {
delegate_->GetExtensionRequest(report_.get());
delegate_->GetProfileId(report_.get());
}
if (policies_enabled_) {
// TODO(crbug.com/40635691): Upload policy error as their IDs.
auto client = delegate_->MakePolicyConversionsClient(is_machine_scope_);
// `client` may not be provided in unit test.
if (client) {
policies_ = policy::PolicyConversions(std::move(client))
.EnableConvertTypes(false)
.EnablePrettyPrint(false)
.ToValueDict();
GetChromePolicyInfo();
GetExtensionPolicyInfo();
GetPolicyFetchTimestampInfo();
} else {
CHECK_IS_TEST();
}
}
std::move(callback).Run(std::move(report_));
}
void ProfileReportGenerator::GetChromePolicyInfo() {
AppendChromePolicyInfoIntoProfileReport(policies_, report_.get());
}
void ProfileReportGenerator::GetExtensionPolicyInfo() {
AppendExtensionPolicyInfoIntoProfileReport(policies_, report_.get());
}
void ProfileReportGenerator::GetPolicyFetchTimestampInfo() {
#if !BUILDFLAG(IS_CHROMEOS)
AppendCloudPolicyFetchTimestamp(
report_.get(), delegate_->GetCloudPolicyManager(is_machine_scope_));
#endif // !BUILDFLAG(IS_CHROMEOS)
}
} // namespace enterprise_reporting
|