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