Commit 676bcc9a authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Add Start/ContinueReadDirectory to SmbProviderClient.

This change adds Start/ContinueReadDirectory methods to
SmbProviderClient. These map 1:1 to corresponding smbprovider daemon
methods.

Bug: chromium:757625
Change-Id: Idb33b81492949b5499fb402686c211948d736f00
Reviewed-on: https://chromium-review.googlesource.com/1228438
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594467}
parent 4a716aeb
......@@ -227,6 +227,28 @@ void FakeSmbProviderClient::ContinueCopy(int32_t mount_id,
FROM_HERE, base::BindOnce(std::move(callback), smbprovider::ERROR_OK));
}
void FakeSmbProviderClient::StartReadDirectory(
int32_t mount_id,
const base::FilePath& directory_path,
StartReadDirectoryCallback callback) {
smbprovider::DirectoryEntryListProto entry_list;
// Simulate a ReadDirectory that completes during the StartReadDirectory call.
// read_dir_token is unset and error is set to ERROR_OK.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), smbprovider::ERROR_OK,
-1 /* read_dir_token */, entry_list));
}
void FakeSmbProviderClient::ContinueReadDirectory(
int32_t mount_id,
int32_t read_dir_token,
ReadDirectoryCallback callback) {
smbprovider::DirectoryEntryListProto entry_list;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), smbprovider::ERROR_OK, entry_list));
}
void FakeSmbProviderClient::ClearShares() {
shares_.clear();
}
......
......@@ -119,6 +119,14 @@ class CHROMEOS_EXPORT FakeSmbProviderClient : public SmbProviderClient {
int32_t copy_token,
StatusCallback callback) override;
void StartReadDirectory(int32_t mount_id,
const base::FilePath& directory_path,
StartReadDirectoryCallback callback) override;
void ContinueReadDirectory(int32_t mount_id,
int32_t read_dir_token,
ReadDirectoryCallback callback) override;
// Adds |share| to the list of shares for |server_url| in |shares_|.
void AddToShares(const std::string& server_url, const std::string& share);
......
......@@ -318,6 +318,30 @@ class SmbProviderClientImpl : public SmbProviderClient {
CallDefaultMethod(&method_call, &callback);
}
void StartReadDirectory(int32_t mount_id,
const base::FilePath& directory_path,
StartReadDirectoryCallback callback) override {
smbprovider::ReadDirectoryOptionsProto options;
options.set_mount_id(mount_id);
options.set_directory_path(directory_path.value());
CallMethod(smbprovider::kStartReadDirectoryMethod, options,
&SmbProviderClientImpl::HandleStartReadDirectoryCallback,
&callback);
}
void ContinueReadDirectory(int32_t mount_id,
int32_t read_dir_token,
ReadDirectoryCallback callback) override {
dbus::MethodCall method_call(smbprovider::kSmbProviderInterface,
smbprovider::kContinueReadDirectoryMethod);
dbus::MessageWriter writer(&method_call);
writer.AppendInt32(mount_id);
writer.AppendInt32(read_dir_token);
CallMethod(&method_call,
&SmbProviderClientImpl::HandleContinueReadDirectoryCallback,
&callback);
}
protected:
// DBusClient override.
void Init(dbus::Bus* bus) override {
......@@ -557,6 +581,58 @@ class SmbProviderClientImpl : public SmbProviderClient {
std::move(callback).Run(smbprovider::ERROR_COPY_PENDING, copy_token);
}
void HandleStartReadDirectoryCallback(StartReadDirectoryCallback callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "StartReadDirectory: failed to call smbprovider";
std::move(callback).Run(smbprovider::ERROR_DBUS_PARSE_FAILED,
-1 /* read_dir_token */,
smbprovider::DirectoryEntryListProto());
return;
}
dbus::MessageReader reader(response);
smbprovider::ErrorType error = GetErrorFromReader(&reader);
smbprovider::DirectoryEntryListProto entries;
int32_t read_dir_token;
if (!reader.PopArrayOfBytesAsProto(&entries) ||
!reader.PopInt32(&read_dir_token)) {
LOG(ERROR) << "StartReadDirectory: Failed to parse protobuf.";
std::move(callback).Run(smbprovider::ERROR_DBUS_PARSE_FAILED,
-1 /* read_dir_token */,
smbprovider::DirectoryEntryListProto());
return;
}
std::move(callback).Run(error, read_dir_token, entries);
}
void HandleContinueReadDirectoryCallback(ReadDirectoryCallback callback,
dbus::Response* response) {
if (!response) {
LOG(ERROR) << "ContinueReadDirectory: failed to call smbprovider";
std::move(callback).Run(smbprovider::ERROR_DBUS_PARSE_FAILED,
smbprovider::DirectoryEntryListProto());
return;
}
dbus::MessageReader reader(response);
smbprovider::ErrorType error = GetErrorFromReader(&reader);
smbprovider::DirectoryEntryListProto entries;
if (!reader.PopArrayOfBytesAsProto(&entries)) {
LOG(ERROR) << "ContinueReadDirectory: Failed to parse protobuf.";
std::move(callback).Run(smbprovider::ERROR_DBUS_PARSE_FAILED,
smbprovider::DirectoryEntryListProto());
return;
}
std::move(callback).Run(error, entries);
}
// Default callback handler for D-Bus calls.
void HandleDefaultCallback(const std::string& method_name,
StatusCallback callback,
......
......@@ -46,6 +46,10 @@ class CHROMEOS_EXPORT SmbProviderClient
using StartCopyCallback =
base::OnceCallback<void(smbprovider::ErrorType error,
int32_t copy_token)>;
using StartReadDirectoryCallback = base::OnceCallback<void(
smbprovider::ErrorType error,
int32_t read_dir_token,
const smbprovider::DirectoryEntryListProto& entries)>;
~SmbProviderClient() override;
......@@ -212,6 +216,19 @@ class CHROMEOS_EXPORT SmbProviderClient
int32_t copy_token,
StatusCallback callback) = 0;
// Calls StartReadDirectory. This starts a read directory of |directory_path|.
// Returns smbprovider::ERROR_OPERATION_PENDING if there is more work to do.
virtual void StartReadDirectory(int32_t mount_id,
const base::FilePath& directory_path,
StartReadDirectoryCallback callback) = 0;
// Calls ContinueReadDirectory. This continues the copy corresponding to
// |read_dir_token|. Returns smbprovider::ERROR_OPERATION_PENDING if there is
// more work to do.
virtual void ContinueReadDirectory(int32_t mount_id,
int32_t read_dir_token,
ReadDirectoryCallback 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