#ifndef CHROMEOS_ASH_COMPONENTS_SMBFS_SMBFS_HOST_H_
#define CHROMEOS_ASH_COMPONENTS_SMBFS_SMBFS_HOST_H_
#include <memory>
#include "base/component_export.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "chromeos/ash/components/disks/mount_point.h"
#include "chromeos/ash/components/smbfs/mojom/smbfs.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace smbfs {
class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_SMBFS) SmbFsHost {
public:
class Delegate {
public:
virtual ~Delegate();
virtual void OnDisconnected() = 0;
using RequestCredentialsCallback =
base::OnceCallback<void(bool cancel,
const std::string& username,
const std::string& workgroup,
const std::string& password)>;
virtual void RequestCredentials(RequestCredentialsCallback callback) = 0;
};
SmbFsHost(std::unique_ptr<ash::disks::MountPoint> mount_point,
Delegate* delegate,
mojo::Remote<mojom::SmbFs> smbfs_remote,
mojo::PendingReceiver<mojom::SmbFsDelegate> delegate_receiver);
SmbFsHost(const SmbFsHost&) = delete;
SmbFsHost& operator=(const SmbFsHost&) = delete;
~SmbFsHost();
const base::FilePath& mount_path() const {
return mount_point_->mount_path();
}
using UnmountCallback = base::OnceCallback<void(ash::MountError)>;
void Unmount(UnmountCallback callback);
using RemoveSavedCredentialsCallback = base::OnceCallback<void(bool)>;
void RemoveSavedCredentials(RemoveSavedCredentialsCallback callback);
using DeleteRecursivelyCallback = base::OnceCallback<void(base::File::Error)>;
void DeleteRecursively(const base::FilePath& path,
DeleteRecursivelyCallback callback);
private:
void OnDisconnect();
void OnUnmountDone(SmbFsHost::UnmountCallback callback,
ash::MountError result);
void OnRemoveSavedCredentialsDone(RemoveSavedCredentialsCallback callback,
bool success);
void OnDeleteRecursivelyDone(DeleteRecursivelyCallback callback,
smbfs::mojom::DeleteRecursivelyError error);
const std::unique_ptr<ash::disks::MountPoint> mount_point_;
const raw_ptr<Delegate> delegate_;
mojo::Remote<mojom::SmbFs> smbfs_;
std::unique_ptr<mojom::SmbFsDelegate> delegate_impl_;
};
}
#endif