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