Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/basictypes.h" | |
| 14 | |
| 15 namespace dbus { | |
| 16 class Bus; | |
| 17 } | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 enum MountType { | |
|
satorux1
2011/11/08 18:07:22
I know this is just inheriting from the original c
hashimoto
2011/11/09 02:33:25
Done.
| |
| 22 MOUNT_TYPE_INVALID, | |
| 23 MOUNT_TYPE_DEVICE, | |
| 24 MOUNT_TYPE_ARCHIVE, | |
| 25 MOUNT_TYPE_NETWORK_STORAGE | |
|
satorux1
2011/11/08 18:07:22
Let's add a comma. It's a good practice, as it'll
hashimoto
2011/11/09 02:33:25
Done.
| |
| 26 }; | |
| 27 | |
| 28 enum DeviceType { | |
| 29 FLASH, | |
| 30 HDD, | |
| 31 OPTICAL, | |
| 32 UNDEFINED | |
| 33 }; | |
| 34 | |
| 35 enum MountError { | |
| 36 MOUNT_ERROR_NONE = 0, | |
| 37 MOUNT_ERROR_UNKNOWN = 1, | |
| 38 MOUNT_ERROR_INTERNAL = 2, | |
| 39 MOUNT_ERROR_UNKNOWN_FILESYSTEM = 101, | |
| 40 MOUNT_ERROR_UNSUPORTED_FILESYSTEM = 102, | |
| 41 MOUNT_ERROR_INVALID_ARCHIVE = 201, | |
| 42 MOUNT_ERROR_LIBRARY_NOT_LOADED = 501, | |
| 43 MOUNT_ERROR_PATH_UNMOUNTED = 901 | |
| 44 // TODO(tbarzic): Add more error codes as they get added to cros-disks and | |
| 45 // consider doing explicit translation from cros-disks error_types. | |
| 46 }; | |
| 47 | |
| 48 typedef std::vector<std::pair<std::string, std::string> > MountPathOptions; | |
|
satorux1
2011/11/08 18:07:22
Why not map<string>? Maybe the order matters? Woul
hashimoto
2011/11/09 02:33:25
Removed because it is no longer used.
| |
| 49 | |
| 50 enum CrosDisksClientEventType { | |
| 51 MOUNT_DISK_ADDED, | |
| 52 MOUNT_DISK_REMOVED, | |
| 53 MOUNT_DISK_CHANGED, | |
| 54 MOUNT_DISK_MOUNTED, | |
| 55 MOUNT_DISK_UNMOUNTED, | |
| 56 MOUNT_DEVICE_ADDED, | |
| 57 MOUNT_DEVICE_REMOVED, | |
| 58 MOUNT_DEVICE_SCANNED, | |
| 59 MOUNT_FORMATTING_STARTED, | |
| 60 MOUNT_FORMATTING_FINISHED | |
| 61 }; | |
| 62 | |
| 63 enum MountCondition { | |
| 64 MOUNT_CONDITION_NONE, | |
| 65 MOUNT_CONDITION_UNKNOWN_FILESYSTEM, | |
| 66 MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM | |
| 67 }; | |
| 68 | |
| 69 // This class handles the interaction with cros-disks. | |
| 70 // Classes can add themselves as observers. | |
| 71 class CrosDisksClient { | |
| 72 public: | |
| 73 enum MountEvent { | |
| 74 MOUNTING, | |
| 75 UNMOUNTING | |
| 76 }; | |
| 77 // Used to house an instance of each found mount device. | |
| 78 class Disk { | |
| 79 public: | |
| 80 Disk(const std::string& device_path, | |
| 81 const std::string& mount_path, | |
| 82 const std::string& system_path, | |
| 83 const std::string& file_path, | |
| 84 const std::string& device_label, | |
| 85 const std::string& drive_label, | |
| 86 const std::string& parent_path, | |
| 87 const std::string& system_path_prefix, | |
| 88 DeviceType device_type, | |
| 89 uint64 total_size, | |
| 90 bool is_parent, | |
| 91 bool is_read_only, | |
| 92 bool has_media, | |
| 93 bool on_boot_device, | |
| 94 bool is_hidden); | |
| 95 ~Disk(); | |
| 96 | |
| 97 // The path of the device, used by devicekit-disks. | |
| 98 const std::string& device_path() const { return device_path_; } | |
|
satorux1
2011/11/08 18:07:22
Please add a blank line between accessors. I think
hashimoto
2011/11/09 02:33:25
Done.
| |
| 99 // The path to the mount point of this device. Will be empty if not mounted. | |
| 100 const std::string& mount_path() const { return mount_path_; } | |
| 101 // The path of the device according to the udev system. | |
| 102 const std::string& system_path() const { return system_path_; } | |
| 103 // The path of the device according to filesystem. | |
| 104 const std::string& file_path() const { return file_path_; } | |
| 105 // Device's label. | |
| 106 const std::string& device_label() const { return device_label_; } | |
| 107 // If disk is a parent, then its label, else parents label. | |
| 108 const std::string& drive_label() const { return drive_label_; } | |
| 109 // Parents device path. If device has no parent, then empty string. | |
| 110 const std::string& parent_path() const { return parent_path_; } | |
| 111 // Path of the system device this device's block is a part of. | |
| 112 const std::string& system_path_prefix() const { | |
| 113 return system_path_prefix_; | |
| 114 } | |
| 115 // Device type. | |
| 116 DeviceType device_type() const { return device_type_; } | |
| 117 // Total size of the device. | |
| 118 uint64 total_size() const { return total_size_; } | |
| 119 // Is the device is a parent device (i.e. sdb rather than sdb1). | |
| 120 bool is_parent() const { return is_parent_; } | |
| 121 // Is the device read only. | |
| 122 bool is_read_only() const { return is_read_only_; } | |
| 123 // Does the device contains media. | |
| 124 bool has_media() const { return has_media_; } | |
| 125 // Is the device on the boot device. | |
| 126 bool on_boot_device() const { return on_boot_device_; } | |
| 127 // Shoud the device be shown in the UI, or automounted. | |
| 128 bool is_hidden() const { return is_hidden_; } | |
| 129 | |
| 130 void set_mount_path(const std::string& mount_path) { | |
| 131 mount_path_ = mount_path; | |
| 132 } | |
| 133 void clear_mount_path() { mount_path_.clear(); } | |
| 134 | |
| 135 private: | |
| 136 std::string device_path_; | |
| 137 std::string mount_path_; | |
| 138 std::string system_path_; | |
| 139 std::string file_path_; | |
| 140 std::string device_label_; | |
| 141 std::string drive_label_; | |
| 142 std::string parent_path_; | |
| 143 std::string system_path_prefix_; | |
| 144 DeviceType device_type_; | |
| 145 uint64 total_size_; | |
| 146 bool is_parent_; | |
| 147 bool is_read_only_; | |
| 148 bool has_media_; | |
| 149 bool on_boot_device_; | |
| 150 bool is_hidden_; | |
| 151 }; | |
| 152 typedef std::map<std::string, Disk*> DiskMap; | |
| 153 typedef std::map<std::string, std::string> PathMap; | |
| 154 | |
| 155 struct MountPointInfo { | |
| 156 std::string source_path; | |
| 157 std::string mount_path; | |
| 158 MountType mount_type; | |
| 159 MountCondition mount_condition; | |
| 160 | |
| 161 MountPointInfo(const std::string& source, const std::string& mount, | |
| 162 const MountType type, MountCondition condition) | |
| 163 : source_path(source), | |
| 164 mount_path(mount), | |
| 165 mount_type(type), | |
| 166 mount_condition(condition) { | |
| 167 } | |
| 168 }; | |
| 169 | |
| 170 // MountPointMap key is mount_path. | |
| 171 typedef std::map<std::string, MountPointInfo> MountPointMap; | |
| 172 | |
| 173 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool); | |
| 174 | |
| 175 class Observer { | |
| 176 public: | |
| 177 virtual ~Observer() {} | |
| 178 // Async API events. | |
| 179 virtual void DiskChanged(CrosDisksClientEventType event, | |
| 180 const Disk* disk) = 0; | |
| 181 virtual void DeviceChanged(CrosDisksClientEventType event, | |
| 182 const std::string& device_path) = 0; | |
| 183 virtual void MountCompleted(MountEvent event_type, | |
| 184 MountError error_code, | |
| 185 const MountPointInfo& mount_info) = 0; | |
|
satorux1
2011/11/08 18:07:22
This may be obvious, but please could you add func
hashimoto
2011/11/09 02:33:25
Done.
| |
| 186 }; | |
| 187 | |
| 188 virtual ~CrosDisksClient() {} | |
| 189 virtual void AddObserver(Observer* observer) = 0; | |
| 190 virtual void RemoveObserver(Observer* observer) = 0; | |
| 191 virtual const DiskMap& disks() const = 0; | |
| 192 virtual const MountPointMap& mount_points() const = 0; | |
| 193 | |
| 194 virtual void RequestMountInfoRefresh() = 0; | |
|
satorux1
2011/11/08 18:07:22
Function comment is missing. Please check other fu
hashimoto
2011/11/09 02:33:25
Done.
| |
| 195 virtual void MountPath(const std::string& source_path, | |
| 196 MountType type, | |
| 197 const MountPathOptions& options) = 0; | |
| 198 // |path| is device's mount path. | |
| 199 virtual void UnmountPath(const std::string& path) = 0; | |
| 200 | |
| 201 // Retrieves total and remaining available size on |mount_path|. | |
| 202 virtual void GetSizeStatsOnFileThread(const std::string& mount_path, | |
| 203 size_t* total_size_kb, | |
| 204 size_t* remaining_size_kb) = 0; | |
| 205 | |
| 206 // Formats device given its file path. | |
| 207 // Example: file_path: /dev/sdb1 | |
| 208 virtual void FormatUnmountedDevice(const std::string& file_path) = 0; | |
| 209 | |
| 210 // Formats Device given its mount path. Unmount's the device | |
| 211 // Example: mount_path: /media/VOLUME_LABEL | |
| 212 virtual void FormatMountedDevice(const std::string& mount_path) = 0; | |
| 213 | |
| 214 // Unmounts device_poath and all of its known children. | |
| 215 virtual void UnmountDeviceRecursive(const std::string& device_path, | |
| 216 UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; | |
| 217 | |
| 218 // Helper functions for parameter conversions. | |
| 219 static std::string MountTypeToString(MountType type); | |
| 220 static MountType MountTypeFromString(const std::string& type_str); | |
| 221 static std::string MountConditionToString(MountCondition type); | |
| 222 | |
| 223 // Factory function, creates a new instance and returns ownership. | |
| 224 // For normal usage, access the singleton via DBusThreadManager::Get(). | |
| 225 static CrosDisksClient* Create(dbus::Bus* bus); | |
| 226 }; | |
| 227 | |
| 228 } // namespace chromeos | |
| 229 | |
| 230 #endif // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_ | |
| OLD | NEW |