storage_info.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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
11namespace storage_monitor {
12
13class 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  // Get the display name for the removable device represented by this
73  // StorageInfo. Include the size for removable devices if |with_size| is true.
74  base::string16 GetDisplayName(bool with_size) const;
75
76  // Same as GetDisplayName(), but may be overridden by |override_display_name|.
77  base::string16 GetDisplayNameWithOverride(
78      const base::string16& override_display_name, bool with_size) const;
79
80  const std::string& device_id() const { return device_id_; }
81  const base::FilePath::StringType& location() const { return location_; }
82  const base::string16& storage_label() const { return storage_label_; }
83  const base::string16& vendor_name() const { return vendor_name_; }
84  const base::string16& model_name() const { return model_name_; }
85  uint64 total_size_in_bytes() const { return total_size_in_bytes_; }
86
87  void set_device_id(const std::string& device_id) { device_id_ = device_id; }
88  void set_location(const base::FilePath::StringType& location) {
89    location_ = location;
90  }
91
92 private:
93  // Unique device id - persists between device attachments.
94  // This is the string that should be used as the label for a particular
95  // storage device when interacting with the API. Clients should treat
96  // this as an opaque string.
97  std::string device_id_;
98
99  // Current attached removable storage device location.
100  base::FilePath::StringType location_;
101
102  // Label given to this storage device by the user.
103  // May be empty if not found or the device is unlabeled.
104  base::string16 storage_label_;
105
106  // Vendor name for the removable device. (Human readable)
107  // May be empty if not collected.
108  base::string16 vendor_name_;
109
110  // Model name for the removable device. (Human readable)
111  // May be empty if not collected.
112  base::string16 model_name_;
113
114  // Size of the removable device in bytes.
115  // Zero if not collected or unknown.
116  uint64 total_size_in_bytes_;
117};
118
119}  // namespace storage_monitor
120
121#endif  // COMPONENTS_STORAGE_MONITOR_STORAGE_INFO_H_
122