Home | History | Annotate | Download | only in storage_monitor
      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 namespace chrome {
     12 
     13 struct 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   };
     31 
     32   StorageInfo();
     33   // Note: |device_id_in| should be constructed with MakeDeviceId.
     34   StorageInfo(const std::string& device_id_in,
     35               const string16& device_name,
     36               const base::FilePath::StringType& device_location,
     37               const string16& label,
     38               const string16& vendor,
     39               const 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   const std::string& device_id() const { return device_id_; }
     70   const string16& name() const { return name_; }
     71   const base::FilePath::StringType& location() const { return location_; }
     72   const string16& storage_label() const { return storage_label_; }
     73   const string16& vendor_name() const { return vendor_name_; }
     74   const string16& model_name() const { return model_name_; }
     75   uint64 total_size_in_bytes() const { return total_size_in_bytes_; }
     76 
     77   void set_device_id(const std::string& device_id) { device_id_ = device_id; }
     78   void set_name(const string16& name) { name_ = name; }
     79   void set_location(const base::FilePath::StringType& location) {
     80     location_ = location;
     81   }
     82 
     83  private:
     84   // Unique device id - persists between device attachments.
     85   // This is the string that should be used as the label for a particular
     86   // storage device when interacting with the API. Clients should treat
     87   // this as an opaque string.
     88   std::string device_id_;
     89 
     90   // Human readable removable storage device name.
     91   string16 name_;
     92 
     93   // Current attached removable storage device location.
     94   base::FilePath::StringType location_;
     95 
     96   // Label given to this storage device by the user.
     97   // May be empty if not found or the device is unlabeled.
     98   string16 storage_label_;
     99 
    100   // Vendor name for the removable device. (Human readable)
    101   // May be empty if not collected.
    102   string16 vendor_name_;
    103 
    104   // Model name for the removable device. (Human readable)
    105   // May be empty if not collected.
    106   string16 model_name_;
    107 
    108   // Size of the removable device in bytes.
    109   // Zero if not collected or unknown.
    110   uint64 total_size_in_bytes_;
    111 };
    112 
    113 }  // namespace chrome
    114 
    115 #endif  // CHROME_BROWSER_STORAGE_MONITOR_STORAGE_INFO_H_
    116