blob: 99ec6064acd65815dd41d21094c0482f64524135 [file] [log] [blame]
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <string>
#include <base/files/file_path.h>
#include <base/macros.h>
#include <base/callback.h>
#include <mojo/public/cpp/bindings/binding.h>
#include "smbfs/mojom/smbfs.mojom.h"
#include "smbfs/smb_filesystem.h"
namespace smbfs {
class Filesystem;
struct SmbCredential;
// Implements mojom::SmbFsBootstrap to mount an SMB share.
class SmbFsBootstrapImpl : public mojom::SmbFsBootstrap {
// Delegate interface used for actions that need to persist after the
// bootstrap process has completed.
class Delegate {
// Sets up Kerberos authentication.
virtual void SetupKerberos(
mojom::KerberosConfigPtr kerberos_config,
base::OnceCallback<void(bool success)> callback) = 0;
// Observer for when the password file path has been determined. The file
// at |path| may not exist at this point, but it will exist if bootstrap
// completes successfully.
virtual void OnPasswordFilePathSet(const base::FilePath& path) = 0;
// Factory function to create an SmbFilesystem instance.
using SmbFilesystemFactory =
using BootstrapCompleteCallback =
base::OnceCallback<void(std::unique_ptr<SmbFilesystem> fs,
mojom::SmbFsRequest smbfs_request,
mojom::SmbFsDelegatePtr delegate_ptr)>;
SmbFsBootstrapImpl(mojom::SmbFsBootstrapRequest request,
SmbFilesystemFactory smb_filesystem_factory,
Delegate* delegate,
const base::FilePath& daemon_store_root);
SmbFsBootstrapImpl(const SmbFsBootstrapImpl&) = delete;
SmbFsBootstrapImpl& operator=(const SmbFsBootstrapImpl&) = delete;
~SmbFsBootstrapImpl() override;
// Start the bootstrap process and run |callback| when finished or the Mojo
// channel is disconnected. If the bootstrap process completed successfully,
// |callback| will be called with a valid SmbFilesystem object. If the Mojo
// channel is disconnected, |callback| will be run with nullptr.
void Start(BootstrapCompleteCallback callback);
// mojom::SmbFsBootstrap overrides.
void MountShare(mojom::MountOptionsPtr options,
mojom::SmbFsDelegatePtr smbfs_delegate,
MountShareCallback callback) override;
// Callback to continue MountShare after setting up credentials
// (username/password, or kerberos).
void OnCredentialsSetup(mojom::MountOptionsPtr options,
mojom::SmbFsDelegatePtr smbfs_delegate,
MountShareCallback callback,
std::unique_ptr<SmbCredential> credential,
bool use_kerberos,
bool setup_success);
// Mojo connection error handler.
void OnMojoConnectionError();
// Return the daemon store directory for the user profile |username_hash|.
base::FilePath GetUserDaemonStoreDirectory(
const std::string& username_hash) const;
mojo::Binding<mojom::SmbFsBootstrap> binding_;
base::OnceClosure disconnect_callback_;
const SmbFilesystemFactory smb_filesystem_factory_;
Delegate* const delegate_;
const base::FilePath daemon_store_root_;
BootstrapCompleteCallback completion_callback_;
} // namespace smbfs