#include "components/enterprise/data_controls/core/browser/rule.h"
#include <string_view>
#include <vector>
#include "base/containers/fixed_flat_map.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "components/enterprise/data_controls/core/browser/conditions/and_condition.h"
#include "components/enterprise/data_controls/core/browser/conditions/attributes_condition.h"
#include "components/enterprise/data_controls/core/browser/conditions/not_condition.h"
#include "components/enterprise/data_controls/core/browser/conditions/or_condition.h"
#include "components/enterprise/data_controls/core/browser/features.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/strings/grit/components_strings.h"
namespace data_controls {
namespace {
constexpr char kKeyName[] = …;
constexpr char kKeyRuleId[] = …;
constexpr char kKeyDescription[] = …;
constexpr char kKeySources[] = …;
constexpr char kKeyDestinations[] = …;
constexpr char kKeyRestrictions[] = …;
constexpr char kKeyAnd[] = …;
constexpr char kKeyOr[] = …;
constexpr char kKeyNot[] = …;
constexpr char kKeyClass[] = …;
constexpr char kKeyLevel[] = …;
std::string GetStringOrEmpty(const base::Value::Dict& dict, const char* key) { … }
std::vector<std::string_view> OneOfConditions(const base::Value::Dict& value) { … }
std::vector<std::string_view> AnyOfConditions(const base::Value::Dict& value) { … }
policy::PolicyErrorPath CreateErrorPath(
const policy::PolicyErrorPath& error_path,
std::string new_value,
std::optional<int> new_list_index = std::nullopt) { … }
bool IgnoreRestriction(Rule::Restriction restriction) { … }
}
Rule::Rule(Rule&& other) = default;
Rule::~Rule() = default;
Rule::Rule(std::string name,
std::string rule_id,
std::string description,
std::unique_ptr<const Condition> condition,
base::flat_map<Restriction, Level> restrictions)
: … { … }
std::optional<Rule> Rule::Create(const base::Value& value) { … }
std::optional<Rule> Rule::Create(const base::Value::Dict& value) { … }
Rule::Level Rule::GetLevel(Restriction restriction,
const ActionContext& context) const { … }
const std::string& Rule::name() const { … }
const std::string& Rule::rule_id() const { … }
const std::string& Rule::description() const { … }
std::unique_ptr<const Condition> Rule::GetCondition(
const base::Value::Dict& value) { … }
std::unique_ptr<const Condition> Rule::GetSourcesAndDestinationsCondition(
const base::Value::Dict& value) { … }
std::vector<std::unique_ptr<const Condition>> Rule::GetListConditions(
const base::Value::List& value) { … }
base::flat_map<Rule::Restriction, Rule::Level> Rule::GetRestrictions(
const base::Value::Dict& value) { … }
Rule::Restriction Rule::StringToRestriction(const std::string& restriction) { … }
Rule::Level Rule::StringToLevel(const std::string& level) { … }
const char* Rule::RestrictionToString(Restriction restriction) { … }
const char* Rule::LevelToString(Level level) { … }
bool Rule::ValidateRuleValue(const char* policy_name,
const base::Value::Dict& root_value,
policy::PolicyErrorPath error_path,
policy::PolicyErrorMap* errors) { … }
bool Rule::ValidateRuleSubValues(
const char* policy_name,
const base::Value::Dict& value,
const base::flat_map<Rule::Restriction, Rule::Level>& restrictions,
policy::PolicyErrorPath error_path,
policy::PolicyErrorMap* errors) { … }
void Rule::AddMutuallyExclusiveErrors(
const std::vector<std::string_view>& oneof_conditions,
const std::vector<std::string_view>& anyof_conditions,
const char* policy_name,
policy::PolicyErrorPath error_path,
policy::PolicyErrorMap* errors) { … }
bool Rule::AddUnsupportedAttributeErrors(
const std::vector<std::string_view>& oneof_conditions,
const std::vector<std::string_view>& anyof_conditions,
base::flat_map<Rule::Restriction, Rule::Level> restrictions,
const char* policy_name,
policy::PolicyErrorPath error_path,
policy::PolicyErrorMap* errors) { … }
bool Rule::AddUnsupportedRestrictionErrors(
const char* policy_name,
const base::flat_map<Rule::Restriction, Rule::Level>& restrictions,
policy::PolicyErrorPath error_path,
policy::PolicyErrorMap* errors) { … }
}