File: stylus_metrics_recorder.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; 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 (6)
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_