device_info.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. #ifndef COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
  5. #define COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_
  6. #include <array>
  7. #include <memory>
  8. #include <set>
  9. #include <string>
  10. #include <vector>
  11. #include "base/time/time.h"
  12. #include "components/sync/base/model_type.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. namespace base {
  15. class DictionaryValue;
  16. }
  17. namespace sync_pb {
  18. enum SharingSpecificFields_EnabledFeatures : int;
  19. enum SyncEnums_DeviceType : int;
  20. } // namespace sync_pb
  21. namespace syncer {
  22. // A class that holds information regarding the properties of a device.
  23. class DeviceInfo {
  24. public:
  25. // A struct that holds information regarding to FCM web push.
  26. struct SharingTargetInfo {
  27. // FCM registration token of device.
  28. std::string fcm_token;
  29. // Public key for Sharing message encryption[RFC8291].
  30. std::string p256dh;
  31. // Auth secret for Sharing message encryption[RFC8291].
  32. std::string auth_secret;
  33. bool operator==(const SharingTargetInfo& other) const;
  34. };
  35. // A struct that holds information regarding to Sharing features.
  36. struct SharingInfo {
  37. SharingInfo(SharingTargetInfo vapid_target_info,
  38. SharingTargetInfo sharing_target_info,
  39. std::set<sync_pb::SharingSpecificFields_EnabledFeatures>
  40. enabled_features);
  41. SharingInfo(const SharingInfo& other);
  42. SharingInfo(SharingInfo&& other);
  43. SharingInfo& operator=(const SharingInfo& other);
  44. ~SharingInfo();
  45. // Target info using VAPID key.
  46. // TODO(crbug.com/1012226): Deprecate when VAPID migration is over.
  47. SharingTargetInfo vapid_target_info;
  48. // Target info using Sharing sender ID.
  49. SharingTargetInfo sender_id_target_info;
  50. // Set of Sharing features enabled on the device.
  51. std::set<sync_pb::SharingSpecificFields_EnabledFeatures> enabled_features;
  52. bool operator==(const SharingInfo& other) const;
  53. };
  54. struct PhoneAsASecurityKeyInfo {
  55. PhoneAsASecurityKeyInfo();
  56. PhoneAsASecurityKeyInfo(const PhoneAsASecurityKeyInfo& other);
  57. PhoneAsASecurityKeyInfo(PhoneAsASecurityKeyInfo&& other);
  58. PhoneAsASecurityKeyInfo& operator=(const PhoneAsASecurityKeyInfo& other);
  59. ~PhoneAsASecurityKeyInfo();
  60. // NonRotatingFieldsEqual returns true if this object is equal to |other|,
  61. // ignoring the |id| and |secret| fields, which update based on the current
  62. // time.
  63. bool NonRotatingFieldsEqual(const PhoneAsASecurityKeyInfo& other) const;
  64. // The domain of the tunnel service. See
  65. // |device::cablev2::tunnelserver::DecodeDomain| to decode this value.
  66. uint16_t tunnel_server_domain;
  67. // contact_id is an opaque value that is sent to the tunnel service in order
  68. // to identify the caBLEv2 authenticator.
  69. std::vector<uint8_t> contact_id;
  70. // secret is the shared secret that authenticates the desktop to the
  71. // authenticator.
  72. std::array<uint8_t, 32> secret;
  73. // id identifies the secret so that the phone knows which secret to use
  74. // for a given connection.
  75. uint32_t id;
  76. // peer_public_key_x962 is the authenticator's public key.
  77. std::array<uint8_t, 65> peer_public_key_x962;
  78. };
  79. DeviceInfo(const std::string& guid,
  80. const std::string& client_name,
  81. const std::string& chrome_version,
  82. const std::string& sync_user_agent,
  83. const sync_pb::SyncEnums_DeviceType device_type,
  84. const std::string& signin_scoped_device_id,
  85. const std::string& manufacturer_name,
  86. const std::string& model_name,
  87. const std::string& full_hardware_class,
  88. base::Time last_updated_timestamp,
  89. base::TimeDelta pulse_interval,
  90. bool send_tab_to_self_receiving_enabled,
  91. const absl::optional<SharingInfo>& sharing_info,
  92. const absl::optional<PhoneAsASecurityKeyInfo>& paask_info,
  93. const std::string& fcm_registration_token,
  94. const ModelTypeSet& interested_data_types);
  95. DeviceInfo(const DeviceInfo&) = delete;
  96. DeviceInfo& operator=(const DeviceInfo&) = delete;
  97. ~DeviceInfo();
  98. // Sync specific unique identifier for the device. Note if a device
  99. // is wiped and sync is set up again this id WILL be different.
  100. // The same device might have more than 1 guid if the device has multiple
  101. // accounts syncing.
  102. const std::string& guid() const;
  103. // The host name for the client.
  104. const std::string& client_name() const;
  105. // Chrome version string.
  106. const std::string& chrome_version() const;
  107. // The user agent is the combination of OS type, chrome version and which
  108. // channel of chrome(stable or beta). For more information see
  109. // |LocalDeviceInfoProviderImpl::MakeUserAgentForSyncApi|.
  110. const std::string& sync_user_agent() const;
  111. // Third party visible id for the device. See |public_id_| for more details.
  112. const std::string& public_id() const;
  113. // Device Type.
  114. sync_pb::SyncEnums_DeviceType device_type() const;
  115. // Device_id that is stable until user signs out. This device_id is used for
  116. // annotating login scoped refresh token.
  117. const std::string& signin_scoped_device_id() const;
  118. // The device manufacturer name.
  119. const std::string& manufacturer_name() const;
  120. // The device model name.
  121. const std::string& model_name() const;
  122. // Returns unique hardware class string which details the
  123. // HW combination of a ChromeOS device. Returns empty on other OS devices or
  124. // when UMA is disabled.
  125. const std::string& full_hardware_class() const;
  126. // Returns the time at which this device was last updated to the sync servers.
  127. base::Time last_updated_timestamp() const;
  128. // Returns the interval with which this device is updated to the sync servers
  129. // if online and while sync is actively running (e.g. excludes backgrounded
  130. // apps on Android).
  131. base::TimeDelta pulse_interval() const;
  132. // Whether the receiving side of the SendTabToSelf feature is enabled.
  133. bool send_tab_to_self_receiving_enabled() const;
  134. // Returns Sharing related info of the device.
  135. const absl::optional<SharingInfo>& sharing_info() const;
  136. const absl::optional<PhoneAsASecurityKeyInfo>& paask_info() const;
  137. // Returns the FCM registration token for sync invalidations.
  138. const std::string& fcm_registration_token() const;
  139. // Returns the data types for which this device receives invalidations.
  140. const ModelTypeSet& interested_data_types() const;
  141. // Gets the OS in string form.
  142. std::string GetOSString() const;
  143. // Gets the device type in string form.
  144. std::string GetDeviceTypeString() const;
  145. // Apps can set ids for a device that is meaningful to them but
  146. // not unique enough so the user can be tracked. Exposing |guid|
  147. // would lead to a stable unique id for a device which can potentially
  148. // be used for tracking.
  149. void set_public_id(const std::string& id);
  150. void set_full_hardware_class(const std::string& full_hardware_class);
  151. void set_send_tab_to_self_receiving_enabled(bool new_value);
  152. void set_sharing_info(const absl::optional<SharingInfo>& sharing_info);
  153. void set_paask_info(PhoneAsASecurityKeyInfo&& paask_info);
  154. void set_client_name(const std::string& client_name);
  155. void set_fcm_registration_token(const std::string& fcm_token);
  156. void set_interested_data_types(const ModelTypeSet& data_types);
  157. // Converts the |DeviceInfo| values to a JS friendly DictionaryValue,
  158. // which extension APIs can expose to third party apps.
  159. std::unique_ptr<base::DictionaryValue> ToValue() const;
  160. private:
  161. const std::string guid_;
  162. std::string client_name_;
  163. const std::string chrome_version_;
  164. const std::string sync_user_agent_;
  165. const sync_pb::SyncEnums_DeviceType device_type_;
  166. const std::string signin_scoped_device_id_;
  167. // Exposing |guid| would lead to a stable unique id for a device which
  168. // can potentially be used for tracking. Public ids are privacy safe
  169. // ids in that the same device will have different id for different apps
  170. // and they are also reset when app/extension is uninstalled.
  171. std::string public_id_;
  172. const std::string manufacturer_name_;
  173. const std::string model_name_;
  174. std::string full_hardware_class_;
  175. const base::Time last_updated_timestamp_;
  176. const base::TimeDelta pulse_interval_;
  177. bool send_tab_to_self_receiving_enabled_;
  178. absl::optional<SharingInfo> sharing_info_;
  179. absl::optional<PhoneAsASecurityKeyInfo> paask_info_;
  180. // An FCM registration token obtained by sync invalidations service.
  181. std::string fcm_registration_token_;
  182. // Data types for which this device receives invalidations.
  183. ModelTypeSet interested_data_types_;
  184. // NOTE: when adding a member, don't forget to update
  185. // |StoredDeviceInfoStillAccurate| in device_info_sync_bridge.cc or else
  186. // changes in that member might not trigger uploads of updated DeviceInfos.
  187. };
  188. } // namespace syncer
  189. #endif // COMPONENTS_SYNC_DEVICE_INFO_DEVICE_INFO_H_