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

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

Issue 9838085: Move files inside chrome/browser/chromeos/dbus to chromeos/dbus (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: _ Created 8 years, 9 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
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_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_GDATA,
28 MOUNT_TYPE_NETWORK_STORAGE,
29 };
30
31 // Type of device.
32 enum DeviceType {
33 DEVICE_TYPE_UNKNOWN,
34 DEVICE_TYPE_USB, // USB stick.
35 DEVICE_TYPE_SD, // SD card.
36 DEVICE_TYPE_OPTICAL_DISC, // e.g. DVD.
37 DEVICE_TYPE_MOBILE // Storage on a mobile device (e.g. Android).
38 };
39
40 // Mount error code used by cros-disks.
41 enum MountError {
42 MOUNT_ERROR_NONE = 0,
43 MOUNT_ERROR_UNKNOWN = 1,
44 MOUNT_ERROR_INTERNAL = 2,
45 MOUNT_ERROR_UNKNOWN_FILESYSTEM = 101,
46 MOUNT_ERROR_UNSUPORTED_FILESYSTEM = 102,
47 MOUNT_ERROR_INVALID_ARCHIVE = 201,
48 MOUNT_ERROR_LIBRARY_NOT_LOADED = 501,
49 MOUNT_ERROR_NOT_AUTHENTICATED = 601,
50 MOUNT_ERROR_NETWORK_ERROR = 602,
51 MOUNT_ERROR_PATH_UNMOUNTED = 901,
52 // TODO(tbarzic): Add more error codes as they get added to cros-disks and
53 // consider doing explicit translation from cros-disks error_types.
54 };
55
56 // Event type each corresponding to a signal sent from cros-disks.
57 enum MountEventType {
58 DISK_ADDED,
59 DISK_REMOVED,
60 DISK_CHANGED,
61 DEVICE_ADDED,
62 DEVICE_REMOVED,
63 DEVICE_SCANNED,
64 FORMATTING_FINISHED,
65 };
66
67 // A class to represent information about a disk sent from cros-disks.
68 class DiskInfo {
69 public:
70 DiskInfo(const std::string& device_path, dbus::Response* response);
71 ~DiskInfo();
72
73 // Device path. (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
74 std::string device_path() const { return device_path_; }
75
76 // Disk mount path. (e.g. /media/removable/VOLUME)
77 std::string mount_path() const { return mount_path_; }
78
79 // Disk system path given by udev.
80 // (e.g. /sys/devices/pci0000:00/.../8:0:0:0/block/sdb/sdb1)
81 std::string system_path() const { return system_path_; }
82
83 // Is a drive or not. (i.e. true with /dev/sdb, false with /dev/sdb1)
84 bool is_drive() const { return is_drive_; }
85
86 // Does the disk have media content.
87 bool has_media() const { return has_media_; }
88
89 // Is the disk on deveice we booted the machine from.
90 bool on_boot_device() const { return on_boot_device_; }
91
92 // Disk file path (e.g. /dev/sdb).
93 std::string file_path() const { return file_path_; }
94
95 // Disk label.
96 std::string label() const { return label_; }
97
98 // Disk model. (e.g. "TransMemory")
99 std::string drive_label() const { return drive_model_; }
100
101 // Device type. Not working well, yet.
102 DeviceType device_type() const { return device_type_; }
103
104 // Total size of the disk in bytes.
105 uint64 total_size_in_bytes() const { return total_size_in_bytes_; }
106
107 // Is the device read-only.
108 bool is_read_only() const { return is_read_only_; }
109
110 // Returns true if the device should be hidden from the file browser.
111 bool is_hidden() const { return is_hidden_; }
112
113 private:
114 void InitializeFromResponse(dbus::Response* response);
115
116 std::string device_path_;
117 std::string mount_path_;
118 std::string system_path_;
119 bool is_drive_;
120 bool has_media_;
121 bool on_boot_device_;
122
123 std::string file_path_;
124 std::string label_;
125 std::string drive_model_;
126 DeviceType device_type_;
127 uint64 total_size_in_bytes_;
128 bool is_read_only_;
129 bool is_hidden_;
130 };
131
132 // A class to make the actual DBus calls for cros-disks service.
133 // This class only makes calls, result/error handling should be done
134 // by callbacks.
135 class CrosDisksClient {
136 public:
137 // A callback to be called when DBus method call fails.
138 typedef base::Callback<void()> ErrorCallback;
139
140 // A callback to handle the result of Mount.
141 typedef base::Callback<void()> MountCallback;
142
143 // A callback to handle the result of Unmount.
144 // The argument is the device path.
145 typedef base::Callback<void(const std::string&)> UnmountCallback;
146
147 // A callback to handle the result of EnumerateAutoMountableDevices.
148 // The argument is the enumerated device paths.
149 typedef base::Callback<void(const std::vector<std::string>&)
150 > EnumerateAutoMountableDevicesCallback;
151
152 // A callback to handle the result of FormatDevice.
153 // The first argument is the device path.
154 // The second argument is true when formatting succeeded, false otherwise.
155 typedef base::Callback<void(const std::string&, bool)> FormatDeviceCallback;
156
157 // A callback to handle the result of GetDeviceProperties.
158 // The argument is the information about the specified device.
159 typedef base::Callback<void(const DiskInfo&)> GetDevicePropertiesCallback;
160
161 // A callback to handle MountCompleted signal.
162 // The first argument is the error code.
163 // The second argument is the source path.
164 // The third argument is the mount type.
165 // The fourth argument is the mount path.
166 typedef base::Callback<void(MountError, const std::string&, MountType,
167 const std::string&)> MountCompletedHandler;
168
169 // A callback to handle mount events.
170 // The first argument is the event type.
171 // The second argument is the device path.
172 typedef base::Callback<void(MountEventType, const std::string&)
173 > MountEventHandler;
174
175 virtual ~CrosDisksClient();
176
177 // Calls Mount method. |callback| is called after the method call succeeds,
178 // otherwise, |error_callback| is called.
179 virtual void Mount(const std::string& source_path,
180 MountType type,
181 MountCallback callback,
182 ErrorCallback error_callback) = 0;
183
184 // Calls Unmount method. |callback| is called after the method call succeeds,
185 // otherwise, |error_callback| is called.
186 virtual void Unmount(const std::string& device_path,
187 UnmountCallback callback,
188 ErrorCallback error_callback) = 0;
189
190 // Calls EnumerateAutoMountableDevices method. |callback| is called after the
191 // method call succeeds, otherwise, |error_callback| is called.
192 virtual void EnumerateAutoMountableDevices(
193 EnumerateAutoMountableDevicesCallback callback,
194 ErrorCallback error_callback) = 0;
195
196 // Calls FormatDevice method. |callback| is called after the method call
197 // succeeds, otherwise, |error_callback| is called.
198 virtual void FormatDevice(const std::string& device_path,
199 const std::string& filesystem,
200 FormatDeviceCallback callback,
201 ErrorCallback error_callback) = 0;
202
203 // Calls GetDeviceProperties method. |callback| is called after the method
204 // call succeeds, otherwise, |error_callback| is called.
205 virtual void GetDeviceProperties(const std::string& device_path,
206 GetDevicePropertiesCallback callback,
207 ErrorCallback error_callback) = 0;
208
209 // Registers given callback for events.
210 // |mount_event_handler| is called when mount event signal is received.
211 // |mount_completed_handler| is called when MountCompleted signal is received.
212 virtual void SetUpConnections(
213 MountEventHandler mount_event_handler,
214 MountCompletedHandler mount_completed_handler) = 0;
215
216 // Factory function, creates a new instance and returns ownership.
217 // For normal usage, access the singleton via DBusThreadManager::Get().
218 static CrosDisksClient* Create(dbus::Bus* bus);
219
220 protected:
221 // Create() should be used instead.
222 CrosDisksClient();
223
224 private:
225 DISALLOW_COPY_AND_ASSIGN(CrosDisksClient);
226 };
227
228 } // namespace chromeos
229
230 #endif // CHROME_BROWSER_CHROMEOS_DBUS_CROS_DISKS_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698