remote_device_ref.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include "ash/components/multidevice/remote_device_ref.h"
  5. #include <sstream>
  6. #include "base/base64.h"
  7. #include "base/containers/contains.h"
  8. namespace ash::multidevice {
  9. // static
  10. std::string RemoteDeviceRef::TruncateDeviceIdForLogs(
  11. const std::string& full_id) {
  12. if (full_id.length() <= 10) {
  13. return full_id;
  14. }
  15. return full_id.substr(0, 5) + "..." +
  16. full_id.substr(full_id.length() - 5, full_id.length());
  17. }
  18. RemoteDeviceRef::RemoteDeviceRef(std::shared_ptr<RemoteDevice> remote_device)
  19. : remote_device_(std::move(remote_device)) {}
  20. RemoteDeviceRef::RemoteDeviceRef(const RemoteDeviceRef& other) = default;
  21. RemoteDeviceRef::~RemoteDeviceRef() = default;
  22. SoftwareFeatureState RemoteDeviceRef::GetSoftwareFeatureState(
  23. const SoftwareFeature& software_feature) const {
  24. if (!base::Contains(remote_device_->software_features, software_feature))
  25. return SoftwareFeatureState::kNotSupported;
  26. return remote_device_->software_features.at(software_feature);
  27. }
  28. std::string RemoteDeviceRef::GetDeviceId() const {
  29. return remote_device_->GetDeviceId();
  30. }
  31. std::string RemoteDeviceRef::GetTruncatedDeviceIdForLogs() const {
  32. return RemoteDeviceRef::TruncateDeviceIdForLogs(GetDeviceId());
  33. }
  34. std::string RemoteDeviceRef::GetInstanceIdDeviceIdForLogs() const {
  35. std::stringstream ss;
  36. ss << "{Instance ID: " << (instance_id().empty() ? "[empty]" : instance_id())
  37. << ", Device ID: "
  38. << (GetTruncatedDeviceIdForLogs().empty() ? "[empty]"
  39. : GetTruncatedDeviceIdForLogs())
  40. << "}";
  41. return ss.str();
  42. }
  43. bool RemoteDeviceRef::operator==(const RemoteDeviceRef& other) const {
  44. return *remote_device_ == *other.remote_device_;
  45. }
  46. bool RemoteDeviceRef::operator!=(const RemoteDeviceRef& other) const {
  47. return !(*this == other);
  48. }
  49. bool RemoteDeviceRef::operator<(const RemoteDeviceRef& other) const {
  50. return *remote_device_ < *other.remote_device_;
  51. }
  52. const RemoteDevice& RemoteDeviceRef::GetRemoteDevice() const {
  53. return *remote_device_;
  54. }
  55. } // namespace ash::multidevice