chromium/components/download/public/common/BUILD.gn

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

import("//mojo/public/tools/bindings/mojom.gni")

if (is_android) {
  import("//build/config/android/config.gni")
  import("//build/config/android/rules.gni")
  import("//third_party/jni_zero/jni_zero.gni")
}

config("components_download_implementation") {
  defines = [ "COMPONENTS_DOWNLOAD_IMPLEMENTATION" ]
}

component("public") {
  sources = [
    "all_download_event_notifier.h",
    "base_file.h",
    "download_content.h",
    "download_create_info.h",
    "download_danger_type.cc",
    "download_danger_type.h",
    "download_destination_observer.cc",
    "download_destination_observer.h",
    "download_features.cc",
    "download_features.h",
    "download_file.cc",
    "download_file.h",
    "download_file_factory.h",
    "download_file_impl.h",
    "download_interrupt_reason_values.h",
    "download_interrupt_reasons.h",
    "download_interrupt_reasons_utils.h",
    "download_item.cc",
    "download_item.h",
    "download_item_factory.cc",
    "download_item_factory.h",
    "download_item_impl.h",
    "download_item_impl_delegate.h",
    "download_item_rename_handler.h",
    "download_job.h",
    "download_job_factory.h",
    "download_path_reservation_tracker.h",
    "download_response_handler.h",
    "download_save_info.cc",
    "download_save_info.h",
    "download_save_item_data.cc",
    "download_save_item_data.h",
    "download_source.h",
    "download_start_observer.h",
    "download_stats.h",
    "download_target_info.cc",
    "download_target_info.h",
    "download_task_runner.h",
    "download_ukm_helper.h",
    "download_url_parameters.cc",
    "download_url_parameters.h",
    "download_utils.h",
    "in_progress_download_manager.h",
    "input_stream.cc",
    "input_stream.h",
    "parallel_download_configs.h",
    "quarantine_connection.h",
    "rate_estimator.h",
    "resume_mode.h",
    "simple_download_manager.h",
    "simple_download_manager_coordinator.h",
    "stream_handle_input_stream.h",
    "url_download_handler_factory.h",
    "url_download_request_handle.h",
    "url_loader_factory_provider.h",
  ]

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

  public_deps = [
    ":interfaces",
    "//base",
    "//components/download/network",
    "//components/download/public/background_service:public",
    "//components/keyed_service/core",
    "//components/services/quarantine/public/mojom",
    "//mojo/public/cpp/bindings",
    "//services/device/public/mojom",
    "//services/network/public/cpp",
    "//services/network/public/mojom:url_loader_base",
  ]

  deps = [
    "//components/download/database",
    "//components/download/internal/common:internal",
    "//components/services/quarantine:quarantine",
    "//crypto",
    "//mojo/public/c/system",
    "//net",
    "//services/metrics/public/cpp:metrics_cpp",
    "//services/network/public/cpp",
    "//ui/base",
  ]

  allow_circular_includes_from = [
    "//components/download/internal/common:internal",
    "//components/download/database",
  ]

  if (is_win && is_component_build) {
    ldflags = [ "/IGNORE:4217" ]
  }

  if (is_android) {
    sources += [
      "android/auto_resumption_handler.cc",
      "android/auto_resumption_handler.h",
    ]
  }

  if (is_chromeos) {
    sources += [
      "download_item_utils.cc",
      "download_item_utils.h",
    ]
    deps += [ "//chromeos/crosapi/mojom" ]
  }
}

if (is_android) {
  android_library("public_java") {
    srcjar_deps = [ ":jni_enums" ]

    deps = [
      "//components/download/internal/common:internal_java",
      "//third_party/androidx:androidx_annotation_annotation_java",
    ]
  }

  java_cpp_enum("jni_enums") {
    sources = [
      "download_item.h",
      "resume_mode.h",
    ]
  }
}

mojom("interfaces") {
  sources = [ "download_stream.mojom" ]

  export_class_attribute = "COMPONENTS_DOWNLOAD_EXPORT"
  export_define = "COMPONENTS_DOWNLOAD_IMPLEMENTATION=1"
  export_header = "components/download/public/common/download_export.h"
}

source_set("test_support") {
  testonly = true

  sources = [
    "mock_download_file.cc",
    "mock_download_file.h",
    "mock_download_item.cc",
    "mock_download_item.h",
    "mock_download_item_impl.cc",
    "mock_download_item_impl.h",
    "mock_input_stream.cc",
    "mock_input_stream.h",
    "mock_simple_download_manager.cc",
    "mock_simple_download_manager.h",
  ]

  public_deps = [
    ":public",
    "//base",
    "//components/download/database",
    "//net",
    "//services/service_manager/public/cpp:cpp",
    "//testing/gmock",
    "//url",
  ]

  if (is_android) {
    deps = [ "//components/download/internal/common:internal_java" ]
  }
}

source_set("unit_tests") {
  testonly = true

  sources = []

  if (is_android) {
    sources += [ "android/auto_resumption_handler_unittest.cc" ]
  }

  deps = [
    ":public",
    ":test_support",
    "//base/test:test_support",
    "//components/download/public/task:test_support",
    "//services/network:test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]
}