Commit 2931faae authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Implement GetDeleteList on SmbProviderClient

This change implements a GetDeleteList function on
SmbProviderClient that maps to the GetDeleteList fn
on the SmbProvider daemon.

Bug: chromium:757625
Change-Id: I7e4e4a8f0e7f21a92c8dd9edd72ad4e26bd6cd07
Reviewed-on: https://chromium-review.googlesource.com/937815Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542248}
parent 3f5130b9
...@@ -131,4 +131,12 @@ void FakeSmbProviderClient::CopyEntry(int32_t mount_id, ...@@ -131,4 +131,12 @@ void FakeSmbProviderClient::CopyEntry(int32_t mount_id,
FROM_HERE, base::BindOnce(std::move(callback), smbprovider::ERROR_OK)); FROM_HERE, base::BindOnce(std::move(callback), smbprovider::ERROR_OK));
} }
void FakeSmbProviderClient::GetDeleteList(int32_t mount_id,
const base::FilePath& entry_path,
GetDeleteListCallback callback) {
smbprovider::DeleteListProto delete_list;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), smbprovider::ERROR_OK, delete_list));
}
} // namespace chromeos } // namespace chromeos
...@@ -76,6 +76,10 @@ class CHROMEOS_EXPORT FakeSmbProviderClient : public SmbProviderClient { ...@@ -76,6 +76,10 @@ class CHROMEOS_EXPORT FakeSmbProviderClient : public SmbProviderClient {
const base::FilePath& target_path, const base::FilePath& target_path,
StatusCallback callback) override; StatusCallback callback) override;
void GetDeleteList(int32_t mount_id,
const base::FilePath& entry_path,
GetDeleteListCallback callback) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(FakeSmbProviderClient); DISALLOW_COPY_AND_ASSIGN(FakeSmbProviderClient);
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/files/file_util.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "dbus/bus.h" #include "dbus/bus.h"
#include "dbus/message.h" #include "dbus/message.h"
...@@ -45,6 +46,16 @@ smbprovider::ErrorType GetErrorAndProto( ...@@ -45,6 +46,16 @@ smbprovider::ErrorType GetErrorAndProto(
return smbprovider::ERROR_OK; return smbprovider::ERROR_OK;
} }
bool ParseDeleteList(const base::ScopedFD& fd,
int32_t bytes_written,
smbprovider::DeleteListProto* delete_list) {
DCHECK(delete_list);
std::vector<uint8_t> buffer(bytes_written);
return base::ReadFromFD(fd.get(), reinterpret_cast<char*>(buffer.data()),
buffer.size()) &&
delete_list->ParseFromArray(buffer.data(), buffer.size());
}
class SmbProviderClientImpl : public SmbProviderClient { class SmbProviderClientImpl : public SmbProviderClient {
public: public:
SmbProviderClientImpl() : weak_ptr_factory_(this) {} SmbProviderClientImpl() : weak_ptr_factory_(this) {}
...@@ -208,6 +219,16 @@ class SmbProviderClientImpl : public SmbProviderClient { ...@@ -208,6 +219,16 @@ class SmbProviderClientImpl : public SmbProviderClient {
CallDefaultMethod(smbprovider::kCopyEntryMethod, options, &callback); CallDefaultMethod(smbprovider::kCopyEntryMethod, options, &callback);
} }
void GetDeleteList(int32_t mount_id,
const base::FilePath& entry_path,
GetDeleteListCallback callback) override {
smbprovider::GetDeleteListOptionsProto options;
options.set_mount_id(mount_id);
options.set_entry_path(entry_path.value());
CallMethod(smbprovider::kGetDeleteListMethod, options,
&SmbProviderClientImpl::HandleGetDeleteListCallback, &callback);
}
protected: protected:
// DBusClient override. // DBusClient override.
void Init(dbus::Bus* bus) override { void Init(dbus::Bus* bus) override {
...@@ -335,6 +356,39 @@ class SmbProviderClientImpl : public SmbProviderClient { ...@@ -335,6 +356,39 @@ class SmbProviderClientImpl : public SmbProviderClient {
std::move(callback).Run(smbprovider::ERROR_OK, fd); std::move(callback).Run(smbprovider::ERROR_OK, fd);
} }
// Handles D-Bus callback for GetDeleteList.
void HandleGetDeleteListCallback(GetDeleteListCallback callback,
dbus::Response* response) {
base::ScopedFD fd;
smbprovider::DeleteListProto delete_list;
if (!response) {
LOG(ERROR) << "GetDeleteList: failed to call smbprovider";
std::move(callback).Run(smbprovider::ERROR_DBUS_PARSE_FAILED,
delete_list);
return;
}
dbus::MessageReader reader(response);
smbprovider::ErrorType error = GetErrorFromReader(&reader);
if (error != smbprovider::ERROR_OK) {
std::move(callback).Run(error, delete_list);
return;
}
int32_t bytes_written;
bool success = reader.PopFileDescriptor(&fd) &&
reader.PopInt32(&bytes_written) &&
ParseDeleteList(fd, bytes_written, &delete_list);
if (!success) {
LOG(ERROR) << "GetDeleteList: parse failure.";
std::move(callback).Run(smbprovider::ERROR_DBUS_PARSE_FAILED,
delete_list);
return;
}
std::move(callback).Run(smbprovider::ERROR_OK, delete_list);
}
// Default callback handler for D-Bus calls. // Default callback handler for D-Bus calls.
void HandleDefaultCallback(const std::string& method_name, void HandleDefaultCallback(const std::string& method_name,
StatusCallback callback, StatusCallback callback,
......
...@@ -34,6 +34,9 @@ class CHROMEOS_EXPORT SmbProviderClient : public DBusClient { ...@@ -34,6 +34,9 @@ class CHROMEOS_EXPORT SmbProviderClient : public DBusClient {
using StatusCallback = base::OnceCallback<void(smbprovider::ErrorType error)>; using StatusCallback = base::OnceCallback<void(smbprovider::ErrorType error)>;
using ReadFileCallback = base::OnceCallback<void(smbprovider::ErrorType error, using ReadFileCallback = base::OnceCallback<void(smbprovider::ErrorType error,
const base::ScopedFD& fd)>; const base::ScopedFD& fd)>;
using GetDeleteListCallback =
base::OnceCallback<void(smbprovider::ErrorType error,
const smbprovider::DeleteListProto& delete_list)>;
~SmbProviderClient() override; ~SmbProviderClient() override;
...@@ -144,6 +147,13 @@ class CHROMEOS_EXPORT SmbProviderClient : public DBusClient { ...@@ -144,6 +147,13 @@ class CHROMEOS_EXPORT SmbProviderClient : public DBusClient {
const base::FilePath& target_path, const base::FilePath& target_path,
StatusCallback callback) = 0; StatusCallback callback) = 0;
// Calls GetDeleteList. Using the corresponding |mount_id|, this generates an
// ordered list of individual entries that must be deleted in order to delete
// |entry_path|. This operations does not modify the filesystem.
virtual void GetDeleteList(int32_t mount_id,
const base::FilePath& entry_path,
GetDeleteListCallback callback) = 0;
protected: protected:
// Create() should be used instead. // Create() should be used instead.
SmbProviderClient(); SmbProviderClient();
......
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