chromium/components/commerce/core/BUILD.gn

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

import("//third_party/protobuf/proto_library.gni")

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

source_set("public") {
  sources = [
    "discount_consent_handler.h",
    "shopping_prompt.h",
  ]
}

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

  deps = [
    ":commerce_types",
    "//base",
    "//url",
  ]
}

source_set("feature_list") {
  sources = [
    "commerce_feature_list.cc",
    "commerce_feature_list.h",
    "flag_descriptions.cc",
    "flag_descriptions.h",
  ]
  deps = [
    ":commerce_heuristics_data",
    ":pref_names",
    "//base",
    "//components/flags_ui",
    "//components/prefs",
    "//components/search",
    "//third_party/re2:re2",
    "//url:url",
  ]
}

source_set("feature_utils") {
  sources = [
    "feature_utils.cc",
    "feature_utils.h",
  ]
  deps = [
    ":account_checker",
    ":feature_list",
    ":pref_names",
    "product_specifications",
    "//components/optimization_guide/core:features",
    "//components/prefs",
    "//components/sync/base",
  ]
}

source_set("feature_list_unittests") {
  testonly = true
  sources = [ "commerce_feature_list_unittest.cc" ]
  deps = [
    ":commerce_heuristics_data",
    ":feature_list",
    ":pref_names",
    ":shopping_service_test_support",
    "//base",
    "//base/test:test_support",
    "//components/prefs:test_support",
    "//testing/gtest",
    "//third_party/re2:re2",
  ]
}

static_library("metrics") {
  sources = [
    "metrics/discounts_metric_collector.cc",
    "metrics/discounts_metric_collector.h",
    "metrics/metrics_utils.cc",
    "metrics/metrics_utils.h",
  ]

  deps = [
    ":account_checker",
    ":feature_list",
    ":proto",
    "//base",
    "//components/optimization_guide/core",
    "//components/optimization_guide/proto:optimization_guide_proto",
    "//components/prefs",
    "//services/metrics/public/cpp:metrics_cpp",
    "//services/metrics/public/cpp:ukm_builders",
  ]
}

proto_library("proto") {
  proto_in_dir = "//"
  sources = [
    "proto/discounts.proto",
    "proto/merchant_trust.proto",
    "proto/parcel.proto",
    "proto/price_insights.proto",
    "proto/price_tracking.proto",
    "proto/product_category.proto",
    "proto/shopping_page_types.proto",
  ]
}

if (is_android) {
  proto_java_library("proto_java") {
    proto_path = "//"
    sources = [
      "proto/price_tracking.proto",
      "proto/product_category.proto",
    ]
  }

  proto_library("merchant_signal_db_proto") {
    proto_in_dir = "//"
    sources = [ "proto/merchant_signal_db_content.proto" ]
  }
} else {
  proto_library("cart_db_content_proto") {
    proto_in_dir = "//"
    sources = [ "proto/cart_db_content.proto" ]
  }

  proto_library("coupon_db_content_proto") {
    proto_in_dir = "//"
    sources = [ "proto/coupon_db_content.proto" ]
  }
}

proto_library("parcel_tracking_db_content_proto") {
  proto_in_dir = "//"
  sources = [ "proto/parcel_tracking_db_content.proto" ]
  deps = [ ":proto" ]
}

proto_library("persisted_state_db_content_proto") {
  proto_in_dir = "//"
  sources = [ "proto/persisted_state_db_content.proto" ]
}

proto_library("commerce_subscription_db_content_proto") {
  proto_in_dir = "//"
  sources = [ "proto/commerce_subscription_db_content.proto" ]
}

proto_library("discounts_db_content_proto") {
  proto_in_dir = "//"
  sources = [ "proto/discounts_db_content.proto" ]
}

source_set("commerce_heuristics_data") {
  sources = [
    "commerce_heuristics_data.cc",
    "commerce_heuristics_data.h",
    "commerce_heuristics_data_metrics_helper.cc",
    "commerce_heuristics_data_metrics_helper.h",
  ]

  deps = [
    "//base",
    "//third_party/re2:re2",
  ]
}

source_set("commerce_heuristics_data_unittests") {
  testonly = true
  sources = [ "commerce_heuristics_data_unittest.cc" ]
  deps = [
    ":commerce_heuristics_data",
    "//base",
    "//base/test:test_support",
    "//testing/gtest",
    "//third_party/re2:re2",
  ]
}

source_set("heuristics_provider") {
  sources = [
    "heuristics/commerce_heuristics_provider.cc",
    "heuristics/commerce_heuristics_provider.h",
  ]

  deps = [
    ":commerce_heuristics_data",
    ":feature_list",
    "//base",
    "//components/resources:components_resources_grit",
    "//net",
    "//third_party/re2:re2",
    "//ui/base",
    "//url:url",
  ]
}

source_set("heuristics_provider_unittests") {
  testonly = true
  sources = [ "heuristics/commerce_heuristics_provider_unittest.cc" ]
  deps = [
    ":feature_list",
    ":heuristics_provider",
    "//base",
    "//base/test:test_support",
    "//components/prefs:test_support",
    "//testing/gtest",
    "//third_party/re2:re2",
    "//url:url",
  ]
}

static_library("shopping_service") {
  sources = [
    "bookmark_update_manager.cc",
    "bookmark_update_manager.h",
    "discounts_storage.cc",
    "discounts_storage.h",
    "metrics/scheduled_metrics_manager.cc",
    "metrics/scheduled_metrics_manager.h",
    "price_tracking_utils.cc",
    "price_tracking_utils.h",
    "shopping_bookmark_model_observer.cc",
    "shopping_bookmark_model_observer.h",
    "shopping_power_bookmark_data_provider.cc",
    "shopping_power_bookmark_data_provider.h",
    "shopping_service.cc",
    "shopping_service.h",
    "web_extractor.cc",
    "web_extractor.h",
    "web_wrapper.cc",
    "web_wrapper.h",
  ]

  deps = [
    ":commerce_constants",
    ":commerce_info_cache",
    ":commerce_subscription_db_content_proto",
    ":discounts_db_content_proto",
    ":feature_list",
    ":metrics",
    ":parcel_tracking_db_content_proto",
    ":pref_names",
    ":proto",
    ":utils",
    "//base",
    "//components/bookmarks/browser",
    "//components/commerce/core/compare",
    "//components/commerce/core/parcel:parcel",
    "//components/commerce/core/product_specifications:product_specifications",
    "//components/history/core/browser",
    "//components/keyed_service/core",
    "//components/leveldb_proto",
    "//components/optimization_guide/core",
    "//components/optimization_guide/proto:optimization_guide_proto",
    "//components/power_bookmarks/core",
    "//components/power_bookmarks/core:proto",
    "//components/prefs:prefs",
    "//components/resources:components_resources_grit",
    "//components/search:search",
    "//components/session_proto_db:core",
    "//components/signin/public/identity_manager:identity_manager",
    "//components/strings:components_strings_grit",
    "//components/sync/service",
    "//components/unified_consent",
    "//services/metrics/public/cpp:metrics_cpp",
    "//services/network/public/cpp:cpp",
    "//ui/base",
    "//url:url",
  ]

  public_deps = [
    ":account_checker",
    ":commerce_types",
    ":feature_utils",
    "//components/commerce/core/subscriptions:subscriptions",
    "//services/data_decoder/public/cpp",
  ]

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

    deps += [ "//components/commerce/core/android:core_jni" ]
  }
}

source_set("shopping_service_test_support") {
  testonly = true

  sources = [
    "mock_cluster_manager.cc",
    "mock_cluster_manager.h",
    "mock_discounts_storage.cc",
    "mock_discounts_storage.h",
    "mock_shopping_service.cc",
    "mock_shopping_service.h",
    "shopping_service_test_base.cc",
    "shopping_service_test_base.h",
    "test_utils.cc",
    "test_utils.h",
  ]

  # Expose all deps for test support.
  public_deps = [
    ":commerce_info_cache",
    ":feature_list",
    ":pref_names",
    ":shopping_service",
    "//base/test:test_support",
    "//components/bookmarks/browser",
    "//components/bookmarks/test",
    "//components/commerce/core:proto",
    "//components/commerce/core/compare:compare",
    "//components/commerce/core/product_specifications:test_support",
    "//components/commerce/core/subscriptions",
    "//components/optimization_guide/core",
    "//components/optimization_guide/core:features",
    "//components/optimization_guide/proto:optimization_guide_proto",
    "//components/power_bookmarks/core",
    "//components/prefs:test_support",
    "//components/signin/public/identity_manager:test_support",
    "//components/sync:test_support",
    "//components/unified_consent:unified_consent",
    "//services/data_decoder/public/cpp:test_support",
    "//services/network:network_service",
    "//services/network:test_support",
    "//services/network/public/cpp",
    "//testing/gmock",
    "//testing/gtest",
    "//url:url",
  ]
}

source_set("shopping_service_unit_tests") {
  testonly = true

  sources = [
    "bookmark_update_manager_unittest.cc",
    "commerce_info_cache_unittest.cc",
    "discounts_storage_unittest.cc",
    "feature_utils_unittest.cc",
    "metrics/scheduled_metrics_manager_unittest.cc",
    "pdp_metrics_unittest.cc",
    "price_tracking_utils_unittest.cc",
    "shopping_bookmark_model_observer_unittest.cc",
    "shopping_power_bookmark_data_provider_unittest.cc",
    "shopping_service_metrics_unittest.cc",
    "shopping_service_unittest.cc",
  ]

  deps = [
    ":account_checker_test_support",
    ":commerce_info_cache",
    ":discounts_db_content_proto",
    ":feature_utils",
    ":metrics",
    ":pref_names",
    ":shopping_service_test_support",
    "compare:unit_tests",
    "parcel:unit_tests",
    "product_specifications",
    "product_specifications:test_support",
    "subscriptions:test_support",
    "webui:unit_tests",
    "//components/history/core/browser",
    "//components/optimization_guide/core:features",
    "//components/search",
    "//components/ukm:test_support",
    "//services/metrics/public/cpp:ukm_builders",
  ]
}

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

  deps = [
    "//base",
    "//components/pref_registry",
    "//components/prefs",
  ]
}

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

  deps = [
    ":commerce_constants",
    ":feature_list",
    ":pref_names",
    "//base",
    "//components/endpoint_fetcher:endpoint_fetcher",
    "//components/prefs:prefs",
    "//components/signin/public/identity_manager:identity_manager",
    "//components/sync/base",
    "//components/sync/service",
    "//components/unified_consent",
    "//net/traffic_annotation:traffic_annotation",
    "//services/network/public/cpp:cpp",
    "//ui/base",
    "//url:url",
  ]

  public_deps = [ "//services/data_decoder/public/cpp" ]
}

source_set("account_checker_test_support") {
  testonly = true

  sources = [
    "mock_account_checker.cc",
    "mock_account_checker.h",
  ]

  deps = [
    ":account_checker",
    "//base",
    "//components/prefs",
    "//components/sync/base",
    "//services/network/public/cpp:cpp",
    "//testing/gmock",
  ]
}

source_set("account_checker_unittests") {
  testonly = true
  sources = [ "account_checker_unittest.cc" ]
  deps = [
    ":account_checker",
    ":commerce_constants",
    ":feature_list",
    ":pref_names",
    "//base",
    "//base/test:test_support",
    "//components/endpoint_fetcher:test_support",
    "//components/prefs:test_support",
    "//components/signin/public/identity_manager:test_support",
    "//components/sync:test_support",
    "//net/traffic_annotation:test_support",
    "//services/data_decoder/public/cpp:test_support",
    "//services/network:test_support",
    "//services/network/public/cpp:cpp",
    "//testing/gmock",
    "//testing/gtest",
    "//url:url",
  ]
}

source_set("commerce_constants") {
  sources = [ "commerce_constants.h" ]
}

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

  deps = [
    ":proto",
    "//base",
    "//url",
  ]
}

source_set("utils") {
  sources = [
    "commerce_utils.cc",
    "commerce_utils.h",
  ]
  deps = [
    ":commerce_constants",
    ":commerce_types",
    ":feature_list",
    "//net:net",
  ]
}

source_set("utils_unit_tests") {
  testonly = true

  sources = [ "commerce_utils_unittest.cc" ]

  deps = [
    ":utils",
    "//base",
    "//base/test:test_support",
    "//components/commerce/core:shopping_service_test_support",
    "//url",
  ]
}