[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 | |
skym | 6d5ecf8 | 2016-10-04 17:43:45 | [diff] [blame] | 8 | #include <memory> |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 9 | #include <set> |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 10 | #include <string> |
| 11 | |
stanisc | 1052875 | 2014-09-23 21:52:19 | [diff] [blame] | 12 | #include "base/callback.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 13 | #include "base/macros.h" |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 14 | #include "base/optional.h" |
Himanshu Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 15 | #include "base/system/sys_info.h" |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 16 | #include "base/time/time.h" |
Max Bogue | fef332d | 2016-07-28 22:09:09 | [diff] [blame] | 17 | #include "components/sync/protocol/sync.pb.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 | |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 23 | namespace syncer { |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 24 | |
| 25 | // A class that holds information regarding the properties of a device. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 26 | class DeviceInfo { |
| 27 | public: |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame^] | 28 | // A struct that holds information regarding to FCM web push. |
| 29 | struct SharingTargetInfo { |
| 30 | // FCM registration token of device. |
| 31 | std::string fcm_token; |
| 32 | |
| 33 | // Public key for Sharing message encryption[RFC8291]. |
| 34 | std::string p256dh; |
| 35 | |
| 36 | // Auth secret for Sharing message encryption[RFC8291]. |
| 37 | std::string auth_secret; |
| 38 | |
| 39 | bool operator==(const SharingTargetInfo& other) const; |
| 40 | }; |
| 41 | |
| 42 | // A struct that holds information regarding to Sharing features. |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 43 | struct SharingInfo { |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame^] | 44 | SharingInfo(SharingTargetInfo vapid_target_info, |
| 45 | SharingTargetInfo sharing_target_info, |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 46 | std::set<sync_pb::SharingSpecificFields::EnabledFeatures> |
| 47 | enabled_features); |
| 48 | SharingInfo(const SharingInfo& other); |
| 49 | SharingInfo(SharingInfo&& other); |
| 50 | SharingInfo& operator=(const SharingInfo& other); |
| 51 | ~SharingInfo(); |
| 52 | |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame^] | 53 | // Target info using VAPID key. |
| 54 | // TODO(crbug.com/1012226): Deprecate when VAPID migration is over. |
| 55 | SharingTargetInfo vapid_target_info; |
Alex Chau | f1de518 | 2019-11-14 14:19:16 | [diff] [blame] | 56 | |
Alex Chau | 965a5a2 | 2019-11-18 16:51:58 | [diff] [blame^] | 57 | // Target info using Sharing sender ID. |
| 58 | SharingTargetInfo sender_id_target_info; |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 59 | |
| 60 | // Set of Sharing features enabled on the device. |
| 61 | std::set<sync_pb::SharingSpecificFields::EnabledFeatures> enabled_features; |
| 62 | |
| 63 | bool operator==(const SharingInfo& other) const; |
| 64 | }; |
| 65 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 66 | DeviceInfo(const std::string& guid, |
| 67 | const std::string& client_name, |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 68 | const std::string& chrome_version, |
| 69 | const std::string& sync_user_agent, |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 70 | const sync_pb::SyncEnums::DeviceType device_type, |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 71 | const std::string& signin_scoped_device_id, |
Himanshu Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 72 | const base::SysInfo::HardwareInfo& hardware_info, |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 73 | base::Time last_updated_timestamp, |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 74 | bool send_tab_to_self_receiving_enabled, |
| 75 | const base::Optional<SharingInfo>& sharing_info); |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 76 | ~DeviceInfo(); |
| 77 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 78 | // Sync specific unique identifier for the device. Note if a device |
| 79 | // is wiped and sync is set up again this id WILL be different. |
| 80 | // The same device might have more than 1 guid if the device has multiple |
| 81 | // accounts syncing. |
| 82 | const std::string& guid() const; |
| 83 | |
| 84 | // The host name for the client. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 85 | const std::string& client_name() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 86 | |
| 87 | // Chrome version string. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 88 | const std::string& chrome_version() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 89 | |
| 90 | // The user agent is the combination of OS type, chrome version and which |
| 91 | // channel of chrome(stable or beta). For more information see |
stanisc | 1052875 | 2014-09-23 21:52:19 | [diff] [blame] | 92 | // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 93 | const std::string& sync_user_agent() const; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 94 | |
[email protected] | 790daf5c | 2013-07-31 18:42:57 | [diff] [blame] | 95 | // Third party visible id for the device. See |public_id_| for more details. |
| 96 | const std::string& public_id() const; |
| 97 | |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 98 | // Device Type. |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 99 | sync_pb::SyncEnums::DeviceType device_type() const; |
| 100 | |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 101 | // Device_id that is stable until user signs out. This device_id is used for |
| 102 | // annotating login scoped refresh token. |
| 103 | const std::string& signin_scoped_device_id() const; |
| 104 | |
Himanshu Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 105 | const base::SysInfo::HardwareInfo& hardware_info() const; |
| 106 | |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 107 | // Returns the time at which this device was last updated to the sync servers. |
| 108 | base::Time last_updated_timestamp() const; |
| 109 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 110 | // Whether the receiving side of the SendTabToSelf feature is enabled. |
| 111 | bool send_tab_to_self_receiving_enabled() const; |
| 112 | |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 113 | // Returns Sharing related info of the device. |
| 114 | const base::Optional<SharingInfo>& sharing_info() const; |
| 115 | |
[email protected] | f32d8ce | 2013-09-24 04:38:40 | [diff] [blame] | 116 | // Gets the OS in string form. |
| 117 | std::string GetOSString() const; |
| 118 | |
| 119 | // Gets the device type in string form. |
| 120 | std::string GetDeviceTypeString() const; |
| 121 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 122 | // Compares this object's fields with another's. |
| 123 | bool Equals(const DeviceInfo& other) const; |
| 124 | |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 125 | // Apps can set ids for a device that is meaningful to them but |
| 126 | // not unique enough so the user can be tracked. Exposing |guid| |
| 127 | // would lead to a stable unique id for a device which can potentially |
| 128 | // be used for tracking. |
ki.stfu | 939799a4 | 2015-09-28 04:41:20 | [diff] [blame] | 129 | void set_public_id(const std::string& id); |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 130 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 131 | void set_send_tab_to_self_receiving_enabled(bool new_value); |
| 132 | |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 133 | void set_sharing_info(const base::Optional<SharingInfo>& sharing_info); |
| 134 | |
Himanshu Jaju | f2c5d73 | 2019-10-21 14:52:33 | [diff] [blame] | 135 | void set_client_name(const std::string& client_name); |
| 136 | |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 137 | // Converts the |DeviceInfo| values to a JS friendly DictionaryValue, |
| 138 | // which extension APIs can expose to third party apps. |
dcheng | 32fd7c4 | 2016-08-27 11:16:06 | [diff] [blame] | 139 | std::unique_ptr<base::DictionaryValue> ToValue(); |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 140 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 141 | private: |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 142 | const std::string guid_; |
| 143 | |
Himanshu Jaju | f2c5d73 | 2019-10-21 14:52:33 | [diff] [blame] | 144 | std::string client_name_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 145 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 146 | const std::string chrome_version_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 147 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 148 | const std::string sync_user_agent_; |
[email protected] | 1e281a4 | 2013-07-16 23:04:08 | [diff] [blame] | 149 | |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 150 | const sync_pb::SyncEnums::DeviceType device_type_; |
[email protected] | 16b85e8 | 2012-11-21 04:16:33 | [diff] [blame] | 151 | |
[email protected] | e0ec8ba | 2014-07-18 23:38:04 | [diff] [blame] | 152 | std::string signin_scoped_device_id_; |
| 153 | |
[email protected] | 790daf5c | 2013-07-31 18:42:57 | [diff] [blame] | 154 | // Exposing |guid| would lead to a stable unique id for a device which |
| 155 | // can potentially be used for tracking. Public ids are privacy safe |
| 156 | // ids in that the same device will have different id for different apps |
| 157 | // and they are also reset when app/extension is uninstalled. |
[email protected] | 648a566 | 2013-07-18 20:45:45 | [diff] [blame] | 158 | std::string public_id_; |
| 159 | |
Himanshu Jaju | 0ddf2c13 | 2019-10-10 16:22:28 | [diff] [blame] | 160 | base::SysInfo::HardwareInfo hardware_info_; |
| 161 | |
Sébastien Séguin-Gagnon | b7cc925 | 2019-05-09 22:00:39 | [diff] [blame] | 162 | const base::Time last_updated_timestamp_; |
| 163 | |
Tanya Gupta | c1dec1c | 2019-04-18 22:56:05 | [diff] [blame] | 164 | bool send_tab_to_self_receiving_enabled_; |
| 165 | |
Alex Chau | 4e13d9b6 | 2019-09-30 17:09:59 | [diff] [blame] | 166 | base::Optional<SharingInfo> sharing_info_; |
| 167 | |
[email protected] | 16b85e8 | 2012-11-21 04:16:33 | [diff] [blame] | 168 | DISALLOW_COPY_AND_ASSIGN(DeviceInfo); |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 169 | }; |
| 170 | |
maxbogue | 7e006db | 2016-10-03 19:48:28 | [diff] [blame] | 171 | } // namespace syncer |
[email protected] | 34e9817 | 2012-10-12 04:01:39 | [diff] [blame] | 172 | |
maxbogue | f1885f7d | 2016-08-16 19:13:20 | [diff] [blame] | 173 | #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_ |