File: device_info.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 (318 lines) | stat: -rw-r--r-- 10,907 bytes parent folder | download | duplicates (3)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
#define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_

#include <array>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <variant>
#include <vector>

#include "base/time/time.h"
#include "base/types/strong_alias.h"
#include "components/sync/base/data_type.h"

namespace sync_pb {
enum SharingSpecificFields_EnabledFeatures : int;
enum SyncEnums_DeviceType : int;
enum SyncEnums_SendTabReceivingType : int;
}  // namespace sync_pb

namespace syncer {

// A class that holds information regarding the properties of a device.
class DeviceInfo {
 public:
  // A struct that holds information regarding to FCM web push.
  struct SharingTargetInfo {
    // FCM registration token of device.
    std::string fcm_token;

    // Public key for Sharing message encryption[RFC8291].
    std::string p256dh;

    // Auth secret for Sharing message encryption[RFC8291].
    std::string auth_secret;

    bool operator==(const SharingTargetInfo& other) const;
  };

  // A struct that holds information regarding to Sharing features.
  struct SharingInfo {
    SharingInfo(SharingTargetInfo sharing_target_info,
                std::string chime_representative_target_id,
                std::set<sync_pb::SharingSpecificFields_EnabledFeatures>
                    enabled_features);
    SharingInfo(const SharingInfo& other);
    SharingInfo(SharingInfo&& other);
    SharingInfo& operator=(const SharingInfo& other);
    ~SharingInfo();

    // Target info using Sharing sender ID.
    SharingTargetInfo sender_id_target_info;

    // Identifier used to send messages to a specific device through Chime.
    std::string chime_representative_target_id;

    // Set of Sharing features enabled on the device.
    std::set<sync_pb::SharingSpecificFields_EnabledFeatures> enabled_features;

    bool operator==(const SharingInfo& other) const;
  };

  struct PhoneAsASecurityKeyInfo {
    // NotReady indicates that more time is needed to calculate the
    // PhoneAsASecurityKeyInfo.
    using NotReady = base::StrongAlias<class NotReadyTag, std::monostate>;
    // NoSupport indicates that phone-as-a-security-key cannot be supported.
    using NoSupport = base::StrongAlias<class NoSupportTag, std::monostate>;
    using StatusOrInfo =
        std::variant<NotReady, NoSupport, PhoneAsASecurityKeyInfo>;

    PhoneAsASecurityKeyInfo();
    PhoneAsASecurityKeyInfo(const PhoneAsASecurityKeyInfo& other);
    PhoneAsASecurityKeyInfo(PhoneAsASecurityKeyInfo&& other);
    PhoneAsASecurityKeyInfo& operator=(const PhoneAsASecurityKeyInfo& other);
    ~PhoneAsASecurityKeyInfo();

    // NonRotatingFieldsEqual returns true if this object is equal to |other|,
    // ignoring the |id| and |secret| fields, which update based on the current
    // time.
    bool NonRotatingFieldsEqual(const PhoneAsASecurityKeyInfo& other) const;

    // The domain of the tunnel service. See
    // |device::cablev2::tunnelserver::DecodeDomain| to decode this value.
    uint16_t tunnel_server_domain;
    // contact_id is an opaque value that is sent to the tunnel service in order
    // to identify the caBLEv2 authenticator.
    std::vector<uint8_t> contact_id;
    // secret is the shared secret that authenticates the desktop to the
    // authenticator.
    std::array<uint8_t, 32> secret;
    // id identifies the secret so that the phone knows which secret to use
    // for a given connection.
    uint32_t id;
    // peer_public_key_x962 is the authenticator's public key.
    std::array<uint8_t, 65> peer_public_key_x962;
  };

  //
  // A Java counterpart will be generated for this enum.
  // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.sync_device_info
  //
  enum class OsType {
    kUnknown = 0,
    kWindows = 1,
    kMac = 2,
    kLinux = 3,
    kChromeOsAsh = 4,
    kAndroid = 5,
    kIOS = 6,
    kChromeOsLacros = 7,
    kFuchsia = 8
  };

  //
  // A Java counterpart will be generated for this enum.
  // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.sync_device_info
  //
  enum class FormFactor {
    kUnknown = 0,
    kDesktop = 1,
    kPhone = 2,
    kTablet = 3,
    kAutomotive = 4,
    kWearable = 5,
    kTv = 6,
  };

  DeviceInfo(
      const std::string& guid,
      const std::string& client_name,
      const std::string& chrome_version,
      const std::string& sync_user_agent,
      const sync_pb::SyncEnums_DeviceType device_type,
      const OsType os_type,
      const FormFactor form_factor,
      const std::string& signin_scoped_device_id,
      const std::string& manufacturer_name,
      const std::string& model_name,
      const std::string& full_hardware_class,
      base::Time last_updated_timestamp,
      base::TimeDelta pulse_interval,
      bool send_tab_to_self_receiving_enabled,
      sync_pb::SyncEnums_SendTabReceivingType send_tab_to_self_receiving_type,
      const std::optional<SharingInfo>& sharing_info,
      const std::optional<PhoneAsASecurityKeyInfo>& paask_info,
      const std::string& fcm_registration_token,
      const DataTypeSet& interested_data_types,
      std::optional<base::Time> floating_workspace_last_signin_timestamp);

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

  ~DeviceInfo();

  // Sync specific unique identifier for the device. Note if a device
  // is wiped and sync is set up again this id WILL be different.
  // The same device might have more than 1 guid if the device has multiple
  // accounts syncing.
  const std::string& guid() const;

  // The host name for the client.
  const std::string& client_name() const;

  // Chrome version string.
  const std::string& chrome_version() const;

  // The user agent is the combination of OS type, chrome version and which
  // channel of chrome(stable or beta). For more information see
  // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|.
  const std::string& sync_user_agent() const;

  // Third party visible id for the device. See |public_id_| for more details.
  const std::string& public_id() const;

  // Device Type.
  sync_pb::SyncEnums_DeviceType device_type() const;

  // Returns the OS of this device.
  OsType os_type() const;

  // Returns the device type (form-factor).
  FormFactor form_factor() const;

  // Device_id that is stable until user signs out. This device_id is used for
  // annotating login scoped refresh token.
  const std::string& signin_scoped_device_id() const;

  // The device manufacturer name.
  const std::string& manufacturer_name() const;

  // The device model name.
  const std::string& model_name() const;

  // Returns unique hardware class string which details the
  // HW combination of a ChromeOS device. Returns empty on other OS devices or
  // when UMA is disabled.
  const std::string& full_hardware_class() const;

  // Returns the time at which this device was last updated to the sync servers.
  base::Time last_updated_timestamp() const;

  // Returns the interval with which this device is updated to the sync servers
  // if online and while sync is actively running (e.g. excludes backgrounded
  // apps on Android).
  base::TimeDelta pulse_interval() const;

  // Whether the receiving side of the SendTabToSelf feature is enabled.
  bool send_tab_to_self_receiving_enabled() const;

  // Enabled message types for the receiving side of the SendTabToSelf feature.
  // This is meaningless if send_tab_to_self_receiving_enabled() returns false.
  // If not set, the in-app message type will be assumed.
  sync_pb::SyncEnums_SendTabReceivingType send_tab_to_self_receiving_type()
      const;

  // Returns Sharing related info of the device.
  const std::optional<SharingInfo>& sharing_info() const;

  const std::optional<PhoneAsASecurityKeyInfo>& paask_info() const;

  // Returns the FCM registration token for sync invalidations.
  const std::string& fcm_registration_token() const;

  // Returns the data types for which this device receives invalidations.
  const DataTypeSet& interested_data_types() const;

  // Returns the time at which this device was last signed into the device.
  std::optional<base::Time> floating_workspace_last_signin_timestamp() const;

  // Apps can set ids for a device that is meaningful to them but
  // not unique enough so the user can be tracked. Exposing |guid|
  // would lead to a stable unique id for a device which can potentially
  // be used for tracking.
  void set_public_id(const std::string& id);

  void set_full_hardware_class(const std::string& full_hardware_class);

  void set_send_tab_to_self_receiving_enabled(bool new_value);

  void set_send_tab_to_self_receiving_type(
      sync_pb::SyncEnums_SendTabReceivingType new_value);

  void set_sharing_info(const std::optional<SharingInfo>& sharing_info);

  void set_paask_info(std::optional<PhoneAsASecurityKeyInfo>&& paask_info);

  void set_client_name(const std::string& client_name);

  void set_fcm_registration_token(const std::string& fcm_token);

  void set_interested_data_types(const DataTypeSet& data_types);

  void set_floating_workspace_last_signin_timestamp(
      std::optional<base::Time> time);

 private:
  const std::string guid_;

  std::string client_name_;

  const std::string chrome_version_;

  const std::string sync_user_agent_;

  const sync_pb::SyncEnums_DeviceType device_type_;

  const OsType os_type_;

  const FormFactor form_factor_;

  const std::string signin_scoped_device_id_;

  // Exposing |guid| would lead to a stable unique id for a device which
  // can potentially be used for tracking. Public ids are privacy safe
  // ids in that the same device will have different id for different apps
  // and they are also reset when app/extension is uninstalled.
  std::string public_id_;

  const std::string manufacturer_name_;

  const std::string model_name_;

  std::string full_hardware_class_;

  const base::Time last_updated_timestamp_;

  const base::TimeDelta pulse_interval_;

  bool send_tab_to_self_receiving_enabled_;

  sync_pb::SyncEnums_SendTabReceivingType send_tab_to_self_receiving_type_;

  std::optional<SharingInfo> sharing_info_;

  std::optional<PhoneAsASecurityKeyInfo> paask_info_;

  // An FCM registration token obtained by sync invalidations service.
  std::string fcm_registration_token_;

  // Data types for which this device receives invalidations.
  DataTypeSet interested_data_types_;

  std::optional<base::Time> floating_workspace_last_signin_timestamp_;

  // NOTE: when adding a member, don't forget to update
  // |StoredDeviceInfoStillAccurate| in device_info_sync_bridge.cc or else
  // changes in that member might not trigger uploads of updated DeviceInfos.
};

}  // namespace syncer

#endif  // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_