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 <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback.h" | |
| 14 | |
| 15 namespace dbus { | |
| 16 class Bus; | |
| 17 class Response; | |
| 18 } | |
| 19 | |
| 20 namespace chromeos { | |
| 21 | |
| 22 // Enum describing types of mount used by cros-disks | |
|
satorux1
2011/11/11 19:01:48
a period is missing. our style guide wants to see
hashimoto
2011/11/14 13:52:45
Done.
| |
| 23 enum MountType { | |
| 24 MOUNT_TYPE_INVALID, | |
| 25 MOUNT_TYPE_DEVICE, | |
| 26 MOUNT_TYPE_ARCHIVE, | |
| 27 MOUNT_TYPE_NETWORK_STORAGE, | |
| 28 }; | |
| 29 | |
| 30 // Type of device | |
| 31 enum DeviceType { | |
| 32 FLASH, | |
| 33 HDD, | |
| 34 OPTICAL, | |
| 35 UNDEFINED, | |
| 36 }; | |
| 37 | |
| 38 // Mount error code used by cros-disks | |
| 39 enum MountError { | |
| 40 MOUNT_ERROR_NONE = 0, | |
| 41 MOUNT_ERROR_UNKNOWN = 1, | |
| 42 MOUNT_ERROR_INTERNAL = 2, | |
| 43 MOUNT_ERROR_UNKNOWN_FILESYSTEM = 101, | |
| 44 MOUNT_ERROR_UNSUPORTED_FILESYSTEM = 102, | |
| 45 MOUNT_ERROR_INVALID_ARCHIVE = 201, | |
| 46 MOUNT_ERROR_LIBRARY_NOT_LOADED = 501, | |
| 47 MOUNT_ERROR_PATH_UNMOUNTED = 901, | |
| 48 // TODO(tbarzic): Add more error codes as they get added to cros-disks and | |
| 49 // consider doing explicit translation from cros-disks error_types. | |
| 50 }; | |
| 51 | |
| 52 // Event type each corresponding to a signal sent from cros-disks | |
| 53 enum MountEventType { | |
| 54 DISK_ADDED, | |
| 55 DISK_REMOVED, | |
| 56 DISK_CHANGED, | |
| 57 DEVICE_ADDED, | |
| 58 DEVICE_REMOVED, | |
| 59 DEVICE_SCANNED, | |
| 60 FORMATTING_FINISHED, | |
| 61 }; | |
| 62 | |
| 63 // A class to represent information about a disk sent from cros-disks | |
| 64 class DiskInfo { | |
| 65 public: | |
| 66 DiskInfo(const std::string& device_path, dbus::Response* response); | |
| 67 ~DiskInfo(); | |
| 68 | |
| 69 // Device path. (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1) | |
|
satorux1
2011/11/11 19:01:48
Great to see examples like this!
| |
| 70 std::string device_path() const { return device_path_; } | |
| 71 | |
| 72 // Disk mount path. (e.g. /media/removable/VOLUME) | |
| 73 std::string mount_path() const { return mount_path_; } | |
| 74 | |
| 75 // Disk system path given by udev. | |
| 76 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1) | |
| 77 std::string system_path() const { return system_path_; } | |
| 78 | |
| 79 // Is disk into a drive (i.e. /dev/sdb vs, /dev/sdb1). | |
|
satorux1
2011/11/11 19:01:48
into -> info. BTW, it wasn't clear for me which on
hashimoto
2011/11/14 13:52:45
Done.
| |
| 80 bool is_drive() const { return is_drive_; } | |
| 81 | |
| 82 // Does the disk have media content. | |
| 83 bool has_media() const { return has_media_; } | |
| 84 | |
| 85 // Is the disk on deveice we booted the machien from. | |
|
satorux1
2011/11/11 19:01:48
machien -> machine
hashimoto
2011/11/14 13:52:45
Done.
| |
| 86 bool on_boot_device() const { return on_boot_device_; } | |
| 87 | |
| 88 // Disk file path (e.g /dev/sdb). | |
|
satorux1
2011/11/11 19:01:48
e.g -> e.g.
hashimoto
2011/11/14 13:52:45
Done.
| |
| 89 std::string file_path() const { return file_path_; } | |
| 90 | |
| 91 // Disk label. | |
| 92 std::string label() const { return label_; } | |
| 93 | |
| 94 // Disk model | |
| 95 std::string drive_label() const { return drive_model_; } | |
|
satorux1
2011/11/11 19:01:48
(e.g. "TransMemory")
hashimoto
2011/11/14 13:52:45
Done.
| |
| 96 | |
| 97 // Partition table path of the device, if device is partition. | |
| 98 std::string partition_slave() const { return partition_slave_; } | |
| 99 | |
| 100 // Device type. Not working well, yet. | |
| 101 DeviceType device_type() const { return device_type_; } | |
| 102 | |
| 103 // Total size of the disk in bytes. | |
| 104 uint64 total_size_in_bytes() const { return total_size_in_bytes_; } | |
| 105 | |
| 106 // Is the device read-only. | |
| 107 bool is_read_only() const { return is_read_only_; } | |
| 108 | |
| 109 // Returns true if the device should be hidden from the file browser. | |
| 110 bool is_hidden() const { return is_hidden_; } | |
| 111 | |
| 112 private: | |
| 113 void InitializeFromResponse(dbus::Response* response); | |
| 114 | |
| 115 std::string device_path_; | |
| 116 std::string mount_path_; | |
| 117 std::string system_path_; | |
| 118 bool is_drive_; | |
| 119 bool has_media_; | |
| 120 bool on_boot_device_; | |
| 121 | |
| 122 std::string file_path_; | |
| 123 std::string label_; | |
| 124 std::string drive_model_; | |
| 125 std::string partition_slave_; | |
| 126 DeviceType device_type_; | |
| 127 uint64 total_size_in_bytes_; | |
| 128 bool is_read_only_; | |
| 129 bool is_hidden_; | |
| 130 }; | |
| 131 | |
| 132 // A class to make the actual DBus calls for cros-disks service. | |
| 133 // This class only makes calls, result/error handling should be done | |
| 134 // by callbacks. | |
| 135 class CrosDisksClient { | |
| 136 public: | |
| 137 // A callback to be called when DBus method call fails. | |
| 138 typedef base::Callback<void()> ErrorCallback; | |
| 139 | |
| 140 // A callback to handle the result of Mount. | |
| 141 typedef base::Callback<void()> MountCallback; | |
| 142 | |
| 143 // A callback to handle the result of Unmount. | |
| 144 // The argument is the device path. | |
| 145 typedef base::Callback<void(const std::string&)> UnmountCallback; | |
| 146 | |
| 147 // A callback to handle the result of EnumerateAutoMountableDevices. | |
| 148 // The argument is the enumerated device paths. | |
| 149 typedef base::Callback<void(const std::vector<std::string>&) | |
| 150 > EnumerateAutoMountableDevicesCallback; | |
| 151 | |
| 152 // A callback to handle the result of FormatDevice. | |
| 153 // The first argument is the device path. | |
| 154 // The second argument is true when formatting succeeded, false otherwise. | |
| 155 typedef base::Callback<void(const std::string&, bool)> FormatDeviceCallback; | |
| 156 | |
| 157 // A callback to handle the result of GetDeviceProperties. | |
| 158 // The argument is the information about the specified device. | |
| 159 typedef base::Callback<void(const DiskInfo&)> GetDevicePropertiesCallback; | |
| 160 | |
| 161 // A callback to handle MountCompleted signal. | |
| 162 // The first argument is the error code. | |
| 163 // The second argument is the source path. | |
| 164 // The third argument is the mount type. | |
| 165 // The fourth argument is the mount path. | |
| 166 typedef base::Callback<void(MountError, const std::string&, MountType, | |
| 167 const std::string&)> MountCompletedHandler; | |
| 168 | |
| 169 // A callback to handle mount events. | |
| 170 // The first argument is the event type. | |
| 171 // The second argument is the device path. | |
| 172 typedef base::Callback<void(MountEventType, const std::string&) | |
| 173 > MountEventHandler; | |
| 174 | |
| 175 virtual ~CrosDisksClient(); | |
| 176 | |
| 177 // Calls Mount method. |callback| is called after the method call succeeds, | |
| 178 // otherwise, |error_callback| is called. | |
| 179 virtual void Mount(const std::string& source_path, | |
| 180 MountType type, | |
| 181 MountCallback callback, | |
| 182 ErrorCallback error_callback) = 0; | |
| 183 | |
| 184 // Calls Unmount method. |callback| is called after the method call succeeds, | |
| 185 // otherwise, |error_callback| is called. | |
| 186 virtual void Unmount(const std::string& device_path, | |
| 187 UnmountCallback callback, | |
| 188 ErrorCallback error_callback) = 0; | |
| 189 | |
| 190 // Calls EnumerateAutoMountableDevices method. |callback| is called after the | |
| 191 // method call succeeds, otherwise, |error_callback| is called. | |
| 192 virtual void EnumerateAutoMountableDevices( | |
| 193 EnumerateAutoMountableDevicesCallback callback, | |
| 194 ErrorCallback error_callback) = 0; | |
| 195 | |
| 196 // Calls FormatDevice method. |callback| is called after the method call | |
| 197 // succeeds, otherwise, |error_callback| is called. | |
| 198 virtual void FormatDevice(const std::string& device_path, | |
| 199 const std::string& filesystem, | |
| 200 FormatDeviceCallback callback, | |
| 201 ErrorCallback error_callback) = 0; | |
| 202 | |
| 203 // Calls GetDeviceProperties method. |callback| is called after the method | |
| 204 // call succeeds, otherwise, |error_callback| is called. | |
| 205 virtual void GetDeviceProperties(const std::string& device_path, | |
| 206 GetDevicePropertiesCallback callback, | |
| 207 ErrorCallback error_callback) = 0; | |
| 208 | |
| 209 // Registers given callback for events. | |
| 210 // |mount_event_handler| is called when mount event signal is received. | |
| 211 // |mount_completed_handler| is called when MountCompleted signal is received. | |
| 212 virtual void SetUpConnections( | |
| 213 MountEventHandler mount_event_handler, | |
| 214 MountCompletedHandler mount_completed_handler) = 0; | |
| 215 | |
| 216 // Factory function, creates a new instance and returns ownership. | |
| 217 // For normal usage, access the singleton via DBusThreadManager::Get(). | |
| 218 static CrosDisksClient* Create(dbus::Bus* bus); | |
| 219 | |
| 220 protected: | |
| 221 // Create() should be used instead. | |
| 222 CrosDisksClient(); | |
| 223 | |
| 224 private: | |
| 225 DISALLOW_COPY_AND_ASSIGN(CrosDisksClient); | |
| 226 }; | |
| 227 | |
| 228 } // namespace chromeos | |
| 229 | |
| 230 #endif // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_ | |
| OLD | NEW |