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

Side by Side Diff: chrome/browser/chromeos/dbus/cros_disks_client.h

Issue 8386031: Move chromeos_mount.cc from libcros to Chrome tree (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up format 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ 6 #define CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 #include <vector>
11 12
12 #include "base/memory/singleton.h" 13 #include "base/basictypes.h"
13 #include "base/observer_list.h" 14
14 #include "base/time.h" 15 namespace dbus {
15 #include "third_party/cros/chromeos_mount.h" 16 class Bus;
17 }
16 18
17 namespace chromeos { 19 namespace chromeos {
18 20
19 typedef enum MountLibraryEventType { 21 enum MountType {
22 MOUNT_TYPE_INVALID,
23 MOUNT_TYPE_DEVICE,
24 MOUNT_TYPE_ARCHIVE,
25 MOUNT_TYPE_NETWORK_STORAGE
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;
49
50 enum CrosDisksClientEventType {
20 MOUNT_DISK_ADDED, 51 MOUNT_DISK_ADDED,
21 MOUNT_DISK_REMOVED, 52 MOUNT_DISK_REMOVED,
22 MOUNT_DISK_CHANGED, 53 MOUNT_DISK_CHANGED,
23 MOUNT_DISK_MOUNTED, 54 MOUNT_DISK_MOUNTED,
24 MOUNT_DISK_UNMOUNTED, 55 MOUNT_DISK_UNMOUNTED,
25 MOUNT_DEVICE_ADDED, 56 MOUNT_DEVICE_ADDED,
26 MOUNT_DEVICE_REMOVED, 57 MOUNT_DEVICE_REMOVED,
27 MOUNT_DEVICE_SCANNED, 58 MOUNT_DEVICE_SCANNED,
28 MOUNT_FORMATTING_STARTED, 59 MOUNT_FORMATTING_STARTED,
29 MOUNT_FORMATTING_FINISHED 60 MOUNT_FORMATTING_FINISHED
30 } MountLibraryEventType; 61 };
31 62
32 typedef enum MountCondition { 63 enum MountCondition {
33 MOUNT_CONDITION_NONE, 64 MOUNT_CONDITION_NONE,
34 MOUNT_CONDITION_UNKNOWN_FILESYSTEM, 65 MOUNT_CONDITION_UNKNOWN_FILESYSTEM,
35 MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM 66 MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM
36 } MountCondition;
37
38 class MountLibcrosProxy {
39 public:
40 virtual ~MountLibcrosProxy() {}
41 virtual void CallMountPath(const char* source_path,
42 MountType type,
43 const MountPathOptions& options,
44 MountCompletedMonitor callback,
45 void* object) = 0;
46 virtual void CallUnmountPath(const char* path,
47 UnmountRequestCallback callback,
48 void* object) = 0;
49 virtual void CallRequestMountInfo(RequestMountInfoCallback callback,
50 void* object) = 0;
51 virtual void CallFormatDevice(const char* device_path,
52 const char* filesystem,
53 FormatRequestCallback callback,
54 void* object) = 0;
55 virtual void CallGetDiskProperties(const char* device_path,
56 GetDiskPropertiesCallback callback,
57 void* object) = 0;
58 virtual MountEventConnection MonitorCrosDisks(MountEventMonitor monitor,
59 MountCompletedMonitor mount_complete_monitor,
60 void* object) = 0;
61 virtual void DisconnectCrosDisksMonitorIfSet(MountEventConnection connection)
62 = 0;
63 }; 67 };
64 68
65 // This class handles the interaction with the ChromeOS mount library APIs. 69 // This class handles the interaction with cros-disks.
66 // Classes can add themselves as observers. Users can get an instance of this 70 // Classes can add themselves as observers.
67 // library class like this: chromeos::CrosLibrary::Get()->GetMountLibrary() 71 class CrosDisksClient {
68 class MountLibrary {
69 public: 72 public:
70 enum MountEvent { 73 enum MountEvent {
71 MOUNTING, 74 MOUNTING,
72 UNMOUNTING 75 UNMOUNTING
73 }; 76 };
74 // Used to house an instance of each found mount device. 77 // Used to house an instance of each found mount device.
75 class Disk { 78 class Disk {
76 public: 79 public:
77 Disk(const std::string& device_path, 80 Disk(const std::string& device_path,
78 const std::string& mount_path, 81 const std::string& mount_path,
79 const std::string& system_path, 82 const std::string& system_path,
80 const std::string& file_path, 83 const std::string& file_path,
81 const std::string& device_label, 84 const std::string& device_label,
82 const std::string& drive_label, 85 const std::string& drive_label,
83 const std::string& parent_path, 86 const std::string& parent_path,
84 const std::string& system_path_prefix, 87 const std::string& system_path_prefix,
85 DeviceType device_type, 88 DeviceType device_type,
86 uint64 total_size, 89 uint64 total_size,
87 bool is_parent, 90 bool is_parent,
88 bool is_read_only, 91 bool is_read_only,
89 bool has_media, 92 bool has_media,
90 bool on_boot_device, 93 bool on_boot_device,
91 bool is_hidden); 94 bool is_hidden);
satorux1 2011/11/07 23:21:55 Wow, 15 parameters including 5 booleans. I know it
hashimoto 2011/11/08 07:31:05 Sounds good.
92 ~Disk(); 95 ~Disk();
93 96
94 // The path of the device, used by devicekit-disks. 97 // The path of the device, used by devicekit-disks.
95 const std::string& device_path() const { return device_path_; } 98 const std::string& device_path() const { return device_path_; }
96 // The path to the mount point of this device. Will be empty if not mounted. 99 // The path to the mount point of this device. Will be empty if not mounted.
97 const std::string& mount_path() const { return mount_path_; } 100 const std::string& mount_path() const { return mount_path_; }
98 // The path of the device according to the udev system. 101 // The path of the device according to the udev system.
99 const std::string& system_path() const { return system_path_; } 102 const std::string& system_path() const { return system_path_; }
100 // The path of the device according to filesystem. 103 // The path of the device according to filesystem.
101 const std::string& file_path() const { return file_path_; } 104 const std::string& file_path() const { return file_path_; }
(...skipping 15 matching lines...) Expand all
117 bool is_parent() const { return is_parent_; } 120 bool is_parent() const { return is_parent_; }
118 // Is the device read only. 121 // Is the device read only.
119 bool is_read_only() const { return is_read_only_; } 122 bool is_read_only() const { return is_read_only_; }
120 // Does the device contains media. 123 // Does the device contains media.
121 bool has_media() const { return has_media_; } 124 bool has_media() const { return has_media_; }
122 // Is the device on the boot device. 125 // Is the device on the boot device.
123 bool on_boot_device() const { return on_boot_device_; } 126 bool on_boot_device() const { return on_boot_device_; }
124 // Shoud the device be shown in the UI, or automounted. 127 // Shoud the device be shown in the UI, or automounted.
125 bool is_hidden() const { return is_hidden_; } 128 bool is_hidden() const { return is_hidden_; }
126 129
127 void set_mount_path(const char* mount_path) { mount_path_ = mount_path; } 130 void set_mount_path(const std::string& mount_path) {
131 mount_path_ = mount_path;
132 }
128 void clear_mount_path() { mount_path_.clear(); } 133 void clear_mount_path() { mount_path_.clear(); }
129 134
130 private: 135 private:
131 std::string device_path_; 136 std::string device_path_;
132 std::string mount_path_; 137 std::string mount_path_;
133 std::string system_path_; 138 std::string system_path_;
134 std::string file_path_; 139 std::string file_path_;
135 std::string device_label_; 140 std::string device_label_;
136 std::string drive_label_; 141 std::string drive_label_;
137 std::string parent_path_; 142 std::string parent_path_;
138 std::string system_path_prefix_; 143 std::string system_path_prefix_;
139 DeviceType device_type_; 144 DeviceType device_type_;
140 uint64 total_size_; 145 uint64 total_size_;
141 bool is_parent_; 146 bool is_parent_;
142 bool is_read_only_; 147 bool is_read_only_;
143 bool has_media_; 148 bool has_media_;
144 bool on_boot_device_; 149 bool on_boot_device_;
145 bool is_hidden_; 150 bool is_hidden_;
146 }; 151 };
147 typedef std::map<std::string, Disk*> DiskMap; 152 typedef std::map<std::string, Disk*> DiskMap;
148 typedef std::map<std::string, std::string> PathMap; 153 typedef std::map<std::string, std::string> PathMap;
149 154
150 struct MountPointInfo { 155 struct MountPointInfo {
151 std::string source_path; 156 std::string source_path;
152 std::string mount_path; 157 std::string mount_path;
153 MountType mount_type; 158 MountType mount_type;
154 MountCondition mount_condition; 159 MountCondition mount_condition;
155 160
156 MountPointInfo(const char* source, const char* mount, const MountType type, 161 MountPointInfo(const std::string& source, const std::string& mount,
157 MountCondition condition) 162 const MountType type, MountCondition condition)
158 : source_path(source ? source : ""), 163 : source_path(source),
159 mount_path(mount ? mount : ""), 164 mount_path(mount),
160 mount_type(type), 165 mount_type(type),
161 mount_condition(condition) { 166 mount_condition(condition) {
162 } 167 }
163 }; 168 };
164 169
165 // MountPointMap key is mount_path. 170 // MountPointMap key is mount_path.
166 typedef std::map<std::string, MountPointInfo> MountPointMap; 171 typedef std::map<std::string, MountPointInfo> MountPointMap;
167 172
168 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool); 173 typedef void(*UnmountDeviceRecursiveCallbackType)(void*, bool);
169 174
170 class Observer { 175 class Observer {
171 public: 176 public:
172 virtual ~Observer() {} 177 virtual ~Observer() {}
173 // Async API events. 178 // Async API events.
174 virtual void DiskChanged(MountLibraryEventType event, 179 virtual void DiskChanged(CrosDisksClientEventType event,
175 const Disk* disk) = 0; 180 const Disk* disk) = 0;
176 virtual void DeviceChanged(MountLibraryEventType event, 181 virtual void DeviceChanged(CrosDisksClientEventType event,
177 const std::string& device_path) = 0; 182 const std::string& device_path) = 0;
178 virtual void MountCompleted(MountEvent event_type, 183 virtual void MountCompleted(MountEvent event_type,
179 MountError error_code, 184 MountError error_code,
180 const MountPointInfo& mount_info) = 0; 185 const MountPointInfo& mount_info) = 0;
181 }; 186 };
182 187
183 virtual ~MountLibrary() {} 188 virtual ~CrosDisksClient() {}
184 virtual void Init() = 0;
185 virtual void AddObserver(Observer* observer) = 0; 189 virtual void AddObserver(Observer* observer) = 0;
186 virtual void RemoveObserver(Observer* observer) = 0; 190 virtual void RemoveObserver(Observer* observer) = 0;
187 virtual const DiskMap& disks() const = 0; 191 virtual const DiskMap& disks() const = 0;
188 virtual const MountPointMap& mount_points() const = 0; 192 virtual const MountPointMap& mount_points() const = 0;
189 193
190 virtual void RequestMountInfoRefresh() = 0; 194 virtual void RequestMountInfoRefresh() = 0;
191 virtual void MountPath(const char* source_path, 195 virtual void MountPath(const std::string& source_path,
192 MountType type, 196 MountType type,
193 const MountPathOptions& options) = 0; 197 const MountPathOptions& options) = 0;
194 // |path| is device's mount path. 198 // |path| is device's mount path.
195 virtual void UnmountPath(const char* path) = 0; 199 virtual void UnmountPath(const std::string& path) = 0;
196 200
197 // Retrieves total and remaining available size on |mount_path|. 201 // Retrieves total and remaining available size on |mount_path|.
198 virtual void GetSizeStatsOnFileThread(const char* mount_path, 202 virtual void GetSizeStatsOnFileThread(const std::string& mount_path,
199 size_t* total_size_kb, 203 size_t* total_size_kb,
200 size_t* remaining_size_kb) = 0; 204 size_t* remaining_size_kb) = 0;
201 205
202 // Formats device given its file path. 206 // Formats device given its file path.
203 // Example: file_path: /dev/sdb1 207 // Example: file_path: /dev/sdb1
204 virtual void FormatUnmountedDevice(const char* file_path) = 0; 208 virtual void FormatUnmountedDevice(const std::string& file_path) = 0;
205 209
206 // Formats Device given its mount path. Unmount's the device 210 // Formats Device given its mount path. Unmount's the device
207 // Example: mount_path: /media/VOLUME_LABEL 211 // Example: mount_path: /media/VOLUME_LABEL
208 virtual void FormatMountedDevice(const char* mount_path) = 0; 212 virtual void FormatMountedDevice(const std::string& mount_path) = 0;
209 213
210 // Unmounts device_poath and all of its known children. 214 // Unmounts device_poath and all of its known children.
211 virtual void UnmountDeviceRecursive(const char* device_path, 215 virtual void UnmountDeviceRecursive(const std::string& device_path,
212 UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0; 216 UnmountDeviceRecursiveCallbackType callback, void* user_data) = 0;
213 217
214 // Helper functions for parameter conversions. 218 // Helper functions for parameter conversions.
215 static std::string MountTypeToString(MountType type); 219 static std::string MountTypeToString(MountType type);
216 static MountType MountTypeFromString(const std::string& type_str); 220 static MountType MountTypeFromString(const std::string& type_str);
217 static std::string MountConditionToString(MountCondition type); 221 static std::string MountConditionToString(MountCondition type);
satorux1 2011/11/07 23:21:55 Do we need to expose these methods? Otherwise, you
hashimoto 2011/11/08 07:31:05 They are used by extension_file_browser_private_ap
218 222
219 // Used in testing. Enables mocking libcros.
220 virtual void SetLibcrosProxy(MountLibcrosProxy* proxy) {}
221
222 // Factory function, creates a new instance and returns ownership. 223 // Factory function, creates a new instance and returns ownership.
223 // For normal usage, access the singleton via CrosLibrary::Get(). 224 // For normal usage, access the singleton via DBusThreadManager::Get().
224 static MountLibrary* GetImpl(bool stub); 225 static CrosDisksClient* Create(dbus::Bus* bus);
225 }; 226 };
226 227
227 } // namespace chromeos 228 } // namespace chromeos
228 229
229 #endif // CHROME_BROWSER_CHROMEOS_CROS_MOUNT_LIBRARY_H_ 230 #endif // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698