File: stylus_metrics_recorder.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (83 lines) | stat: -rw-r--r-- 3,006 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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.

#ifndef ASH_METRICS_STYLUS_METRICS_RECORDER_H_
#define ASH_METRICS_STYLUS_METRICS_RECORDER_H_

#include <optional>

#include "ash/ash_export.h"
#include "ash/system/power/peripheral_battery_listener.h"
#include "chromeos/ash/components/feature_usage/feature_usage_metrics.h"

namespace ash {

// Combine delegate callbacks and FeatureUsageMetrics state for each metric.
class StylusSessionMetricsDelegate final
    : public feature_usage::FeatureUsageMetrics::Delegate {
 public:
  explicit StylusSessionMetricsDelegate(const std::string& feature_name);
  StylusSessionMetricsDelegate(const StylusSessionMetricsDelegate&) = delete;
  StylusSessionMetricsDelegate& operator=(const StylusSessionMetricsDelegate&) =
      delete;
  ~StylusSessionMetricsDelegate() final;

  // feature_usage::FeatureUsageMetrics::Delegate:
  bool IsEligible() const final;
  bool IsEnabled() const final;

  void SetState(bool now_capable, bool in_session);

 private:
  bool capable_ = false;
  bool active_ = false;
  feature_usage::FeatureUsageMetrics metrics_;
};

// A metrics recorder that records stylus related metrics.
class ASH_EXPORT StylusMetricsRecorder
    : public PeripheralBatteryListener::Observer {
 public:
  StylusMetricsRecorder();
  StylusMetricsRecorder(const StylusMetricsRecorder&) = delete;
  StylusMetricsRecorder& operator=(const StylusMetricsRecorder&) = delete;
  ~StylusMetricsRecorder() override;

  // ash::PeripheralBatteryListener::Observer:
  void OnAddingBattery(
      const PeripheralBatteryListener::BatteryInfo& battery) override;
  void OnRemovingBattery(
      const PeripheralBatteryListener::BatteryInfo& battery) override;
  void OnUpdatedBatteryLevel(
      const PeripheralBatteryListener::BatteryInfo& battery) override;

 private:
  void UpdateStylusState();

  std::optional<bool> stylus_on_charge_ = std::nullopt;

  // Indicate whether a stylus garage is known to be present on this device:
  // garage refers to a charger that holds the stylus within the body of the
  // device, and can detect whether the stylus is currently 'garaged'.
  bool stylus_garage_present_ = false;

  // Indicate whether a stylus dock is known to be present on this device:
  // dock refers to a charger that holds the stylus to the body of the device,
  // and can detect whether stylus is currently 'docked'.
  bool stylus_dock_present_ = false;

  StylusSessionMetricsDelegate
      stylus_detached_from_garage_session_metrics_delegate_{
          "StylusDetachedFromGarageSession"};
  StylusSessionMetricsDelegate
      stylus_detached_from_dock_session_metrics_delegate_{
          "StylusDetachedFromDockSession"};
  StylusSessionMetricsDelegate
      stylus_detached_from_garage_or_dock_session_metrics_delegate_{
          "StylusDetachedFromGarageOrDockSession"};
};

}  // namespace ash

#endif  // ASH_METRICS_STYLUS_METRICS_RECORDER_H_