chromium/remoting/host/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/linux/pkg_config.gni")
import("//build/util/process_version.gni")
import("//remoting/build/config/remoting_build.gni")
import("//remoting/build/config/remoting_logging.gni")
import("//third_party/webrtc/webrtc.gni")

assert(!remoting_use_x11 || is_linux, "X11 is only supported on Linux")

group("all_tests") {
  testonly = true

  deps = [ ":unit_tests" ]
}

group("all") {
  testonly = true

  deps = [ ":host" ]
  if (enable_me2me_host) {
    deps += [ "//remoting/host:remoting_me2me_host" ]
  }

  if (is_chrome_branded) {
    deps += [ ":remoting_host_branded" ]
  }

  if (!is_chromeos && !is_android && !is_ios) {
    deps += [
      "//remoting/host:remoting_native_messaging_host",
      "//remoting/host:remoting_native_messaging_manifests",
      "//remoting/host:remoting_start_host",
      "//remoting/host/it2me:remote_assistance_host",
      "//remoting/host/webauthn:remote_webauthn",
    ]

    if (is_linux || is_win) {
      deps += [ "//remoting/host/crash:remoting_crash_uploader" ]
    }

    if (enable_me2me_host && (is_linux || is_win)) {
      deps += [ "//remoting/host/remote_open_url" ]
    }
  }
}

process_version("remoting_version") {
  template_file = "//remoting/host/version.h.in"
  sources = [ branding_path ]
  output = "$target_gen_dir/version.h"
}

# ChromeOS enterprise parameters used in common host classes.
# Split out in its own target to prevent GN from pulling in chromeos deps.
source_set("enterprise_params") {
  sources = [ "//remoting/host/chromeos/chromeos_enterprise_params.h" ]
}

source_set("host") {
  public_deps = [
    ":common",
    "//remoting/host/base",
  ]
  deps = [ "//remoting/host/file_transfer" ]
}

source_set("host_main_headers") {
  visibility = [
    ":*",
    "//remoting/host/crash:crash_uploader_main_headers",
    "//remoting/host/it2me:main_headers",
    "//remoting/host/mac:remoting_native_messaging_host",
    "//remoting/host/mac:remoting_native_messaging_host_executable",
    "//remoting/host/remote_open_url:remote_open_url_main_headers",
    "//remoting/host/security_key:remote_security_key_main_headers",
    "//remoting/host/setup:native_messaging_host_main_headers",
    "//remoting/host/setup:start_host_main_headers",
    "//remoting/host/webauthn:remote_webauthn_main_headers",
    "//remoting/host/win:remoting_console",
    "//remoting/host/win:remoting_core",
    "//remoting/host/win:remoting_desktop",
    "//remoting/host/win:remoting_me2me_host",
  ]
  sources = [
    "host_export.h",
    "host_main.h",
  ]
}

source_set("capturer_interfaces") {
  visibility = [ ":*" ]
  sources = [ "desktop_and_cursor_composer.h" ]
  deps = [
    "//base:base",
    "//third_party/webrtc_overrides:webrtc_component",
  ]
}

source_set("common_headers") {
  visibility = [ "//remoting/host/*" ]
  sources = [
    "action_executor.h",
    "audio_capturer.h",
    "audio_silence_detector.h",
    "audio_volume_filter.h",
    "basic_desktop_environment.h",
    "desktop_and_cursor_conditional_composer.h",
    "desktop_environment.h",
    "evaluate_capability.h",
    "input_injector.h",
    "input_injector_metadata.h",
    "sas_injector.h",
    "usage_stats_consent.h",
    "worker_process_ipc_delegate.h",
  ]
  if (!is_chromeos_ash) {
    sources += [ "me2me_desktop_environment.h" ]
  }
  deps = [
    ":capturer_interfaces",
    "//ipc",
    "//remoting/base",
    "//remoting/host/base",
    "//remoting/protocol",
  ]
}

source_set("ipc_constants") {
  sources = [
    "ipc_constants.cc",
    "ipc_constants.h",
  ]
  deps = [
    "//base",
    "//components/named_mojo_ipc_server",
    "//mojo/public/cpp/platform",
    "//remoting/host/base",
  ]
}

source_set("chromoting_host_services_client") {
  sources = [
    "chromoting_host_services_client.cc",
    "chromoting_host_services_client.h",
    "chromoting_host_services_provider.h",
  ]
  deps = [
    ":ipc_constants",
    "//base",
    "//components/named_mojo_ipc_server",
    "//mojo/public/cpp/platform",
    "//remoting/host/mojom",
  ]
  if (is_win) {
    deps += [ "//remoting/host/win:acl_util" ]
  }
}

# Split up from common to avoid circular dependency.
source_set("client_session_control") {
  sources = [ "client_session_control.h" ]

  deps = [
    "//remoting/protocol",
    "//ui/events:events",
  ]
}

source_set("clipboard") {
  sources = [ "clipboard.h" ]

  deps = [
    "//base",
    "//remoting/base:base",
    "//remoting/host/base",
    "//remoting/proto",
    "//remoting/protocol",
  ]

  if (remoting_use_x11) {
    sources += [ "clipboard_x11.cc" ]

    deps += [
      "//remoting/host/linux:x11",
      "//ui/gfx/x",
    ]
  }

  if (is_mac) {
    sources += [ "clipboard_mac.mm" ]
  }

  if (is_win) {
    sources += [ "clipboard_win.cc" ]
  }
}

source_set("settings") {
  sources = [
    "host_setting_keys.h",
    "user_setting_keys.h",
  ]
  public_deps = [ "//remoting/base:settings" ]
}

source_set("host_extension") {
  sources = [
    "client_session_details.h",
    "host_extension.h",
    "host_extension_session.h",
  ]
}

source_set("resources") {
  sources = [ "resources.h" ]
  deps = [
    "//base",
    "//ui/base",
  ]

  if (is_linux || is_chromeos) {
    sources += [ "resources_linux.cc" ]
  }

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

  if (is_win) {
    sources += [ "resources_win.cc" ]
  }
}

if (is_linux) {
  pkg_config("xkbcommon") {
    packages = [ "xkbcommon" ]
  }
}

# This must be a static library instead of a source set because
# remoting_unittests requires that remoting_me2me_host.cc not be pulled in,
# which in turn depends on remoting_me2me_host_static which isn't part of that
# build.
#
# TODO fix this, successful builds should not depend on static libraries
# stripping code.
static_library("common") {
  sources = [
    "action_executor.cc",
    "action_message_handler.cc",
    "action_message_handler.h",
    "active_display_monitor.cc",
    "active_display_monitor.h",
    "audio_capturer.cc",
    "audio_silence_detector.cc",
    "audio_volume_filter.cc",
    "backoff_timer.cc",
    "backoff_timer.h",
    "basic_desktop_environment.cc",
    "branding.cc",
    "branding.h",
    "chromoting_host.cc",
    "chromoting_host.h",
    "chromoting_host_context.cc",
    "chromoting_host_context.h",
    "client_session.cc",
    "client_session.h",
    "client_session_events.h",
    "config_file_watcher.cc",
    "config_file_watcher.h",
    "config_watcher.h",
    "continue_window.cc",
    "continue_window.h",
    "corp_host_status_logger.cc",
    "corp_host_status_logger.h",
    "crash_process.cc",
    "crash_process.h",
    "curtain_mode.h",
    "daemon_process.cc",
    "daemon_process.h",
    "desktop_and_cursor_composer.h",
    "desktop_and_cursor_composer_notifier.cc",
    "desktop_and_cursor_composer_notifier.h",
    "desktop_and_cursor_conditional_composer.cc",
    "desktop_capturer_checker.cc",
    "desktop_capturer_checker.h",
    "desktop_capturer_proxy.cc",
    "desktop_capturer_proxy.h",
    "desktop_capturer_wrapper.cc",
    "desktop_capturer_wrapper.h",
    "desktop_display_info.cc",
    "desktop_display_info.h",
    "desktop_display_info_loader.h",
    "desktop_display_info_monitor.cc",
    "desktop_display_info_monitor.h",
    "desktop_process.cc",
    "desktop_process.h",
    "desktop_resizer.h",
    "desktop_session.cc",
    "desktop_session.h",
    "desktop_session_agent.cc",
    "desktop_session_agent.h",
    "desktop_session_connector.h",
    "desktop_session_proxy.cc",
    "desktop_session_proxy.h",
    "evaluate_capability.cc",
    "ftl_echo_message_listener.cc",
    "ftl_echo_message_listener.h",
    "ftl_host_change_notification_listener.cc",
    "ftl_host_change_notification_listener.h",
    "ftl_signaling_connector.cc",
    "ftl_signaling_connector.h",
    "heartbeat_sender.cc",
    "heartbeat_sender.h",
    "host_attributes.cc",
    "host_attributes.h",
    "host_config.cc",
    "host_config.h",
    "host_details.cc",
    "host_details.h",
    "host_event_logger.h",
    "host_event_reporter.h",
    "host_experiment_session_plugin.cc",
    "host_experiment_session_plugin.h",
    "host_extension_session_manager.cc",
    "host_extension_session_manager.h",
    "host_power_save_blocker.cc",
    "host_power_save_blocker.h",
    "host_secret.cc",
    "host_secret.h",
    "host_status_logger.cc",
    "host_status_logger.h",
    "host_status_monitor.cc",
    "host_status_monitor.h",
    "host_status_observer.h",
    "host_window.cc",
    "host_window.h",
    "host_window_proxy.cc",
    "host_window_proxy.h",
    "ipc_action_executor.cc",
    "ipc_action_executor.h",
    "ipc_audio_capturer.cc",
    "ipc_audio_capturer.h",
    "ipc_desktop_environment.cc",
    "ipc_desktop_environment.h",
    "ipc_host_event_logger.cc",
    "ipc_host_event_logger.h",
    "ipc_input_injector.cc",
    "ipc_input_injector.h",
    "ipc_keyboard_layout_monitor.cc",
    "ipc_keyboard_layout_monitor.h",
    "ipc_mouse_cursor_monitor.cc",
    "ipc_mouse_cursor_monitor.h",
    "ipc_screen_controls.cc",
    "ipc_screen_controls.h",
    "ipc_url_forwarder_configurator.cc",
    "ipc_url_forwarder_configurator.h",
    "ipc_video_frame_capturer.cc",
    "ipc_video_frame_capturer.h",
    "it2me_desktop_environment.cc",
    "it2me_desktop_environment.h",
    "keyboard_layout_monitor.cc",
    "keyboard_layout_monitor.h",
    "mojo_caller_security_checker.cc",
    "mojo_caller_security_checker.h",
    "mojo_video_capturer.cc",
    "mojo_video_capturer.h",
    "mojo_video_capturer_list.cc",
    "mojo_video_capturer_list.h",
    "mouse_cursor_monitor_proxy.cc",
    "mouse_cursor_monitor_proxy.h",
    "mouse_shape_pump.cc",
    "mouse_shape_pump.h",
    "pairing_registry_delegate.cc",
    "pairing_registry_delegate.h",
    "passthrough_register_support_host_request.cc",
    "passthrough_register_support_host_request.h",
    "pin_hash.cc",
    "pin_hash.h",
    "policy_watcher.cc",
    "policy_watcher.h",
    "register_support_host_request.h",
    "remote_input_filter.cc",
    "remote_input_filter.h",
    "remoting_register_support_host_request.cc",
    "remoting_register_support_host_request.h",
    "resizing_host_observer.cc",
    "resizing_host_observer.h",
    "server_log_entry_host.cc",
    "server_log_entry_host.h",
    "session_policies_from_dict.cc",
    "session_policies_from_dict.h",
    "shutdown_watchdog.cc",
    "shutdown_watchdog.h",
    "test_echo_extension.cc",
    "test_echo_extension.h",
    "test_echo_extension_session.cc",
    "test_echo_extension_session.h",
    "video_memory_utils.cc",
    "video_memory_utils.h",
    "xmpp_register_support_host_request.cc",
    "xmpp_register_support_host_request.h",
    "xsession_chooser_ui.inc",
    "zombie_host_detector.cc",
    "zombie_host_detector.h",
  ]

  # ChromotingHostServices currently only works on Linux and Windows.
  if (is_linux || is_win) {
    sources += [
      "chromoting_host_services_server.cc",
      "chromoting_host_services_server.h",
    ]
  }

  libs = []

  configs += [
    "//build/config/compiler:wexit_time_destructors",
    "//remoting/build/config:version",
  ]

  defines = [ "WEBRTC_CHROMIUM_BUILD" ]

  deps = [
    ":client_session_control",
    ":clipboard",
    ":display_layout",
    ":host_main_headers",
    ":ipc_constants",
    ":resources",
    ":settings",
    "//base:i18n",
    "//build:branding_buildflags",
    "//build:chromeos_buildflags",
    "//components/named_mojo_ipc_server",
    "//components/policy/core/common",
    "//components/webrtc:thread_wrapper",
    "//crypto",
    "//google_apis",
    "//ipc:protobuf_support",
    "//media",
    "//remoting/base",
    "//remoting/base:authorization",
    "//remoting/base:errors",
    "//remoting/base:session_policies",
    "//remoting/host/file_transfer:common",
    "//remoting/host/input_monitor",
    "//remoting/host/mojom",
    "//remoting/host/remote_open_url:common",
    "//remoting/host/security_key",
    "//remoting/host/webauthn",
    "//remoting/proto/ftl/v1:ftl_messages",
    "//remoting/proto/remoting/v1:chrome_os_enterprise_options",
    "//remoting/proto/remoting/v1:remote_support_host_messages",
    "//remoting/protocol",
    "//remoting/resources",
    "//remoting/signaling:signaling",
    "//services/network:network_service",
    "//services/network/public/cpp:cpp",
    "//third_party/libjingle_xmpp:rtc_xmllite",
    "//third_party/webrtc_overrides:webrtc_component",
    "//ui/events:events",

    # //remoting uses the power_save_blocker directly. See crbug.com/689423
    "//services/device/wake_lock/power_save_blocker",
    "//ui/base",
    "//ui/events:dom_keycode_converter",
    "//ui/events/platform",
  ]

  public_deps = [
    ":common_headers",
    ":enterprise_params",
    ":host_extension",
    "//ipc",
    "//remoting/host/base",
    "//remoting/proto",
    "//remoting/proto/remoting/v1:directory_proto",
  ]

  if (is_posix) {
    sources += [
      "host_event_logger_posix.cc",
      "posix/signal_handler.cc",
      "posix/signal_handler.h",
    ]

    if (!is_android) {
      deps += [ "//components/policy/core/common:policy_path_constants" ]
    }
  }

  if (!is_ios) {
    deps += [ "//components/policy:generated" ]
  }

  if (is_linux) {
    sources += [
      "host_utmp_logger.cc",
      "host_utmp_logger.h",
    ]

    libs += [
      "utempter",
      "util",
    ]

    if (ozone_platform_wayland) {
      deps += [ "//ui/events/platform/wayland:wayland_event_watcher" ]
    }
  }

  if (is_linux) {
    sources += [
      "desktop_resizer_linux.cc",
      "linux/audio_pipe_reader.cc",
      "linux/audio_pipe_reader.h",
      "linux/certificate_watcher.cc",
      "linux/certificate_watcher.h",
    ]

    libs += [ "pam" ]

    deps += [ "//build/config/linux/gtk" ]

    if (remoting_use_x11) {
      deps += [ "linux:x11" ]
    }
  }

  if (remoting_use_x11) {
    assert(use_glib)
    defines += [ "REMOTING_USE_X11" ]
    sources -= [ "active_display_monitor.cc" ]
    sources += [
      "active_display_monitor_linux.cc",
      "curtain_mode_linux.cc",
      "desktop_display_info_loader_linux.cc",
      "desktop_display_info_loader_x11.cc",
      "desktop_display_info_loader_x11.h",
      "desktop_resizer_x11.cc",
      "desktop_resizer_x11.h",
      "input_injector_constants_linux.h",
      "input_injector_linux.cc",
      "input_injector_x11.cc",
      "input_injector_x11.h",
      "keyboard_layout_monitor_linux.cc",
      "linux/active_display_monitor_x11.cc",
      "linux/active_display_monitor_x11.h",
      "linux/clipboard_portal.cc",
      "linux/clipboard_portal.h",
      "linux/clipboard_portal_injector.cc",
      "linux/clipboard_portal_injector.h",
      "linux/clipboard_wayland.cc",
      "linux/clipboard_wayland.h",
      "linux/desktop_display_info_loader_wayland.cc",
      "linux/desktop_display_info_loader_wayland.h",
      "linux/desktop_resizer_wayland.cc",
      "linux/desktop_resizer_wayland.h",
      "linux/ei_event_watcher_glib.cc",
      "linux/ei_event_watcher_glib.h",
      "linux/input_injector_wayland.cc",
      "linux/input_injector_wayland.h",
      "linux/remote_desktop_portal.cc",
      "linux/remote_desktop_portal.h",
      "linux/remote_desktop_portal_injector.cc",
      "linux/remote_desktop_portal_injector.h",
      "linux/wayland_connection.cc",
      "linux/wayland_connection.h",
      "linux/wayland_desktop_capturer.cc",
      "linux/wayland_desktop_capturer.h",
      "linux/wayland_display.cc",
      "linux/wayland_display.h",
      "linux/wayland_display_info.cc",
      "linux/wayland_display_info.h",
      "linux/wayland_keyboard.cc",
      "linux/wayland_keyboard.h",
      "linux/wayland_manager.cc",
      "linux/wayland_manager.h",
      "linux/wayland_seat.cc",
      "linux/wayland_seat.h",
    ]
    libs += [ "//third_party/libei/cipd/lib64/libei.a" ]
    public_deps += [
      "//third_party/wayland:wayland_client",
      "//third_party/wayland-protocols:xdg_output_protocol",
    ]
    deps += [
      ":x11_display_utils",
      "//remoting/host/linux:wayland",
      "//ui/base/x",
      "//ui/events/platform/x11",
      "//ui/gfx/x",
      "//ui/gtk:gtk_config",
    ]
    public_configs = [ ":xkbcommon" ]
  }

  if (is_linux) {
    sources += [
      "audio_capturer_linux.cc",
      "audio_capturer_linux.h",
      "continue_window_linux.cc",
      "disconnect_window_linux.cc",
      "pairing_registry_delegate_linux.cc",
      "pairing_registry_delegate_linux.h",
      "usage_stats_consent_linux.cc",
      "xsession_chooser_linux.cc",
    ]
    if (remoting_use_x11) {
      sources += [
        "linux/keyboard_layout_monitor_utils.cc",
        "linux/keyboard_layout_monitor_utils.h",
        "linux/keyboard_layout_monitor_wayland.cc",
        "linux/keyboard_layout_monitor_wayland.h",
      ]
    }

    # WebRTC only enables portal support if PipeWire support is enabled
    if (rtc_use_pipewire) {
      configs += [ "//third_party/webrtc/modules/portal:gio" ]
    }
  }

  if (is_chromeos_ash) {
    sources += [
      "audio_capturer_chromeos.cc",
      "continue_window_chromeos.cc",
      "curtain_mode_chromeos.cc",
      "curtain_mode_chromeos.h",
      "desktop_display_info_loader_chromeos.cc",
      "disconnect_window_chromeos.cc",
      "input_injector_chromeos.cc",
      "input_injector_chromeos.h",
      "keyboard_layout_monitor_chromeos.cc",
    ]
    deps += [
      "//ash",
      "//remoting/host/chromeos",
      "//remoting/host/chromeos:features",
      "//ui/base/ime/ash",
    ]

    if (use_ozone) {
      deps += [
        "//ui/events/ozone/layout",
        "//ui/ozone",
      ]
    }
  } else {
    sources += [ "me2me_desktop_environment.cc" ]
  }

  if (is_mac) {
    sources += [
      "audio_capturer_mac.cc",
      "audio_capturer_mac.h",
      "continue_window_mac.mm",
      "curtain_mode_mac.cc",
      "desktop_display_info_loader_mac.mm",
      "desktop_resizer_mac.cc",
      "disconnect_window_mac.h",
      "disconnect_window_mac.mm",
      "input_injector_mac.cc",
      "keyboard_layout_monitor_mac.cc",
      "pairing_registry_delegate_mac.cc",
      "usage_stats_consent_mac.cc",
    ]
    frameworks = [
      "Accelerate.framework",
      "AudioToolbox.framework",
      "Carbon.framework",
      "CoreAudio.framework",
    ]

    deps += [
      ":remoting_version",
      "//remoting/host/base",
      "//remoting/host/mac:permission_checking",
      "//ui/events:events",
    ]
  }

  if (is_win) {
    sources += [
      "audio_capturer_win.cc",
      "audio_capturer_win.h",
      "continue_window_win.cc",
      "curtain_mode_win.cc",
      "daemon_process_win.cc",
      "desktop_display_info_loader_win.cc",
      "desktop_resizer_win.cc",
      "desktop_session_win.cc",
      "desktop_session_win.h",
      "disconnect_window_win.cc",
      "host_event_logger_win.cc",
      "input_injector_win.cc",
      "keyboard_layout_monitor_win.cc",
      "pairing_registry_delegate_win.cc",
      "pairing_registry_delegate_win.h",
      "sas_injector_win.cc",
      "touch_injector_win.cc",
      "touch_injector_win.h",
      "usage_stats_consent_win.cc",
    ]
    libs += [ "crypt32.lib" ]
    deps += [
      # On Windows, we use //media/gpu/MediaFoundationVideoEncodeAcceleratorWin
      # to detect whether HW encoder is supported by the system.
      "//media",
      "//media/gpu:gpu",
      "//mojo/core/embedder:embedder",
      "//remoting/base:breakpad",
      "//remoting/host/crash:crash_uploader",
      "//remoting/host/win",
      "//remoting/host/win:messages",
      "//remoting/host/win:remoting_lib_idl",
      "//remoting/host/win:trust_util",
    ]
    public_deps += [ "//remoting/host/win" ]
  }
}

source_set("display_layout") {
  sources = [
    "desktop_display_layout_util.cc",
    "desktop_display_layout_util.h",
    "desktop_geometry.cc",
    "desktop_geometry.h",
  ]
  deps = [ "//ui/gfx" ]
}

if (is_linux && (ozone_platform_x11 || remoting_use_x11)) {
  source_set("x11_display_utils") {
    sources = [
      "linux/gnome_display_config.cc",
      "linux/gnome_display_config.h",
      "linux/gnome_display_config_dbus_client.cc",
      "linux/gnome_display_config_dbus_client.h",
      "linux/scoped_glib.cc",
      "linux/scoped_glib.h",
      "x11_crtc_resizer.cc",
      "x11_crtc_resizer.h",
      "x11_desktop_resizer.cc",
      "x11_desktop_resizer.h",
      "x11_display_util.cc",
      "x11_display_util.h",
    ]
    deps = [
      ":display_layout",
      "//build/config/linux/gtk",
      "//remoting/base:logging",
      "//remoting/host/linux:x11",
      "//third_party/webrtc_overrides:webrtc_component",
      "//ui/base",
      "//ui/base/x",
      "//ui/gfx/geometry",
    ]
  }
}

static_library("test_support") {
  testonly = true

  sources = [
    "fake_active_display_monitor.cc",
    "fake_active_display_monitor.h",
    "fake_desktop_environment.cc",
    "fake_desktop_environment.h",
    "fake_host_extension.cc",
    "fake_host_extension.h",
    "fake_keyboard_layout_monitor.cc",
    "fake_keyboard_layout_monitor.h",
    "fake_mouse_cursor_monitor.cc",
    "fake_mouse_cursor_monitor.h",
    "host_mock_objects.cc",
    "host_mock_objects.h",
  ]

  configs += [ "//remoting/build/config:version" ]

  deps = [
    ":chromoting_host_services_client",
    ":client_session_control",
    "//remoting/codec:encoder",
    "//remoting/host/base",
    "//remoting/host/file_transfer:common",
    "//remoting/host/mojom",
    "//remoting/host/remote_open_url:common",
    "//remoting/host/remote_open_url:test_support",
    "//remoting/host/security_key:security_key",
    "//remoting/host/webauthn",
    "//remoting/proto",
    "//remoting/protocol:protocol",
    "//remoting/protocol:test_support",
    "//testing/gmock",
    "//testing/gtest",
    "//ui/events:events",
  ]
  public_deps = [
    ":common",
    "//remoting/base:test_support",
    "//remoting/host/file_transfer:test_support",
    "//third_party/libjingle_xmpp:rtc_xmllite",
    "//third_party/protobuf:protobuf_lite",
    "//third_party/webrtc_overrides:webrtc_component",
  ]
}

# The host portions of the remoting unit tests.
source_set("unit_tests") {
  testonly = true

  sources = [
    "audio_silence_detector_unittest.cc",
    "audio_volume_filter_unittest.cc",
    "backoff_timer_unittest.cc",
    "chromoting_host_context_unittest.cc",
    "chromoting_host_unittest.cc",
    "client_session_unittest.cc",
    "config_file_watcher_unittest.cc",
    "corp_host_status_logger_unittest.cc",
    "daemon_process_unittest.cc",
    "desktop_display_info_unittest.cc",
    "desktop_display_layout_util_unittest.cc",
    "desktop_process_unittest.cc",
    "desktop_session_agent_unittest.cc",
    "ftl_echo_message_listener_unittest.cc",
    "ftl_host_change_notification_listener_unittest.cc",
    "ftl_signaling_connector_unittest.cc",
    "heartbeat_sender_unittest.cc",
    "host_attributes_unittest.cc",
    "host_config_unittest.cc",
    "host_experiment_session_plugin_unittest.cc",
    "host_extension_session_manager_unittest.cc",
    "host_power_save_blocker_unittest.cc",
    "host_status_logger_unittest.cc",
    "input_monitor/local_input_monitor_unittest.cc",
    "ipc_desktop_environment_unittest.cc",
    "it2me/it2me_confirmation_dialog_proxy_unittest.cc",
    "it2me/it2me_host_unittest.cc",
    "it2me/it2me_native_messaging_host_unittest.cc",
    "it2me_desktop_environment_unittest.cc",
    "mojo_video_capturer_list_unittest.cc",
    "mouse_cursor_monitor_proxy_unittest.cc",
    "mouse_shape_pump_unittest.cc",
    "native_messaging/native_messaging_reader_unittest.cc",
    "native_messaging/native_messaging_writer_unittest.cc",
    "pin_hash_unittest.cc",
    "policy_watcher_unittest.cc",
    "remote_input_filter_unittest.cc",
    "remoting_register_support_host_request_unittest.cc",
    "resizing_host_observer_unittest.cc",
    "resources_unittest.cc",
    "server_log_entry_host_unittest.cc",
    "session_policies_from_dict_unittest.cc",
    "setup/host_starter_oauth_helper_unittest.cc",
    "setup/me2me_native_messaging_host_unittest.cc",
    "setup/pin_validator_unittest.cc",
    "xmpp_register_support_host_request_unittest.cc",
    "zombie_host_detector_unittest.cc",
  ]

  if (use_ozone || is_chromeos_ash) {
    sources -= [ "input_monitor/local_input_monitor_unittest.cc" ]
  }

  configs += [ "//remoting/build/config:version" ]

  deps = [
    ":chromoting_host_services_client",
    ":client_session_control",
    ":common",
    ":display_layout",
    ":resources",
    ":test_support",
    "//build:branding_buildflags",
    "//build:chromeos_buildflags",
    "//components/named_mojo_ipc_server",
    "//components/named_mojo_ipc_server:test_support",
    "//net:test_support",
    "//remoting/base:session_policies",
    "//remoting/codec:encoder",
    "//remoting/host/base",
    "//remoting/host/file_transfer:unit_tests",
    "//remoting/host/input_monitor:input_monitor",
    "//remoting/host/it2me:common",
    "//remoting/host/it2me:constants",
    "//remoting/host/mojom",
    "//remoting/host/native_messaging",
    "//remoting/host/remote_open_url:test_support",
    "//remoting/host/remote_open_url:unit_tests",
    "//remoting/host/security_key:unit_tests",
    "//remoting/host/setup:common",
    "//remoting/host/setup:start_host_common",
    "//remoting/host/webauthn:unit_tests",
    "//remoting/proto",
    "//remoting/proto:internal_structs",
    "//remoting/proto/remoting/v1:chrome_os_enterprise_options",
    "//remoting/proto/remoting/v1:remote_support_host_messages",
    "//remoting/protocol:test_support",
    "//remoting/resources",
    "//remoting/signaling",
    "//remoting/signaling:test_support",
    "//remoting/signaling:unit_tests",
    "//services/network:test_support",
    "//skia",
    "//testing/gmock",
    "//testing/gtest",
    "//ui/base",
    "//ui/events",
  ]

  # ChromotingHostServices currently only works on Linux and Windows.
  if (is_linux || is_win) {
    sources += [
      "chromoting_host_services_client_unittest.cc",
      "chromoting_host_services_server_unittest.cc",
    ]

    deps += [ "//remoting/host:ipc_constants" ]
  }

  # start_host is only supported on Linux and Windows.
  if (is_linux || is_win) {
    sources += [ "setup/host_starter_base_unittest.cc" ]
  }

  if (is_linux) {
    deps += [
      "//remoting/host/linux:wayland",
      "//ui/gtk:gtk_config",
    ]
  }

  if (is_linux) {
    sources += [ "pairing_registry_delegate_linux_unittest.cc" ]
    deps += [ "//remoting/host/linux:unit_tests" ]
  }

  if (remoting_use_x11) {
    sources += [
      "x11_crtc_resizer_unittest.cc",
      "x11_display_util_unittest.cc",
    ]
    deps += [
      ":x11_display_utils",
      "//ui/gfx/x",
    ]
  }

  if (is_chromeos_ash) {
    sources += [
      "desktop_display_info_loader_chromeos_unittest.cc",
      "input_injector_chromeos_unittest.cc",
      "it2me/it2me_confirmation_dialog_chromeos_unittest.cc",
    ]
    deps += [
      "//ash:test_support",
      "//chromeos/ash/components:test_support",
      "//components/user_manager:test_support",
      "//remoting/host/chromeos",
      "//remoting/host/chromeos:features",
      "//remoting/host/chromeos:reporter_unit_tests",
      "//remoting/host/chromeos:unit_tests",
      "//ui/message_center:test_support",
      "//ui/ozone",
    ]
  }

  if (is_win) {
    sources += [
      "pairing_registry_delegate_win_unittest.cc",
      "touch_injector_win_unittest.cc",
    ]
    deps += [ "//remoting/host/win:unit_tests" ]
  }

  if (!is_ios) {
    deps += [ "//components/policy/core/browser:test_support" ]
  }

  if (enable_me2me_host) {
    sources += [ "evaluate_capability_unittest.cc" ]
    data_deps = [ "//remoting/test:capability_test_stub" ]
  }
}

group("remoting_host_branded") {
  testonly = true
  deps = []
  if (enable_remoting_host) {
    deps += [ ":remoting_host_installation" ]
  }
  if (enable_me2me_host) {
    deps += [ "//remoting/host:remoting_me2me_host_archive" ]
  }
}

if (enable_remoting_host) {
  group("remoting_host_installation") {
    deps = []
    if (is_win) {
      deps += [ "//remoting/host/installer/win:remoting_host_installation" ]
    }
  }
}

if (enable_remoting_host) {
  executable("remoting_start_host") {
    sources = [ "setup/start_host_entry_point.cc" ]

    deps = [ "//remoting/host/setup:start_host_main_headers" ]

    if (is_win || is_linux) {
      deps += [ ":remoting_core" ]
    } else {
      deps += [ "//remoting/host/setup:start_host_main" ]
    }

    configs += [ "//build/config/compiler:wexit_time_destructors" ]

    if (is_win) {
      defines = host_predefines +
                [ "REMOTING_HOST_BINARY=BINARY_REMOTING_START_HOST" ]

      sources += [ "$root_gen_dir/remoting/version.rc" ]

      deps += [
        "//remoting/host/win:elevated_exe_manifest",
        "//remoting/host/win:remoting_windows_resources",
      ]
    }
  }

  action_foreach("remoting_native_messaging_manifests") {
    if (is_mac) {
      me2me_host_path = "/Library/PrivilegedHelperTools/$me2me_host_bundle_name/Contents/MacOS/$native_messaging_host_bundle_name/Contents/MacOS/native_messaging_host"
      it2me_host_path = "/Library/PrivilegedHelperTools/$me2me_host_bundle_name/Contents/MacOS/$remote_assistance_host_bundle_name/Contents/MacOS/remote_assistance_host"
      remote_webauthn_path = "/Library/PrivilegedHelperTools/$me2me_host_bundle_name/Contents/MacOS/$remote_assistance_host_bundle_name/Contents/MacOS/remote_webauthn"
    } else if (is_win) {
      me2me_host_path = "remoting_native_messaging_host.exe"
      it2me_host_path = "remote_assistance_host.exe"
      remote_webauthn_path = "remote_webauthn.exe"
    } else {
      me2me_host_path =
          "/opt/google/chrome-remote-desktop/native-messaging-host"
      it2me_host_path =
          "/opt/google/chrome-remote-desktop/remote-assistance-host"
      remote_webauthn_path = "/opt/google/chrome-remote-desktop/remote-webauthn"
    }

    script = "../tools/build/remoting_localize.py"

    sources = [
      "it2me/com.google.chrome.remote_assistance-firefox.json.jinja2",
      "it2me/com.google.chrome.remote_assistance.json.jinja2",
      "setup/com.google.chrome.remote_desktop-firefox.json.jinja2",
      "setup/com.google.chrome.remote_desktop.json.jinja2",
      "setup/com.google.chrome.remote_webauthn.json.jinja2",
    ]

    inputs = [ branding_path ]

    outputs = [ "$root_build_dir/remoting/{{source_name_part}}" ]

    args = [
      "--define",
      "ME2ME_HOST_PATH=$me2me_host_path",
      "--define",
      "IT2ME_HOST_PATH=$it2me_host_path",
      "--define",
      "REMOTE_WEBAUTHN_PATH=$remote_webauthn_path",
      "--variables",
      rebase_path(branding_path, root_build_dir),
      "--template",
      "{{source}}",
      "--output",
      "remoting/{{source_name_part}}",
      "en",
    ]
  }

  if (is_mac) {
    action_foreach("remoting_infoplist_strings") {
      sources = [
        "installer/mac/uninstaller/remoting_uninstaller-InfoPlist.strings.jinja2",
        "it2me/remote_assistance_host-InfoPlist.strings.jinja2",
        "remoting_me2me_host-InfoPlist.strings.jinja2",
        "setup/native_messaging_host-InfoPlist.strings.jinja2",
      ]

      script = "//remoting/tools/build/remoting_localize.py"
      args = [
               "--locale_dir",
               rebase_path(resources_locale_dir, root_build_dir),
               "--variables",
               rebase_path(branding_path, root_build_dir),
               "--template",
               "{{source}}",
               "--locale_output",
               rebase_path(
                   "$root_gen_dir/remoting/host/{{source_name_part}}/@{json_suffix}.lproj/InfoPlist.strings",
                   root_build_dir),
             ] + remoting_locales_with_underscores

      outputs = []
      foreach(locale, remoting_locales_with_underscores) {
        outputs += [ "$root_gen_dir/remoting/host/{{source_name_part}}/$locale.lproj/InfoPlist.strings" ]
      }

      deps = [
        "//remoting/resources",
        "//remoting/resources:strings",
      ]
    }
  }
}

if (enable_me2me_host) {
  static_library("remoting_me2me_host_static") {
    sources = [ "remoting_me2me_host.cc" ]
    defines = []

    configs += [
      "//remoting/build/config:version",
      "//remoting/build/config:remoting_me2me_host",
    ]

    deps = [
      ":settings",
      "//base",
      "//base:i18n",
      "//components/policy/core/common",
      "//components/webrtc:thread_wrapper",
      "//ipc",
      "//mojo/core/embedder",
      "//net",
      "//remoting/base",
      "//remoting/base:authorization",
      "//remoting/base:session_policies",
      "//remoting/host",
      "//remoting/host/base",
      "//remoting/host/mojom",
      "//remoting/host/security_key:security_key",
      "//remoting/proto",
      "//remoting/protocol:protocol",
      "//remoting/signaling:signaling",
      "//services/network/public/cpp:cpp",
      "//third_party/libjingle_xmpp:rtc_xmllite",
      "//third_party/webrtc_overrides:webrtc_component",
    ]

    if (remoting_use_x11) {
      defines += [ "REMOTING_USE_X11" ]
      deps += [
        "//remoting/host/linux:wayland",
        "//ui/events/platform/x11:x11",
      ]
      if (is_linux) {
        deps += [ "//ui/gtk:gtk_config" ]
      }
      if (ozone_platform_wayland) {
        deps += [ "//ui/events/platform/wayland:wayland_event_watcher" ]
      }
    }

    if (is_posix) {
      sources += [
        "pam_authorization_factory_posix.cc",
        "pam_authorization_factory_posix.h",
      ]
    }

    if (!is_ios) {
      deps += [ "//components/policy:generated" ]
    }

    if (is_linux || is_chromeos_lacros) {
      deps += [ "//build/config/linux/gtk" ]
    }
    if (is_linux || is_chromeos_lacros || is_mac) {
      libs = [ "pam" ]
    }

    if (is_mac) {
      deps += [ "//remoting/host/mac:permission_checking" ]
    }
  }

  source_set("main") {
    configs += [
      "//remoting/build/config:host_implementation",
      "//remoting/build/config:version",
    ]
    sources = [ "host_main.cc" ]
    deps = [
      ":common",
      ":host_main_headers",
      ":remoting_me2me_host_static",
      ":resources",
      "//base",
      "//base:debugging_buildflags",
      "//mojo/core/embedder:embedder",
      "//remoting/base",
      "//remoting/base:breakpad",
      "//remoting/host/base",
      "//remoting/host/setup:common",
    ]
  }

  # Windows defines its own entry point function.
  # TODO(yuweih): Enable shared library on Mac.
  if (!is_win) {
    source_set("entry_point") {
      sources = [ "entry_point.cc" ]
      deps = [ ":host_main_headers" ]
      if (is_mac) {
        deps += [ ":main" ]
      } else {
        deps += [ ":remoting_core" ]
      }
    }
  }

  if (is_win || is_linux) {
    group("implementation") {
      deps = [
        ":main",
        "//remoting/host/crash:crash_uploader_main",
        "//remoting/host/it2me:main",
        "//remoting/host/remote_open_url:main",
        "//remoting/host/setup:native_messaging_host_main",
        "//remoting/host/setup:start_host_main",
        "//remoting/host/webauthn:main",
      ]
      if (is_win) {
        deps += [ "//remoting/host/security_key:main" ]
      }
    }
    if (is_win) {
      group("remoting_core") {
        deps = [ "//remoting/host/win:remoting_core" ]
      }
    } else {
      shared_library("remoting_core") {
        deps = [ ":implementation" ]

        if (!is_component_build) {
          # Set rpath on dependent executables so that they can find the shared
          # lib in the same directory, in a non-component build.
          all_dependent_configs =
              [ "//build/config/gcc:rpath_for_built_shared_libraries" ]
        }
      }
    }
  }

  if (is_win) {
    group("remoting_me2me_host") {
      deps = [ "//remoting/host/win:remoting_me2me_host" ]
    }
    group("remoting_native_messaging_host") {
      deps = [ "//remoting/host/win:remoting_native_messaging_host" ]
    }
  } else {
    if (is_mac) {
      group("remoting_me2me_host") {
        deps = [ "//remoting/host/mac:remoting_me2me_host" ]
      }
    } else {
      executable("remoting_me2me_host") {
        deps = [ ":entry_point" ]

        # https://crbug.com/1198747
        assert_no_deps = [ "//ui/gtk" ]
      }
    }

    if (is_mac) {
      group("remoting_native_messaging_host") {
        deps = [ "//remoting/host/mac:remoting_native_messaging_host" ]
      }
    } else {
      group("remoting_native_messaging_host") {
        public_deps = [ "//remoting/host/linux:remoting_native_messaging_host" ]
      }
    }
  }
  if (is_chrome_branded && enable_me2me_host &&
      (is_linux || is_chromeos_lacros)) {
    group("remoting_me2me_host_archive") {
      deps = [ "//remoting/host/installer/linux:remoting_me2me_host_archive" ]
    }
  } else if (is_win) {
    group("remoting_me2me_host_archive") {
      deps = [ "//remoting/host/installer/win:remoting_me2me_host_archive" ]
    }
  } else if (is_mac) {
    group("remoting_me2me_host_archive") {
      deps = [ "//remoting/host/installer/mac:remoting_me2me_host_archive" ]
    }
  } else {
    group("remoting_me2me_host_archive") {
    }
  }
}