Index: chromeos/dbus/cros_disks_client.cc |
diff --git a/chromeos/dbus/cros_disks_client.cc b/chromeos/dbus/cros_disks_client.cc |
index cca2b17e7c720b7054c650f9d273a61d2647e9d5..aea7de822227019698e26170a6691ac7d790c6df 100644 |
--- a/chromeos/dbus/cros_disks_client.cc |
+++ b/chromeos/dbus/cros_disks_client.cc |
@@ -148,6 +148,20 @@ class CrosDisksClientImpl : public CrosDisksClient { |
} |
// 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, |
const base::Closure& callback, |
@@ -264,7 +278,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 +326,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) || |
+ !MountEntry::ReadFromDbus(&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 +401,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 (!MountEntry::ReadFromDbus(&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 +509,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 +604,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))); |
} |
} |
@@ -739,6 +788,43 @@ void DiskInfo::InitializeFromResponse(dbus::Response* response) { |
} |
//////////////////////////////////////////////////////////////////////////////// |
+// MountEntry |
+ |
+MountEntry::MountEntry() |
+ : error_code_(MOUNT_ERROR_UNKNOWN), mount_type_(MOUNT_TYPE_INVALID) { |
+} |
+ |
+MountEntry::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) { |
+} |
+ |
+MountEntry::~MountEntry() { |
+} |
+ |
+// static |
+bool MountEntry::ReadFromDbus(dbus::MessageReader* reader, MountEntry* entry) { |
stevenjb
2014/05/14 17:45:11
If this is only used in this file we can just make
kinaba
2014/05/15 02:14:59
Done.
|
+ 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; |
+} |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
// CrosDisksClient |
CrosDisksClient::CrosDisksClient() {} |