File: phone_hub_structured_metrics_logger.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 (138 lines) | stat: -rw-r--r-- 4,786 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_PHONEHUB_PHONE_HUB_STRUCTURED_METRICS_LOGGER_H_
#define CHROMEOS_ASH_COMPONENTS_PHONEHUB_PHONE_HUB_STRUCTURED_METRICS_LOGGER_H_

#include <optional>

#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "chromeos/ash/components/phonehub/proto/phonehub_api.pb.h"
#include "chromeos/ash/services/secure_channel/public/cpp/client/secure_channel_structured_metrics_logger.h"
#include "chromeos/ash/services/secure_channel/public/mojom/nearby_connector.mojom-shared.h"
#include "chromeos/ash/services/secure_channel/public/mojom/secure_channel.mojom-shared.h"
#include "chromeos/ash/services/secure_channel/public/mojom/secure_channel.mojom.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
#include "components/metrics/structured/event.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"

namespace {
base::TimeDelta kMaxStructuredMetricsPseudonymousIdDays = base::Days(90);
}  // namespace

namespace ash::phonehub {

enum class DiscoveryEntryPoint {
  kUserSignIn = 0,
  kChromebookUnlock = 1,
  // TODO(b/324320785): Record attempt times with entrypoint instead of
  // recording retry as separate entrypoints.
  kAutomaticConnectionRetry = 2,
  kManualConnectionRetry = 3,
  kConnectionRetryAfterConnected = 4,
  kPhoneHubBubbleOpen = 5,
  kMultiDeviceFeatureSetup = 6,
  kBluetoothEnabled = 7,
  kUserEnabledFeature = 8,
  kUserOnboardedToFeature = 9
};

enum class PhoneHubMessageDirection {
  kPhoneToChromebook = 0,
  kChromebookToPhone = 1
};

enum class PhoneHubUiState {
  kDisconnected = 0,
  kConnecting = 1,
  kConnected = 2
};

enum class BluetoothStack { kBlueZ = 0, kFloss = 1 };

enum class NetworkState {
  kUnknown = 0,
  kSameNetwork = 1,
  kDifferentNetwork = 2,
  kPhoneOnCellular = 3
};

enum class Medium { kBluetooth = 0, kWebRTC = 1 };

class PhoneHubStructuredMetricsLogger
    : public ash::secure_channel::SecureChannelStructuredMetricsLogger {
 public:
  static void RegisterPrefs(PrefRegistrySimple* registry);

  explicit PhoneHubStructuredMetricsLogger(PrefService* pref_service);
  ~PhoneHubStructuredMetricsLogger() override;

  PhoneHubStructuredMetricsLogger(const PhoneHubStructuredMetricsLogger&) =
      delete;
  PhoneHubStructuredMetricsLogger& operator=(
      const PhoneHubStructuredMetricsLogger&) = delete;

  void LogPhoneHubDiscoveryStarted(DiscoveryEntryPoint entry_point);

  // secure_channel::mojom::SecureChannelStructuredMetricsLogger
  void LogDiscoveryAttempt(
      secure_channel::mojom::DiscoveryResult result,
      std::optional<secure_channel::mojom::DiscoveryErrorCode> error_code)
      override;
  void LogNearbyConnectionState(
      secure_channel::mojom::NearbyConnectionStep step,
      secure_channel::mojom::NearbyConnectionStepResult result) override;
  void LogSecureChannelState(
      secure_channel::mojom::SecureChannelState state) override;

  void LogPhoneHubMessageEvent(proto::MessageType message_type,
                               PhoneHubMessageDirection message_direction);
  void LogPhoneHubUiStateUpdated(PhoneHubUiState ui_state);

  void ProcessPhoneInformation(const proto::PhoneProperties& phone_properties);

  void ResetCachedInformation();

  void ResetSessionId();

  void SetChromebookInfo(proto::CrosState& cros_state_message);

 private:
  FRIEND_TEST_ALL_PREFIXES(PhoneHubStructuredMetricsLoggerTest,
                           ProcessPhoneInformation_MissingFields);
  FRIEND_TEST_ALL_PREFIXES(PhoneHubStructuredMetricsLoggerTest,
                           ProcessPhoneInformation_AllFields);
  FRIEND_TEST_ALL_PREFIXES(PhoneHubStructuredMetricsLoggerTest, LogEvents);

  void UpdateIdentifiersIfNeeded();
  void OnNetworkStateListFetched(
      std::vector<chromeos::network_config::mojom::NetworkStatePropertiesPtr>
          networks);
  void UploadDeviceInfo();

  // Phone information
  std::optional<proto::NetworkStatus> phone_network_status_;
  std::optional<std::string> phone_network_ssid_;

  // Chromebook information
  BluetoothStack bluetooth_stack_;
  NetworkState network_state_ = NetworkState::kUnknown;
  std::string chromebook_locale_;

  std::string phone_hub_session_id_;
  Medium medium_ = Medium::kBluetooth;

  mojo::Remote<chromeos::network_config::mojom::CrosNetworkConfig>
      cros_network_config_;
  raw_ptr<PrefService> pref_service_;
};

}  // namespace ash::phonehub

#endif  // CHROMEOS_ASH_COMPONENTS_PHONEHUB_PHONE_HUB_STRUCTURED_METRICS_LOGGER_H_