Commit d7760592 authored by kinaba@chromium.org's avatar kinaba@chromium.org

Add EnumerateMountEntries method in CrosDisksClient.

The corresponding dbus level method is already added in
https://chromium-review.googlesource.com/#/c/195111/.
This CL is for adding the method to the wrapper client class.

BUG=356583

Review URL: https://codereview.chromium.org/281063002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270958 0039d316-1c4b-4281-b951-d872f2087c98
parent 3e92ee1a
......@@ -76,6 +76,22 @@ DeviceType DeviceMediaTypeToDeviceType(uint32 media_type_uint32) {
}
}
bool ReadMountEntryFromDbus(dbus::MessageReader* reader, MountEntry* entry) {
uint32 error_code = 0;
std::string source_path;
uint32 mount_type = 0;
std::string mount_path;
if (!reader->PopUint32(&error_code) ||
!reader->PopString(&source_path) ||
!reader->PopUint32(&mount_type) ||
!reader->PopString(&mount_path)) {
return false;
}
*entry = MountEntry(static_cast<MountError>(error_code), source_path,
static_cast<MountType>(mount_type), mount_path);
return true;
}
// The CrosDisksClient implementation.
class CrosDisksClientImpl : public CrosDisksClient {
public:
......@@ -147,6 +163,20 @@ class CrosDisksClientImpl : public CrosDisksClient {
error_callback));
}
// CrosDisksClient override.
virtual void EnumerateMountEntries(
const EnumerateMountEntriesCallback& callback,
const base::Closure& error_callback) OVERRIDE {
dbus::MethodCall method_call(cros_disks::kCrosDisksInterface,
cros_disks::kEnumerateMountEntries);
proxy_->CallMethod(
&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
base::Bind(&CrosDisksClientImpl::OnEnumerateMountEntries,
weak_ptr_factory_.GetWeakPtr(),
callback,
error_callback));
}
// CrosDisksClient override.
virtual void Format(const std::string& device_path,
const std::string& filesystem,
......@@ -264,7 +294,7 @@ class CrosDisksClientImpl : public CrosDisksClient {
callback.Run();
}
// Handles the result of Unount and calls |callback| or |error_callback|.
// Handles the result of Unmount and calls |callback| or |error_callback|.
void OnUnmount(const base::Closure& callback,
const base::Closure& error_callback,
dbus::Response* response) {
......@@ -312,6 +342,40 @@ class CrosDisksClientImpl : public CrosDisksClient {
callback.Run(device_paths);
}
// Handles the result of EnumerateMountEntries and calls |callback| or
// |error_callback|.
void OnEnumerateMountEntries(
const EnumerateMountEntriesCallback& callback,
const base::Closure& error_callback,
dbus::Response* response) {
if (!response) {
error_callback.Run();
return;
}
dbus::MessageReader reader(response);
dbus::MessageReader array_reader(NULL);
if (!reader.PopArray(&array_reader)) {
LOG(ERROR) << "Invalid response: " << response->ToString();
error_callback.Run();
return;
}
std::vector<MountEntry> entries;
while (array_reader.HasMoreData()) {
MountEntry entry;
dbus::MessageReader sub_reader(NULL);
if (!array_reader.PopStruct(&sub_reader) ||
!ReadMountEntryFromDbus(&sub_reader, &entry)) {
LOG(ERROR) << "Invalid response: " << response->ToString();
error_callback.Run();
return;
}
entries.push_back(entry);
}
callback.Run(entries);
}
// Handles the result of Format and calls |callback| or |error_callback|.
void OnFormat(const base::Closure& callback,
const base::Closure& error_callback,
......@@ -353,19 +417,12 @@ class CrosDisksClientImpl : public CrosDisksClient {
// Handles MountCompleted signal and calls |handler|.
void OnMountCompleted(MountCompletedHandler handler, dbus::Signal* signal) {
dbus::MessageReader reader(signal);
uint32 error_code = 0;
std::string source_path;
uint32 mount_type = 0;
std::string mount_path;
if (!reader.PopUint32(&error_code) ||
!reader.PopString(&source_path) ||
!reader.PopUint32(&mount_type) ||
!reader.PopString(&mount_path)) {
MountEntry entry;
if (!ReadMountEntryFromDbus(&reader, &entry)) {
LOG(ERROR) << "Invalid signal: " << signal->ToString();
return;
}
handler.Run(static_cast<MountError>(error_code), source_path,
static_cast<MountType>(mount_type), mount_path);
handler.Run(entry);
}
// Handles FormatCompleted signal and calls |handler|.
......@@ -468,6 +525,14 @@ class CrosDisksClientStubImpl : public CrosDisksClient {
FROM_HERE, base::Bind(callback, device_paths));
}
virtual void EnumerateMountEntries(
const EnumerateMountEntriesCallback& callback,
const base::Closure& error_callback) OVERRIDE {
std::vector<MountEntry> entries;
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(callback, entries));
}
virtual void Format(const std::string& device_path,
const std::string& filesystem,
const base::Closure& callback,
......@@ -555,7 +620,7 @@ class CrosDisksClientStubImpl : public CrosDisksClient {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(mount_completed_handler_,
error, source_path, type, mounted_path));
MountEntry(error, source_path, type, mounted_path)));
}
}
......
......@@ -19,6 +19,7 @@ class FilePath;
}
namespace dbus {
class MessageReader;
class Response;
}
......@@ -121,7 +122,7 @@ class CHROMEOS_EXPORT DiskInfo {
// Does the disk have media content.
bool has_media() const { return has_media_; }
// Is the disk on deveice we booted the machine from.
// Is the disk on device we booted the machine from.
bool on_boot_device() const { return on_boot_device_; }
// Disk file path (e.g. /dev/sdb).
......@@ -184,6 +185,35 @@ class CHROMEOS_EXPORT DiskInfo {
std::string uuid_;
};
// A struct to represent information about a mount point sent from cros-disks.
struct CHROMEOS_EXPORT MountEntry {
public:
MountEntry()
: error_code_(MOUNT_ERROR_UNKNOWN), mount_type_(MOUNT_TYPE_INVALID) {
}
MountEntry(MountError error_code,
const std::string& source_path,
MountType mount_type,
const std::string& mount_path)
: error_code_(error_code),
source_path_(source_path),
mount_type_(mount_type),
mount_path_(mount_path) {
}
MountError error_code() const { return error_code_; }
const std::string& source_path() const { return source_path_; }
MountType mount_type() const { return mount_type_; }
const std::string& mount_path() const { return mount_path_; }
private:
MountError error_code_;
std::string source_path_;
MountType mount_type_;
std::string mount_path_;
};
// A class to make the actual DBus calls for cros-disks service.
// This class only makes calls, result/error handling should be done
// by callbacks.
......@@ -194,21 +224,18 @@ class CHROMEOS_EXPORT CrosDisksClient : public DBusClient {
typedef base::Callback<void(const std::vector<std::string>& device_paths)>
EnumerateAutoMountableDevicesCallback;
// A callback to handle the result of EnumerateMountEntries.
// The argument is the enumerated mount entries.
typedef base::Callback<void(const std::vector<MountEntry>& entries)>
EnumerateMountEntriesCallback;
// A callback to handle the result of GetDeviceProperties.
// The argument is the information about the specified device.
typedef base::Callback<void(const DiskInfo& disk_info)>
GetDevicePropertiesCallback;
// A callback to handle MountCompleted signal.
// The first argument is the error code.
// The second argument is the source path.
// The third argument is the mount type.
// The fourth argument is the mount path.
typedef base::Callback<void(MountError error_code,
const std::string& source_path,
MountType mount_type,
const std::string& mount_path)>
MountCompletedHandler;
typedef base::Callback<void(const MountEntry& entry)> MountCompletedHandler;
// A callback to handle FormatCompleted signal.
// The first argument is the error code.
......@@ -254,6 +281,12 @@ class CHROMEOS_EXPORT CrosDisksClient : public DBusClient {
const EnumerateAutoMountableDevicesCallback& callback,
const base::Closure& error_callback) = 0;
// Calls EnumerateMountEntries. |callback| is called after the
// method call succeeds, otherwise, |error_callback| is called.
virtual void EnumerateMountEntries(
const EnumerateMountEntriesCallback& callback,
const base::Closure& error_callback) = 0;
// Calls Format method. |callback| is called after the method call succeeds,
// otherwise, |error_callback| is called.
virtual void Format(const std::string& device_path,
......
......@@ -51,6 +51,11 @@ void FakeCrosDisksClient::EnumerateAutoMountableDevices(
const base::Closure& error_callback) {
}
void FakeCrosDisksClient::EnumerateMountEntries(
const EnumerateMountEntriesCallback& callback,
const base::Closure& error_callback) {
}
void FakeCrosDisksClient::Format(const std::string& device_path,
const std::string& filesystem,
const base::Closure& callback,
......@@ -104,7 +109,8 @@ bool FakeCrosDisksClient::SendMountCompletedEvent(
const std::string& mount_path) {
if (mount_completed_handler_.is_null())
return false;
mount_completed_handler_.Run(error_code, source_path, mount_type, mount_path);
mount_completed_handler_.Run(
MountEntry(error_code, source_path, mount_type, mount_path));
return true;
}
......
......@@ -33,6 +33,9 @@ class FakeCrosDisksClient : public CrosDisksClient {
virtual void EnumerateAutoMountableDevices(
const EnumerateAutoMountableDevicesCallback& callback,
const base::Closure& error_callback) OVERRIDE;
virtual void EnumerateMountEntries(
const EnumerateMountEntriesCallback& callback,
const base::Closure& error_callback) OVERRIDE;
virtual void Format(const std::string& device_path,
const std::string& filesystem,
const base::Closure& callback,
......
......@@ -65,7 +65,8 @@ class DiskMountManagerImpl : public DiskMountManager {
if (type == MOUNT_TYPE_DEVICE) {
DiskMap::const_iterator it = disks_.find(source_path);
if (it == disks_.end() || it->second->is_hidden()) {
OnMountCompleted(MOUNT_ERROR_INTERNAL, source_path, type, "");
OnMountCompleted(MountEntry(MOUNT_ERROR_INTERNAL, source_path, type,
""));
return;
}
}
......@@ -78,10 +79,7 @@ class DiskMountManagerImpl : public DiskMountManager {
base::Bind(&base::DoNothing),
base::Bind(&DiskMountManagerImpl::OnMountCompleted,
weak_ptr_factory_.GetWeakPtr(),
MOUNT_ERROR_INTERNAL,
source_path,
type,
""));
MountEntry(MOUNT_ERROR_INTERNAL, source_path, type, "")));
}
// DiskMountManager override.
......@@ -300,32 +298,33 @@ class DiskMountManagerImpl : public DiskMountManager {
}
// Callback to handle MountCompleted signal and Mount method call failure.
void OnMountCompleted(MountError error_code,
const std::string& source_path,
MountType mount_type,
const std::string& mount_path) {
void OnMountCompleted(const MountEntry& entry) {
MountCondition mount_condition = MOUNT_CONDITION_NONE;
if (mount_type == MOUNT_TYPE_DEVICE) {
if (error_code == MOUNT_ERROR_UNKNOWN_FILESYSTEM) {
if (entry.mount_type() == MOUNT_TYPE_DEVICE) {
if (entry.error_code() == MOUNT_ERROR_UNKNOWN_FILESYSTEM) {
mount_condition = MOUNT_CONDITION_UNKNOWN_FILESYSTEM;
}
if (error_code == MOUNT_ERROR_UNSUPPORTED_FILESYSTEM) {
if (entry.error_code() == MOUNT_ERROR_UNSUPPORTED_FILESYSTEM) {
mount_condition = MOUNT_CONDITION_UNSUPPORTED_FILESYSTEM;
}
}
const MountPointInfo mount_info(source_path, mount_path, mount_type,
const MountPointInfo mount_info(entry.source_path(),
entry.mount_path(),
entry.mount_type(),
mount_condition);
NotifyMountStatusUpdate(MOUNTING, error_code, mount_info);
NotifyMountStatusUpdate(MOUNTING, entry.error_code(), mount_info);
// If the device is corrupted but it's still possible to format it, it will
// be fake mounted.
if ((error_code == MOUNT_ERROR_NONE || mount_info.mount_condition) &&
if ((entry.error_code() == MOUNT_ERROR_NONE ||
mount_info.mount_condition) &&
mount_points_.find(mount_info.mount_path) == mount_points_.end()) {
mount_points_.insert(MountPointMap::value_type(mount_info.mount_path,
mount_info));
}
if ((error_code == MOUNT_ERROR_NONE || mount_info.mount_condition) &&
if ((entry.error_code() == MOUNT_ERROR_NONE ||
mount_info.mount_condition) &&
mount_info.mount_type == MOUNT_TYPE_DEVICE &&
!mount_info.source_path.empty() &&
!mount_info.mount_path.empty()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment