blob: fbaa5c9b1b2ec5184372058be00c890d2e565428 [file] [log] [blame]
[email protected]34e98172012-10-12 04:01:391// Copyright (c) 2012 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
maxboguef1885f7d2016-08-16 19:13:205#ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
6#define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
[email protected]34e98172012-10-12 04:01:397
Adam Langley1b4e4a62021-03-25 23:07:398#include <array>
skym6d5ecf82016-10-04 17:43:459#include <memory>
Alex Chau4e13d9b62019-09-30 17:09:5910#include <set>
[email protected]34e98172012-10-12 04:01:3911#include <string>
12
stanisc10528752014-09-23 21:52:1913#include "base/callback.h"
avi5dd91f82015-12-25 22:30:4614#include "base/macros.h"
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:3915#include "base/time/time.h"
Paula Vidasd3c720e62020-09-03 07:20:0616#include "components/sync/base/model_type.h"
Anton Bikineev1156b5f2021-05-15 22:35:3617#include "third_party/abseil-cpp/absl/types/optional.h"
[email protected]34e98172012-10-12 04:01:3918
[email protected]648a5662013-07-18 20:45:4519namespace base {
20class DictionaryValue;
21}
22
Hans Wennborgcf86a6f2021-04-22 15:18:0623namespace sync_pb {
24enum SharingSpecificFields_EnabledFeatures : int;
25enum SyncEnums_DeviceType : int;
26} // namespace sync_pb
27
maxbogue7e006db2016-10-03 19:48:2828namespace syncer {
[email protected]34e98172012-10-12 04:01:3929
30// A class that holds information regarding the properties of a device.
[email protected]34e98172012-10-12 04:01:3931class DeviceInfo {
32 public:
Alex Chau965a5a22019-11-18 16:51:5833 // A struct that holds information regarding to FCM web push.
34 struct SharingTargetInfo {
35 // FCM registration token of device.
36 std::string fcm_token;
37
38 // Public key for Sharing message encryption[RFC8291].
39 std::string p256dh;
40
41 // Auth secret for Sharing message encryption[RFC8291].
42 std::string auth_secret;
43
44 bool operator==(const SharingTargetInfo& other) const;
45 };
46
47 // A struct that holds information regarding to Sharing features.
Alex Chau4e13d9b62019-09-30 17:09:5948 struct SharingInfo {
Alex Chau965a5a22019-11-18 16:51:5849 SharingInfo(SharingTargetInfo vapid_target_info,
50 SharingTargetInfo sharing_target_info,
Hans Wennborgcf86a6f2021-04-22 15:18:0651 std::set<sync_pb::SharingSpecificFields_EnabledFeatures>
Alex Chau4e13d9b62019-09-30 17:09:5952 enabled_features);
53 SharingInfo(const SharingInfo& other);
54 SharingInfo(SharingInfo&& other);
55 SharingInfo& operator=(const SharingInfo& other);
56 ~SharingInfo();
57
Alex Chau965a5a22019-11-18 16:51:5858 // Target info using VAPID key.
59 // TODO(crbug.com/1012226): Deprecate when VAPID migration is over.
60 SharingTargetInfo vapid_target_info;
Alex Chauf1de5182019-11-14 14:19:1661
Alex Chau965a5a22019-11-18 16:51:5862 // Target info using Sharing sender ID.
63 SharingTargetInfo sender_id_target_info;
Alex Chau4e13d9b62019-09-30 17:09:5964
65 // Set of Sharing features enabled on the device.
Hans Wennborgcf86a6f2021-04-22 15:18:0666 std::set<sync_pb::SharingSpecificFields_EnabledFeatures> enabled_features;
Alex Chau4e13d9b62019-09-30 17:09:5967
68 bool operator==(const SharingInfo& other) const;
69 };
70
Adam Langley1b4e4a62021-03-25 23:07:3971 struct PhoneAsASecurityKeyInfo {
72 PhoneAsASecurityKeyInfo();
73 PhoneAsASecurityKeyInfo(const PhoneAsASecurityKeyInfo& other);
74 PhoneAsASecurityKeyInfo(PhoneAsASecurityKeyInfo&& other);
75 PhoneAsASecurityKeyInfo& operator=(const PhoneAsASecurityKeyInfo& other);
76 ~PhoneAsASecurityKeyInfo();
77
Adam Langley21b6dbbd2021-06-25 18:50:5978 // NonRotatingFieldsEqual returns true if this object is equal to |other|,
79 // ignoring the |id| and |secret| fields, which update based on the current
80 // time.
81 bool NonRotatingFieldsEqual(const PhoneAsASecurityKeyInfo& other) const;
Adam Langley1b4e4a62021-03-25 23:07:3982
83 // The domain of the tunnel service. See
84 // |device::cablev2::tunnelserver::DecodeDomain| to decode this value.
85 uint16_t tunnel_server_domain;
86 // contact_id is an opaque value that is sent to the tunnel service in order
87 // to identify the caBLEv2 authenticator.
88 std::vector<uint8_t> contact_id;
89 // secret is the shared secret that authenticates the desktop to the
90 // authenticator.
91 std::array<uint8_t, 32> secret;
92 // id identifies the secret so that the phone knows which secret to use
93 // for a given connection.
94 uint32_t id;
95 // peer_public_key_x962 is the authenticator's public key.
96 std::array<uint8_t, 65> peer_public_key_x962;
97 };
98
[email protected]1e281a42013-07-16 23:04:0899 DeviceInfo(const std::string& guid,
100 const std::string& client_name,
[email protected]34e98172012-10-12 04:01:39101 const std::string& chrome_version,
102 const std::string& sync_user_agent,
Hans Wennborgcf86a6f2021-04-22 15:18:06103 const sync_pb::SyncEnums_DeviceType device_type,
Tanya Guptac1dec1c2019-04-18 22:56:05104 const std::string& signin_scoped_device_id,
Richard Knoll5b608be2020-07-10 08:39:40105 const std::string& manufacturer_name,
106 const std::string& model_name,
Hirthanan Subenderane6657f72021-04-16 10:43:12107 const std::string& full_hardware_class,
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:39108 base::Time last_updated_timestamp,
Michael van Ouwerkerka91ab6e2020-02-03 12:55:38109 base::TimeDelta pulse_interval,
Alex Chau4e13d9b62019-09-30 17:09:59110 bool send_tab_to_self_receiving_enabled,
Anton Bikineev1156b5f2021-05-15 22:35:36111 const absl::optional<SharingInfo>& sharing_info,
112 const absl::optional<PhoneAsASecurityKeyInfo>& paask_info,
Paula Vidasd3c720e62020-09-03 07:20:06113 const std::string& fcm_registration_token,
114 const ModelTypeSet& interested_data_types);
[email protected]34e98172012-10-12 04:01:39115 ~DeviceInfo();
116
[email protected]1e281a42013-07-16 23:04:08117 // Sync specific unique identifier for the device. Note if a device
118 // is wiped and sync is set up again this id WILL be different.
119 // The same device might have more than 1 guid if the device has multiple
120 // accounts syncing.
121 const std::string& guid() const;
122
123 // The host name for the client.
[email protected]34e98172012-10-12 04:01:39124 const std::string& client_name() const;
[email protected]1e281a42013-07-16 23:04:08125
126 // Chrome version string.
[email protected]34e98172012-10-12 04:01:39127 const std::string& chrome_version() const;
[email protected]1e281a42013-07-16 23:04:08128
129 // The user agent is the combination of OS type, chrome version and which
130 // channel of chrome(stable or beta). For more information see
stanisc10528752014-09-23 21:52:19131 // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|.
[email protected]34e98172012-10-12 04:01:39132 const std::string& sync_user_agent() const;
[email protected]1e281a42013-07-16 23:04:08133
[email protected]790daf5c2013-07-31 18:42:57134 // Third party visible id for the device. See |public_id_| for more details.
135 const std::string& public_id() const;
136
[email protected]1e281a42013-07-16 23:04:08137 // Device Type.
Hans Wennborgcf86a6f2021-04-22 15:18:06138 sync_pb::SyncEnums_DeviceType device_type() const;
[email protected]34e98172012-10-12 04:01:39139
[email protected]e0ec8ba2014-07-18 23:38:04140 // Device_id that is stable until user signs out. This device_id is used for
141 // annotating login scoped refresh token.
142 const std::string& signin_scoped_device_id() const;
143
Richard Knoll5b608be2020-07-10 08:39:40144 // The device manufacturer name.
145 const std::string& manufacturer_name() const;
146
147 // The device model name.
148 const std::string& model_name() const;
Himanshu Jaju0ddf2c132019-10-10 16:22:28149
Hirthanan Subenderane6657f72021-04-16 10:43:12150 // Returns unique hardware class string which details the
151 // HW combination of a ChromeOS device. Returns empty on other OS devices or
152 // when UMA is disabled.
153 const std::string& full_hardware_class() const;
154
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:39155 // Returns the time at which this device was last updated to the sync servers.
156 base::Time last_updated_timestamp() const;
157
Michael van Ouwerkerka91ab6e2020-02-03 12:55:38158 // Returns the interval with which this device is updated to the sync servers
159 // if online and while sync is actively running (e.g. excludes backgrounded
160 // apps on Android).
161 base::TimeDelta pulse_interval() const;
162
Tanya Guptac1dec1c2019-04-18 22:56:05163 // Whether the receiving side of the SendTabToSelf feature is enabled.
164 bool send_tab_to_self_receiving_enabled() const;
165
Alex Chau4e13d9b62019-09-30 17:09:59166 // Returns Sharing related info of the device.
Anton Bikineev1156b5f2021-05-15 22:35:36167 const absl::optional<SharingInfo>& sharing_info() const;
Alex Chau4e13d9b62019-09-30 17:09:59168
Anton Bikineev1156b5f2021-05-15 22:35:36169 const absl::optional<PhoneAsASecurityKeyInfo>& paask_info() const;
Adam Langley1b4e4a62021-03-25 23:07:39170
Rushan Suleymanov74e7ee2592020-08-02 19:30:40171 // Returns the FCM registration token for sync invalidations.
172 const std::string& fcm_registration_token() const;
173
Paula Vidasd3c720e62020-09-03 07:20:06174 // Returns the data types for which this device receives invalidations.
175 const ModelTypeSet& interested_data_types() const;
176
[email protected]f32d8ce2013-09-24 04:38:40177 // Gets the OS in string form.
178 std::string GetOSString() const;
179
180 // Gets the device type in string form.
181 std::string GetDeviceTypeString() const;
182
[email protected]648a5662013-07-18 20:45:45183 // Apps can set ids for a device that is meaningful to them but
184 // not unique enough so the user can be tracked. Exposing |guid|
185 // would lead to a stable unique id for a device which can potentially
186 // be used for tracking.
ki.stfu939799a42015-09-28 04:41:20187 void set_public_id(const std::string& id);
[email protected]648a5662013-07-18 20:45:45188
Hirthanan Subenderane6657f72021-04-16 10:43:12189 void set_full_hardware_class(const std::string& full_hardware_class);
190
Tanya Guptac1dec1c2019-04-18 22:56:05191 void set_send_tab_to_self_receiving_enabled(bool new_value);
192
Anton Bikineev1156b5f2021-05-15 22:35:36193 void set_sharing_info(const absl::optional<SharingInfo>& sharing_info);
Alex Chau4e13d9b62019-09-30 17:09:59194
Adam Langley1b4e4a62021-03-25 23:07:39195 void set_paask_info(PhoneAsASecurityKeyInfo&& paask_info);
196
Himanshu Jajuf2c5d732019-10-21 14:52:33197 void set_client_name(const std::string& client_name);
198
Rushan Suleymanov74e7ee2592020-08-02 19:30:40199 void set_fcm_registration_token(const std::string& fcm_token);
200
Paula Vidasd3c720e62020-09-03 07:20:06201 void set_interested_data_types(const ModelTypeSet& data_types);
202
[email protected]648a5662013-07-18 20:45:45203 // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
204 // which extension APIs can expose to third party apps.
Richard Knoll5b608be2020-07-10 08:39:40205 std::unique_ptr<base::DictionaryValue> ToValue() const;
[email protected]648a5662013-07-18 20:45:45206
[email protected]34e98172012-10-12 04:01:39207 private:
[email protected]1e281a42013-07-16 23:04:08208 const std::string guid_;
209
Himanshu Jajuf2c5d732019-10-21 14:52:33210 std::string client_name_;
[email protected]1e281a42013-07-16 23:04:08211
[email protected]34e98172012-10-12 04:01:39212 const std::string chrome_version_;
[email protected]1e281a42013-07-16 23:04:08213
[email protected]34e98172012-10-12 04:01:39214 const std::string sync_user_agent_;
[email protected]1e281a42013-07-16 23:04:08215
Hans Wennborgcf86a6f2021-04-22 15:18:06216 const sync_pb::SyncEnums_DeviceType device_type_;
[email protected]16b85e82012-11-21 04:16:33217
Richard Knoll5b608be2020-07-10 08:39:40218 const std::string signin_scoped_device_id_;
[email protected]e0ec8ba2014-07-18 23:38:04219
[email protected]790daf5c2013-07-31 18:42:57220 // Exposing |guid| would lead to a stable unique id for a device which
221 // can potentially be used for tracking. Public ids are privacy safe
222 // ids in that the same device will have different id for different apps
223 // and they are also reset when app/extension is uninstalled.
[email protected]648a5662013-07-18 20:45:45224 std::string public_id_;
225
Richard Knoll5b608be2020-07-10 08:39:40226 const std::string manufacturer_name_;
227
228 const std::string model_name_;
Himanshu Jaju0ddf2c132019-10-10 16:22:28229
Hirthanan Subenderane6657f72021-04-16 10:43:12230 std::string full_hardware_class_;
231
Sébastien Séguin-Gagnonb7cc9252019-05-09 22:00:39232 const base::Time last_updated_timestamp_;
233
Michael van Ouwerkerka91ab6e2020-02-03 12:55:38234 const base::TimeDelta pulse_interval_;
235
Tanya Guptac1dec1c2019-04-18 22:56:05236 bool send_tab_to_self_receiving_enabled_;
237
Anton Bikineev1156b5f2021-05-15 22:35:36238 absl::optional<SharingInfo> sharing_info_;
Alex Chau4e13d9b62019-09-30 17:09:59239
Anton Bikineev1156b5f2021-05-15 22:35:36240 absl::optional<PhoneAsASecurityKeyInfo> paask_info_;
Adam Langley1b4e4a62021-03-25 23:07:39241
Rushan Suleymanov74e7ee2592020-08-02 19:30:40242 // An FCM registration token obtained by sync invalidations service.
243 std::string fcm_registration_token_;
244
Paula Vidasd3c720e62020-09-03 07:20:06245 // Data types for which this device receives invalidations.
246 ModelTypeSet interested_data_types_;
247
Adam Langley21b6dbbd2021-06-25 18:50:59248 // NOTE: when adding a member, don't forget to update
249 // |StoredDeviceInfoStillAccurate| in device_info_sync_bridge.cc or else
250 // changes in that member might not trigger uploads of updated DeviceInfos.
251
[email protected]16b85e82012-11-21 04:16:33252 DISALLOW_COPY_AND_ASSIGN(DeviceInfo);
[email protected]34e98172012-10-12 04:01:39253};
254
maxbogue7e006db2016-10-03 19:48:28255} // namespace syncer
[email protected]34e98172012-10-12 04:01:39256
maxboguef1885f7d2016-08-16 19:13:20257#endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_