form_factor_metrics_provider.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/metrics/form_factor_metrics_provider.h"
  5. #include "build/build_config.h"
  6. #include "ui/base/device_form_factor.h"
  7. #if BUILDFLAG(IS_ANDROID)
  8. #include "base/android/build_info.h"
  9. #endif // BUILDFLAG(IS_ANDROID)
  10. namespace metrics {
  11. void FormFactorMetricsProvider::ProvideSystemProfileMetrics(
  12. SystemProfileProto* system_profile_proto) {
  13. system_profile_proto->mutable_hardware()->set_form_factor(GetFormFactor());
  14. }
  15. SystemProfileProto::Hardware::FormFactor
  16. FormFactorMetricsProvider::GetFormFactor() const {
  17. #if BUILDFLAG(IS_ANDROID)
  18. // TODO(crbug.com/1300338): Move the TV form factor logic to
  19. // ui/base/device_form_factor_android.cc.
  20. if (base::android::BuildInfo::GetInstance()->is_tv())
  21. return SystemProfileProto::Hardware::FORM_FACTOR_TV;
  22. #endif // BUILDFLAG(IS_ANDROID)
  23. switch (ui::GetDeviceFormFactor()) {
  24. case ui::DEVICE_FORM_FACTOR_DESKTOP:
  25. return SystemProfileProto::Hardware::FORM_FACTOR_DESKTOP;
  26. case ui::DEVICE_FORM_FACTOR_PHONE:
  27. return SystemProfileProto::Hardware::FORM_FACTOR_PHONE;
  28. case ui::DEVICE_FORM_FACTOR_TABLET:
  29. return SystemProfileProto::Hardware::FORM_FACTOR_TABLET;
  30. default:
  31. return SystemProfileProto::Hardware::FORM_FACTOR_UNKNOWN;
  32. }
  33. }
  34. } // namespace metrics