[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 64e19925 | 2012-04-06 01:54:36 | [diff] [blame] | 5 | #include "chromeos/dbus/cros_disks_client.h" |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 6 | |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
[email protected] | 85b95a201 | 2012-08-07 18:57:27 | [diff] [blame] | 10 | #include <map> |
Hidehiko Abe | 5a138a2 | 2017-10-05 16:22:21 | [diff] [blame^] | 11 | #include <memory> |
[email protected] | 85b95a201 | 2012-08-07 18:57:27 | [diff] [blame] | 12 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 13 | #include "base/bind.h" |
[email protected] | a5a8b41 | 2013-03-04 15:03:11 | [diff] [blame] | 14 | #include "base/files/file_path.h" |
thestig | b44bd35 | 2014-09-10 01:47:06 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
[email protected] | 593cf3b | 2013-03-05 04:16:52 | [diff] [blame] | 16 | #include "base/location.h" |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 17 | #include "base/macros.h" |
[email protected] | b307bceb | 2011-11-17 07:49:55 | [diff] [blame] | 18 | #include "base/stl_util.h" |
[email protected] | afa339d7 | 2013-06-11 06:32:51 | [diff] [blame] | 19 | #include "base/strings/stringprintf.h" |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 20 | #include "base/sys_info.h" |
[email protected] | 593cf3b | 2013-03-05 04:16:52 | [diff] [blame] | 21 | #include "base/task_runner_util.h" |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 22 | #include "base/values.h" |
satorux | 8fd29380 | 2014-10-30 08:23:12 | [diff] [blame] | 23 | #include "chromeos/dbus/fake_cros_disks_client.h" |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 24 | #include "dbus/bus.h" |
| 25 | #include "dbus/message.h" |
[email protected] | 216ed0b | 2012-02-14 21:29:06 | [diff] [blame] | 26 | #include "dbus/object_path.h" |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 27 | #include "dbus/object_proxy.h" |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 28 | #include "dbus/values_util.h" |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 29 | #include "third_party/cros_system_api/dbus/service_constants.h" |
| 30 | |
| 31 | namespace chromeos { |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | const char* kDefaultMountOptions[] = { |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 36 | "nodev", "noexec", "nosuid", |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 37 | }; |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 38 | const char kReadOnlyOption[] = "ro"; |
| 39 | const char kReadWriteOption[] = "rw"; |
yamaguchi | fa8efc7 | 2016-10-21 15:05:51 | [diff] [blame] | 40 | const char kRemountOption[] = "remount"; |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 41 | const char kMountLabelOption[] = "mountlabel"; |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 42 | |
[email protected] | 10795ae | 2012-10-10 07:33:49 | [diff] [blame] | 43 | const char kLazyUnmountOption[] = "lazy"; |
| 44 | |
[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 45 | // Checks if retrieved media type is in boundaries of DeviceMediaType. |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 46 | bool IsValidMediaType(uint32_t type) { |
| 47 | return type < static_cast<uint32_t>(cros_disks::DEVICE_MEDIA_NUM_VALUES); |
[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 48 | } |
| 49 | |
[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 50 | // Translates enum used in cros-disks to enum used in Chrome. |
| 51 | // Note that we could just do static_cast, but this is less sensitive to |
| 52 | // changes in cros-disks. |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 53 | DeviceType DeviceMediaTypeToDeviceType(uint32_t media_type_uint32) { |
[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 54 | if (!IsValidMediaType(media_type_uint32)) |
| 55 | return DEVICE_TYPE_UNKNOWN; |
| 56 | |
| 57 | cros_disks::DeviceMediaType media_type = |
| 58 | cros_disks::DeviceMediaType(media_type_uint32); |
| 59 | |
| 60 | switch (media_type) { |
| 61 | case(cros_disks::DEVICE_MEDIA_UNKNOWN): |
| 62 | return DEVICE_TYPE_UNKNOWN; |
| 63 | case(cros_disks::DEVICE_MEDIA_USB): |
| 64 | return DEVICE_TYPE_USB; |
| 65 | case(cros_disks::DEVICE_MEDIA_SD): |
| 66 | return DEVICE_TYPE_SD; |
| 67 | case(cros_disks::DEVICE_MEDIA_OPTICAL_DISC): |
| 68 | return DEVICE_TYPE_OPTICAL_DISC; |
| 69 | case(cros_disks::DEVICE_MEDIA_MOBILE): |
| 70 | return DEVICE_TYPE_MOBILE; |
[email protected] | f4ae40ac | 2012-05-04 21:57:00 | [diff] [blame] | 71 | case(cros_disks::DEVICE_MEDIA_DVD): |
| 72 | return DEVICE_TYPE_DVD; |
[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 73 | default: |
| 74 | return DEVICE_TYPE_UNKNOWN; |
| 75 | } |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 76 | } |
| 77 | |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 78 | bool ReadMountEntryFromDbus(dbus::MessageReader* reader, MountEntry* entry) { |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 79 | uint32_t error_code = 0; |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 80 | std::string source_path; |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 81 | uint32_t mount_type = 0; |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 82 | std::string mount_path; |
| 83 | if (!reader->PopUint32(&error_code) || |
| 84 | !reader->PopString(&source_path) || |
| 85 | !reader->PopUint32(&mount_type) || |
| 86 | !reader->PopString(&mount_path)) { |
| 87 | return false; |
| 88 | } |
| 89 | *entry = MountEntry(static_cast<MountError>(error_code), source_path, |
| 90 | static_cast<MountType>(mount_type), mount_path); |
| 91 | return true; |
| 92 | } |
| 93 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 94 | // The CrosDisksClient implementation. |
| 95 | class CrosDisksClientImpl : public CrosDisksClient { |
| 96 | public: |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 97 | CrosDisksClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 98 | |
| 99 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 100 | void Mount(const std::string& source_path, |
| 101 | const std::string& source_format, |
| 102 | const std::string& mount_label, |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 103 | MountAccessMode access_mode, |
yamaguchi | fa8efc7 | 2016-10-21 15:05:51 | [diff] [blame] | 104 | RemountOption remount, |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 105 | const base::Closure& callback, |
| 106 | const base::Closure& error_callback) override { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 107 | dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
| 108 | cros_disks::kMount); |
| 109 | dbus::MessageWriter writer(&method_call); |
| 110 | writer.AppendString(source_path); |
[email protected] | b9f22d1 | 2012-04-25 21:46:48 | [diff] [blame] | 111 | writer.AppendString(source_format); |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 112 | std::vector<std::string> mount_options = |
yamaguchi | fa8efc7 | 2016-10-21 15:05:51 | [diff] [blame] | 113 | ComposeMountOptions(mount_label, access_mode, remount); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 114 | writer.AppendArrayOfStrings(mount_options); |
| 115 | proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
Hidehiko Abe | d62ed3e | 2017-09-05 05:16:56 | [diff] [blame] | 116 | base::BindOnce(&CrosDisksClientImpl::OnMount, |
| 117 | weak_ptr_factory_.GetWeakPtr(), callback, |
| 118 | error_callback)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 122 | void Unmount(const std::string& device_path, |
| 123 | UnmountOptions options, |
| 124 | const base::Closure& callback, |
| 125 | const base::Closure& error_callback) override { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 126 | dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
| 127 | cros_disks::kUnmount); |
| 128 | dbus::MessageWriter writer(&method_call); |
| 129 | writer.AppendString(device_path); |
[email protected] | 10795ae | 2012-10-10 07:33:49 | [diff] [blame] | 130 | |
benchan | 8bcaea1 | 2017-03-11 00:26:50 | [diff] [blame] | 131 | std::vector<std::string> unmount_options; |
[email protected] | 10795ae | 2012-10-10 07:33:49 | [diff] [blame] | 132 | if (options == UNMOUNT_OPTIONS_LAZY) |
| 133 | unmount_options.push_back(kLazyUnmountOption); |
| 134 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 135 | writer.AppendArrayOfStrings(unmount_options); |
| 136 | proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
Hidehiko Abe | d62ed3e | 2017-09-05 05:16:56 | [diff] [blame] | 137 | base::BindOnce(&CrosDisksClientImpl::OnUnmount, |
| 138 | weak_ptr_factory_.GetWeakPtr(), callback, |
| 139 | error_callback)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 143 | void EnumerateAutoMountableDevices( |
[email protected] | 4a404e5 | 2012-04-11 02:25:35 | [diff] [blame] | 144 | const EnumerateAutoMountableDevicesCallback& callback, |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 145 | const base::Closure& error_callback) override { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 146 | dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
| 147 | cros_disks::kEnumerateAutoMountableDevices); |
| 148 | proxy_->CallMethod( |
| 149 | &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
Hidehiko Abe | d62ed3e | 2017-09-05 05:16:56 | [diff] [blame] | 150 | base::BindOnce(&CrosDisksClientImpl::OnEnumerateAutoMountableDevices, |
| 151 | weak_ptr_factory_.GetWeakPtr(), callback, |
| 152 | error_callback)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 156 | void EnumerateMountEntries(const EnumerateMountEntriesCallback& callback, |
| 157 | const base::Closure& error_callback) override { |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 158 | dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
| 159 | cros_disks::kEnumerateMountEntries); |
| 160 | proxy_->CallMethod( |
| 161 | &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
Hidehiko Abe | d62ed3e | 2017-09-05 05:16:56 | [diff] [blame] | 162 | base::BindOnce(&CrosDisksClientImpl::OnEnumerateMountEntries, |
| 163 | weak_ptr_factory_.GetWeakPtr(), callback, |
| 164 | error_callback)); |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 168 | void Format(const std::string& device_path, |
| 169 | const std::string& filesystem, |
| 170 | const base::Closure& callback, |
| 171 | const base::Closure& error_callback) override { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 172 | dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
[email protected] | f026c0f | 2014-05-06 21:52:35 | [diff] [blame] | 173 | cros_disks::kFormat); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 174 | dbus::MessageWriter writer(&method_call); |
| 175 | writer.AppendString(device_path); |
| 176 | writer.AppendString(filesystem); |
[email protected] | f026c0f | 2014-05-06 21:52:35 | [diff] [blame] | 177 | // No format option is currently specified, but we can later use this |
| 178 | // argument to specify options for the format operation. |
| 179 | std::vector<std::string> format_options; |
| 180 | writer.AppendArrayOfStrings(format_options); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 181 | proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
Hidehiko Abe | d62ed3e | 2017-09-05 05:16:56 | [diff] [blame] | 182 | base::BindOnce(&CrosDisksClientImpl::OnFormat, |
| 183 | weak_ptr_factory_.GetWeakPtr(), callback, |
| 184 | error_callback)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 185 | } |
| 186 | |
Klemen Kozjek | bf5610f | 2017-08-25 20:20:09 | [diff] [blame] | 187 | void Rename(const std::string& device_path, |
| 188 | const std::string& volume_name, |
| 189 | const base::Closure& callback, |
| 190 | const base::Closure& error_callback) override { |
| 191 | dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
| 192 | cros_disks::kRename); |
| 193 | dbus::MessageWriter writer(&method_call); |
| 194 | writer.AppendString(device_path); |
| 195 | writer.AppendString(volume_name); |
Hidehiko Abe | d62ed3e | 2017-09-05 05:16:56 | [diff] [blame] | 196 | proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 197 | base::BindOnce(&CrosDisksClientImpl::OnRename, |
| 198 | weak_ptr_factory_.GetWeakPtr(), callback, |
| 199 | error_callback)); |
Klemen Kozjek | bf5610f | 2017-08-25 20:20:09 | [diff] [blame] | 200 | } |
| 201 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 202 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 203 | void GetDeviceProperties(const std::string& device_path, |
| 204 | const GetDevicePropertiesCallback& callback, |
| 205 | const base::Closure& error_callback) override { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 206 | dbus::MethodCall method_call(cros_disks::kCrosDisksInterface, |
| 207 | cros_disks::kGetDeviceProperties); |
| 208 | dbus::MessageWriter writer(&method_call); |
| 209 | writer.AppendString(device_path); |
Hidehiko Abe | d62ed3e | 2017-09-05 05:16:56 | [diff] [blame] | 210 | proxy_->CallMethod( |
| 211 | &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 212 | base::BindOnce(&CrosDisksClientImpl::OnGetDeviceProperties, |
| 213 | weak_ptr_factory_.GetWeakPtr(), device_path, callback, |
| 214 | error_callback)); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 218 | void SetMountEventHandler( |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 219 | const MountEventHandler& mount_event_handler) override { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 220 | static const SignalEventTuple kSignalEventTuples[] = { |
[email protected] | e3c1fc9 | 2012-11-15 00:56:46 | [diff] [blame] | 221 | { cros_disks::kDeviceAdded, CROS_DISKS_DEVICE_ADDED }, |
| 222 | { cros_disks::kDeviceScanned, CROS_DISKS_DEVICE_SCANNED }, |
| 223 | { cros_disks::kDeviceRemoved, CROS_DISKS_DEVICE_REMOVED }, |
| 224 | { cros_disks::kDiskAdded, CROS_DISKS_DISK_ADDED }, |
| 225 | { cros_disks::kDiskChanged, CROS_DISKS_DISK_CHANGED }, |
| 226 | { cros_disks::kDiskRemoved, CROS_DISKS_DISK_REMOVED }, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 227 | }; |
| 228 | const size_t kNumSignalEventTuples = arraysize(kSignalEventTuples); |
| 229 | |
| 230 | for (size_t i = 0; i < kNumSignalEventTuples; ++i) { |
| 231 | proxy_->ConnectToSignal( |
| 232 | cros_disks::kCrosDisksInterface, |
| 233 | kSignalEventTuples[i].signal_name, |
| 234 | base::Bind(&CrosDisksClientImpl::OnMountEvent, |
| 235 | weak_ptr_factory_.GetWeakPtr(), |
| 236 | kSignalEventTuples[i].event_type, |
| 237 | mount_event_handler), |
| 238 | base::Bind(&CrosDisksClientImpl::OnSignalConnected, |
| 239 | weak_ptr_factory_.GetWeakPtr())); |
| 240 | } |
[email protected] | a0278d5 | 2014-05-06 03:36:15 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 244 | void SetMountCompletedHandler( |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 245 | const MountCompletedHandler& mount_completed_handler) override { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 246 | proxy_->ConnectToSignal( |
| 247 | cros_disks::kCrosDisksInterface, |
[email protected] | b3e3f49 | 2011-11-18 18:46:00 | [diff] [blame] | 248 | cros_disks::kMountCompleted, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 249 | base::Bind(&CrosDisksClientImpl::OnMountCompleted, |
| 250 | weak_ptr_factory_.GetWeakPtr(), |
[email protected] | 85b95a201 | 2012-08-07 18:57:27 | [diff] [blame] | 251 | mount_completed_handler), |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 252 | base::Bind(&CrosDisksClientImpl::OnSignalConnected, |
| 253 | weak_ptr_factory_.GetWeakPtr())); |
| 254 | } |
| 255 | |
[email protected] | a0278d5 | 2014-05-06 03:36:15 | [diff] [blame] | 256 | // CrosDisksClient override. |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 257 | void SetFormatCompletedHandler( |
mostynb | 4f4cf14 | 2014-10-06 13:57:52 | [diff] [blame] | 258 | const FormatCompletedHandler& format_completed_handler) override { |
[email protected] | a0278d5 | 2014-05-06 03:36:15 | [diff] [blame] | 259 | proxy_->ConnectToSignal( |
| 260 | cros_disks::kCrosDisksInterface, |
| 261 | cros_disks::kFormatCompleted, |
| 262 | base::Bind(&CrosDisksClientImpl::OnFormatCompleted, |
| 263 | weak_ptr_factory_.GetWeakPtr(), |
| 264 | format_completed_handler), |
| 265 | base::Bind(&CrosDisksClientImpl::OnSignalConnected, |
| 266 | weak_ptr_factory_.GetWeakPtr())); |
| 267 | } |
| 268 | |
Klemen Kozjek | bf5610f | 2017-08-25 20:20:09 | [diff] [blame] | 269 | // CrosDisksClient override. |
| 270 | void SetRenameCompletedHandler( |
| 271 | const RenameCompletedHandler& rename_completed_handler) override { |
| 272 | proxy_->ConnectToSignal( |
| 273 | cros_disks::kCrosDisksInterface, cros_disks::kRenameCompleted, |
| 274 | base::Bind(&CrosDisksClientImpl::OnRenameCompleted, |
| 275 | weak_ptr_factory_.GetWeakPtr(), rename_completed_handler), |
| 276 | base::Bind(&CrosDisksClientImpl::OnSignalConnected, |
| 277 | weak_ptr_factory_.GetWeakPtr())); |
| 278 | } |
| 279 | |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 280 | protected: |
dcheng | 0280cb6 | 2015-01-16 07:37:50 | [diff] [blame] | 281 | void Init(dbus::Bus* bus) override { |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 282 | proxy_ = bus->GetObjectProxy( |
| 283 | cros_disks::kCrosDisksServiceName, |
| 284 | dbus::ObjectPath(cros_disks::kCrosDisksServicePath)); |
| 285 | } |
| 286 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 287 | private: |
| 288 | // A struct to contain a pair of signal name and mount event type. |
[email protected] | a0278d5 | 2014-05-06 03:36:15 | [diff] [blame] | 289 | // Used by SetMountEventHandler. |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 290 | struct SignalEventTuple { |
| 291 | const char *signal_name; |
| 292 | MountEventType event_type; |
| 293 | }; |
| 294 | |
| 295 | // Handles the result of Mount and calls |callback| or |error_callback|. |
[email protected] | 5624a25 | 2013-07-04 03:17:53 | [diff] [blame] | 296 | void OnMount(const base::Closure& callback, |
| 297 | const base::Closure& error_callback, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 298 | dbus::Response* response) { |
| 299 | if (!response) { |
| 300 | error_callback.Run(); |
| 301 | return; |
| 302 | } |
| 303 | callback.Run(); |
| 304 | } |
| 305 | |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 306 | // Handles the result of Unmount and calls |callback| or |error_callback|. |
[email protected] | ffdcc7a9c | 2013-07-02 06:59:39 | [diff] [blame] | 307 | void OnUnmount(const base::Closure& callback, |
| 308 | const base::Closure& error_callback, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 309 | dbus::Response* response) { |
| 310 | if (!response) { |
[email protected] | ffdcc7a9c | 2013-07-02 06:59:39 | [diff] [blame] | 311 | error_callback.Run(); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 312 | return; |
| 313 | } |
[email protected] | ddcb18e | 2013-09-19 07:17:28 | [diff] [blame] | 314 | |
| 315 | // Temporarly allow Unmount method to report failure both by setting dbus |
| 316 | // error (in which case response is not set) and by returning mount error |
| 317 | // different from MOUNT_ERROR_NONE. This is done so we can change Unmount |
| 318 | // method to return mount error (http://crbug.com/288974) without breaking |
| 319 | // Chrome. |
| 320 | // TODO(tbarzic): When Unmount implementation is changed on cros disks side, |
| 321 | // make this fail if reader is not able to read the error code value from |
| 322 | // the response. |
| 323 | dbus::MessageReader reader(response); |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 324 | uint32_t error_code = 0; |
[email protected] | ddcb18e | 2013-09-19 07:17:28 | [diff] [blame] | 325 | if (reader.PopUint32(&error_code) && |
| 326 | static_cast<MountError>(error_code) != MOUNT_ERROR_NONE) { |
| 327 | error_callback.Run(); |
| 328 | return; |
| 329 | } |
| 330 | |
[email protected] | ffdcc7a9c | 2013-07-02 06:59:39 | [diff] [blame] | 331 | callback.Run(); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // Handles the result of EnumerateAutoMountableDevices and calls |callback| or |
| 335 | // |error_callback|. |
| 336 | void OnEnumerateAutoMountableDevices( |
[email protected] | 4a404e5 | 2012-04-11 02:25:35 | [diff] [blame] | 337 | const EnumerateAutoMountableDevicesCallback& callback, |
[email protected] | 5624a25 | 2013-07-04 03:17:53 | [diff] [blame] | 338 | const base::Closure& error_callback, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 339 | dbus::Response* response) { |
| 340 | if (!response) { |
| 341 | error_callback.Run(); |
| 342 | return; |
| 343 | } |
| 344 | dbus::MessageReader reader(response); |
| 345 | std::vector<std::string> device_paths; |
| 346 | if (!reader.PopArrayOfStrings(&device_paths)) { |
| 347 | LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 348 | error_callback.Run(); |
| 349 | return; |
| 350 | } |
| 351 | callback.Run(device_paths); |
| 352 | } |
| 353 | |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 354 | // Handles the result of EnumerateMountEntries and calls |callback| or |
| 355 | // |error_callback|. |
| 356 | void OnEnumerateMountEntries( |
| 357 | const EnumerateMountEntriesCallback& callback, |
| 358 | const base::Closure& error_callback, |
| 359 | dbus::Response* response) { |
| 360 | if (!response) { |
| 361 | error_callback.Run(); |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | dbus::MessageReader reader(response); |
| 366 | dbus::MessageReader array_reader(NULL); |
| 367 | if (!reader.PopArray(&array_reader)) { |
| 368 | LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 369 | error_callback.Run(); |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | std::vector<MountEntry> entries; |
| 374 | while (array_reader.HasMoreData()) { |
| 375 | MountEntry entry; |
| 376 | dbus::MessageReader sub_reader(NULL); |
| 377 | if (!array_reader.PopStruct(&sub_reader) || |
| 378 | !ReadMountEntryFromDbus(&sub_reader, &entry)) { |
| 379 | LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 380 | error_callback.Run(); |
| 381 | return; |
| 382 | } |
| 383 | entries.push_back(entry); |
| 384 | } |
| 385 | callback.Run(entries); |
| 386 | } |
| 387 | |
[email protected] | f026c0f | 2014-05-06 21:52:35 | [diff] [blame] | 388 | // Handles the result of Format and calls |callback| or |error_callback|. |
| 389 | void OnFormat(const base::Closure& callback, |
| 390 | const base::Closure& error_callback, |
| 391 | dbus::Response* response) { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 392 | if (!response) { |
| 393 | error_callback.Run(); |
| 394 | return; |
| 395 | } |
[email protected] | f026c0f | 2014-05-06 21:52:35 | [diff] [blame] | 396 | callback.Run(); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 397 | } |
| 398 | |
Klemen Kozjek | bf5610f | 2017-08-25 20:20:09 | [diff] [blame] | 399 | // Handles the result of Rename and calls |callback| or |error_callback|. |
| 400 | void OnRename(const base::Closure& callback, |
| 401 | const base::Closure& error_callback, |
| 402 | dbus::Response* response) { |
| 403 | if (!response) { |
| 404 | error_callback.Run(); |
| 405 | return; |
| 406 | } |
| 407 | callback.Run(); |
| 408 | } |
| 409 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 410 | // Handles the result of GetDeviceProperties and calls |callback| or |
| 411 | // |error_callback|. |
| 412 | void OnGetDeviceProperties(const std::string& device_path, |
[email protected] | 4a404e5 | 2012-04-11 02:25:35 | [diff] [blame] | 413 | const GetDevicePropertiesCallback& callback, |
[email protected] | 5624a25 | 2013-07-04 03:17:53 | [diff] [blame] | 414 | const base::Closure& error_callback, |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 415 | dbus::Response* response) { |
| 416 | if (!response) { |
| 417 | error_callback.Run(); |
| 418 | return; |
| 419 | } |
| 420 | DiskInfo disk(device_path, response); |
| 421 | callback.Run(disk); |
| 422 | } |
| 423 | |
| 424 | // Handles mount event signals and calls |handler|. |
| 425 | void OnMountEvent(MountEventType event_type, |
| 426 | MountEventHandler handler, |
| 427 | dbus::Signal* signal) { |
| 428 | dbus::MessageReader reader(signal); |
| 429 | std::string device; |
| 430 | if (!reader.PopString(&device)) { |
| 431 | LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 432 | return; |
| 433 | } |
| 434 | handler.Run(event_type, device); |
| 435 | } |
| 436 | |
| 437 | // Handles MountCompleted signal and calls |handler|. |
| 438 | void OnMountCompleted(MountCompletedHandler handler, dbus::Signal* signal) { |
| 439 | dbus::MessageReader reader(signal); |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 440 | MountEntry entry; |
| 441 | if (!ReadMountEntryFromDbus(&reader, &entry)) { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 442 | LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 443 | return; |
| 444 | } |
[email protected] | d776059 | 2014-05-16 07:57:52 | [diff] [blame] | 445 | handler.Run(entry); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 446 | } |
| 447 | |
[email protected] | a0278d5 | 2014-05-06 03:36:15 | [diff] [blame] | 448 | // Handles FormatCompleted signal and calls |handler|. |
| 449 | void OnFormatCompleted(FormatCompletedHandler handler, dbus::Signal* signal) { |
| 450 | dbus::MessageReader reader(signal); |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 451 | uint32_t error_code = 0; |
[email protected] | a0278d5 | 2014-05-06 03:36:15 | [diff] [blame] | 452 | std::string device_path; |
| 453 | if (!reader.PopUint32(&error_code) || !reader.PopString(&device_path)) { |
| 454 | LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 455 | return; |
| 456 | } |
| 457 | handler.Run(static_cast<FormatError>(error_code), device_path); |
| 458 | } |
| 459 | |
Klemen Kozjek | bf5610f | 2017-08-25 20:20:09 | [diff] [blame] | 460 | // Handles RenameCompleted signal and calls |handler|. |
| 461 | void OnRenameCompleted(RenameCompletedHandler handler, dbus::Signal* signal) { |
| 462 | dbus::MessageReader reader(signal); |
| 463 | uint32_t error_code = 0; |
| 464 | std::string device_path; |
| 465 | if (!reader.PopUint32(&error_code) || !reader.PopString(&device_path)) { |
| 466 | LOG(ERROR) << "Invalid signal: " << signal->ToString(); |
| 467 | return; |
| 468 | } |
| 469 | handler.Run(static_cast<RenameError>(error_code), device_path); |
| 470 | } |
| 471 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 472 | // Handles the result of signal connection setup. |
| 473 | void OnSignalConnected(const std::string& interface, |
| 474 | const std::string& signal, |
[email protected] | d6311dcb | 2012-10-22 03:40:43 | [diff] [blame] | 475 | bool succeeded) { |
| 476 | LOG_IF(ERROR, !succeeded) << "Connect to " << interface << " " << |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 477 | signal << " failed."; |
| 478 | } |
| 479 | |
| 480 | dbus::ObjectProxy* proxy_; |
[email protected] | 926957b | 2012-09-07 05:34:16 | [diff] [blame] | 481 | |
| 482 | // Note: This should remain the last member so it'll be destroyed and |
| 483 | // invalidate its weak pointers before any other members are destroyed. |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 484 | base::WeakPtrFactory<CrosDisksClientImpl> weak_ptr_factory_; |
| 485 | |
| 486 | DISALLOW_COPY_AND_ASSIGN(CrosDisksClientImpl); |
| 487 | }; |
| 488 | |
[email protected] | 85b95a201 | 2012-08-07 18:57:27 | [diff] [blame] | 489 | } // namespace |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 490 | |
| 491 | //////////////////////////////////////////////////////////////////////////////// |
| 492 | // DiskInfo |
| 493 | |
| 494 | DiskInfo::DiskInfo(const std::string& device_path, dbus::Response* response) |
| 495 | : device_path_(device_path), |
| 496 | is_drive_(false), |
| 497 | has_media_(false), |
| 498 | on_boot_device_(false), |
[email protected] | 79ed457b | 2014-07-22 04:07:26 | [diff] [blame] | 499 | on_removable_device_(false), |
[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 500 | device_type_(DEVICE_TYPE_UNKNOWN), |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 501 | total_size_in_bytes_(0), |
| 502 | is_read_only_(false), |
| 503 | is_hidden_(true) { |
| 504 | InitializeFromResponse(response); |
| 505 | } |
| 506 | |
| 507 | DiskInfo::~DiskInfo() { |
| 508 | } |
| 509 | |
[email protected] | 85b95a201 | 2012-08-07 18:57:27 | [diff] [blame] | 510 | // Initializes |this| from |response| given by the cros-disks service. |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 511 | // Below is an example of |response|'s raw message (long string is ellipsized). |
| 512 | // |
| 513 | // |
| 514 | // message_type: MESSAGE_METHOD_RETURN |
| 515 | // destination: :1.8 |
| 516 | // sender: :1.16 |
| 517 | // signature: a{sv} |
| 518 | // serial: 96 |
| 519 | // reply_serial: 267 |
| 520 | // |
| 521 | // array [ |
| 522 | // dict entry { |
| 523 | // string "DeviceFile" |
| 524 | // variant string "/dev/sdb" |
| 525 | // } |
| 526 | // dict entry { |
| 527 | // string "DeviceIsDrive" |
| 528 | // variant bool true |
| 529 | // } |
| 530 | // dict entry { |
| 531 | // string "DeviceIsMediaAvailable" |
| 532 | // variant bool true |
| 533 | // } |
| 534 | // dict entry { |
| 535 | // string "DeviceIsMounted" |
| 536 | // variant bool false |
| 537 | // } |
| 538 | // dict entry { |
| 539 | // string "DeviceIsOnBootDevice" |
| 540 | // variant bool false |
| 541 | // } |
| 542 | // dict entry { |
[email protected] | 79ed457b | 2014-07-22 04:07:26 | [diff] [blame] | 543 | // string "DeviceIsOnRemovableDevice" |
| 544 | // variant bool true |
| 545 | // } |
| 546 | // dict entry { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 547 | // string "DeviceIsReadOnly" |
| 548 | // variant bool false |
| 549 | // } |
| 550 | // dict entry { |
| 551 | // string "DeviceIsVirtual" |
| 552 | // variant bool false |
| 553 | // } |
| 554 | // dict entry { |
| 555 | // string "DeviceMediaType" |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 556 | // variant uint32_t 1 |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 557 | // } |
| 558 | // dict entry { |
| 559 | // string "DeviceMountPaths" |
| 560 | // variant array [ |
| 561 | // ] |
| 562 | // } |
| 563 | // dict entry { |
| 564 | // string "DevicePresentationHide" |
| 565 | // variant bool true |
| 566 | // } |
| 567 | // dict entry { |
| 568 | // string "DeviceSize" |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 569 | // variant uint64_t 7998537728 |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 570 | // } |
| 571 | // dict entry { |
| 572 | // string "DriveIsRotational" |
| 573 | // variant bool false |
| 574 | // } |
| 575 | // dict entry { |
[email protected] | 202e9fee | 2012-09-13 20:21:29 | [diff] [blame] | 576 | // string "VendorId" |
| 577 | // variant string "18d1" |
| 578 | // } |
| 579 | // dict entry { |
| 580 | // string "VendorName" |
| 581 | // variant string "Google Inc." |
| 582 | // } |
| 583 | // dict entry { |
| 584 | // string "ProductId" |
| 585 | // variant string "4e11" |
| 586 | // } |
| 587 | // dict entry { |
| 588 | // string "ProductName" |
| 589 | // variant string "Nexus One" |
| 590 | // } |
| 591 | // dict entry { |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 592 | // string "DriveModel" |
| 593 | // variant string "TransMemory" |
| 594 | // } |
| 595 | // dict entry { |
| 596 | // string "IdLabel" |
| 597 | // variant string "" |
| 598 | // } |
| 599 | // dict entry { |
| 600 | // string "IdUuid" |
| 601 | // variant string "" |
| 602 | // } |
| 603 | // dict entry { |
| 604 | // string "NativePath" |
| 605 | // variant string "/sys/devices/pci0000:00/0000:00:1d.7/usb1/1-4/... |
| 606 | // } |
Klemen Kozjek | 46f1c619 | 2017-08-25 19:20:54 | [diff] [blame] | 607 | // dict entry { |
| 608 | // string "FileSystemType" |
| 609 | // variant string "vfat" |
| 610 | // } |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 611 | // ] |
| 612 | void DiskInfo::InitializeFromResponse(dbus::Response* response) { |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 613 | dbus::MessageReader reader(response); |
dcheng | 0a6e80c | 2016-04-08 18:37:38 | [diff] [blame] | 614 | std::unique_ptr<base::Value> value(dbus::PopDataAsValue(&reader)); |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 615 | base::DictionaryValue* properties = NULL; |
| 616 | if (!value || !value->GetAsDictionary(&properties)) |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 617 | return; |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 618 | |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 619 | properties->GetBooleanWithoutPathExpansion( |
| 620 | cros_disks::kDeviceIsDrive, &is_drive_); |
| 621 | properties->GetBooleanWithoutPathExpansion( |
| 622 | cros_disks::kDeviceIsReadOnly, &is_read_only_); |
| 623 | properties->GetBooleanWithoutPathExpansion( |
| 624 | cros_disks::kDevicePresentationHide, &is_hidden_); |
| 625 | properties->GetBooleanWithoutPathExpansion( |
| 626 | cros_disks::kDeviceIsMediaAvailable, &has_media_); |
| 627 | properties->GetBooleanWithoutPathExpansion( |
| 628 | cros_disks::kDeviceIsOnBootDevice, &on_boot_device_); |
[email protected] | 79ed457b | 2014-07-22 04:07:26 | [diff] [blame] | 629 | properties->GetBooleanWithoutPathExpansion( |
| 630 | cros_disks::kDeviceIsOnRemovableDevice, &on_removable_device_); |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 631 | properties->GetStringWithoutPathExpansion( |
| 632 | cros_disks::kNativePath, &system_path_); |
| 633 | properties->GetStringWithoutPathExpansion( |
| 634 | cros_disks::kDeviceFile, &file_path_); |
| 635 | properties->GetStringWithoutPathExpansion(cros_disks::kVendorId, &vendor_id_); |
| 636 | properties->GetStringWithoutPathExpansion( |
| 637 | cros_disks::kVendorName, &vendor_name_); |
| 638 | properties->GetStringWithoutPathExpansion( |
| 639 | cros_disks::kProductId, &product_id_); |
| 640 | properties->GetStringWithoutPathExpansion( |
| 641 | cros_disks::kProductName, &product_name_); |
| 642 | properties->GetStringWithoutPathExpansion( |
| 643 | cros_disks::kDriveModel, &drive_model_); |
| 644 | properties->GetStringWithoutPathExpansion(cros_disks::kIdLabel, &label_); |
| 645 | properties->GetStringWithoutPathExpansion(cros_disks::kIdUuid, &uuid_); |
Klemen Kozjek | 46f1c619 | 2017-08-25 19:20:54 | [diff] [blame] | 646 | properties->GetStringWithoutPathExpansion(cros_disks::kFileSystemType, |
| 647 | &file_system_type_); |
[email protected] | 2321d28 | 2012-01-31 23:06:59 | [diff] [blame] | 648 | |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 649 | // dbus::PopDataAsValue() pops uint64_t as double. |
| 650 | // The top 11 bits of uint64_t are dropped by the use of double. But, this |
| 651 | // works |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 652 | // unless the size exceeds 8 PB. |
| 653 | double device_size_double = 0; |
| 654 | if (properties->GetDoubleWithoutPathExpansion(cros_disks::kDeviceSize, |
| 655 | &device_size_double)) |
| 656 | total_size_in_bytes_ = device_size_double; |
| 657 | |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 658 | // dbus::PopDataAsValue() pops uint32_t as double. |
[email protected] | 81836aed | 2013-07-09 23:41:12 | [diff] [blame] | 659 | double media_type_double = 0; |
| 660 | if (properties->GetDoubleWithoutPathExpansion(cros_disks::kDeviceMediaType, |
| 661 | &media_type_double)) |
| 662 | device_type_ = DeviceMediaTypeToDeviceType(media_type_double); |
| 663 | |
| 664 | base::ListValue* mount_paths = NULL; |
| 665 | if (properties->GetListWithoutPathExpansion(cros_disks::kDeviceMountPaths, |
| 666 | &mount_paths)) |
| 667 | mount_paths->GetString(0, &mount_path_); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | //////////////////////////////////////////////////////////////////////////////// |
| 671 | // CrosDisksClient |
| 672 | |
| 673 | CrosDisksClient::CrosDisksClient() {} |
| 674 | |
| 675 | CrosDisksClient::~CrosDisksClient() {} |
| 676 | |
| 677 | // static |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 678 | CrosDisksClient* CrosDisksClient::Create(DBusClientImplementationType type) { |
[email protected] | e8db03d6 | 2012-03-31 04:08:38 | [diff] [blame] | 679 | if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
[email protected] | c5fd536 | 2013-08-27 12:23:04 | [diff] [blame] | 680 | return new CrosDisksClientImpl(); |
jamescook | 2b59099 | 2016-09-14 15:28:45 | [diff] [blame] | 681 | DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
satorux | 8fd29380 | 2014-10-30 08:23:12 | [diff] [blame] | 682 | return new FakeCrosDisksClient(); |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 683 | } |
| 684 | |
[email protected] | a5a8b41 | 2013-03-04 15:03:11 | [diff] [blame] | 685 | // static |
| 686 | base::FilePath CrosDisksClient::GetArchiveMountPoint() { |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 687 | return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ? |
[email protected] | a5a8b41 | 2013-03-04 15:03:11 | [diff] [blame] | 688 | FILE_PATH_LITERAL("/media/archive") : |
| 689 | FILE_PATH_LITERAL("/tmp/chromeos/media/archive")); |
| 690 | } |
| 691 | |
| 692 | // static |
| 693 | base::FilePath CrosDisksClient::GetRemovableDiskMountPoint() { |
[email protected] | 49c4cf85 | 2013-09-27 19:28:24 | [diff] [blame] | 694 | return base::FilePath(base::SysInfo::IsRunningOnChromeOS() ? |
[email protected] | a5a8b41 | 2013-03-04 15:03:11 | [diff] [blame] | 695 | FILE_PATH_LITERAL("/media/removable") : |
| 696 | FILE_PATH_LITERAL("/tmp/chromeos/media/removable")); |
| 697 | } |
| 698 | |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 699 | // static |
| 700 | std::vector<std::string> CrosDisksClient::ComposeMountOptions( |
| 701 | const std::string& mount_label, |
yamaguchi | fa8efc7 | 2016-10-21 15:05:51 | [diff] [blame] | 702 | MountAccessMode access_mode, |
| 703 | RemountOption remount) { |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 704 | std::vector<std::string> mount_options( |
| 705 | kDefaultMountOptions, |
| 706 | kDefaultMountOptions + arraysize(kDefaultMountOptions)); |
| 707 | switch (access_mode) { |
| 708 | case MOUNT_ACCESS_MODE_READ_ONLY: |
| 709 | mount_options.push_back(kReadOnlyOption); |
| 710 | break; |
| 711 | case MOUNT_ACCESS_MODE_READ_WRITE: |
| 712 | mount_options.push_back(kReadWriteOption); |
| 713 | break; |
| 714 | } |
yamaguchi | fa8efc7 | 2016-10-21 15:05:51 | [diff] [blame] | 715 | if (remount == REMOUNT_OPTION_REMOUNT_EXISTING_DEVICE) { |
| 716 | mount_options.push_back(kRemountOption); |
| 717 | } |
yamaguchi | 585d540 | 2016-08-02 09:27:36 | [diff] [blame] | 718 | |
| 719 | if (!mount_label.empty()) { |
| 720 | std::string mount_label_option = |
| 721 | base::StringPrintf("%s=%s", kMountLabelOption, mount_label.c_str()); |
| 722 | mount_options.push_back(mount_label_option); |
| 723 | } |
| 724 | return mount_options; |
| 725 | } |
| 726 | |
[email protected] | 4ae7329 | 2011-11-15 05:20:18 | [diff] [blame] | 727 | } // namespace chromeos |