chromium/third_party/blink/renderer/platform/scheduler/BUILD.gn

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

import("//testing/libfuzzer/fuzzer_test.gni")
import("//third_party/blink/renderer/platform/platform.gni")
import("//third_party/protobuf/proto_library.gni")

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

blink_platform_sources("scheduler") {
  sources = [
    "common/auto_advancing_virtual_time_domain.cc",
    "common/auto_advancing_virtual_time_domain.h",
    "common/back_forward_cache_disabling_feature_tracker.cc",
    "common/back_forward_cache_disabling_feature_tracker.h",
    "common/blink_scheduler_single_thread_task_runner.cc",
    "common/blink_scheduler_single_thread_task_runner.h",
    "common/cancelable_closure_holder.cc",
    "common/cancelable_closure_holder.h",
    "common/cooperative_scheduling_manager.cc",
    "common/dummy_schedulers.cc",
    "common/event_loop.cc",
    "common/features.cc",
    "common/features.h",
    "common/frame_or_worker_scheduler.cc",
    "common/idle_helper.cc",
    "common/idle_helper.h",
    "common/metrics_helper.cc",
    "common/metrics_helper.h",
    "common/pollable_thread_safe_flag.cc",
    "common/pollable_thread_safe_flag.h",
    "common/post_cancellable_task.cc",
    "common/process_state.cc",
    "common/process_state.h",
    "common/process_time_override_coordinator.cc",
    "common/process_time_override_coordinator.h",
    "common/scheduler_helper.cc",
    "common/scheduler_helper.h",
    "common/scheduling_lifecycle_state.cc",
    "common/simple_main_thread_scheduler.cc",
    "common/simple_main_thread_scheduler.h",
    "common/single_thread_idle_task_runner.cc",
    "common/single_thread_idle_task_runner.h",
    "common/task_priority.cc",
    "common/task_priority.h",
    "common/thread.cc",
    "common/thread_cpu_throttler.cc",
    "common/thread_load_tracker.cc",
    "common/thread_load_tracker.h",
    "common/thread_scheduler.cc",
    "common/thread_scheduler_base.cc",
    "common/thread_scheduler_base.h",
    "common/thread_type.cc",
    "common/throttling/budget_pool.cc",
    "common/throttling/budget_pool.h",
    "common/throttling/cpu_time_budget_pool.cc",
    "common/throttling/cpu_time_budget_pool.h",
    "common/throttling/task_queue_throttler.cc",
    "common/throttling/task_queue_throttler.h",
    "common/throttling/type.cc",
    "common/throttling/type.h",
    "common/throttling/wake_up_budget_pool.cc",
    "common/throttling/wake_up_budget_pool.h",
    "common/tracing_helper.cc",
    "common/tracing_helper.h",
    "common/ukm_task_sampler.cc",
    "common/ukm_task_sampler.h",
    "common/web_scheduling_priority.cc",
    "common/web_thread_scheduler.cc",
    "common/worker_pool.cc",
    "main_thread/agent_group_scheduler_impl.cc",
    "main_thread/agent_group_scheduler_impl.h",
    "main_thread/attribution_group.h",
    "main_thread/deadline_task_runner.cc",
    "main_thread/deadline_task_runner.h",
    "main_thread/find_in_page_budget_pool_controller.cc",
    "main_thread/find_in_page_budget_pool_controller.h",
    "main_thread/frame_origin_type.cc",
    "main_thread/frame_origin_type.h",
    "main_thread/frame_scheduler_impl.cc",
    "main_thread/frame_scheduler_impl.h",
    "main_thread/frame_status.cc",
    "main_thread/frame_task_queue_controller.cc",
    "main_thread/frame_task_queue_controller.h",
    "main_thread/idle_time_estimator.cc",
    "main_thread/idle_time_estimator.h",
    "main_thread/main_thread_impl.cc",
    "main_thread/main_thread_impl.h",
    "main_thread/main_thread_metrics_helper.cc",
    "main_thread/main_thread_metrics_helper.h",
    "main_thread/main_thread_scheduler_helper.cc",
    "main_thread/main_thread_scheduler_helper.h",
    "main_thread/main_thread_scheduler_impl.cc",
    "main_thread/main_thread_scheduler_impl.h",
    "main_thread/main_thread_task_queue.cc",
    "main_thread/main_thread_task_queue.h",
    "main_thread/main_thread_web_scheduling_task_queue_impl.cc",
    "main_thread/main_thread_web_scheduling_task_queue_impl.h",
    "main_thread/memory_purge_manager.cc",
    "main_thread/memory_purge_manager.h",
    "main_thread/page_scheduler_impl.cc",
    "main_thread/page_scheduler_impl.h",
    "main_thread/page_visibility_state.cc",
    "main_thread/page_visibility_state.h",
    "main_thread/pending_user_input.cc",
    "main_thread/pending_user_input.h",
    "main_thread/policy_updater.cc",
    "main_thread/policy_updater.h",
    "main_thread/render_widget_signals.cc",
    "main_thread/render_widget_signals.h",
    "main_thread/task_type_names.cc",
    "main_thread/task_type_names.h",
    "main_thread/use_case.cc",
    "main_thread/use_case.h",
    "main_thread/user_model.cc",
    "main_thread/user_model.h",
    "main_thread/web_agent_group_scheduler.cc",
    "main_thread/web_scoped_virtual_time_pauser.cc",
    "main_thread/widget_scheduler_impl.cc",
    "main_thread/widget_scheduler_impl.h",
    "public/agent_group_scheduler.h",
    "public/aggregated_metric_reporter.h",
    "public/compositor_thread_scheduler.h",
    "public/cooperative_scheduling_manager.h",
    "public/dummy_schedulers.h",
    "public/event_loop.h",
    "public/feature_and_js_location_blocking_bfcache.cc",
    "public/feature_and_js_location_blocking_bfcache.h",
    "public/frame_or_worker_scheduler.h",
    "public/frame_scheduler.h",
    "public/frame_status.h",
    "public/main_thread.h",
    "public/main_thread_scheduler.h",
    "public/non_main_thread.h",
    "public/page_scheduler.h",
    "public/post_cancellable_task.h",
    "public/post_cross_thread_task.h",
    "public/rail_mode_observer.h",
    "public/scheduling_lifecycle_state.h",
    "public/scheduling_policy.h",
    "public/task_attribution_info.h",
    "public/task_attribution_tracker.h",
    "public/thread.h",
    "public/thread_cpu_throttler.h",
    "public/thread_scheduler.h",
    "public/thread_type.h",
    "public/virtual_time_controller.h",
    "public/web_scheduling_priority.h",
    "public/web_scheduling_queue_type.h",
    "public/web_scheduling_task_queue.h",
    "public/widget_scheduler.h",
    "public/worker_pool.h",
    "public/worker_scheduler.h",
    "worker/compositor_metrics_helper.cc",
    "worker/compositor_metrics_helper.h",
    "worker/compositor_thread.cc",
    "worker/compositor_thread.h",
    "worker/compositor_thread_scheduler_impl.cc",
    "worker/compositor_thread_scheduler_impl.h",
    "worker/non_main_thread_impl.cc",
    "worker/non_main_thread_impl.h",
    "worker/non_main_thread_scheduler_base.cc",
    "worker/non_main_thread_scheduler_base.h",
    "worker/non_main_thread_scheduler_helper.cc",
    "worker/non_main_thread_scheduler_helper.h",
    "worker/non_main_thread_task_queue.cc",
    "worker/non_main_thread_task_queue.h",
    "worker/non_main_thread_web_scheduling_task_queue_impl.cc",
    "worker/non_main_thread_web_scheduling_task_queue_impl.h",
    "worker/worker_scheduler_impl.cc",
    "worker/worker_scheduler_impl.h",
    "worker/worker_scheduler_proxy.cc",
    "worker/worker_scheduler_proxy.h",
    "worker/worker_thread_scheduler.cc",
    "worker/worker_thread_scheduler.h",
  ]

  deps = [
    "//base",
    "//cc",
    "//components/miracle_parameter/common",
    "//device/base/synchronization",
    "//services/metrics/public/cpp:ukm_builders",
    "//services/metrics/public/mojom",
    "//third_party/blink/renderer/platform:allow_discouraged_type",
    "//third_party/blink/renderer/platform:make_platform_generated",
    "//third_party/blink/renderer/platform/heap:heap",
    "//third_party/blink/renderer/platform/instrumentation",
    "//third_party/blink/renderer/platform/wtf",
    "//v8",
  ]

  allow_circular_includes_from = [
    "//third_party/blink/renderer/platform/heap:heap",
    "//third_party/blink/renderer/platform/instrumentation",
  ]
}

source_set("test_support") {
  testonly = true

  sources = [
    "test/fake_agent_group_scheduler_scheduler.h",
    "test/fake_frame_scheduler.h",
    "test/fake_page_scheduler.h",
    "test/fake_task_runner.cc",
    "test/fake_task_runner.h",
    "test/fake_widget_scheduler.cc",
    "test/fake_widget_scheduler.h",
    "test/recording_task_time_observer.cc",
    "test/recording_task_time_observer.h",
    "test/renderer_scheduler_test_support.cc",
    "test/web_fake_thread_scheduler.cc",
    "test/web_scheduling_test_helper.cc",
    "test/web_scheduling_test_helper.h",
  ]

  deps = [
    "//base",
    "//base/test:test_support",
    "//mojo/public/cpp/bindings",
    "//skia",
    "//testing/gmock",
    "//third_party/blink/public:test_headers",
    "//third_party/blink/public/mojom:mojom_platform_blink_headers",
    "//third_party/blink/renderer/platform:platform",
  ]

  configs += [ "//third_party/blink/renderer/platform:blink_platform_config" ]
}

source_set("unit_tests") {
  testonly = true

  sources = [
    "common/auto_advancing_virtual_time_domain_unittest.cc",
    "common/back_forward_cache_disabling_feature_tracker_unittest.cc",
    "common/blink_scheduler_single_thread_task_runner_unittest.cc",
    "common/cooperative_scheduling_manager_unittest.cc",
    "common/idle_helper_unittest.cc",
    "common/post_cancellable_task_unittest.cc",
    "common/process_time_override_coordinator_unittest.cc",
    "common/scheduler_helper_unittest.cc",
    "common/thread_load_tracker_unittest.cc",
    "common/thread_unittest.cc",
    "common/throttling/budget_pool_unittest.cc",
    "common/throttling/task_queue_throttler_unittest.cc",
    "common/tracing_helper_unittest.cc",
    "common/ukm_task_sampler_unittest.cc",
    "common/worker_pool_unittest.cc",
    "main_thread/deadline_task_runner_unittest.cc",
    "main_thread/frame_scheduler_impl_unittest.cc",
    "main_thread/frame_task_queue_controller_unittest.cc",
    "main_thread/idle_time_estimator_unittest.cc",
    "main_thread/main_thread_metrics_helper_unittest.cc",
    "main_thread/main_thread_perftest.cc",
    "main_thread/main_thread_scheduler_impl_unittest.cc",
    "main_thread/main_thread_unittest.cc",
    "main_thread/memory_purge_manager_unittest.cc",
    "main_thread/page_scheduler_impl_unittest.cc",
    "main_thread/pending_user_input_unittest.cc",
    "main_thread/render_widget_signals_unittest.cc",
    "main_thread/user_model_unittest.cc",
    "worker/non_main_thread_impl_unittest.cc",
    "worker/worker_scheduler_impl_unittest.cc",
    "worker/worker_scheduler_proxy_unittest.cc",
    "worker/worker_thread_scheduler_unittest.cc",
  ]

  deps = [
    "//base",
    "//base/test:test_support",
    "//components/ukm:test_support",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/blink/public:test_support",
    "//third_party/googletest:gmock",
  ]

  configs += [ "//third_party/blink/renderer/platform:blink_platform_config" ]
}

source_set("scheduler_fuzzer_tests") {
  testonly = true

  sources = []
  deps = [
    "//base",
    "//base/test:test_support",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/blink/renderer/platform/scheduler:test_support",
  ]

  if (is_linux || is_chromeos || is_fuchsia) {
    sources += [
      "test/fuzzer/sequence_manager_fuzzer_processor.cc",
      "test/fuzzer/sequence_manager_fuzzer_processor.h",
      "test/fuzzer/sequence_manager_fuzzer_processor_unittest.cc",
      "test/fuzzer/simple_thread_impl.cc",
      "test/fuzzer/simple_thread_impl.h",
      "test/fuzzer/task_queue_with_voters.h",
      "test/fuzzer/thread_manager.cc",
      "test/fuzzer/thread_manager.h",
      "test/fuzzer/thread_pool_manager.cc",
      "test/fuzzer/thread_pool_manager.h",
    ]

    deps += [
      ":sequence_manager_test_description_proto",
      "//third_party/blink/renderer/platform:platform",
      "//third_party/libprotobuf-mutator",
    ]
  }

  configs += [ "//third_party/blink/renderer/platform:blink_platform_config" ]
}

fuzzer_test("sequence_manager_fuzzer") {
  sources = [
    "test/fuzzer/sequence_manager_fuzzer.cc",
    "test/fuzzer/sequence_manager_fuzzer_processor.cc",
    "test/fuzzer/sequence_manager_fuzzer_processor.h",
    "test/fuzzer/simple_thread_impl.cc",
    "test/fuzzer/simple_thread_impl.h",
    "test/fuzzer/task_queue_with_voters.h",
    "test/fuzzer/thread_manager.cc",
    "test/fuzzer/thread_manager.h",
    "test/fuzzer/thread_pool_manager.cc",
    "test/fuzzer/thread_pool_manager.h",
  ]

  deps = [
    ":sequence_manager_test_description_proto",
    "//base/test:test_support",
    "//third_party/blink/renderer/platform:blink_fuzzer_test_support",
    "//third_party/blink/renderer/platform:platform",
    "//third_party/blink/renderer/platform:test_support",
    "//third_party/libprotobuf-mutator",
  ]
}

proto_library("sequence_manager_test_description_proto") {
  sources = [ "test/fuzzer/proto/sequence_manager_test_description.proto" ]
}

if (is_android) {
  java_cpp_features("java_features_srcjar") {
    # External code should depend on ":blink_scheduler_java" instead.
    visibility = [ ":*" ]
    sources =
        [ "//third_party/blink/renderer/platform/scheduler/common/features.cc" ]
    template = "//third_party/blink/renderer/platform/scheduler/common/android/java_templates/BlinkSchedulerFeatures.java.tmpl"
  }

  android_library("blink_scheduler_java") {
    # Right now, this only includes the Java features. But if we need more Java
    # files, they should be added here as necessary.
    srcjar_deps = [ ":java_features_srcjar" ]
  }
}