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

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

Issue 8499007: Add CrosDisksClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split a part of code into disk_mount_manager.cc/h 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_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
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 : device_path_(device_path),
68 is_drive_(false),
69 has_media_(false),
70 on_boot_device_(false),
71 device_type_(UNDEFINED),
72 total_size_(0),
73 is_read_only_(false),
74 is_hidden_(true) {
75 InitializeFromResponse(response);
76 }
77
78 // Device path. (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
79 std::string device_path() const { return device_path_; }
80
81 // Disk mount path. (e.g. /media/removable/VOLUME)
82 std::string mount_path() const { return mount_path_; }
83
84 // Disk system path given by udev.
85 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
86 std::string system_path() const { return system_path_; }
87
88 // Is disk into a drive (i.e. /dev/sdb vs, /dev/sdb1).
89 bool is_drive() const { return is_drive_; }
90
91 // Does the disk have media content.
92 bool has_media() const { return has_media_; }
93
94 // Is the disk on deveice we booted the machien from.
95 bool on_boot_device() const { return on_boot_device_; }
96
97 // Disk file path (e.g /dev/sdb).
98 std::string file_path() const { return file_path_; }
99
100 // Disk label.
101 std::string label() const { return label_; }
102
103 // Disk model
104 std::string drive_label() const { return drive_model_; }
105
106 // Partition table path of the device, if device is partition.
107 std::string partition_slave() const { return partition_slave_; }
108
109 // Device type. Not working well, yet.
110 DeviceType device_type() const { return device_type_; }
111
112 // Total size of the disk.
113 uint64 size() const { return total_size_; }
114
115 // Is the device read-only.
116 bool is_read_only() const { return is_read_only_; }
117
118 bool is_hidden() const { return is_hidden_; }
satorux1 2011/11/11 00:43:55 function comment missing.
hashimoto 2011/11/11 08:00:53 Done.
119
120 private:
121 void InitializeFromResponse(dbus::Response* response);
122
123 std::string device_path_;
124 std::string mount_path_;
125 std::string system_path_;
126 bool is_drive_;
127 bool has_media_;
128 bool on_boot_device_;
129
130 std::string file_path_;
131 std::string label_;
132 std::string drive_model_;
133 std::string partition_slave_;
134 DeviceType device_type_;
135 uint64 total_size_;
136 bool is_read_only_;
137 bool is_hidden_;
138 };
139
140 // A class to make the actual DBus calls for cros-disks service.
141 // This class only makes calls, result/error handling should be done
142 // by callbacks.
143 class CrosDisksClient {
144 public:
145 // A callback to be called when DBus method call fails.
146 typedef base::Callback<void()> ErrorCallback;
147
148 // A callback to handle the result of Mount.
149 typedef base::Callback<void()> MountCallback;
150
151 // A callback to handle the result of Unmount.
152 // The argument is the device path.
153 typedef base::Callback<void(const std::string&)> UnmountCallback;
154
155 // A callback to handle the result of EnumerateAutoMountableDevices.
156 // The argument is the enumerated device paths.
157 typedef base::Callback<void(const std::vector<std::string>&)
158 > EnumerateAutoMountableDevicesCallback;
159
160 // A callback to handle the result of FormatDevice.
161 // The first argument is the device path.
162 // The second argument is true when formatting succeeded, false otherwise.
163 typedef base::Callback<void(const std::string&, bool)> FormatDeviceCallback;
164
165 // A callback to handle the result of GetDeviceProperties.
166 // The argument is the information about the specified device.
167 typedef base::Callback<void(const DiskInfo&)> GetDevicePropertiesCallback;
168
169 // A callback to handle MountCompleted signal.
170 // The first argument is the error code.
171 // The second argument is the source path.
172 // The third argument is the mount type.
173 // The fourth argument is the mount path.
174 typedef base::Callback<void(MountError, const std::string&, MountType,
175 const std::string&)> MountCompletedHandler;
176
177 // A callback to handle mount events.
178 // The first argument is the event type.
179 // The second argument is the device path.
180 typedef base::Callback<void(MountEventType, const std::string&)
181 > MountEventHandler;
182
183 virtual ~CrosDisksClient();
184
185 // Calls Mount method. |callback| is called after the method call succeeds,
186 // otherwise, |error_callback| is called.
187 virtual void Mount(const std::string& source_path,
188 MountType type,
189 MountCallback callback,
190 ErrorCallback error_callback) = 0;
191
192 // Calls Unmount method. |callback| is called after the method call succeeds,
193 // otherwise, |error_callback| is called.
194 virtual void Unmount(const std::string& device_path,
195 UnmountCallback callback,
196 ErrorCallback error_callback) = 0;
197
198 // Calls EnumerateAutoMountableDevices method. |callback| is called after the
199 // method call succeeds, otherwise, |error_callback| is called.
200 virtual void EnumerateAutoMountableDevices(
201 EnumerateAutoMountableDevicesCallback callback,
202 ErrorCallback error_callback) = 0;
203
204 // Calls FormatDevice method. |callback| is called after the method call
205 // succeeds, otherwise, |error_callback| is called.
206 virtual void FormatDevice(const std::string& device_path,
207 const std::string& filesystem,
208 FormatDeviceCallback callback,
209 ErrorCallback error_callback) = 0;
210
211 // Calls GetDeviceProperties method. |callback| is called after the method
212 // call succeeds, otherwise, |error_callback| is called.
213 virtual void GetDeviceProperties(const std::string& device_path,
214 GetDevicePropertiesCallback callback,
215 ErrorCallback error_callback) = 0;
216
217 // Registers given callback for events.
218 // |mount_event_handler| is called when mount event signal is received.
219 // |mount_completed_handler| is called when MountCompleted signal is received.
220 virtual void SetUpConnections(
221 MountEventHandler mount_event_handler,
222 MountCompletedHandler mount_completed_handler) = 0;
223
224 // Factory function, creates a new instance and returns ownership.
225 // For normal usage, access the singleton via DBusThreadManager::Get().
226 static CrosDisksClient* Create(dbus::Bus* bus);
227
228 protected:
229 // Create() should be used instead.
230 CrosDisksClient();
231
232 private:
233 DISALLOW_COPY_AND_ASSIGN(CrosDisksClient);
234 };
235
236 } // namespace chromeos
237
238 #endif // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/dbus/cros_disks_client.cc » ('j') | chrome/browser/chromeos/dbus/cros_disks_client.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698