Commit 58881f7e authored by Allen Vicencio's avatar Allen Vicencio Committed by Commit Bot

Add Truncate to SmbProviderClient

Adds Truncate to SmbProviderClient and FakeSmbProviderClient

CQ-DEPEND=CL:879387

Bug: chromium:757625
Change-Id: Iff2f62efc059a41ad4d15c3cbb18bafac277c690
Reviewed-on: https://chromium-review.googlesource.com/879566
Commit-Queue: Allen Vicencio <allenvic@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533156}
parent 6abfd13f
......@@ -88,4 +88,12 @@ void FakeSmbProviderClient::CreateFile(int32_t mount_id,
FROM_HERE, base::BindOnce(std::move(callback), smbprovider::ERROR_OK));
}
void FakeSmbProviderClient::Truncate(int32_t mount_id,
const base::FilePath& file_path,
int64_t length,
StatusCallback callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), smbprovider::ERROR_OK));
}
} // namespace chromeos
......@@ -49,6 +49,11 @@ class CHROMEOS_EXPORT FakeSmbProviderClient : public SmbProviderClient {
const base::FilePath& file_path,
StatusCallback callback) override;
void Truncate(int32_t mount_id,
const base::FilePath& file_path,
int64_t length,
StatusCallback callback) override;
private:
DISALLOW_COPY_AND_ASSIGN(FakeSmbProviderClient);
};
......
......@@ -148,6 +148,18 @@ class SmbProviderClientImpl : public SmbProviderClient {
&SmbProviderClientImpl::HandleCreateFileCallback, &callback);
}
void Truncate(int32_t mount_id,
const base::FilePath& file_path,
int64_t length,
StatusCallback callback) override {
smbprovider::TruncateOptionsProto options;
options.set_mount_id(mount_id);
options.set_file_path(file_path.value());
options.set_length(length);
CallMethod(smbprovider::kTruncateMethod, options,
&SmbProviderClientImpl::HandleTruncateCallback, &callback);
}
protected:
// DBusClient override.
void Init(dbus::Bus* bus) override {
......@@ -287,6 +299,17 @@ class SmbProviderClientImpl : public SmbProviderClient {
std::move(callback).Run(GetErrorFromReader(&reader));
}
// Handles D-Bus callback for Truncate.
void HandleTruncateCallback(StatusCallback callback,
dbus::Response* response) {
if (!response) {
DLOG(ERROR) << "Truncate: failed to call smbprovider";
std::move(callback).Run(smbprovider::ERROR_DBUS_PARSE_FAILED);
}
dbus::MessageReader reader(response);
std::move(callback).Run(GetErrorFromReader(&reader));
}
// Handles D-Bus responses for methods that return an error and a protobuf
// object.
template <class T>
......
......@@ -102,6 +102,13 @@ class CHROMEOS_EXPORT SmbProviderClient : public DBusClient {
const base::FilePath& file_path,
StatusCallback callback) = 0;
// Calls Truncate. Using the corresponding mount |mount_id|, this truncates
// the file in |file_path| to the desired |length|.
virtual void Truncate(int32_t mount_id,
const base::FilePath& file_path,
int64_t length,
StatusCallback callback) = 0;
protected:
// Create() should be used instead.
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