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