# 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.
if (is_android) {
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//third_party/jni_zero/jni_zero.gni")
}
import("//components/optimization_guide/features.gni")
import("//testing/libfuzzer/fuzzer_test.gni")
static_library("internal") {
#TODO(crbug.com/347191610): Refactor code to eliminate visibility
#requirement below for `visited_url_ranking`.
visibility = [
":*",
"//chrome/browser",
"//chrome/browser/segmentation_platform:*",
"//chrome/test:*",
"//components/segmentation_platform/embedder/*",
"//components/visited_url_ranking/internal/*",
"//ios/chrome/browser/segmentation_platform/model:*",
]
sources = [
"config_parser.cc",
"config_parser.h",
"constants.cc",
"constants.h",
"data_collection/training_data_cache.cc",
"data_collection/training_data_cache.h",
"data_collection/training_data_collector.cc",
"data_collection/training_data_collector.h",
"data_collection/training_data_collector_impl.cc",
"data_collection/training_data_collector_impl.h",
"database/cached_result_provider.cc",
"database/cached_result_provider.h",
"database/cached_result_writer.cc",
"database/cached_result_writer.h",
"database/client_result_prefs.cc",
"database/client_result_prefs.h",
"database/config_holder.cc",
"database/config_holder.h",
"database/database_maintenance.h",
"database/database_maintenance_impl.cc",
"database/database_maintenance_impl.h",
"database/segment_info_cache.cc",
"database/segment_info_cache.h",
"database/segment_info_database.cc",
"database/segment_info_database.h",
"database/signal_database.h",
"database/signal_database_impl.cc",
"database/signal_database_impl.h",
"database/signal_key.cc",
"database/signal_key.h",
"database/signal_key_internal.cc",
"database/signal_key_internal.h",
"database/signal_sample_view.cc",
"database/signal_sample_view.h",
"database/signal_storage_config.cc",
"database/signal_storage_config.h",
"database/storage_service.cc",
"database/storage_service.h",
"database/ukm_database.cc",
"database/ukm_database.h",
"database/ukm_database_backend.cc",
"database/ukm_database_backend.h",
"database/ukm_database_impl.cc",
"database/ukm_database_impl.h",
"database/ukm_metrics_table.cc",
"database/ukm_metrics_table.h",
"database/ukm_types.cc",
"database/ukm_types.h",
"database/ukm_url_table.cc",
"database/ukm_url_table.h",
"database/uma_metrics_table.cc",
"database/uma_metrics_table.h",
"database_client_impl.cc",
"database_client_impl.h",
"dummy_segmentation_platform_service.cc",
"dummy_segmentation_platform_service.h",
"dummy_ukm_data_manager.cc",
"dummy_ukm_data_manager.h",
"execution/execution_request.cc",
"execution/execution_request.h",
"execution/model_execution_status.h",
"execution/model_executor.h",
"execution/model_executor_impl.cc",
"execution/model_executor_impl.h",
"execution/model_manager.h",
"execution/model_manager_impl.cc",
"execution/model_manager_impl.h",
"execution/processing/custom_input_processor.cc",
"execution/processing/custom_input_processor.h",
"execution/processing/feature_aggregator.h",
"execution/processing/feature_aggregator_impl.cc",
"execution/processing/feature_aggregator_impl.h",
"execution/processing/feature_list_query_processor.cc",
"execution/processing/feature_list_query_processor.h",
"execution/processing/feature_processor_state.cc",
"execution/processing/feature_processor_state.h",
"execution/processing/processing_utils.cc",
"execution/processing/processing_utils.h",
"execution/processing/query_processor.h",
"execution/processing/sql_feature_processor.cc",
"execution/processing/sql_feature_processor.h",
"execution/processing/sync_device_info_observer.cc",
"execution/processing/sync_device_info_observer.h",
"execution/processing/uma_feature_processor.cc",
"execution/processing/uma_feature_processor.h",
"local_state_helper_impl.cc",
"local_state_helper_impl.h",
"logging.cc",
"logging.h",
"metadata/feature_query.cc",
"metadata/feature_query.h",
"metadata/metadata_utils.cc",
"metadata/metadata_utils.h",
"metadata/metadata_writer.cc",
"metadata/metadata_writer.h",
"metrics/field_trial_recorder.cc",
"metrics/field_trial_recorder.h",
"migration/adaptive_toolbar_migration.cc",
"migration/adaptive_toolbar_migration.h",
"migration/binary_classifier_migration.cc",
"migration/binary_classifier_migration.h",
"migration/migration_test_utils.cc",
"migration/migration_test_utils.h",
"migration/prefs_migrator.cc",
"migration/prefs_migrator.h",
"migration/result_migration_utils.cc",
"migration/result_migration_utils.h",
"platform_options.cc",
"platform_options.h",
"post_processor/post_processor.cc",
"post_processor/post_processor.h",
"scheduler/execution_service.cc",
"scheduler/execution_service.h",
"scheduler/model_execution_scheduler.h",
"scheduler/model_execution_scheduler_impl.cc",
"scheduler/model_execution_scheduler_impl.h",
"segment_id_convertor.cc",
"segment_id_convertor.h",
"segmentation_platform_service_impl.cc",
"segmentation_platform_service_impl.h",
"segmentation_ukm_helper.cc",
"segmentation_ukm_helper.h",
"selection/experimental_group_recorder.cc",
"selection/experimental_group_recorder.h",
"selection/request_dispatcher.cc",
"selection/request_dispatcher.h",
"selection/request_handler.cc",
"selection/request_handler.h",
"selection/result_refresh_manager.cc",
"selection/result_refresh_manager.h",
"selection/segment_result_provider.cc",
"selection/segment_result_provider.h",
"selection/segment_score_provider.cc",
"selection/segment_score_provider.h",
"selection/segment_selector.h",
"selection/segment_selector_impl.cc",
"selection/segment_selector_impl.h",
"selection/segmentation_result_prefs.cc",
"selection/segmentation_result_prefs.h",
"selection/selection_utils.cc",
"selection/selection_utils.h",
"service_proxy_impl.cc",
"service_proxy_impl.h",
"signals/histogram_signal_handler.cc",
"signals/histogram_signal_handler.h",
"signals/history_delegate_impl.cc",
"signals/history_delegate_impl.h",
"signals/history_service_observer.cc",
"signals/history_service_observer.h",
"signals/signal_filter_processor.cc",
"signals/signal_filter_processor.h",
"signals/signal_handler.cc",
"signals/signal_handler.h",
"signals/ukm_config.cc",
"signals/ukm_config.h",
"signals/ukm_observer.cc",
"signals/ukm_observer.h",
"signals/url_signal_handler.cc",
"signals/url_signal_handler.h",
"signals/user_action_signal_handler.cc",
"signals/user_action_signal_handler.h",
"stats.cc",
"stats.h",
"ukm_data_manager.h",
"ukm_data_manager_impl.cc",
"ukm_data_manager_impl.h",
]
deps = [
"//components/database_utils:database_utils",
"//components/history/core/browser:browser",
"//components/keyed_service/core",
"//components/leveldb_proto",
"//components/prefs",
"//components/segmentation_platform/internal/proto",
"//components/segmentation_platform/public/proto",
"//components/sync_device_info",
"//components/ukm:ukm_recorder",
"//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders",
"//sql:sql",
"//url:url",
]
public_deps = [
"//base",
"//components/optimization_guide/proto:optimization_guide_proto",
"//components/segmentation_platform/public",
]
if (is_android) {
sources += [
"android/execution/processing/custom_device_utils.cc",
"android/execution/processing/custom_device_utils.h",
"android/segmentation_platform_service_android.cc",
"android/segmentation_platform_service_android.h",
]
deps += [ ":jni_headers" ]
}
}
if (build_with_tflite_lib) {
static_library("optimization_guide_segmentation_handler") {
sources = [
"execution/optimization_guide/optimization_guide_segmentation_model_handler.cc",
"execution/optimization_guide/optimization_guide_segmentation_model_handler.h",
"execution/optimization_guide/optimization_guide_segmentation_model_provider.cc",
"execution/optimization_guide/optimization_guide_segmentation_model_provider.h",
"execution/optimization_guide/segmentation_model_executor.cc",
"execution/optimization_guide/segmentation_model_executor.h",
]
deps = [
":internal",
"//base",
"//components/optimization_guide/core",
"//components/segmentation_platform/internal/proto",
"//components/segmentation_platform/public",
]
}
}
source_set("unit_tests") {
testonly = true
visibility = [ "//components/segmentation_platform:unit_tests" ]
# IMPORTANT NOTE: When adding new tests, also remember to update the list of
# tests in //components/segmentation_platform/components_unittests.filter
sources = [
"config_parser_unittest.cc",
"data_collection/training_data_cache_unittest.cc",
"data_collection/training_data_collector_impl_unittest.cc",
"database/cached_result_provider_unittest.cc",
"database/cached_result_writer_unittest.cc",
"database/client_result_prefs_unittest.cc",
"database/database_maintenance_impl_unittest.cc",
"database/mock_signal_database.cc",
"database/mock_signal_database.h",
"database/mock_signal_storage_config.cc",
"database/mock_signal_storage_config.h",
"database/mock_ukm_database.cc",
"database/mock_ukm_database.h",
"database/segment_info_cache_unittest.cc",
"database/segment_info_database_unittest.cc",
"database/signal_database_impl_unittest.cc",
"database/signal_key_internal_unittest.cc",
"database/signal_key_unittest.cc",
"database/signal_sample_view_unittest.cc",
"database/signal_storage_config_unittest.cc",
"database/test_segment_info_database.cc",
"database/test_segment_info_database.h",
"database/ukm_database_backend_unittest.cc",
"database/ukm_database_test_utils.cc",
"database/ukm_database_test_utils.h",
"database/ukm_metrics_table_unittest.cc",
"database/ukm_url_table_unittest.cc",
"database/uma_metrics_table_unittest.cc",
"database_client_impl_unittest.cc",
"dummy_segmentation_platform_service_unittest.cc",
"execution/model_executor_impl_unittest.cc",
"execution/model_manager_impl_unittest.cc",
"execution/processing/custom_input_processor_unittest.cc",
"execution/processing/feature_aggregator_impl_unittest.cc",
"execution/processing/feature_list_query_processor_unittest.cc",
"execution/processing/mock_feature_aggregator.cc",
"execution/processing/mock_feature_aggregator.h",
"execution/processing/mock_feature_list_query_processor.cc",
"execution/processing/mock_feature_list_query_processor.h",
"execution/processing/query_processor.h",
"execution/processing/sql_feature_processor_unittest.cc",
"execution/processing/sync_device_info_observer_unittest.cc",
"execution/processing/uma_feature_processor_unittest.cc",
"metadata/metadata_utils_unittest.cc",
"metrics/field_trial_recorder_unittest.cc",
"migration/prefs_migrator_unittest.cc",
"migration/result_migration_utils_unittest.cc",
"mock_ukm_data_manager.cc",
"mock_ukm_data_manager.h",
"post_processor/post_processing_test_utils.cc",
"post_processor/post_processing_test_utils.h",
"post_processor/post_processor_unittest.cc",
"scheduler/model_execution_scheduler_unittest.cc",
"segmentation_platform_service_impl_unittest.cc",
"segmentation_platform_service_test_base.cc",
"segmentation_platform_service_test_base.h",
"segmentation_ukm_helper_unittest.cc",
"selection/request_dispatcher_unittest.cc",
"selection/request_handler_unittest.cc",
"selection/result_refresh_manager_unittest.cc",
"selection/segment_result_provider_unittest.cc",
"selection/segment_score_provider_unittest.cc",
"selection/segment_selector_unittest.cc",
"selection/segmentation_result_prefs_unittest.cc",
"selection/selection_utils_unittest.cc",
"service_proxy_impl_unittest.cc",
"signals/histogram_signal_handler_unittest.cc",
"signals/history_delegate_impl_unittest.cc",
"signals/mock_histogram_signal_handler.cc",
"signals/mock_histogram_signal_handler.h",
"signals/mock_user_action_signal_handler.cc",
"signals/mock_user_action_signal_handler.h",
"signals/signal_filter_processor_unittest.cc",
"signals/ukm_config_unittest.cc",
"signals/ukm_observer_unittest.cc",
"signals/url_signal_handler_unittest.cc",
"signals/user_action_signal_handler_unittest.cc",
"stats_unittest.cc",
"ukm_data_manager_impl_unittest.cc",
]
deps = [
":internal",
":test_support",
"//base",
"//base/test:test_support",
"//components/history/core/browser:browser",
"//components/history/core/test",
"//components/leveldb_proto:test_support",
"//components/optimization_guide/core",
"//components/optimization_guide/core:test_support",
"//components/prefs",
"//components/prefs:test_support",
"//components/segmentation_platform/internal/proto",
"//components/segmentation_platform/public",
"//components/sync_device_info",
"//components/sync_device_info:test_support",
"//components/ukm:test_support",
"//services/metrics/public/cpp:metrics_cpp",
"//services/metrics/public/cpp:ukm_builders",
"//sql:sql",
"//sql:test_support",
"//testing/gmock",
"//testing/gtest",
"//url:url",
]
if (build_with_tflite_lib) {
# IMPORTANT NOTE: When adding new tests, also remember to update the list of
# tests in //components/segmentation_platform/components_unittests.filter
sources += [
"execution/optimization_guide/optimization_guide_segmentation_model_provider_unittest.cc",
"execution/optimization_guide/segmentation_model_executor_unittest.cc",
]
deps += [
":optimization_guide_segmentation_handler",
":unit_tests_bundle_data",
]
}
}
source_set("test_support") {
testonly = true
sources = [
"execution/mock_model_provider.cc",
"execution/mock_model_provider.h",
]
deps = [
"//base",
"//components/segmentation_platform/public:public",
"//testing/gmock",
"//testing/gtest",
]
}
bundle_data("unit_tests_bundle_data") {
visibility = [ ":unit_tests" ]
testonly = true
sources = [ "//components/test/data/segmentation_platform/adder.tflite" ]
outputs = [ "{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}" ]
}
if (is_android) {
android_library("internal_java") {
visibility = [
":javatests",
"//chrome/android:chrome_all_java",
]
srcjar_deps = [ ":jni_headers" ]
sources = [
"android/java/src/org/chromium/components/segmentation_platform/SegmentationPlatformServiceImpl.java",
"android/java/src/org/chromium/components/segmentation_platform/execution/processing/CustomDeviceUtils.java",
]
deps = [
"//base:base_java",
"//build/android:build_java",
"//components/optimization_guide/proto:optimization_guide_proto_java",
"//components/segmentation_platform/public:public_java",
"//third_party/jni_zero:jni_zero_java",
]
}
generate_jni("jni_headers") {
visibility = [
":*",
"//chrome/browser",
]
sources = [
"android/java/src/org/chromium/components/segmentation_platform/SegmentationPlatformServiceImpl.java",
"android/java/src/org/chromium/components/segmentation_platform/execution/processing/CustomDeviceUtils.java",
]
}
}
fuzzer_test("segmentation_platform_config_parser_fuzzer") {
deps = [ ":internal" ]
sources = [ "config_parser_fuzzer.cc" ]
}