Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/chromeos/disks/disk_mount_manager.h

Issue 10874067: chromeos: Move src/chrome/browser/chromeos/disks to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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_CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_
7
8 #include <map>
9
10 #include "chromeos/dbus/cros_disks_client.h"
11
12 namespace chromeos {
13 namespace disks {
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.
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 // Event type given to observers' MountCompleted method.
41 enum MountEvent {
42 MOUNTING,
43 UNMOUNTING,
44 };
45
46 // Used to house an instance of each found mount device.
47 class Disk {
48 public:
49 Disk(const std::string& device_path,
50 const std::string& mount_path,
51 const std::string& system_path,
52 const std::string& file_path,
53 const std::string& device_label,
54 const std::string& drive_label,
55 const std::string& fs_uuid,
56 const std::string& system_path_prefix,
57 DeviceType device_type,
58 uint64 total_size_in_bytes,
59 bool is_parent,
60 bool is_read_only,
61 bool has_media,
62 bool on_boot_device,
63 bool is_hidden);
64 ~Disk();
65
66 // The path of the device, used by devicekit-disks.
67 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
68 const std::string& device_path() const { return device_path_; }
69
70 // The path to the mount point of this device. Will be empty if not mounted.
71 // (e.g. /media/removable/VOLUME)
72 const std::string& mount_path() const { return mount_path_; }
73
74 // The path of the device according to the udev system.
75 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
76 const std::string& system_path() const { return system_path_; }
77
78 // The path of the device according to filesystem.
79 // (e.g. /dev/sdb)
80 const std::string& file_path() const { return file_path_; }
81
82 // Device's label.
83 const std::string& device_label() const { return device_label_; }
84
85 // If disk is a parent, then its label, else parents label.
86 // (e.g. "TransMemory")
87 const std::string& drive_label() const { return drive_label_; }
88
89 // Returns the file system uuid string.
90 const std::string& fs_uuid() const { return fs_uuid_; }
91
92 // Path of the system device this device's block is a part of.
93 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/)
94 const std::string& system_path_prefix() const {
95 return system_path_prefix_;
96 }
97
98 // Device type.
99 DeviceType device_type() const { return device_type_; }
100
101 // Total size of the device in bytes.
102 uint64 total_size_in_bytes() const { return total_size_in_bytes_; }
103
104 // Is the device is a parent device (i.e. sdb rather than sdb1).
105 bool is_parent() const { return is_parent_; }
106
107 // Is the device read only.
108 bool is_read_only() const { return is_read_only_; }
109
110 // Does the device contains media.
111 bool has_media() const { return has_media_; }
112
113 // Is the device on the boot device.
114 bool on_boot_device() const { return on_boot_device_; }
115
116 // Shoud the device be shown in the UI, or automounted.
117 bool is_hidden() const { return is_hidden_; }
118
119 void set_mount_path(const std::string& mount_path) {
120 mount_path_ = mount_path;
121 }
122
123 void clear_mount_path() { mount_path_.clear(); }
124
125 private:
126 std::string device_path_;
127 std::string mount_path_;
128 std::string system_path_;
129 std::string file_path_;
130 std::string device_label_;
131 std::string drive_label_;
132 std::string fs_uuid_;
133 std::string system_path_prefix_;
134 DeviceType device_type_;
135 uint64 total_size_in_bytes_;
136 bool is_parent_;
137 bool is_read_only_;
138 bool has_media_;
139 bool on_boot_device_;
140 bool is_hidden_;
141 };
142 typedef std::map<std::string, Disk*> DiskMap;
143
144 // A struct to store information about mount point.
145 struct MountPointInfo {
146 // Device's path.
147 std::string source_path;
148 // Mounted path.
149 std::string mount_path;
150 // Type of mount.
151 MountType mount_type;
152 // Condition of mount.
153 MountCondition mount_condition;
154
155 MountPointInfo(const std::string& source,
156 const std::string& mount,
157 const MountType type,
158 MountCondition condition)
159 : source_path(source),
160 mount_path(mount),
161 mount_type(type),
162 mount_condition(condition) {
163 }
164 };
165
166 // MountPointMap key is mount_path.
167 typedef std::map<std::string, MountPointInfo> MountPointMap;
168
169 // A callback function type which is called after UnmountDeviceRecursive
170 // finishes.
171 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool);
172
173 // Implement this interface to be notified about disk/mount related events.
174 class Observer {
175 public:
176 virtual ~Observer() {}
177
178 // A function called when disk mount status is changed.
179 virtual void DiskChanged(DiskMountManagerEventType event,
180 const Disk* disk) = 0;
181 // A function called when device status is changed.
182 virtual void DeviceChanged(DiskMountManagerEventType event,
183 const std::string& device_path) = 0;
184 // A function called after mount is completed.
185 virtual void MountCompleted(MountEvent event_type,
186 MountError error_code,
187 const MountPointInfo& mount_info) = 0;
188 };
189
190 virtual ~DiskMountManager() {}
191
192 // Adds an observer.
193 virtual void AddObserver(Observer* observer) = 0;
194
195 // Removes an observer.
196 virtual void RemoveObserver(Observer* observer) = 0;
197
198 // Gets the list of disks found.
199 virtual const DiskMap& disks() const = 0;
200
201 // Returns Disk object corresponding to |source_path| or NULL on failure.
202 virtual const Disk* FindDiskBySourcePath(
203 const std::string& source_path) const = 0;
204
205 // Gets the list of mount points.
206 virtual const MountPointMap& mount_points() const = 0;
207
208 // Requests refreshing all the information about mounted disks.
209 virtual void RequestMountInfoRefresh() = 0;
210
211 // Mounts a device.
212 virtual void MountPath(const std::string& source_path,
213 const std::string& source_format,
214 const std::string& mount_label,
215 MountType type) = 0;
216
217 // Unmounts a mounted disk.
218 virtual void UnmountPath(const std::string& mount_path) = 0;
219
220 // Retrieves total and remaining available size on |mount_path|.
221 virtual void GetSizeStatsOnFileThread(const std::string& mount_path,
222 size_t* total_size_kb,
223 size_t* remaining_size_kb) = 0;
224 // Formats device given its file path.
225 // Example: file_path: /dev/sdb1
226 virtual void FormatUnmountedDevice(const std::string& file_path) = 0;
227
228 // Formats Device given its mount path. Unmounts the device.
229 // Example: mount_path: /media/VOLUME_LABEL
230 virtual void FormatMountedDevice(const std::string& mount_path) = 0;
231
232 // Unmounts device_path and all of its known children.
233 virtual void UnmountDeviceRecursive(
234 const std::string& device_path,
235 UnmountDeviceRecursiveCallbackType callback,
236 void* user_data) = 0;
237
238 // Returns corresponding string to |type| like "device" or "file".
239 static std::string MountTypeToString(MountType type);
240
241 // The inverse function of MountTypeToString.
242 static MountType MountTypeFromString(const std::string& type_str);
243
244 // Returns corresponding string to |type| like "unknown_filesystem".
245 static std::string MountConditionToString(MountCondition type);
246
247 // Returns corresponding string to |type|, like "sd", "usb".
248 static std::string DeviceTypeToString(DeviceType type);
249
250 // Creates the global DiskMountManager instance.
251 static void Initialize();
252
253 // Similar to Initialize(), but can inject an alternative
254 // DiskMountManager such as MockDiskMountManager for testing.
255 // The injected object will be owned by the internal pointer and deleted
256 // by Shutdown().
257 static void InitializeForTesting(DiskMountManager* disk_mount_manager);
258
259 // Destroys the global DiskMountManager instance if it exists.
260 static void Shutdown();
261
262 // Returns a pointer to the global DiskMountManager instance.
263 // Initialize() should already have been called.
264 static DiskMountManager* GetInstance();
265 };
266
267 } // namespace disks
268 } // namespace chromeos
269
270 #endif // CHROME_BROWSER_CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/burn_library.cc ('k') | chrome/browser/chromeos/disks/disk_mount_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698