stylus_metrics_recorder.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2021 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. #ifndef ASH_METRICS_STYLUS_METRICS_RECORDER_H_
  5. #define ASH_METRICS_STYLUS_METRICS_RECORDER_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/system/power/peripheral_battery_listener.h"
  8. #include "chromeos/ash/components/feature_usage/feature_usage_metrics.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace ash {
  11. // Combine delegate callbacks and FeatureUsageMetrics state for each metric.
  12. class StylusSessionMetricsDelegate final
  13. : public feature_usage::FeatureUsageMetrics::Delegate {
  14. public:
  15. explicit StylusSessionMetricsDelegate(const std::string& feature_name);
  16. StylusSessionMetricsDelegate(const StylusSessionMetricsDelegate&) = delete;
  17. StylusSessionMetricsDelegate& operator=(const StylusSessionMetricsDelegate&) =
  18. delete;
  19. ~StylusSessionMetricsDelegate() final;
  20. // feature_usage::FeatureUsageMetrics::Delegate:
  21. bool IsEligible() const final;
  22. bool IsEnabled() const final;
  23. void SetState(bool now_capable, bool in_session);
  24. private:
  25. bool capable_ = false;
  26. bool active_ = false;
  27. feature_usage::FeatureUsageMetrics metrics_;
  28. };
  29. // A metrics recorder that records stylus related metrics.
  30. class ASH_EXPORT StylusMetricsRecorder
  31. : public PeripheralBatteryListener::Observer {
  32. public:
  33. StylusMetricsRecorder();
  34. StylusMetricsRecorder(const StylusMetricsRecorder&) = delete;
  35. StylusMetricsRecorder& operator=(const StylusMetricsRecorder&) = delete;
  36. ~StylusMetricsRecorder() override;
  37. // ash::PeripheralBatteryListener::Observer:
  38. void OnAddingBattery(
  39. const PeripheralBatteryListener::BatteryInfo& battery) override;
  40. void OnRemovingBattery(
  41. const PeripheralBatteryListener::BatteryInfo& battery) override;
  42. void OnUpdatedBatteryLevel(
  43. const PeripheralBatteryListener::BatteryInfo& battery) override;
  44. private:
  45. void UpdateStylusState();
  46. absl::optional<bool> stylus_on_charge_ = absl::nullopt;
  47. // Indicate whether a stylus garage is known to be present on this device:
  48. // garage refers to a charger that holds the stylus within the body of the
  49. // device, and can detect whether the stylus is currently 'garaged'.
  50. bool stylus_garage_present_ = false;
  51. // Indicate whether a stylus dock is known to be present on this device:
  52. // dock refers to a charger that holds the stylus to the body of the device,
  53. // and can detect whether stylus is currently 'docked'.
  54. bool stylus_dock_present_ = false;
  55. StylusSessionMetricsDelegate
  56. stylus_detached_from_garage_session_metrics_delegate_{
  57. "StylusDetachedFromGarageSession"};
  58. StylusSessionMetricsDelegate
  59. stylus_detached_from_dock_session_metrics_delegate_{
  60. "StylusDetachedFromDockSession"};
  61. StylusSessionMetricsDelegate
  62. stylus_detached_from_garage_or_dock_session_metrics_delegate_{
  63. "StylusDetachedFromGarageOrDockSession"};
  64. };
  65. } // namespace ash
  66. #endif // ASH_METRICS_STYLUS_METRICS_RECORDER_H_