chromium/chrome/browser/enterprise/connectors/analysis/analysis_service_settings.cc

// Copyright 2020 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/connectors/analysis/analysis_service_settings.h"

#include "base/containers/contains.h"
#include "base/strings/utf_string_conversions.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/enterprise/connectors/core/common.h"
#include "components/enterprise/connectors/core/service_provider_config.h"
#include "components/url_matcher/url_util.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/enterprise/connectors/analysis/source_destination_matcher_ash.h"
#endif

namespace enterprise_connectors {

AnalysisServiceSettings::AnalysisServiceSettings(
    const base::Value& settings_value,
    const ServiceProviderConfig& service_provider_config) {}

// static
std::optional<AnalysisServiceSettings::URLPatternSettings>
AnalysisServiceSettings::GetPatternSettings(
    const PatternSettings& patterns,
    base::MatcherStringPattern::ID match) {}

AnalysisSettings AnalysisServiceSettings::GetAnalysisSettingsWithTags(
    std::map<std::string, TagSettings> tags,
    DataRegion data_region) const {}

std::optional<AnalysisSettings> AnalysisServiceSettings::GetAnalysisSettings(
    const GURL& url,
    DataRegion data_region) const {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
std::optional<AnalysisSettings> AnalysisServiceSettings::GetAnalysisSettings(
    content::BrowserContext* context,
    const storage::FileSystemURL& source_url,
    const storage::FileSystemURL& destination_url,
    DataRegion data_region) const {
  if (!IsValid())
    return std::nullopt;
  DCHECK(source_destination_matcher_);

  auto matches =
      source_destination_matcher_->Match(context, source_url, destination_url);
  if (matches.empty())
    return std::nullopt;

  auto tags = GetTags(matches);
  if (tags.empty())
    return std::nullopt;

  return GetAnalysisSettingsWithTags(std::move(tags), data_region);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

bool AnalysisServiceSettings::ShouldBlockUntilVerdict() const {}

bool AnalysisServiceSettings::ShouldBlockByDefault() const {}

std::optional<std::u16string> AnalysisServiceSettings::GetCustomMessage(
    const std::string& tag) {}

std::optional<GURL> AnalysisServiceSettings::GetLearnMoreUrl(
    const std::string& tag) {}

bool AnalysisServiceSettings::GetBypassJustificationRequired(
    const std::string& tag) {}

bool AnalysisServiceSettings::is_cloud_analysis() const {}

bool AnalysisServiceSettings::is_local_analysis() const {}

void AnalysisServiceSettings::AddUrlPatternSettings(
    const base::Value::Dict& url_settings_dict,
    bool enabled,
    base::MatcherStringPattern::ID* id) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void AnalysisServiceSettings::AddSourceDestinationSettings(
    const base::Value::Dict& source_destination_settings_value,
    bool enabled,
    base::MatcherStringPattern::ID* id) {
  DCHECK(id);
  DCHECK(analysis_config_);
  DCHECK(source_destination_matcher_);
  if (enabled)
    DCHECK(disabled_patterns_settings_.empty());
  else
    DCHECK(!enabled_patterns_settings_.empty());

  URLPatternSettings setting;

  const base::Value::List* tags =
      source_destination_settings_value.FindList(kKeyTags);
  if (!tags)
    return;

  for (const base::Value& tag : *tags) {
    if (tag.is_string()) {
      for (const auto& supported_tag : analysis_config_->supported_tags) {
        if (tag.GetString() == supported_tag.name)
          setting.tags.insert(tag.GetString());
      }
    }
  }

  // Add the source destination rules to the source_destination_matcher and
  // store the condition set IDs.
  const base::Value::List* source_destination_list =
      source_destination_settings_value.FindList(kKeySourceDestinationList);
  if (!source_destination_list) {
    return;
  }

  base::MatcherStringPattern::ID previous_id = *id;
  source_destination_matcher_->AddFilters(id, source_destination_list);
  if (previous_id == *id) {
    // No rules were added, so don't save settings, as they would override other
    // valid settings.
    return;
  }

  if (enabled)
    enabled_patterns_settings_[*id] = std::move(setting);
  else
    disabled_patterns_settings_[*id] = std::move(setting);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

std::map<std::string, TagSettings> AnalysisServiceSettings::GetTags(
    const std::set<base::MatcherStringPattern::ID>& matches) const {}

bool AnalysisServiceSettings::IsValid() const {}

AnalysisServiceSettings::AnalysisServiceSettings(AnalysisServiceSettings&&) =
    default;
AnalysisServiceSettings::~AnalysisServiceSettings() = default;

AnalysisServiceSettings::URLPatternSettings::URLPatternSettings() = default;
AnalysisServiceSettings::URLPatternSettings::URLPatternSettings(
    const AnalysisServiceSettings::URLPatternSettings&) = default;
AnalysisServiceSettings::URLPatternSettings::URLPatternSettings(
    AnalysisServiceSettings::URLPatternSettings&&) = default;
AnalysisServiceSettings::URLPatternSettings&
AnalysisServiceSettings::URLPatternSettings::operator=(
    const AnalysisServiceSettings::URLPatternSettings&) = default;
AnalysisServiceSettings::URLPatternSettings&
AnalysisServiceSettings::URLPatternSettings::operator=(
    AnalysisServiceSettings::URLPatternSettings&&) = default;
AnalysisServiceSettings::URLPatternSettings::~URLPatternSettings() = default;

}  // namespace enterprise_connectors