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

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

Issue 8499007: Add CrosDisksClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix to please clang Created 9 years, 1 month 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) 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_DISKS_DISK_MOUNT_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_DISKS_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 {
satorux1 2011/11/11 19:01:48 Would be nice to introduce a sub namespace. names
hashimoto 2011/11/14 13:52:45 Done.
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& parent_path,
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 const std::string& device_path() const { return device_path_; }
68
69 // The path to the mount point of this device. Will be empty if not mounted.
70 const std::string& mount_path() const { return mount_path_; }
71
72 // The path of the device according to the udev system.
73 const std::string& system_path() const { return system_path_; }
74
75 // The path of the device according to filesystem.
76 const std::string& file_path() const { return file_path_; }
satorux1 2011/11/11 19:01:48 Like DiskInfo in cros_disks_client.h, can you add
hashimoto 2011/11/14 13:52:45 Done.
77
78 // Device's label.
79 const std::string& device_label() const { return device_label_; }
80
81 // If disk is a parent, then its label, else parents label.
82 const std::string& drive_label() const { return drive_label_; }
83
84 // Parents device path. If device has no parent, then empty string.
85 const std::string& parent_path() const { return parent_path_; }
hashimoto 2011/11/14 13:52:45 parent_path is removed because it is never used by
satorux1 2011/11/14 17:56:23 Nice!
86
87 // Path of the system device this device's block is a part of.
88 const std::string& system_path_prefix() const {
89 return system_path_prefix_;
90 }
91
92 // Device type.
93 DeviceType device_type() const { return device_type_; }
94
95 // Total size of the device in bytes.
96 uint64 total_size_in_bytes() const { return total_size_in_bytes_; }
97
98 // Is the device is a parent device (i.e. sdb rather than sdb1).
99 bool is_parent() const { return is_parent_; }
100
101 // Is the device read only.
102 bool is_read_only() const { return is_read_only_; }
103
104 // Does the device contains media.
105 bool has_media() const { return has_media_; }
106
107 // Is the device on the boot device.
108 bool on_boot_device() const { return on_boot_device_; }
109
110 // Shoud the device be shown in the UI, or automounted.
111 bool is_hidden() const { return is_hidden_; }
112
113 void set_mount_path(const std::string& mount_path) {
114 mount_path_ = mount_path;
115 }
116
117 void clear_mount_path() { mount_path_.clear(); }
118
119 private:
120 std::string device_path_;
121 std::string mount_path_;
122 std::string system_path_;
123 std::string file_path_;
124 std::string device_label_;
125 std::string drive_label_;
126 std::string parent_path_;
127 std::string system_path_prefix_;
128 DeviceType device_type_;
129 uint64 total_size_in_bytes_;
130 bool is_parent_;
131 bool is_read_only_;
132 bool has_media_;
133 bool on_boot_device_;
134 bool is_hidden_;
135 };
136 typedef std::map<std::string, Disk*> DiskMap;
137 typedef std::map<std::string, std::string> PathMap;
138
139 // A struct to store information about mount point.
140 struct MountPointInfo {
141 // Device's path.
142 std::string source_path;
143 // Mounted path.
144 std::string mount_path;
145 // Type of mount.
146 MountType mount_type;
147 // Condition of mount.
148 MountCondition mount_condition;
149
150 MountPointInfo(const std::string& source,
151 const std::string& mount,
152 const MountType type,
153 MountCondition condition)
154 : source_path(source),
155 mount_path(mount),
156 mount_type(type),
157 mount_condition(condition) {
158 }
159 };
160
161 // MountPointMap key is mount_path.
162 typedef std::map<std::string, MountPointInfo> MountPointMap;
163
164 // A callback function type which is called after UnmountDeviceRecursive
165 // finishes.
166 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool);
167
168 // Implement this interface to be notified about disk/mount related events.
169 class Observer {
170 public:
171 virtual ~Observer() {}
172
173 // A function called when disk mount status is changed.
174 virtual void DiskChanged(DiskMountManagerEventType event,
175 const Disk* disk) = 0;
176 // A function called when device status is changed.
177 virtual void DeviceChanged(DiskMountManagerEventType event,
178 const std::string& device_path) = 0;
179 // A function called after mount is completed.
180 virtual void MountCompleted(MountEvent event_type,
181 MountError error_code,
182 const MountPointInfo& mount_info) = 0;
183 };
184
185 virtual ~DiskMountManager() {}
186
187 // Adds an observer.
188 virtual void AddObserver(Observer* observer) = 0;
189
190 // Removes an observer.
191 virtual void RemoveObserver(Observer* observer) = 0;
192
193 // Gets the list of disks found.
194 virtual const DiskMap& disks() const = 0;
195
196 // Gets the list of mount points.
197 virtual const MountPointMap& mount_points() const = 0;
198
199 // Requests refreshing all the information about mounted disks.
200 virtual void RequestMountInfoRefresh() = 0;
201
202 // Mounts a device.
203 virtual void MountPath(const std::string& source_path, MountType type) = 0;
204
205 // Unmounts a mounted disk.
206 virtual void UnmountPath(const std::string& mount_path) = 0;
207
208 // Retrieves total and remaining available size on |mount_path|.
209 virtual void GetSizeStatsOnFileThread(const std::string& mount_path,
210 size_t* total_size_kb,
211 size_t* remaining_size_kb) = 0;
212 // Formats device given its file path.
213 // Example: file_path: /dev/sdb1
214 virtual void FormatUnmountedDevice(const std::string& file_path) = 0;
215
216 // Formats Device given its mount path. Unmounts the device.
217 // Example: mount_path: /media/VOLUME_LABEL
218 virtual void FormatMountedDevice(const std::string& mount_path) = 0;
219
220 // Unmounts device_path and all of its known children.
221 virtual void UnmountDeviceRecursive(
222 const std::string& device_path,
223 UnmountDeviceRecursiveCallbackType callback,
224 void* user_data) = 0;
225
226 // Returns corresponding string to |type| like "device" or "file".
227 static std::string MountTypeToString(MountType type);
228
229 // The inverse function of MountTypeToString.
230 static MountType MountTypeFromString(const std::string& type_str);
231
232 // Returns corresponding string to |type| like "unknown_filesystem".
233 static std::string MountConditionToString(MountCondition type);
234
235 // Creates the global DiskMountManager instance.
236 static void Initialize();
237
238 // Destroys the global DiskMountManager instance if it exists.
239 static void Shutdown();
240
241 // Returns a pointer to the global DiskMountManager instance.
242 // Initialize() should already have been called.
243 static DiskMountManager* GetInstance();
244 };
245
246 } // namespace chromeos
247
248 #endif // CHROME_BROWSER_CHROMEOS_DISKS_DISK_MOUNT_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698