chromium/components/policy/core/common/BUILD.gn

# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//testing/libfuzzer/fuzzer_test.gni")

group("policy_namespace") {
  public_deps = [ ":policy_namespace_internal" ]
}

group("common") {
  if (is_component_build) {
    public_deps = [ "//components/policy" ]
  } else {
    public_deps = [ ":internal" ]
  }
}

source_set("policy_namespace_internal") {
  visibility = [ "//components/policy/*" ]

  configs += [ "//components/policy:component_implementation" ]

  sources = [
    "../../policy_export.h",
    "policy_namespace.cc",
    "policy_namespace.h",
  ]
}

source_set("util") {
  sources = [
    "cloud/cloud_policy_util.cc",
    "cloud/cloud_policy_util.h",
  ]

  configs += [ "//components/policy:component_implementation" ]

  public_deps = [
    ":common_constants",
    "//components/policy/proto",
    "//components/version_info",
  ]

  deps = [
    "//base",
    "//build:chromeos_buildflags",
  ]

  if (is_chromeos) {
    deps += [ "//components/user_manager" ]
  }
  if (is_chromeos_lacros) {
    deps += [ "//chromeos/startup:startup" ]
  }
  if (is_chromeos_ash) {
    deps += [ "//chromeos/ash/components/system" ]
  }
}

source_set("internal") {
  visibility = [ "//components/policy/*" ]

  configs += [ "//components/policy:component_implementation" ]

  sources = [
    "async_policy_loader.cc",
    "async_policy_loader.h",
    "async_policy_provider.cc",
    "async_policy_provider.h",
    "chrome_schema.cc",
    "chrome_schema.h",
    "cloud/affiliation.cc",
    "cloud/affiliation.h",
    "cloud/chrome_browser_cloud_management_metrics.h",
    "cloud/client_data_delegate.h",
    "cloud/cloud_external_data_manager.cc",
    "cloud/cloud_external_data_manager.h",
    "cloud/cloud_external_data_store.cc",
    "cloud/cloud_external_data_store.h",
    "cloud/cloud_policy_client.cc",
    "cloud/cloud_policy_client.h",
    "cloud/cloud_policy_client_registration_helper.cc",
    "cloud/cloud_policy_client_registration_helper.h",
    "cloud/cloud_policy_core.cc",
    "cloud/cloud_policy_core.h",
    "cloud/cloud_policy_manager.cc",
    "cloud/cloud_policy_manager.h",
    "cloud/cloud_policy_refresh_scheduler.cc",
    "cloud/cloud_policy_refresh_scheduler.h",
    "cloud/cloud_policy_refresh_scheduler_observer.h",
    "cloud/cloud_policy_service.cc",
    "cloud/cloud_policy_service.h",
    "cloud/cloud_policy_store.cc",
    "cloud/cloud_policy_store.h",
    "cloud/cloud_policy_validator.cc",
    "cloud/cloud_policy_validator.h",
    "cloud/component_cloud_policy_service.cc",
    "cloud/component_cloud_policy_service.h",
    "cloud/component_cloud_policy_service_observer.h",
    "cloud/component_cloud_policy_store.cc",
    "cloud/component_cloud_policy_store.h",
    "cloud/component_cloud_policy_updater.cc",
    "cloud/component_cloud_policy_updater.h",
    "cloud/device_management_service.cc",
    "cloud/device_management_service.h",
    "cloud/dm_auth.cc",
    "cloud/dm_auth.h",
    "cloud/dm_token.cc",
    "cloud/dm_token.h",
    "cloud/dmserver_job_configurations.cc",
    "cloud/dmserver_job_configurations.h",
    "cloud/encrypted_reporting_job_configuration.cc",
    "cloud/encrypted_reporting_job_configuration.h",
    "cloud/enterprise_metrics.h",
    "cloud/external_policy_data_fetcher.cc",
    "cloud/external_policy_data_fetcher.h",
    "cloud/external_policy_data_updater.cc",
    "cloud/external_policy_data_updater.h",
    "cloud/machine_level_user_cloud_policy_manager.cc",
    "cloud/machine_level_user_cloud_policy_manager.h",
    "cloud/machine_level_user_cloud_policy_store.cc",
    "cloud/machine_level_user_cloud_policy_store.h",
    "cloud/policy_invalidation_scope.h",
    "cloud/policy_invalidation_util.cc",
    "cloud/policy_invalidation_util.h",
    "cloud/policy_value_validator.h",
    "cloud/realtime_reporting_job_configuration.cc",
    "cloud/realtime_reporting_job_configuration.h",
    "cloud/reporting_job_configuration_base.cc",
    "cloud/reporting_job_configuration_base.h",
    "cloud/resource_cache.cc",
    "cloud/resource_cache.h",
    "cloud/signing_service.h",
    "cloud/user_cloud_policy_manager.cc",
    "cloud/user_cloud_policy_manager.h",
    "cloud/user_cloud_policy_store.cc",
    "cloud/user_cloud_policy_store.h",
    "cloud/user_cloud_policy_store_base.cc",
    "cloud/user_cloud_policy_store_base.h",
    "cloud/user_info_fetcher.cc",
    "cloud/user_info_fetcher.h",
    "cloud/user_policy_metrics_recorder.cc",
    "cloud/user_policy_metrics_recorder.h",
    "command_line_policy_provider.cc",
    "command_line_policy_provider.h",
    "config_dir_policy_loader.cc",
    "config_dir_policy_loader.h",
    "configuration_policy_provider.cc",
    "configuration_policy_provider.h",
    "device_local_account_type.cc",
    "device_local_account_type.h",
    "external_data_fetcher.cc",
    "external_data_fetcher.h",
    "external_data_manager.h",
    "features.cc",
    "features.h",
    "json_schema_constants.cc",
    "json_schema_constants.h",
    "local_test_policy_loader.cc",
    "local_test_policy_loader.h",
    "local_test_policy_provider.cc",
    "local_test_policy_provider.h",
    "management/management_service.cc",
    "management/management_service.h",
    "management/platform_management_service.cc",
    "management/platform_management_service.h",
    "policy_bundle.cc",
    "policy_bundle.h",
    "policy_details.h",
    "policy_loader_command_line.cc",
    "policy_loader_command_line.h",
    "policy_loader_common.cc",
    "policy_loader_common.h",
    "policy_logger.cc",
    "policy_logger.h",
    "policy_map.cc",
    "policy_map.h",
    "policy_merger.cc",
    "policy_merger.h",
    "policy_migrator.cc",
    "policy_migrator.h",
    "policy_proto_decoders.cc",
    "policy_proto_decoders.h",
    "policy_service.cc",
    "policy_service.h",
    "policy_service_impl.cc",
    "policy_service_impl.h",
    "policy_statistics_collector.cc",
    "policy_statistics_collector.h",
    "policy_utils.cc",
    "policy_utils.h",
    "proxy_policy_provider.cc",
    "proxy_policy_provider.h",
    "remote_commands/remote_command_job.cc",
    "remote_commands/remote_command_job.h",
    "remote_commands/remote_commands_factory.cc",
    "remote_commands/remote_commands_factory.h",
    "remote_commands/remote_commands_invalidator.cc",
    "remote_commands/remote_commands_invalidator.h",
    "remote_commands/remote_commands_invalidator_impl.cc",
    "remote_commands/remote_commands_invalidator_impl.h",
    "remote_commands/remote_commands_queue.cc",
    "remote_commands/remote_commands_queue.h",
    "remote_commands/remote_commands_service.cc",
    "remote_commands/remote_commands_service.h",
    "schema.cc",
    "schema.h",
    "schema_internal.h",
    "schema_map.cc",
    "schema_map.h",
    "schema_registry.cc",
    "schema_registry.h",
    "schema_registry_tracking_policy_provider.cc",
    "schema_registry_tracking_policy_provider.h",
    "values_util.cc",
    "values_util.h",
  ]

  configs += [ "//build/config:precompiled_headers" ]

  public_deps = [
    ":common_constants",
    ":policy_namespace",
    ":util",
    "//components/invalidation:invalidation",
    "//components/invalidation/public",
    "//components/policy:generated",
    "//components/policy/proto",
    "//components/reporting/proto:record_constants",
    "//components/reporting/proto:record_proto",
  ]

  deps = [
    "//base:i18n",
    "//build:chromeos_buildflags",
    "//components/account_id",
    "//components/enterprise/common:strings",
    "//components/prefs",
    "//components/signin/public/identity_manager",
    "//components/strings",
    "//components/user_manager",
    "//components/version_info",
    "//extensions/buildflags",
    "//google_apis",
    "//net",
    "//services/network/public/cpp",
    "//third_party/libxml:xml_writer",
    "//third_party/re2",
    "//ui/base",
    "//url",
  ]

  if (is_chromeos_lacros) {
    sources += [
      "management/platform_management_status_provider_lacros.cc",
      "management/platform_management_status_provider_lacros.h",
      "policy_loader_lacros.cc",
      "policy_loader_lacros.h",
    ]
    deps += [
      "//chromeos/crosapi/mojom",
      "//chromeos/lacros",
      "//chromeos/startup:startup",
    ]
  }

  allow_circular_includes_from = [
    # Generated files use policy_details.h and policy_map.h from this target.
    # TODO(https://crbug.com/945868) - refactor so we don't have dep cycles.
    "//components/policy:generated",
  ]

  if (is_mac) {
    sources += [
      "management/platform_management_status_provider_mac.cc",
      "management/platform_management_status_provider_mac.h",
    ]
  }

  if (is_win) {
    sources += [
      "management/platform_management_status_provider_win.cc",
      "management/platform_management_status_provider_win.h",
      "policy_loader_win.cc",
      "policy_loader_win.h",
      "scoped_critical_policy_section.cc",
      "scoped_critical_policy_section.h",
    ]
    libs = [
      "netapi32.lib",
      "ntdsapi.lib",
      "secur32.lib",
      "shlwapi.lib",
      "userenv.lib",
    ]
  }

  if (is_win || is_mac || is_linux) {
    sources += [
      "cloud/profile_cloud_policy_manager.cc",
      "cloud/profile_cloud_policy_manager.h",
      "cloud/profile_cloud_policy_store.cc",
      "cloud/profile_cloud_policy_store.h",
    ]
  }

  # Compile on Linux for fuzzer and since code is reused on Chrome OS.
  if (is_win || is_linux || is_chromeos) {
    sources += [
      "registry_dict.cc",
      "registry_dict.h",
    ]
  }
  if (is_android || is_ios) {
    sources += [ "cloud/component_cloud_policy_service_stub.cc" ]
    sources -= [
      "cloud/cloud_external_data_store.cc",
      "cloud/cloud_external_data_store.h",
      "cloud/component_cloud_policy_service.cc",
      "cloud/component_cloud_policy_store.cc",
      "cloud/component_cloud_policy_store.h",
      "cloud/component_cloud_policy_updater.cc",
      "cloud/component_cloud_policy_updater.h",
      "cloud/external_policy_data_fetcher.cc",
      "cloud/external_policy_data_fetcher.h",
      "cloud/external_policy_data_updater.cc",
      "cloud/external_policy_data_updater.h",
      "cloud/resource_cache.cc",
      "cloud/resource_cache.h",
      "config_dir_policy_loader.cc",
      "config_dir_policy_loader.h",
    ]
  }
  if (is_android) {
    sources += [
      "android/android_combined_policy_provider.cc",
      "android/android_combined_policy_provider.h",
      "android/policy_converter.cc",
      "android/policy_converter.h",
      "android/policy_map_android.cc",
      "android/policy_map_android.h",
      "android/policy_service_android.cc",
      "android/policy_service_android.h",
    ]
    deps += [ "//components/policy/android:jni_headers" ]
  }
  if (is_chromeos) {
    sources += [
      "default_chrome_apps_migrator.cc",
      "default_chrome_apps_migrator.h",
    ]
  }
  if (is_chromeos_ash) {
    deps += [ "//chromeos/ash/components/system" ]
    sources += [
      "policy_scheduler.cc",
      "policy_scheduler.h",
    ]
    sources -= [
      "cloud/chrome_browser_cloud_management_metrics.h",
      "cloud/cloud_policy_client_registration_helper.cc",
      "cloud/cloud_policy_client_registration_helper.h",
      "cloud/machine_level_user_cloud_policy_manager.cc",
      "cloud/machine_level_user_cloud_policy_manager.h",
      "cloud/machine_level_user_cloud_policy_store.cc",
      "cloud/machine_level_user_cloud_policy_store.h",
      "cloud/user_cloud_policy_manager.cc",
      "cloud/user_cloud_policy_manager.h",
      "cloud/user_cloud_policy_store.cc",
      "cloud/user_cloud_policy_store.h",
    ]
  }
  if (is_apple) {
    sources += [
      "mac_util.cc",
      "mac_util.h",
    ]
    frameworks = [ "Foundation.framework" ]

    if (is_mac) {
      sources += [
        "policy_loader_mac.h",
        "policy_loader_mac.mm",
        "preferences_mac.h",
        "preferences_mac.mm",
      ]
      frameworks += [ "SystemConfiguration.framework" ]
    }

    if (is_ios) {
      sources += [
        "policy_loader_ios.h",
        "policy_loader_ios.mm",
      ]
    }
  }
}

static_library("test_support") {
  testonly = true
  sources = [
    "cloud/mock_cloud_external_data_manager.cc",
    "cloud/mock_cloud_external_data_manager.h",
    "cloud/mock_cloud_policy_client.cc",
    "cloud/mock_cloud_policy_client.h",
    "cloud/mock_cloud_policy_manager.cc",
    "cloud/mock_cloud_policy_manager.h",
    "cloud/mock_cloud_policy_service.cc",
    "cloud/mock_cloud_policy_service.h",
    "cloud/mock_cloud_policy_store.cc",
    "cloud/mock_cloud_policy_store.h",
    "cloud/mock_device_management_service.cc",
    "cloud/mock_device_management_service.h",
    "cloud/mock_signing_service.cc",
    "cloud/mock_signing_service.h",
    "cloud/mock_user_cloud_policy_store.cc",
    "cloud/mock_user_cloud_policy_store.h",
    "cloud/test/policy_builder.cc",
    "cloud/test/policy_builder.h",
    "configuration_policy_provider_test.cc",
    "configuration_policy_provider_test.h",
    "fake_async_policy_loader.cc",
    "fake_async_policy_loader.h",
    "management/scoped_management_service_override_for_testing.cc",
    "management/scoped_management_service_override_for_testing.h",
    "mock_configuration_policy_provider.cc",
    "mock_configuration_policy_provider.h",
    "mock_policy_service.cc",
    "mock_policy_service.h",
    "policy_service_stub.cc",
    "policy_service_stub.h",
    "policy_test_utils.cc",
    "policy_test_utils.h",
    "remote_commands/test_support/echo_remote_command_job.cc",
    "remote_commands/test_support/echo_remote_command_job.h",
    "remote_commands/test_support/remote_command_builders.cc",
    "remote_commands/test_support/remote_command_builders.h",
    "remote_commands/test_support/testing_remote_commands_server.cc",
    "remote_commands/test_support/testing_remote_commands_server.h",
  ]

  if (is_chromeos_ash) {
    sources -= [
      "cloud/mock_user_cloud_policy_store.cc",
      "cloud/mock_user_cloud_policy_store.h",
    ]
  }

  if (is_mac) {
    sources += [
      "preferences_mock_mac.cc",
      "preferences_mock_mac.h",
    ]
  }

  if (is_win || is_mac || is_linux) {
    sources += [
      "cloud/mock_profile_cloud_policy_store.cc",
      "cloud/mock_profile_cloud_policy_store.h",
    ]
  }

  public_deps = [
    ":common",
    "//base",
    "//base/test:test_support",

    # Explicitly link in the generated policy target into the test support
    # so it will be linked to dependent targets. Otherwise in component
    # build, it will be hidden inside the policy component.
    "//components/account_id",
    "//components/policy:generated",
    "//components/policy/proto",
    "//components/reporting/proto:record_constants",
    "//components/reporting/proto:record_proto",
    "//components/strings",
    "//crypto",
    "//net",
    "//services/network/public/cpp",
    "//testing/gmock",
    "//testing/gtest",
  ]

  deps = [
    "//build:chromeos_buildflags",
    "//services/network:test_support",
  ]
}

source_set("common_constants") {
  configs += [ "//components/policy:component_implementation" ]
  deps = [
    "//base",
    "//build:chromeos_buildflags",
  ]
  sources = [
    "../../policy_export.h",
    "cloud/cloud_policy_constants.cc",
    "cloud/cloud_policy_constants.h",
    "policy_pref_names.cc",
    "policy_pref_names.h",
    "policy_switches.cc",
    "policy_switches.h",
    "policy_types.h",
    "proxy_settings_constants.cc",
    "proxy_settings_constants.h",
  ]

  if (is_ios) {
    sources += [
      "policy_loader_ios_constants.h",
      "policy_loader_ios_constants.mm",
    ]
    frameworks = [ "Foundation.framework" ]
  }
}

source_set("policy_path_constants") {
  sources = [
    "policy_paths.cc",
    "policy_paths.h",
  ]

  # NOTE: This target is intentionally separated from other targets, with
  # minimal dependencies.
  deps = [ "//build:branding_buildflags" ]
}

source_set("unit_tests") {
  testonly = true
  sources = [
    "cloud/affiliation_unittest.cc",
    "cloud/cloud_policy_client_unittest.cc",
    "cloud/cloud_policy_core_unittest.cc",
    "cloud/cloud_policy_refresh_scheduler_unittest.cc",
    "cloud/cloud_policy_service_unittest.cc",
    "cloud/device_management_service_unittest.cc",
    "cloud/dm_token_unittest.cc",
    "cloud/user_info_fetcher_unittest.cc",
    "cloud/user_policy_metrics_recorder_unittest.cc",
    "command_line_policy_provider_unittest.cc",
    "generate_policy_source_unittest.cc",
    "local_test_policy_loader_unittest.cc",
    "management/management_service_unittest.cc",
    "policy_bundle_unittest.cc",
    "policy_loader_command_line_unittest.cc",
    "policy_logger_unittest.cc",
    "policy_map_unittest.cc",
    "policy_proto_decoders_unittest.cc",
    "policy_service_impl_unittest.cc",
    "policy_statistics_collector_unittest.cc",
    "proxy_policy_provider_unittest.cc",
    "remote_commands/remote_commands_invalidator_unittest.cc",
    "remote_commands/remote_commands_invalidator_with_listener_unittest.cc",
    "remote_commands/remote_commands_queue_unittest.cc",
    "remote_commands/remote_commands_service_unittest.cc",
    "schema_map_unittest.cc",
    "schema_registry_tracking_policy_provider_unittest.cc",
    "schema_registry_unittest.cc",
    "schema_unittest.cc",
    "values_util_unittest.cc",
  ]

  # TODO(crbug.com/40205363): Enable these tests on Fuchsia if appropriate.
  if (!is_fuchsia) {
    sources += [
      "cloud/cloud_policy_manager_unittest.cc",
      "cloud/cloud_policy_validator_unittest.cc",
    ]
  }

  if (is_win || is_linux || is_chromeos) {
    sources += [ "registry_dict_unittest.cc" ]
  }
  if (is_chromeos_ash) {
    sources += [
      "default_chrome_apps_migrator_unittest.cc",
      "policy_scheduler_unittest.cc",
    ]
  } else {
    sources += [
      "cloud/machine_level_user_cloud_policy_manager_unittest.cc",
      "cloud/user_cloud_policy_manager_unittest.cc",
    ]

    # TODO(crbug.com/40205363): Enable these tests on Fuchsia if appropriate.
    if (!is_fuchsia) {
      sources += [
        "cloud/machine_level_user_cloud_policy_store_unittest.cc",
        "cloud/user_cloud_policy_store_unittest.cc",
      ]
    }
  }

  if (is_win || is_mac) {
    sources += [ "policy_loader_common_unittest.cc" ]
  }

  if (is_win || is_mac || is_linux) {
    sources += [
      "cloud/profile_cloud_policy_manager_unittest.cc",
      "cloud/profile_cloud_policy_store_unittest.cc",
    ]
  }

  if (is_android) {
    sources += [
      "android/android_combined_policy_provider_unittest.cc",
      "android/policy_converter_unittest.cc",
      "android/policy_map_android_unittest.cc",
      "android/policy_service_android_unittest.cc",
    ]
  } else {
    sources += [ "async_policy_provider_unittest.cc" ]
  }
  if (!is_android && !is_ios) {
    sources += [
      "cloud/cloud_external_data_store_unittest.cc",
      "cloud/component_cloud_policy_service_unittest.cc",
      "cloud/component_cloud_policy_store_unittest.cc",
      "cloud/component_cloud_policy_updater_unittest.cc",
      "cloud/encrypted_reporting_job_configuration_unittest.cc",
      "cloud/external_policy_data_fetcher_unittest.cc",
      "cloud/external_policy_data_updater_unittest.cc",
      "cloud/realtime_reporting_job_configuration_unittest.cc",
      "cloud/resource_cache_unittest.cc",
      "config_dir_policy_loader_unittest.cc",
    ]
  }
  if (is_apple) {
    sources += [ "mac_util_unittest.cc" ]

    if (is_mac) {
      sources += [ "policy_loader_mac_unittest.cc" ]
    }

    if (is_ios) {
      sources += [ "policy_loader_ios_unittest.mm" ]
    }
  }
  if (is_win || is_linux || is_chromeos) {
    # Needed by policy_loader_win_unittest.cc
    data = [ "//chrome/test/data/policy/" ]
  }
  if (is_win) {
    sources += [
      "policy_loader_win_unittest.cc",
      "scoped_critical_policy_section_unittest.cc",
    ]
  }
  if (is_chromeos_lacros) {
    sources += [ "policy_loader_lacros_unittest.cc" ]
  }

  deps = [
    ":common_constants",
    ":test_support",
    "//base",
    "//base/test:test_support",
    "//build:chromeos_buildflags",
    "//components/account_id",
    "//components/invalidation:test_support",
    "//components/invalidation/impl:test_support",
    "//components/policy:generated",
    "//components/prefs:test_support",
    "//components/version_info:version_info",
    "//extensions/buildflags",
    "//google_apis",
    "//net:test_support",
    "//services/network:test_support",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/libxml:xml_reader",
    "//ui/base",
  ]
  if (is_chromeos_ash) {
    deps += [ "//chromeos/ash/components/system" ]
  }
  if (is_android) {
    deps += [ "//components/policy/android:test_jni_headers" ]
  }
  if (is_chromeos_lacros) {
    deps += [
      "//chrome/browser",
      "//chromeos/crosapi/mojom",
      "//chromeos/lacros",
      "//chromeos/lacros:test_support",
      "//chromeos/startup:startup",
    ]
  }
}

fuzzer_test("policy_schema_fuzzer") {
  sources = [ "schema_fuzzer.cc" ]
  deps = [
    ":internal",
    "//base",
  ]
}