storage_info.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright 2014 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_STORAGE_MONITOR_STORAGE_INFO_H_
  5. #define COMPONENTS_STORAGE_MONITOR_STORAGE_INFO_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include "base/files/file_path.h"
  9. namespace storage_monitor {
  10. class StorageInfo {
  11. public:
  12. enum Type {
  13. // A removable mass storage device with a DCIM directory.
  14. REMOVABLE_MASS_STORAGE_WITH_DCIM,
  15. // A removable mass storage device without a DCIM directory.
  16. REMOVABLE_MASS_STORAGE_NO_DCIM,
  17. // A fixed mass storage device.
  18. FIXED_MASS_STORAGE,
  19. // A MTP or PTP device.
  20. MTP_OR_PTP,
  21. // A Mac ImageCapture device.
  22. MAC_IMAGE_CAPTURE,
  23. };
  24. StorageInfo();
  25. // Note: |device_id_in| should be constructed with MakeDeviceId.
  26. StorageInfo(const std::string& device_id_in,
  27. const base::FilePath::StringType& device_location,
  28. const std::u16string& label,
  29. const std::u16string& vendor,
  30. const std::u16string& model,
  31. uint64_t size_in_bytes);
  32. StorageInfo(const StorageInfo& other);
  33. ~StorageInfo();
  34. // Returns a device id given properties of the device. A prefix dependent on
  35. // |type| is added so |unique_id| need only be unique within the given type.
  36. // Returns an empty string if an invalid type is passed in.
  37. static std::string MakeDeviceId(Type type, const std::string& unique_id);
  38. // Extracts the device |type| and |unique_id| from |device_id|. Returns false
  39. // if the device_id isn't properly formatted.
  40. static bool CrackDeviceId(const std::string& device_id,
  41. Type* type, std::string* unique_id);
  42. // Looks inside |device_id| to determine if it is a media device
  43. // (type is REMOVABLE_MASS_STORAGE_WITH_DCIM or MTP_OR_PTP).
  44. static bool IsMediaDevice(const std::string& device_id);
  45. // Looks inside |device_id| to determine if it is a media device
  46. // (type isn't FIXED_MASS_STORAGE).
  47. static bool IsRemovableDevice(const std::string& device_id);
  48. // Looks inside |device_id| to determine if it is a mass storage device
  49. // (type isn't MTP_OR_PTP).
  50. static bool IsMassStorageDevice(const std::string& device_id);
  51. static bool IsMTPDevice(const std::string& device_id);
  52. // Get the display name for the removable device represented by this
  53. // StorageInfo. Include the size for removable devices if |with_size| is true.
  54. std::u16string GetDisplayName(bool with_size) const;
  55. // Same as GetDisplayName(), but may be overridden by |override_display_name|.
  56. std::u16string GetDisplayNameWithOverride(
  57. const std::u16string& override_display_name,
  58. bool with_size) const;
  59. const std::string& device_id() const { return device_id_; }
  60. const base::FilePath::StringType& location() const { return location_; }
  61. const std::u16string& storage_label() const { return storage_label_; }
  62. const std::u16string& vendor_name() const { return vendor_name_; }
  63. const std::u16string& model_name() const { return model_name_; }
  64. uint64_t total_size_in_bytes() const { return total_size_in_bytes_; }
  65. void set_device_id(const std::string& device_id) { device_id_ = device_id; }
  66. void set_location(const base::FilePath::StringType& location) {
  67. location_ = location;
  68. }
  69. private:
  70. // Unique device id - persists between device attachments.
  71. // This is the string that should be used as the label for a particular
  72. // storage device when interacting with the API. Clients should treat
  73. // this as an opaque string.
  74. std::string device_id_;
  75. // Current attached removable storage device location.
  76. base::FilePath::StringType location_;
  77. // Label given to this storage device by the user.
  78. // May be empty if not found or the device is unlabeled.
  79. std::u16string storage_label_;
  80. // Vendor name for the removable device. (Human readable)
  81. // May be empty if not collected.
  82. std::u16string vendor_name_;
  83. // Model name for the removable device. (Human readable)
  84. // May be empty if not collected.
  85. std::u16string model_name_;
  86. // Size of the removable device in bytes.
  87. // Zero if not collected or unknown.
  88. uint64_t total_size_in_bytes_;
  89. };
  90. } // namespace storage_monitor
  91. #endif // COMPONENTS_STORAGE_MONITOR_STORAGE_INFO_H_