Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
|
satorux1
2011/11/11 00:43:55
chrome/browser/chromeos directly contains many fil
hashimoto
2011/11/11 08:00:53
Done.
| |
| 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_DISK_MOUNT_MANAGER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_DISK_MOUNT_MANAGER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <map> | |
| 10 | |
| 11 #include "chrome/browser/chromeos/dbus/cros_disks_client.h" | |
| 12 | |
| 13 namespace chromeos { | |
| 14 | |
| 15 // Types of events DiskMountManager sends to its observers. | |
| 16 enum DiskMountManagerEventType { | |
| 17 MOUNT_DISK_ADDED, | |
| 18 MOUNT_DISK_REMOVED, | |
| 19 MOUNT_DISK_CHANGED, | |
| 20 MOUNT_DISK_MOUNTED, | |
| 21 MOUNT_DISK_UNMOUNTED, | |
| 22 MOUNT_DEVICE_ADDED, | |
| 23 MOUNT_DEVICE_REMOVED, | |
| 24 MOUNT_DEVICE_SCANNED, | |
| 25 MOUNT_FORMATTING_STARTED, | |
| 26 MOUNT_FORMATTING_FINISHED, | |
| 27 }; | |
| 28 | |
| 29 // Condition of mounted filesystem | |
|
satorux1
2011/11/11 00:43:55
period is missing.
hashimoto
2011/11/11 08:00:53
Done.
| |
| 30 enum MountCondition { | |
| 31 MOUNT_CONDITION_NONE, | |
| 32 MOUNT_CONDITION_UNKNOWN_FILESYSTEM, | |
| 33 MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM, | |
| 34 }; | |
| 35 | |
| 36 // This class handles the interaction with cros-disks. | |
| 37 // Other classes can add themselves as observers. | |
| 38 class DiskMountManager { | |
| 39 public: | |
| 40 enum MountEvent { | |
|
satorux1
2011/11/11 00:43:55
Add a one-line comment?
hashimoto
2011/11/11 08:00:53
Done.
| |
| 41 MOUNTING, | |
| 42 UNMOUNTING, | |
| 43 }; | |
|
satorux1
2011/11/11 00:43:55
Add a blank line here.
hashimoto
2011/11/11 08:00:53
Done.
| |
| 44 // Used to house an instance of each found mount device. | |
| 45 class Disk { | |
| 46 public: | |
| 47 Disk(const std::string& device_path, | |
| 48 const std::string& mount_path, | |
| 49 const std::string& system_path, | |
| 50 const std::string& file_path, | |
| 51 const std::string& device_label, | |
| 52 const std::string& drive_label, | |
| 53 const std::string& parent_path, | |
| 54 const std::string& system_path_prefix, | |
| 55 DeviceType device_type, | |
| 56 uint64 total_size, | |
| 57 bool is_parent, | |
| 58 bool is_read_only, | |
| 59 bool has_media, | |
| 60 bool on_boot_device, | |
| 61 bool is_hidden); | |
| 62 ~Disk(); | |
| 63 | |
| 64 // The path of the device, used by devicekit-disks. | |
| 65 const std::string& device_path() const { return device_path_; } | |
| 66 | |
| 67 // The path to the mount point of this device. Will be empty if not mounted. | |
| 68 const std::string& mount_path() const { return mount_path_; } | |
| 69 | |
| 70 // The path of the device according to the udev system. | |
| 71 const std::string& system_path() const { return system_path_; } | |
| 72 | |
| 73 // The path of the device according to filesystem. | |
| 74 const std::string& file_path() const { return file_path_; } | |
| 75 | |
| 76 // Device's label. | |
| 77 const std::string& device_label() const { return device_label_; } | |
| 78 | |
| 79 // If disk is a parent, then its label, else parents label. | |
| 80 const std::string& drive_label() const { return drive_label_; } | |
| 81 | |
| 82 // Parents device path. If device has no parent, then empty string. | |
| 83 const std::string& parent_path() const { return parent_path_; } | |
| 84 | |
| 85 // Path of the system device this device's block is a part of. | |
| 86 const std::string& system_path_prefix() const { | |
| 87 return system_path_prefix_; | |
| 88 } | |
| 89 | |
| 90 // Device type. | |
| 91 DeviceType device_type() const { return device_type_; } | |
| 92 | |
| 93 // Total size of the device. | |
|
satorux1
2011/11/11 00:43:55
in bytes? in mega bytes? let's make it clear.
hashimoto
2011/11/11 08:00:53
Done.
| |
| 94 uint64 total_size() const { return total_size_; } | |
|
satorux1
2011/11/11 00:43:55
something like total_size_in_bytes() will be clear
hashimoto
2011/11/11 08:00:53
Done.
| |
| 95 | |
| 96 // Is the device is a parent device (i.e. sdb rather than sdb1). | |
| 97 bool is_parent() const { return is_parent_; } | |
| 98 | |
| 99 // Is the device read only. | |
| 100 bool is_read_only() const { return is_read_only_; } | |
| 101 | |
| 102 // Does the device contains media. | |
| 103 bool has_media() const { return has_media_; } | |
| 104 | |
| 105 // Is the device on the boot device. | |
| 106 bool on_boot_device() const { return on_boot_device_; } | |
| 107 | |
| 108 // Shoud the device be shown in the UI, or automounted. | |
| 109 bool is_hidden() const { return is_hidden_; } | |
| 110 | |
| 111 void set_mount_path(const std::string& mount_path) { | |
| 112 mount_path_ = mount_path; | |
| 113 } | |
| 114 | |
| 115 void clear_mount_path() { mount_path_.clear(); } | |
| 116 | |
| 117 private: | |
| 118 std::string device_path_; | |
| 119 std::string mount_path_; | |
| 120 std::string system_path_; | |
| 121 std::string file_path_; | |
| 122 std::string device_label_; | |
| 123 std::string drive_label_; | |
| 124 std::string parent_path_; | |
| 125 std::string system_path_prefix_; | |
| 126 DeviceType device_type_; | |
| 127 uint64 total_size_; | |
| 128 bool is_parent_; | |
| 129 bool is_read_only_; | |
| 130 bool has_media_; | |
| 131 bool on_boot_device_; | |
| 132 bool is_hidden_; | |
| 133 }; | |
| 134 typedef std::map<std::string, Disk*> DiskMap; | |
| 135 typedef std::map<std::string, std::string> PathMap; | |
| 136 | |
| 137 struct MountPointInfo { | |
|
satorux1
2011/11/11 00:43:55
Could you add a comment?
hashimoto
2011/11/11 08:00:53
Done.
| |
| 138 std::string source_path; | |
| 139 std::string mount_path; | |
| 140 MountType mount_type; | |
| 141 MountCondition mount_condition; | |
| 142 | |
| 143 MountPointInfo(const std::string& source, const std::string& mount, | |
| 144 const MountType type, MountCondition condition) | |
|
satorux1
2011/11/11 00:43:55
You might want to list parameters vertically
hashimoto
2011/11/11 08:00:53
Done.
| |
| 145 : source_path(source), | |
| 146 mount_path(mount), | |
| 147 mount_type(type), | |
| 148 mount_condition(condition) { | |
| 149 } | |
| 150 }; | |
| 151 | |
| 152 // MountPointMap key is mount_path. | |
| 153 typedef std::map<std::string, MountPointInfo> MountPointMap; | |
| 154 | |
| 155 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool); | |
| 156 | |
| 157 class Observer { | |
|
satorux1
2011/11/11 00:43:55
A brief class comment would be nice.
hashimoto
2011/11/11 08:00:53
Done.
| |
| 158 public: | |
| 159 virtual ~Observer() {} | |
| 160 | |
| 161 // A function called when disk mount status is changed. | |
| 162 virtual void DiskChanged(DiskMountManagerEventType event, | |
| 163 const Disk* disk) = 0; | |
| 164 // A function called when device status is changed. | |
| 165 virtual void DeviceChanged(DiskMountManagerEventType event, | |
| 166 const std::string& device_path) = 0; | |
| 167 // A function called after mount is completed. | |
| 168 virtual void MountCompleted(MountEvent event_type, | |
| 169 MountError error_code, | |
| 170 const MountPointInfo& mount_info) = 0; | |
| 171 }; | |
| 172 | |
| 173 virtual ~DiskMountManager() {} | |
| 174 | |
| 175 // Adds an observer | |
|
satorux1
2011/11/11 00:43:55
period is missing. please check other places. sorr
hashimoto
2011/11/11 08:00:53
Done.
| |
| 176 virtual void AddObserver(Observer* observer) = 0; | |
| 177 | |
| 178 // Removes an observer | |
| 179 virtual void RemoveObserver(Observer* observer) = 0; | |
| 180 | |
| 181 // Gets the list of disks found. | |
| 182 virtual const DiskMap& disks() const = 0; | |
| 183 | |
| 184 // Gets the list of mount points. | |
| 185 virtual const MountPointMap& mount_points() const = 0; | |
| 186 | |
| 187 // Requests refreshing all the information about mounted disks. | |
| 188 virtual void RequestMountInfoRefresh() = 0; | |
| 189 | |
| 190 // Mount a device | |
| 191 virtual void MountPath(const std::string& source_path, MountType type) = 0; | |
| 192 | |
| 193 // Unmount a mounted disk | |
| 194 virtual void UnmountPath(const std::string& mount_path) = 0; | |
| 195 | |
| 196 // Retrieves total and remaining available size on |mount_path|. | |
| 197 virtual void GetSizeStatsOnFileThread(const std::string& mount_path, | |
| 198 size_t* total_size_kb, | |
| 199 size_t* remaining_size_kb) = 0; | |
| 200 // Formats device given its file path. | |
| 201 // Example: file_path: /dev/sdb1 | |
| 202 virtual void FormatUnmountedDevice(const std::string& file_path) = 0; | |
| 203 | |
| 204 // Formats Device given its mount path. Unmount's the device | |
| 205 // Example: mount_path: /media/VOLUME_LABEL | |
| 206 virtual void FormatMountedDevice(const std::string& mount_path) = 0; | |
| 207 | |
| 208 // Unmounts device_path and all of its known children. | |
| 209 virtual void UnmountDeviceRecursive( | |
| 210 const std::string& device_path, | |
| 211 UnmountDeviceRecursiveCallbackType callback, | |
| 212 void* user_data) = 0; | |
| 213 | |
| 214 // Returns corresponding string to |type| like "device" or "file". | |
| 215 static std::string MountTypeToString(MountType type); | |
| 216 | |
| 217 // The inverse function of MountTypeToString. | |
| 218 static MountType MountTypeFromString(const std::string& type_str); | |
| 219 | |
| 220 // Returns corresponding string to |type| like "unknown_filesystem". | |
| 221 static std::string MountConditionToString(MountCondition type); | |
| 222 | |
| 223 // Creates the global DiskMountManager instance. | |
| 224 static void Initialize(); | |
| 225 | |
| 226 // Destroys the global DiskMountManager instance if it exists. | |
| 227 static void Shutdown(); | |
| 228 | |
| 229 // Returns a pointer to the global DiskMountManager instance. | |
| 230 // Initialize() should already have been called. | |
| 231 static DiskMountManager* GetInstance(); | |
| 232 }; | |
| 233 | |
| 234 } // namespace chromeos | |
| 235 | |
| 236 #endif // CHROME_BROWSER_CHROMEOS_DISK_MOUNT_MANAGER_H_ | |
| OLD | NEW |