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