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

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

Powered by Google App Engine
This is Rietveld 408576698