xref: /aosp_15_r20/external/cronet/components/metrics/BUILD.gn (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2014 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/chromeos/ui_mode.gni")
6import("//build/config/cronet/config.gni")
7import("//build/config/features.gni")
8import("//testing/test.gni")
9
10if (is_android) {
11  import("//build/config/android/rules.gni")
12  import("//third_party/jni_zero/jni_zero.gni")
13}
14
15# Dependency for histogram manager users: cronet and ios/webview
16source_set("library_support") {
17  public = [
18    "histogram_encoder.h",
19    "library_support/histogram_manager.h",
20  ]
21  sources = [
22    "histogram_encoder.cc",
23    "library_support/histogram_manager.cc",
24  ]
25
26  deps = [
27    "//base",
28    "//third_party/metrics_proto",
29  ]
30}
31
32if (!is_cronet_build && is_android) {
33  generate_jni("jni_headers") {
34    namespace = "metrics"
35    sources = [
36      "android/java/src/org/chromium/components/metrics/LowEntropySource.java",
37    ]
38  }
39
40  java_cpp_features("java_features_srcjar") {
41    # External code should depend on ":foo_java" instead.
42    visibility = [ ":*" ]
43    sources = [ "//components/metrics/metrics_features.cc" ]
44    template =
45        "//components/metrics/android/java_templates/MetricsFeatures.java.tmpl"
46  }
47
48  java_cpp_strings("java_switches_srcjar") {
49    # External code should depend on ":metrics_java" instead.
50    visibility = [ ":*" ]
51    sources = [ "//components/metrics/metrics_switches.cc" ]
52    template =
53        "//components/metrics/android/java_templates/MetricsSwitches.java.tmpl"
54  }
55
56  java_cpp_enum("java_enum_srcjar") {
57    # External code should depend on ":metrics_java" instead.
58    visibility = [ ":*" ]
59    sources = [ "stability_metrics_helper.h" ]
60  }
61
62  android_library("metrics_java") {
63    # Right now, this only includes the Java switches. But if we need more Java
64    # files, they should be added here as necessary.
65    srcjar_deps = [
66      ":java_enum_srcjar",
67      ":java_features_srcjar",
68      ":java_switches_srcjar",
69    ]
70    sources = [
71      "android/java/src/org/chromium/components/metrics/LowEntropySource.java",
72    ]
73    deps = [
74      "//base:base_java",
75      "//third_party/androidx:androidx_annotation_annotation_java",
76      "//third_party/jni_zero:jni_zero_java",
77    ]
78  }
79}
80
81# Used by the Chrome installer, which doesn't need the whole metrics library.
82source_set("client_info") {
83  sources = [
84    "client_info.cc",
85    "client_info.h",
86  ]
87}
88
89# Used by the Chrome installer, which doesn't need the whole metrics library.
90source_set("metrics_pref_names") {
91  sources = [
92    "metrics_pref_names.cc",
93    "metrics_pref_names.h",
94  ]
95}
96
97if (!is_cronet_build || is_ios) {
98  static_library("metrics") {
99    sources = [
100      "android_metrics_helper.cc",
101      "android_metrics_helper.h",
102      "call_stacks/call_stack_profile_metrics_provider.cc",
103      "call_stacks/call_stack_profile_metrics_provider.h",
104      "child_histogram_fetcher_impl.cc",
105      "child_histogram_fetcher_impl.h",
106      "clean_exit_beacon.cc",
107      "clean_exit_beacon.h",
108      "cloned_install_detector.cc",
109      "cloned_install_detector.h",
110      "cpu_metrics_provider.cc",
111      "cpu_metrics_provider.h",
112      "daily_event.cc",
113      "daily_event.h",
114      "data_use_tracker.cc",
115      "data_use_tracker.h",
116      "date_changed_helper.cc",
117      "date_changed_helper.h",
118      "delegating_provider.cc",
119      "delegating_provider.h",
120      "drive_metrics_provider.cc",
121      "drive_metrics_provider.h",
122      "enabled_state_provider.cc",
123      "enabled_state_provider.h",
124      "entropy_state.cc",
125      "entropy_state.h",
126      "entropy_state_provider.cc",
127      "entropy_state_provider.h",
128      "environment_recorder.cc",
129      "environment_recorder.h",
130      "expired_histogram_util.cc",
131      "expired_histogram_util.h",
132      "expired_histograms_checker.cc",
133      "expired_histograms_checker.h",
134      "field_trials_provider.cc",
135      "field_trials_provider.h",
136      "file_metrics_provider.cc",
137      "file_metrics_provider.h",
138      "histogram_child_process.h",
139      "histogram_controller.cc",
140      "histogram_controller.h",
141      "histogram_subscriber.h",
142      "log_decoder.cc",
143      "log_decoder.h",
144      "log_store.h",
145      "machine_id_provider.h",
146      "metrics_data_validation.cc",
147      "metrics_data_validation.h",
148      "metrics_features.cc",
149      "metrics_features.h",
150      "metrics_log.cc",
151      "metrics_log.h",
152      "metrics_log_store.cc",
153      "metrics_log_store.h",
154      "metrics_log_uploader.h",
155      "metrics_logs_event_manager.cc",
156      "metrics_logs_event_manager.h",
157      "metrics_provider.cc",
158      "metrics_provider.h",
159      "metrics_reporting_default_state.cc",
160      "metrics_reporting_default_state.h",
161      "metrics_reporting_service.cc",
162      "metrics_reporting_service.h",
163      "metrics_rotation_scheduler.cc",
164      "metrics_rotation_scheduler.h",
165      "metrics_scheduler.cc",
166      "metrics_scheduler.h",
167      "metrics_service.cc",
168      "metrics_service.h",
169      "metrics_service_accessor.cc",
170      "metrics_service_accessor.h",
171      "metrics_service_client.cc",
172      "metrics_service_client.h",
173      "metrics_service_observer.cc",
174      "metrics_service_observer.h",
175      "metrics_shutdown.cc",
176      "metrics_shutdown.h",
177      "metrics_state_manager.cc",
178      "metrics_state_manager.h",
179      "metrics_switches.cc",
180      "metrics_switches.h",
181      "metrics_upload_scheduler.cc",
182      "metrics_upload_scheduler.h",
183      "persistent_histograms.cc",
184      "persistent_histograms.h",
185      "persistent_synthetic_trial_observer.cc",
186      "persistent_synthetic_trial_observer.h",
187      "persistent_system_profile.cc",
188      "persistent_system_profile.h",
189      "reporting_service.cc",
190      "reporting_service.h",
191      "sampling_metrics_provider.cc",
192      "sampling_metrics_provider.h",
193      "stability_metrics_helper.cc",
194      "stability_metrics_helper.h",
195      "stability_metrics_provider.cc",
196      "stability_metrics_provider.h",
197      "ukm_demographic_metrics_provider.h",
198      "unsent_log_store.cc",
199      "unsent_log_store.h",
200      "unsent_log_store_metrics.cc",
201      "unsent_log_store_metrics.h",
202      "unsent_log_store_metrics_impl.cc",
203      "unsent_log_store_metrics_impl.h",
204      "url_constants.h",
205      "version_utils.cc",
206      "version_utils.h",
207    ]
208
209    if (is_chrome_branded) {
210      sources += [ "internal/url_constants.cc" ]
211    } else {
212      sources += [ "url_constants.cc" ]
213    }
214
215    public_deps = [
216      "//components/metrics:client_info",
217      "//components/metrics:metrics_pref_names",
218      "//third_party/metrics_proto",
219      "//third_party/zlib/google:compression_utils",
220    ]
221
222    deps = [
223      ":library_support",
224      "//base",
225      "//base:base_static",
226      "//base:i18n",
227      "//build:branding_buildflags",
228      "//build:chromeos_buildflags",
229      "//components/flags_ui:switches",
230      "//components/metrics/public/mojom:histogram_fetcher_mojo_bindings",
231      "//components/network_time",
232      "//components/prefs",
233      "//components/variations",
234      "//components/variations/field_trial_config",
235      "//components/version_info:version_info",
236      "//crypto",
237      "//extensions/buildflags",
238      "//third_party/icu",
239      "//url",
240    ]
241
242    if (is_android) {
243      sources += [
244        "android_metrics_provider.cc",
245        "android_metrics_provider.h",
246        "drive_metrics_provider_android.cc",
247        "gms_metrics_provider.cc",
248        "gms_metrics_provider.h",
249      ]
250      deps += [ ":jni_headers" ]
251    } else {
252      deps += [ "//components/keep_alive_registry" ]
253    }
254
255    if (is_ios) {
256      sources += [
257        "clean_exit_beacon_ios.mm",
258        "drive_metrics_provider_ios.mm",
259      ]
260    }
261
262    if (is_linux || is_chromeos) {
263      sources += [
264        "drive_metrics_provider_linux.cc",
265        "psi_memory_parser.h",
266        "psi_memory_parser_linux.cc",
267      ]
268    }
269
270    if (is_mac) {
271      sources += [ "drive_metrics_provider_mac.mm" ]
272      frameworks = [
273        # The below are all needed for drive_metrics_provider_mac.mm.
274        "CoreFoundation.framework",
275        "DiskArbitration.framework",
276        "Foundation.framework",
277        "IOKit.framework",
278      ]
279    }
280
281    if (is_win) {
282      sources += [
283        "drive_metrics_provider_win.cc",
284        "machine_id_provider_win.cc",
285        "system_session_analyzer/system_session_analyzer_win.cc",
286        "system_session_analyzer/system_session_analyzer_win.h",
287      ]
288      libs = [ "wevtapi.lib" ]
289    } else {
290      sources += [ "machine_id_provider_nonwin.cc" ]
291    }
292
293    if (is_fuchsia) {
294      sources += [ "drive_metrics_provider_fuchsia.cc" ]
295    }
296
297    if (is_win || is_linux) {
298      sources += [
299        "motherboard.cc",
300        "motherboard.h",
301        "motherboard_metrics_provider.cc",
302        "motherboard_metrics_provider.h",
303      ]
304    }
305  }
306
307  static_library("test_support") {
308    testonly = true
309    sources = [
310      "test/test_enabled_state_provider.cc",
311      "test/test_enabled_state_provider.h",
312      "test/test_metrics_log_uploader.cc",
313      "test/test_metrics_log_uploader.h",
314      "test/test_metrics_provider.cc",
315      "test/test_metrics_provider.h",
316      "test/test_metrics_service_client.cc",
317      "test/test_metrics_service_client.h",
318    ]
319
320    public_deps = [ ":metrics" ]
321    deps = [ "//base" ]
322  }
323}
324
325if (!is_cronet_build) {
326  # The component metrics provider is a separate target because it depends upon
327  # (the large) component_updater code, and is not needed for some entities that
328  # depend on :metrics.
329  static_library("component_metrics") {
330    sources = [
331      "component_metrics_provider.cc",
332      "component_metrics_provider.h",
333    ]
334
335    public_deps = [ "//third_party/metrics_proto" ]
336
337    deps = [
338      ":metrics",
339      "//base",
340      "//components/component_updater",
341    ]
342  }
343
344  if (use_blink) {
345    static_library("content") {
346      sources = [
347        # ChromeOS accessibility metrics provider is in chromeos_metrics_provider.
348        "content/accessibility_metrics_provider.cc",
349        "content/accessibility_metrics_provider.h",
350        "content/content_stability_metrics_provider.cc",
351        "content/content_stability_metrics_provider.h",
352        "content/extensions_helper.h",
353        "content/gpu_metrics_provider.cc",
354        "content/gpu_metrics_provider.h",
355        "content/metrics_services_web_contents_observer.cc",
356        "content/metrics_services_web_contents_observer.h",
357        "content/rendering_perf_metrics_provider.cc",
358        "content/rendering_perf_metrics_provider.h",
359        "content/subprocess_metrics_provider.cc",
360        "content/subprocess_metrics_provider.h",
361      ]
362      public_deps = [ ":metrics" ]
363      deps = [
364        "//base",
365        "//content/public/browser",
366        "//extensions/buildflags",
367        "//gpu/config",
368      ]
369      if (is_android) {
370        deps += [ "//components/crash/content/browser" ]
371      }
372    }
373  }
374
375  static_library("net") {
376    sources = [
377      "net/cellular_logic_helper.cc",
378      "net/cellular_logic_helper.h",
379      "net/net_metrics_log_uploader.cc",
380      "net/net_metrics_log_uploader.h",
381      "net/network_metrics_provider.cc",
382      "net/network_metrics_provider.h",
383    ]
384
385    public_deps = [ ":metrics" ]
386    allow_circular_includes_from = [ ":metrics" ]
387
388    deps = [
389      "//base",
390      "//build:chromeos_buildflags",
391      "//components/encrypted_messages:encrypted_message_proto",
392      "//components/encrypted_messages:encrypted_messages",
393      "//components/variations",
394      "//net",
395      "//services/network/public/cpp",
396      "//services/network/public/mojom",
397      "//third_party/metrics_proto",
398      "//third_party/zlib/google:compression_utils",
399      "//url",
400    ]
401  }
402
403  static_library("ui") {
404    sources = [
405      "ui/form_factor_metrics_provider.cc",
406      "ui/form_factor_metrics_provider.h",
407      "ui/screen_info_metrics_provider.cc",
408      "ui/screen_info_metrics_provider.h",
409    ]
410
411    public_deps = [ ":metrics" ]
412    deps = [
413      "//base",
414      "//build/config/chromebox_for_meetings:buildflags",
415      "//ui/base",
416      "//ui/display",
417      "//ui/gfx",
418      "//ui/gfx/geometry",
419    ]
420  }
421
422  static_library("single_sample_metrics") {
423    sources = [
424      "single_sample_metrics.cc",
425      "single_sample_metrics.h",
426      "single_sample_metrics_factory_impl.cc",
427      "single_sample_metrics_factory_impl.h",
428    ]
429
430    deps = [
431      "//mojo/public/cpp/bindings",
432      "//services/service_manager/public/cpp",
433      "//services/service_manager/public/mojom",
434    ]
435
436    public_deps = [
437      "//components/metrics/public/mojom:single_sample_metrics_mojo_bindings",
438    ]
439  }
440
441  source_set("call_stack_profile_params") {
442    public = [
443      "call_stacks/call_stack_profile_encoding.h",
444      "call_stacks/call_stack_profile_params.h",
445    ]
446    sources = [ "call_stacks/call_stack_profile_encoding.cc" ]
447
448    deps = [
449      "//base:base",
450      "//third_party/metrics_proto",
451    ]
452  }
453
454  # Dependency for child processes that use the CallStackProfileBuilder.
455  source_set("child_call_stack_profile_builder") {
456    public = [
457      "call_stacks/call_stack_profile_builder.h",
458      "call_stacks/call_stack_profile_metadata.h",
459      "call_stacks/child_call_stack_profile_collector.h",
460    ]
461    sources = [
462      "call_stacks/call_stack_profile_builder.cc",
463      "call_stacks/call_stack_profile_metadata.cc",
464      "call_stacks/child_call_stack_profile_collector.cc",
465    ]
466    public_deps = [ ":call_stack_profile_params" ]
467    deps = [
468      "//base",
469      "//components/metrics/public/mojom:call_stack_mojo_bindings",
470      "//third_party/metrics_proto",
471    ]
472
473    # This target must not depend on :metrics because that code is intended solely
474    # for use in the browser process.
475    assert_no_deps = [ ":metrics" ]
476  }
477
478  # Dependency for browser process use of the CallStackProfileBuilder.
479  source_set("call_stack_profile_builder") {
480    deps = [ ":metrics" ]
481    public_deps = [ ":child_call_stack_profile_builder" ]
482  }
483
484  # The browser process mojo service for collecting profiles from child
485  # processes.
486  source_set("call_stack_profile_collector") {
487    sources = [
488      "call_stacks/call_stack_profile_collector.cc",
489      "call_stacks/call_stack_profile_collector.h",
490    ]
491    deps = [
492      ":call_stack_profile_params",
493      ":metrics",
494      "//components/metrics/public/mojom:call_stack_mojo_bindings",
495    ]
496  }
497
498  if (is_linux || is_chromeos) {
499    static_library("serialization") {
500      sources = [
501        "serialization/metric_sample.cc",
502        "serialization/metric_sample.h",
503        "serialization/serialization_utils.cc",
504        "serialization/serialization_utils.h",
505      ]
506      deps = [ "//base" ]
507    }
508  }
509
510  source_set("unit_tests") {
511    testonly = true
512    sources = [
513      "android_metrics_helper_unittest.cc",
514      "call_stacks/call_stack_profile_builder_unittest.cc",
515      "call_stacks/call_stack_profile_metadata_unittest.cc",
516      "call_stacks/call_stack_profile_metrics_provider_unittest.cc",
517      "call_stacks/child_call_stack_profile_collector_unittest.cc",
518      "clean_exit_beacon_unittest.cc",
519      "cloned_install_detector_unittest.cc",
520      "component_metrics_provider_unittest.cc",
521      "daily_event_unittest.cc",
522      "data_use_tracker_unittest.cc",
523      "date_changed_helper_unittest.cc",
524      "drive_metrics_provider_unittest.cc",
525      "entropy_state_provider_unittest.cc",
526      "entropy_state_unittest.cc",
527      "environment_recorder_unittest.cc",
528      "expired_histograms_checker_unittest.cc",
529      "field_trials_provider_unittest.cc",
530      "file_metrics_provider_unittest.cc",
531      "histogram_encoder_unittest.cc",
532      "library_support/histogram_manager_unittest.cc",
533      "log_decoder_unittest.cc",
534      "metrics_data_validation_unittest.cc",
535      "metrics_log_store_unittest.cc",
536      "metrics_log_unittest.cc",
537      "metrics_service_client_unittest.cc",
538      "metrics_service_observer_unittest.cc",
539      "metrics_service_unittest.cc",
540      "metrics_state_manager_unittest.cc",
541      "net/net_metrics_log_uploader_unittest.cc",
542      "net/network_metrics_provider_unittest.cc",
543      "persistent_synthetic_trial_observer_unittest.cc",
544      "persistent_system_profile_unittest.cc",
545      "reporting_service_unittest.cc",
546      "single_sample_metrics_factory_impl_unittest.cc",
547      "stability_metrics_helper_unittest.cc",
548      "stability_metrics_provider_unittest.cc",
549      "ui/form_factor_metrics_provider_unittest.cc",
550      "ui/screen_info_metrics_provider_unittest.cc",
551      "unsent_log_store_metrics_impl_unittest.cc",
552      "unsent_log_store_unittest.cc",
553    ]
554
555    deps = [
556      ":call_stack_profile_builder",
557      ":component_metrics",
558      ":library_support",
559      ":metrics",
560      ":net",
561      ":single_sample_metrics",
562      ":test_support",
563      ":ui",
564      "//base",
565      "//base:base_stack_sampling_profiler_test_util",
566      "//base/test:test_support",
567      "//build:chromeos_buildflags",
568      "//components/component_updater:test_support",
569      "//components/encrypted_messages:encrypted_message_proto",
570      "//components/metrics/public/mojom:call_stack_mojo_bindings",
571      "//components/network_time:network_time_test_support",
572      "//components/prefs:test_support",
573      "//components/sync:test_support",
574      "//components/sync/base",
575      "//components/variations",
576      "//components/variations:test_support",
577      "//extensions/buildflags",
578      "//mojo/public/cpp/bindings",
579      "//net:test_support",
580      "//services/network:test_support",
581      "//services/network/public/cpp:cpp",
582      "//services/service_manager/public/cpp",
583      "//testing/gmock",
584      "//testing/gtest",
585      "//third_party/metrics_proto",
586      "//third_party/zlib/google:compression_utils",
587      "//ui/gfx/geometry",
588    ]
589
590    if (is_win) {
591      sources += [
592        "machine_id_provider_win_unittest.cc",
593        "system_session_analyzer/system_session_analyzer_win_unittest.cc",
594      ]
595    } else {
596      sources += [ "machine_id_provider_nonwin_unittest.cc" ]
597    }
598
599    if (is_linux || is_chromeos) {
600      sources += [
601        "psi_memory_parser_linux_unittest.cc",
602        "serialization/serialization_utils_unittest.cc",
603      ]
604      deps += [ ":serialization" ]
605    }
606
607    if (is_chromeos_ash) {
608      deps += [
609        "//chromeos/ash/components/dbus:test_support",
610        "//chromeos/ash/components/network:test_support",
611      ]
612    }
613
614    if (is_android) {
615      sources += [
616        "android_metrics_provider_unittest.cc",
617        "gms_metrics_provider_unittest.cc",
618      ]
619    }
620
621    if (use_blink) {
622      deps += [
623        ":content",
624        "//content/test:test_support",
625      ]
626    }
627
628    # iOS is not supported by the profiler and the ios-simulator bot chokes on
629    # these tests.
630    if (is_ios) {
631      sources -=
632          [ "call_stacks/child_call_stack_profile_collector_unittest.cc" ]
633      deps += [ "//ios/web/public/test" ]
634    } else {
635      sources += [
636        "content/content_stability_metrics_provider_unittest.cc",
637        "content/subprocess_metrics_provider_unittest.cc",
638      ]
639      deps += [ "//extensions/buildflags" ]
640    }
641
642    if (is_win || is_linux) {
643      sources += [ "motherboard_metrics_provider_unittest.cc" ]
644    }
645  }
646
647  # Convenience testing target
648  test("metrics_unittests") {
649    sources = [ "//components/test/run_all_unittests.cc" ]
650    deps = [
651      ":unit_tests",
652      "//components/metrics/demographics:unit_tests",
653      "//components/test:test_support",
654    ]
655  }
656}
657