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
|
// 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.
#ifndef COMPONENTS_ENTERPRISE_BROWSER_REPORTING_PROFILE_REPORT_GENERATOR_H_
#define COMPONENTS_ENTERPRISE_BROWSER_REPORTING_PROFILE_REPORT_GENERATOR_H_
#include <memory>
#include <string>
#include "base/values.h"
#include "components/enterprise/browser/reporting/report_type.h"
#include "components/policy/core/browser/policy_conversions_client.h"
#include "components/policy/proto/device_management_backend.pb.h"
namespace base {
class FilePath;
}
namespace policy {
class CloudPolicyManager;
}
namespace enterprise_reporting {
class ReportingDelegateFactory;
/**
* A report generator that collects Profile related information that is selected
* by policies.
*/
class ProfileReportGenerator {
public:
using ExtensionsEnabledCallback = base::RepeatingCallback<bool()>;
class Delegate {
public:
Delegate() = default;
Delegate(const Delegate&) = delete;
Delegate& operator=(const Delegate&) = delete;
virtual ~Delegate() = default;
// Fetch the profile for the given path, and store it for report generation.
// Returns false if the profile can't be retrieved.
virtual bool Init(const base::FilePath& path) = 0;
// Sets sign-in information in the report, including email and gaia id.
virtual void GetSigninUserInfo(
enterprise_management::ChromeUserProfileInfo* report) = 0;
// Set affiliation information in the report.
virtual void GetAffiliationInfo(
enterprise_management::ChromeUserProfileInfo* report) = 0;
// Sets installed extension information in the report.
virtual void GetExtensionInfo(
enterprise_management::ChromeUserProfileInfo* report) = 0;
// Sets extension requests information in the report.
virtual void GetExtensionRequest(
enterprise_management::ChromeUserProfileInfo* report) = 0;
// Sets profile id in the report.
virtual void GetProfileId(
enterprise_management::ChromeUserProfileInfo* report) = 0;
// Sets profile name in the report.
virtual void GetProfileName(
enterprise_management::ChromeUserProfileInfo* report) = 0;
// Returns a new platform-specific policy conversions client.
virtual std::unique_ptr<policy::PolicyConversionsClient>
MakePolicyConversionsClient(bool is_machine_scope) = 0;
// Get a pointer to the current platform's cloud policy manager.
virtual policy::CloudPolicyManager* GetCloudPolicyManager(
bool is_machine_scope) = 0;
};
explicit ProfileReportGenerator(ReportingDelegateFactory* delegate_factory);
ProfileReportGenerator(const ProfileReportGenerator&) = delete;
ProfileReportGenerator& operator=(const ProfileReportGenerator&) = delete;
~ProfileReportGenerator();
void set_extensions_enabled(bool enabled);
void set_policies_enabled(bool enabled);
void set_is_machine_scope(bool is_machine);
// Pass a callback to enable/disable extension report with dynamic condition.
void SetExtensionsEnabledCallback(ExtensionsEnabledCallback callback);
// Generates a report for the profile associated with `path` if
// it's activated, and returns the report by invoking `callback` with its
// value. The report is null if it can't be generated.
void MaybeGenerate(
const base::FilePath& path,
ReportType report_type,
base::OnceCallback<
void(std::unique_ptr<enterprise_management::ChromeUserProfileInfo>)>
callback);
protected:
void GetChromePolicyInfo();
void GetExtensionPolicyInfo();
void GetPolicyFetchTimestampInfo();
private:
std::unique_ptr<Delegate> delegate_;
base::Value::Dict policies_;
bool extensions_enabled_ = true;
bool policies_enabled_ = true;
bool is_machine_scope_ = true;
base::RepeatingCallback<bool()> extensions_enabled_callback_;
std::unique_ptr<enterprise_management::ChromeUserProfileInfo> report_;
};
} // namespace enterprise_reporting
#endif // COMPONENTS_ENTERPRISE_BROWSER_REPORTING_PROFILE_REPORT_GENERATOR_H_
|