[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 1 | // 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 | |
maxbogue | f1885f7d | 2016-08-16 19:13:20 | [diff] [blame] | 5 | #ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ |
| 6 | #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 7 | |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 8 | #include <array> |
skym | 6d5ecf8 | 2016-10-04 17:43:45 | [diff] [blame] | 9 | #include <memory> |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 10 | #include <set> |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 11 | #include <string> |
| 12 | |
stanisc | 1052875 | 2014-09-23 21:52:19 | [diff] [blame] | 13 | #include "base/callback.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 14 | #include "base/macros.h" |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 15 | #include "base/time/time.h" |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 16 | #include "components/sync/base/model_type.h" |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame] | 17 | #include "third_party/abseil-cpp/absl/types/optional.h" |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 18 | |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 19 | namespace base { |
| 20 | class DictionaryValue; |
| 21 | } |
| 22 | |
Hans Wennborg | cf86a6f | 2021-04-22 15:18:06 | [diff] [blame] | 23 | namespace sync_pb { |
| 24 | enum SharingSpecificFields_EnabledFeatures : int; |
| 25 | enum SyncEnums_DeviceType : int; |
| 26 | } // namespace sync_pb |
| 27 | |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 28 | namespace syncer { |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 29 | |
| 30 | // A class that holds information regarding the properties of a device. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 31 | class DeviceInfo { |
| 32 | public: |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 33 | // 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 Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 48 | struct SharingInfo { |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 49 | SharingInfo(SharingTargetInfo vapid_target_info, |
| 50 | SharingTargetInfo sharing_target_info, |
Hans Wennborg | cf86a6f | 2021-04-22 15:18:06 | [diff] [blame] | 51 | std::set<sync_pb::SharingSpecificFields_EnabledFeatures> |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 52 | enabled_features); |
| 53 | SharingInfo(const SharingInfo& other); |
| 54 | SharingInfo(SharingInfo&& other); |
| 55 | SharingInfo& operator=(const SharingInfo& other); |
| 56 | ~SharingInfo(); |
| 57 | |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 58 | // Target info using VAPID key. |
| 59 | // TODO(crbug.com/1012226): Deprecate when VAPID migration is over. |
| 60 | SharingTargetInfo vapid_target_info; |
Alex Chau | f1de518 | 2019-11-14 14:19:16 | [diff] [blame] | 61 | |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 62 | // Target info using Sharing sender ID. |
| 63 | SharingTargetInfo sender_id_target_info; |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 64 | |
| 65 | // Set of Sharing features enabled on the device. |
Hans Wennborg | cf86a6f | 2021-04-22 15:18:06 | [diff] [blame] | 66 | std::set<sync_pb::SharingSpecificFields_EnabledFeatures> enabled_features; |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 67 | |
| 68 | bool operator==(const SharingInfo& other) const; |
| 69 | }; |
| 70 | |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 71 | struct PhoneAsASecurityKeyInfo { |
| 72 | PhoneAsASecurityKeyInfo(); |
| 73 | PhoneAsASecurityKeyInfo(const PhoneAsASecurityKeyInfo& other); |
| 74 | PhoneAsASecurityKeyInfo(PhoneAsASecurityKeyInfo&& other); |
| 75 | PhoneAsASecurityKeyInfo& operator=(const PhoneAsASecurityKeyInfo& other); |
| 76 | ~PhoneAsASecurityKeyInfo(); |
| 77 | |
Adam Langley | 21b6dbbd | 2021-06-25 18:50:59 | [diff] [blame] | 78 | // 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 Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 82 | |
| 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] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 99 | DeviceInfo(const std::string& guid, |
| 100 | const std::string& client_name, |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 101 | const std::string& chrome_version, |
| 102 | const std::string& sync_user_agent, |
Hans Wennborg | cf86a6f | 2021-04-22 15:18:06 | [diff] [blame] | 103 | const sync_pb::SyncEnums_DeviceType device_type, |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 104 | const std::string& signin_scoped_device_id, |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 105 | const std::string& manufacturer_name, |
| 106 | const std::string& model_name, |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame] | 107 | const std::string& full_hardware_class, |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 108 | base::Time last_updated_timestamp, |
Michael van Ouwerkerk | a91ab6e | 2020-02-03 12:55:38 | [diff] [blame] | 109 | base::TimeDelta pulse_interval, |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 110 | bool send_tab_to_self_receiving_enabled, |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame] | 111 | const absl::optional<SharingInfo>& sharing_info, |
| 112 | const absl::optional<PhoneAsASecurityKeyInfo>& paask_info, |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 113 | const std::string& fcm_registration_token, |
| 114 | const ModelTypeSet& interested_data_types); |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 115 | ~DeviceInfo(); |
| 116 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 117 | // 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] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 124 | const std::string& client_name() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 125 | |
| 126 | // Chrome version string. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 127 | const std::string& chrome_version() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 128 | |
| 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 |
stanisc | 1052875 | 2014-09-23 21:52:19 | [diff] [blame] | 131 | // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 132 | const std::string& sync_user_agent() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 133 | |
[email protected] | 790daf5c | 2013-07-31 18:42:57 | [diff] [blame] | 134 | // Third party visible id for the device. See |public_id_| for more details. |
| 135 | const std::string& public_id() const; |
| 136 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 137 | // Device Type. |
Hans Wennborg | cf86a6f | 2021-04-22 15:18:06 | [diff] [blame] | 138 | sync_pb::SyncEnums_DeviceType device_type() const; |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 139 | |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 140 | // 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 Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 144 | // 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 Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 149 | |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame] | 150 | // 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-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 155 | // Returns the time at which this device was last updated to the sync servers. |
| 156 | base::Time last_updated_timestamp() const; |
| 157 | |
Michael van Ouwerkerk | a91ab6e | 2020-02-03 12:55:38 | [diff] [blame] | 158 | // 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 Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 163 | // Whether the receiving side of the SendTabToSelf feature is enabled. |
| 164 | bool send_tab_to_self_receiving_enabled() const; |
| 165 | |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 166 | // Returns Sharing related info of the device. |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame] | 167 | const absl::optional<SharingInfo>& sharing_info() const; |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 168 | |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame] | 169 | const absl::optional<PhoneAsASecurityKeyInfo>& paask_info() const; |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 170 | |
Rushan Suleymanov | 74e7ee259 | 2020-08-02 19:30:40 | [diff] [blame] | 171 | // Returns the FCM registration token for sync invalidations. |
| 172 | const std::string& fcm_registration_token() const; |
| 173 | |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 174 | // Returns the data types for which this device receives invalidations. |
| 175 | const ModelTypeSet& interested_data_types() const; |
| 176 | |
[email protected] | f32d8ce | 2013-09-24 04:38:40 | [diff] [blame] | 177 | // 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] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 183 | // 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.stfu | 939799a4 | 2015-09-28 04:41:20 | [diff] [blame] | 187 | void set_public_id(const std::string& id); |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 188 | |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame] | 189 | void set_full_hardware_class(const std::string& full_hardware_class); |
| 190 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 191 | void set_send_tab_to_self_receiving_enabled(bool new_value); |
| 192 | |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame] | 193 | void set_sharing_info(const absl::optional<SharingInfo>& sharing_info); |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 194 | |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 195 | void set_paask_info(PhoneAsASecurityKeyInfo&& paask_info); |
| 196 | |
Himanshu Jaju | f2c5d73 | 2019-10-21 14:52:33 | [diff] [blame] | 197 | void set_client_name(const std::string& client_name); |
| 198 | |
Rushan Suleymanov | 74e7ee259 | 2020-08-02 19:30:40 | [diff] [blame] | 199 | void set_fcm_registration_token(const std::string& fcm_token); |
| 200 | |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 201 | void set_interested_data_types(const ModelTypeSet& data_types); |
| 202 | |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 203 | // Converts the |DeviceInfo| values to a JS friendly DictionaryValue, |
| 204 | // which extension APIs can expose to third party apps. |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 205 | std::unique_ptr<base::DictionaryValue> ToValue() const; |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 206 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 207 | private: |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 208 | const std::string guid_; |
| 209 | |
Himanshu Jaju | f2c5d73 | 2019-10-21 14:52:33 | [diff] [blame] | 210 | std::string client_name_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 211 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 212 | const std::string chrome_version_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 213 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 214 | const std::string sync_user_agent_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 215 | |
Hans Wennborg | cf86a6f | 2021-04-22 15:18:06 | [diff] [blame] | 216 | const sync_pb::SyncEnums_DeviceType device_type_; |
[email protected] | 16b85e8 | 2012-11-21 04:16:33 | [diff] [blame] | 217 | |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 218 | const std::string signin_scoped_device_id_; |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 219 | |
[email protected] | 790daf5c | 2013-07-31 18:42:57 | [diff] [blame] | 220 | // 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] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 224 | std::string public_id_; |
| 225 | |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 226 | const std::string manufacturer_name_; |
| 227 | |
| 228 | const std::string model_name_; |
Himanshu Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 229 | |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame] | 230 | std::string full_hardware_class_; |
| 231 | |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 232 | const base::Time last_updated_timestamp_; |
| 233 | |
Michael van Ouwerkerk | a91ab6e | 2020-02-03 12:55:38 | [diff] [blame] | 234 | const base::TimeDelta pulse_interval_; |
| 235 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 236 | bool send_tab_to_self_receiving_enabled_; |
| 237 | |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame] | 238 | absl::optional<SharingInfo> sharing_info_; |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 239 | |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame] | 240 | absl::optional<PhoneAsASecurityKeyInfo> paask_info_; |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 241 | |
Rushan Suleymanov | 74e7ee259 | 2020-08-02 19:30:40 | [diff] [blame] | 242 | // An FCM registration token obtained by sync invalidations service. |
| 243 | std::string fcm_registration_token_; |
| 244 | |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 245 | // Data types for which this device receives invalidations. |
| 246 | ModelTypeSet interested_data_types_; |
| 247 | |
Adam Langley | 21b6dbbd | 2021-06-25 18:50:59 | [diff] [blame] | 248 | // 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] | 16b85e8 | 2012-11-21 04:16:33 | [diff] [blame] | 252 | DISALLOW_COPY_AND_ASSIGN(DeviceInfo); |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 253 | }; |
| 254 | |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 255 | } // namespace syncer |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 256 | |
maxbogue | f1885f7d | 2016-08-16 19:13:20 | [diff] [blame] | 257 | #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ |