[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" |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 15 | #include "base/optional.h" |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 16 | #include "base/time/time.h" |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 17 | #include "components/sync/base/model_type.h" |
Max Bogue | fef332d | 2016-07-28 22:09:09 | [diff] [blame] | 18 | #include "components/sync/protocol/sync.pb.h" |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 19 | |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 20 | namespace base { |
| 21 | class DictionaryValue; |
| 22 | } |
| 23 | |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 24 | namespace syncer { |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 25 | |
| 26 | // A class that holds information regarding the properties of a device. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 27 | class DeviceInfo { |
| 28 | public: |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 29 | // A struct that holds information regarding to FCM web push. |
| 30 | struct SharingTargetInfo { |
| 31 | // FCM registration token of device. |
| 32 | std::string fcm_token; |
| 33 | |
| 34 | // Public key for Sharing message encryption[RFC8291]. |
| 35 | std::string p256dh; |
| 36 | |
| 37 | // Auth secret for Sharing message encryption[RFC8291]. |
| 38 | std::string auth_secret; |
| 39 | |
| 40 | bool operator==(const SharingTargetInfo& other) const; |
| 41 | }; |
| 42 | |
| 43 | // A struct that holds information regarding to Sharing features. |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 44 | struct SharingInfo { |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 45 | SharingInfo(SharingTargetInfo vapid_target_info, |
| 46 | SharingTargetInfo sharing_target_info, |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 47 | std::set<sync_pb::SharingSpecificFields::EnabledFeatures> |
| 48 | enabled_features); |
| 49 | SharingInfo(const SharingInfo& other); |
| 50 | SharingInfo(SharingInfo&& other); |
| 51 | SharingInfo& operator=(const SharingInfo& other); |
| 52 | ~SharingInfo(); |
| 53 | |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 54 | // Target info using VAPID key. |
| 55 | // TODO(crbug.com/1012226): Deprecate when VAPID migration is over. |
| 56 | SharingTargetInfo vapid_target_info; |
Alex Chau | f1de518 | 2019-11-14 14:19:16 | [diff] [blame] | 57 | |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame] | 58 | // Target info using Sharing sender ID. |
| 59 | SharingTargetInfo sender_id_target_info; |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 60 | |
| 61 | // Set of Sharing features enabled on the device. |
| 62 | std::set<sync_pb::SharingSpecificFields::EnabledFeatures> enabled_features; |
| 63 | |
| 64 | bool operator==(const SharingInfo& other) const; |
| 65 | }; |
| 66 | |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 67 | struct PhoneAsASecurityKeyInfo { |
| 68 | PhoneAsASecurityKeyInfo(); |
| 69 | PhoneAsASecurityKeyInfo(const PhoneAsASecurityKeyInfo& other); |
| 70 | PhoneAsASecurityKeyInfo(PhoneAsASecurityKeyInfo&& other); |
| 71 | PhoneAsASecurityKeyInfo& operator=(const PhoneAsASecurityKeyInfo& other); |
| 72 | ~PhoneAsASecurityKeyInfo(); |
| 73 | |
| 74 | bool operator==(const PhoneAsASecurityKeyInfo& other) const; |
| 75 | |
| 76 | // The domain of the tunnel service. See |
| 77 | // |device::cablev2::tunnelserver::DecodeDomain| to decode this value. |
| 78 | uint16_t tunnel_server_domain; |
| 79 | // contact_id is an opaque value that is sent to the tunnel service in order |
| 80 | // to identify the caBLEv2 authenticator. |
| 81 | std::vector<uint8_t> contact_id; |
| 82 | // secret is the shared secret that authenticates the desktop to the |
| 83 | // authenticator. |
| 84 | std::array<uint8_t, 32> secret; |
| 85 | // id identifies the secret so that the phone knows which secret to use |
| 86 | // for a given connection. |
| 87 | uint32_t id; |
| 88 | // peer_public_key_x962 is the authenticator's public key. |
| 89 | std::array<uint8_t, 65> peer_public_key_x962; |
| 90 | }; |
| 91 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 92 | DeviceInfo(const std::string& guid, |
| 93 | const std::string& client_name, |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 94 | const std::string& chrome_version, |
| 95 | const std::string& sync_user_agent, |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 96 | const sync_pb::SyncEnums::DeviceType device_type, |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 97 | const std::string& signin_scoped_device_id, |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 98 | const std::string& manufacturer_name, |
| 99 | const std::string& model_name, |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame^] | 100 | const std::string& full_hardware_class, |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 101 | base::Time last_updated_timestamp, |
Michael van Ouwerkerk | a91ab6e | 2020-02-03 12:55:38 | [diff] [blame] | 102 | base::TimeDelta pulse_interval, |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 103 | bool send_tab_to_self_receiving_enabled, |
Rushan Suleymanov | 74e7ee259 | 2020-08-02 19:30:40 | [diff] [blame] | 104 | const base::Optional<SharingInfo>& sharing_info, |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 105 | const base::Optional<PhoneAsASecurityKeyInfo>& paask_info, |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 106 | const std::string& fcm_registration_token, |
| 107 | const ModelTypeSet& interested_data_types); |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 108 | ~DeviceInfo(); |
| 109 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 110 | // Sync specific unique identifier for the device. Note if a device |
| 111 | // is wiped and sync is set up again this id WILL be different. |
| 112 | // The same device might have more than 1 guid if the device has multiple |
| 113 | // accounts syncing. |
| 114 | const std::string& guid() const; |
| 115 | |
| 116 | // The host name for the client. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 117 | const std::string& client_name() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 118 | |
| 119 | // Chrome version string. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 120 | const std::string& chrome_version() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 121 | |
| 122 | // The user agent is the combination of OS type, chrome version and which |
| 123 | // channel of chrome(stable or beta). For more information see |
stanisc | 1052875 | 2014-09-23 21:52:19 | [diff] [blame] | 124 | // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 125 | const std::string& sync_user_agent() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 126 | |
[email protected] | 790daf5c | 2013-07-31 18:42:57 | [diff] [blame] | 127 | // Third party visible id for the device. See |public_id_| for more details. |
| 128 | const std::string& public_id() const; |
| 129 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 130 | // Device Type. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 131 | sync_pb::SyncEnums::DeviceType device_type() const; |
| 132 | |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 133 | // Device_id that is stable until user signs out. This device_id is used for |
| 134 | // annotating login scoped refresh token. |
| 135 | const std::string& signin_scoped_device_id() const; |
| 136 | |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 137 | // The device manufacturer name. |
| 138 | const std::string& manufacturer_name() const; |
| 139 | |
| 140 | // The device model name. |
| 141 | const std::string& model_name() const; |
Himanshu Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 142 | |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame^] | 143 | // Returns unique hardware class string which details the |
| 144 | // HW combination of a ChromeOS device. Returns empty on other OS devices or |
| 145 | // when UMA is disabled. |
| 146 | const std::string& full_hardware_class() const; |
| 147 | |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 148 | // Returns the time at which this device was last updated to the sync servers. |
| 149 | base::Time last_updated_timestamp() const; |
| 150 | |
Michael van Ouwerkerk | a91ab6e | 2020-02-03 12:55:38 | [diff] [blame] | 151 | // Returns the interval with which this device is updated to the sync servers |
| 152 | // if online and while sync is actively running (e.g. excludes backgrounded |
| 153 | // apps on Android). |
| 154 | base::TimeDelta pulse_interval() const; |
| 155 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 156 | // Whether the receiving side of the SendTabToSelf feature is enabled. |
| 157 | bool send_tab_to_self_receiving_enabled() const; |
| 158 | |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 159 | // Returns Sharing related info of the device. |
| 160 | const base::Optional<SharingInfo>& sharing_info() const; |
| 161 | |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 162 | const base::Optional<PhoneAsASecurityKeyInfo>& paask_info() const; |
| 163 | |
Rushan Suleymanov | 74e7ee259 | 2020-08-02 19:30:40 | [diff] [blame] | 164 | // Returns the FCM registration token for sync invalidations. |
| 165 | const std::string& fcm_registration_token() const; |
| 166 | |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 167 | // Returns the data types for which this device receives invalidations. |
| 168 | const ModelTypeSet& interested_data_types() const; |
| 169 | |
[email protected] | f32d8ce | 2013-09-24 04:38:40 | [diff] [blame] | 170 | // Gets the OS in string form. |
| 171 | std::string GetOSString() const; |
| 172 | |
| 173 | // Gets the device type in string form. |
| 174 | std::string GetDeviceTypeString() const; |
| 175 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 176 | // Compares this object's fields with another's. |
| 177 | bool Equals(const DeviceInfo& other) const; |
| 178 | |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 179 | // Apps can set ids for a device that is meaningful to them but |
| 180 | // not unique enough so the user can be tracked. Exposing |guid| |
| 181 | // would lead to a stable unique id for a device which can potentially |
| 182 | // be used for tracking. |
ki.stfu | 939799a4 | 2015-09-28 04:41:20 | [diff] [blame] | 183 | void set_public_id(const std::string& id); |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 184 | |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame^] | 185 | void set_full_hardware_class(const std::string& full_hardware_class); |
| 186 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 187 | void set_send_tab_to_self_receiving_enabled(bool new_value); |
| 188 | |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 189 | void set_sharing_info(const base::Optional<SharingInfo>& sharing_info); |
| 190 | |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 191 | void set_paask_info(PhoneAsASecurityKeyInfo&& paask_info); |
| 192 | |
Himanshu Jaju | f2c5d73 | 2019-10-21 14:52:33 | [diff] [blame] | 193 | void set_client_name(const std::string& client_name); |
| 194 | |
Rushan Suleymanov | 74e7ee259 | 2020-08-02 19:30:40 | [diff] [blame] | 195 | void set_fcm_registration_token(const std::string& fcm_token); |
| 196 | |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 197 | void set_interested_data_types(const ModelTypeSet& data_types); |
| 198 | |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 199 | // Converts the |DeviceInfo| values to a JS friendly DictionaryValue, |
| 200 | // which extension APIs can expose to third party apps. |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 201 | std::unique_ptr<base::DictionaryValue> ToValue() const; |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 202 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 203 | private: |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 204 | const std::string guid_; |
| 205 | |
Himanshu Jaju | f2c5d73 | 2019-10-21 14:52:33 | [diff] [blame] | 206 | std::string client_name_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 207 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 208 | const std::string chrome_version_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 209 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 210 | const std::string sync_user_agent_; |
[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 sync_pb::SyncEnums::DeviceType device_type_; |
[email protected] | 16b85e8 | 2012-11-21 04:16:33 | [diff] [blame] | 213 | |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 214 | const std::string signin_scoped_device_id_; |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 215 | |
[email protected] | 790daf5c | 2013-07-31 18:42:57 | [diff] [blame] | 216 | // Exposing |guid| would lead to a stable unique id for a device which |
| 217 | // can potentially be used for tracking. Public ids are privacy safe |
| 218 | // ids in that the same device will have different id for different apps |
| 219 | // and they are also reset when app/extension is uninstalled. |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 220 | std::string public_id_; |
| 221 | |
Richard Knoll | 5b608be | 2020-07-10 08:39:40 | [diff] [blame] | 222 | const std::string manufacturer_name_; |
| 223 | |
| 224 | const std::string model_name_; |
Himanshu Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 225 | |
Hirthanan Subenderan | e6657f7 | 2021-04-16 10:43:12 | [diff] [blame^] | 226 | std::string full_hardware_class_; |
| 227 | |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 228 | const base::Time last_updated_timestamp_; |
| 229 | |
Michael van Ouwerkerk | a91ab6e | 2020-02-03 12:55:38 | [diff] [blame] | 230 | const base::TimeDelta pulse_interval_; |
| 231 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 232 | bool send_tab_to_self_receiving_enabled_; |
| 233 | |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 234 | base::Optional<SharingInfo> sharing_info_; |
| 235 | |
Adam Langley | 1b4e4a6 | 2021-03-25 23:07:39 | [diff] [blame] | 236 | base::Optional<PhoneAsASecurityKeyInfo> paask_info_; |
| 237 | |
Rushan Suleymanov | 74e7ee259 | 2020-08-02 19:30:40 | [diff] [blame] | 238 | // An FCM registration token obtained by sync invalidations service. |
| 239 | std::string fcm_registration_token_; |
| 240 | |
Paula Vidas | d3c720e6 | 2020-09-03 07:20:06 | [diff] [blame] | 241 | // Data types for which this device receives invalidations. |
| 242 | ModelTypeSet interested_data_types_; |
| 243 | |
[email protected] | 16b85e8 | 2012-11-21 04:16:33 | [diff] [blame] | 244 | DISALLOW_COPY_AND_ASSIGN(DeviceInfo); |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 245 | }; |
| 246 | |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 247 | } // namespace syncer |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 248 | |
maxbogue | f1885f7d | 2016-08-16 19:13:20 | [diff] [blame] | 249 | #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ |