remote_device_ref.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2018 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 ASH_COMPONENTS_MULTIDEVICE_REMOTE_DEVICE_REF_H_
  5. #define ASH_COMPONENTS_MULTIDEVICE_REMOTE_DEVICE_REF_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/components/multidevice/remote_device.h"
  10. #include "ash/components/multidevice/software_feature_state.h"
  11. #include "base/gtest_prod_util.h"
  12. namespace ash {
  13. class EasyUnlockServiceRegular;
  14. namespace multidevice_setup {
  15. class MultiDeviceSetupImpl;
  16. }
  17. namespace secure_channel {
  18. class PresenceMonitorClientImpl;
  19. class SecureChannelClientImpl;
  20. } // namespace secure_channel
  21. namespace tether {
  22. class TetherHostFetcherImpl;
  23. class TetherHostFetcherImplTest;
  24. } // namespace tether
  25. namespace multidevice {
  26. class ProximityAuthWebUIHandler;
  27. // Contains metadata specific to a device associated with a user's account.
  28. // Because this metadata contains large and expensive data types, and that data
  29. // can become stale if a Device Sync occurs during a client application's
  30. // lifecycle, RemoteDeviceRef is implemented using a pointer to a struct
  31. // containing this metadata; if multiple clients want to reference the same
  32. // device, multiple RemoteDeviceRefs can be created cheaply without duplicating
  33. // the underlying data. Should be passed by value.
  34. class RemoteDeviceRef {
  35. public:
  36. // Static method for truncated device ID for logs.
  37. static std::string TruncateDeviceIdForLogs(const std::string& full_id);
  38. RemoteDeviceRef(const RemoteDeviceRef& other);
  39. ~RemoteDeviceRef();
  40. const std::string& user_email() const { return remote_device_->user_email; }
  41. const std::string& instance_id() const { return remote_device_->instance_id; }
  42. const std::string& name() const { return remote_device_->name; }
  43. const std::string& pii_free_name() const {
  44. return remote_device_->pii_free_name;
  45. }
  46. const std::string& public_key() const { return remote_device_->public_key; }
  47. const std::string& persistent_symmetric_key() const {
  48. return remote_device_->persistent_symmetric_key;
  49. }
  50. int64_t last_update_time_millis() const {
  51. return remote_device_->last_update_time_millis;
  52. }
  53. const std::vector<BeaconSeed>& beacon_seeds() const {
  54. return remote_device_->beacon_seeds;
  55. }
  56. const std::string& bluetooth_public_address() const {
  57. return remote_device_->bluetooth_public_address;
  58. }
  59. std::string GetDeviceId() const;
  60. SoftwareFeatureState GetSoftwareFeatureState(
  61. const SoftwareFeature& software_feature) const;
  62. // Returns a shortened device ID for the purpose of concise logging (device
  63. // IDs are often so long that logs are difficult to read). Note that this
  64. // ID is not guaranteed to be unique, so it should only be used for log.
  65. std::string GetTruncatedDeviceIdForLogs() const;
  66. // Returns the pair of IDs used with RemoteDevices: Instance ID and device ID.
  67. // If either ID is missing, this string will make note of that. If a device ID
  68. // exists, the truncated version will be presented. This function should only
  69. // be used for logging.
  70. std::string GetInstanceIdDeviceIdForLogs() const;
  71. bool operator==(const RemoteDeviceRef& other) const;
  72. bool operator!=(const RemoteDeviceRef& other) const;
  73. bool operator<(const RemoteDeviceRef& other) const;
  74. private:
  75. friend class multidevice_setup::MultiDeviceSetupImpl;
  76. friend class secure_channel::SecureChannelClientImpl;
  77. friend class secure_channel::PresenceMonitorClientImpl;
  78. friend class RemoteDeviceCache;
  79. friend class RemoteDeviceRefBuilder;
  80. friend class RemoteDeviceRefTest;
  81. friend bool IsSameDevice(const RemoteDevice& remote_device,
  82. RemoteDeviceRef remote_device_ref);
  83. friend RemoteDevice* GetMutableRemoteDevice(
  84. const RemoteDeviceRef& remote_device_ref);
  85. FRIEND_TEST_ALL_PREFIXES(RemoteDeviceRefTest, TestFields);
  86. FRIEND_TEST_ALL_PREFIXES(RemoteDeviceRefTest, TestCopyAndAssign);
  87. // TODO(crbug.com/752273): Remove these once clients have migrated to Device
  88. // Sync service.
  89. friend class EasyUnlockServiceRegular;
  90. friend class tether::TetherHostFetcherImplTest;
  91. friend class tether::TetherHostFetcherImpl;
  92. friend class ProximityAuthWebUIHandler;
  93. explicit RemoteDeviceRef(std::shared_ptr<RemoteDevice> remote_device);
  94. // Returns the raw RemoteDevice object. Should only be used when passing
  95. // RemoteDevice objects through a Mojo API, which requires that the raw type
  96. // is passed instead of the RemoteDeviceRef wrapper object.
  97. const RemoteDevice& GetRemoteDevice() const;
  98. std::shared_ptr<const RemoteDevice> remote_device_;
  99. };
  100. typedef std::vector<RemoteDeviceRef> RemoteDeviceRefList;
  101. } // namespace multidevice
  102. } // namespace ash
  103. // TODO(https://crbug.com/1164001): remove after the //chrome/browser/chromeos
  104. // source migration is finished.
  105. namespace chromeos::multidevice {
  106. using ::ash::multidevice::RemoteDeviceRef;
  107. }
  108. #endif // ASH_COMPONENTS_MULTIDEVICE_REMOTE_DEVICE_REF_H_