Commit b2a53aaf authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Clean up SMB classes.

This change does some cleanup of SmbService, SmbFileSystem, and SmbProvider.
These changes include:
- Use AsWeakPtr() for SmbService.
- Add an SmbService::GetSmbProviderClient() helper method.
- Store provider_id_ as a member variable on SmbService.
- Remove provider_id as a parameter from SmbService::Unmount()
  - Remove provider_id from the UnmountCallbacks held by SmbProvider
    and SmbFileSystem

Bug: chromium:757625
Change-Id: Iaec9388b04f8bcd2aa781c654b00268ba0948aa2
Reviewed-on: https://chromium-review.googlesource.com/986629
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547439}
parent 63821c9b
......@@ -203,9 +203,9 @@ void SmbFileSystem::HandleRequestUnmountCallback(
task_queue_.TaskFinished();
base::File::Error result = TranslateError(error);
if (result == base::File::FILE_OK) {
result = RunUnmountCallback(
file_system_info_.provider_id(), file_system_info_.file_system_id(),
file_system_provider::Service::UNMOUNT_REASON_USER);
result =
RunUnmountCallback(file_system_info_.file_system_id(),
file_system_provider::Service::UNMOUNT_REASON_USER);
}
std::move(callback).Run(result);
}
......@@ -575,11 +575,10 @@ void SmbFileSystem::HandleRequestGetMetadataEntryCallback(
}
base::File::Error SmbFileSystem::RunUnmountCallback(
const ProviderId& provider_id,
const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason) {
base::File::Error error =
std::move(unmount_callback_).Run(provider_id, file_system_id, reason);
std::move(unmount_callback_).Run(file_system_id, reason);
return error;
}
......
......@@ -46,7 +46,6 @@ class SmbFileSystem : public file_system_provider::ProvidedFileSystemInterface,
public base::SupportsWeakPtr<SmbFileSystem> {
public:
using UnmountCallback = base::OnceCallback<base::File::Error(
const ProviderId&,
const std::string&,
file_system_provider::Service::UnmountReason)>;
......@@ -204,7 +203,6 @@ class SmbFileSystem : public file_system_provider::ProvidedFileSystemInterface,
smbprovider::ErrorType error) const;
base::File::Error RunUnmountCallback(
const ProviderId& provider_id,
const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason);
......
......@@ -29,7 +29,6 @@ using file_system_provider::ProviderInterface;
class SmbProvider : public ProviderInterface {
public:
using UnmountCallback = base::RepeatingCallback<base::File::Error(
const ProviderId&,
const std::string&,
file_system_provider::Service::UnmountReason)>;
......
......@@ -21,8 +21,7 @@ namespace chromeos {
namespace smb_client {
SmbService::SmbService(Profile* profile)
: profile_(profile),
weak_ptr_factory_(this) {
: provider_id_(ProviderId::CreateFromNativeId("smb")), profile_(profile) {
if (base::FeatureList::IsEnabled(features::kNativeSmb))
GetProviderService()->RegisterProvider(std::make_unique<SmbProvider>(
base::BindRepeating(&SmbService::Unmount, base::Unretained(this))));
......@@ -38,9 +37,8 @@ SmbService* SmbService::Get(content::BrowserContext* context) {
void SmbService::Mount(const file_system_provider::MountOptions& options,
const base::FilePath& share_path,
MountResponse callback) {
chromeos::DBusThreadManager::Get()->GetSmbProviderClient()->Mount(
share_path, base::BindOnce(&SmbService::OnMountResponse,
weak_ptr_factory_.GetWeakPtr(),
GetSmbProviderClient()->Mount(
share_path, base::BindOnce(&SmbService::OnMountResponse, AsWeakPtr(),
base::Passed(&callback), options));
}
......@@ -59,17 +57,16 @@ void SmbService::OnMountResponse(
file_system_provider::MountOptions mount_options(options);
mount_options.file_system_id = base::NumberToString(mount_id);
base::File::Error result = GetProviderService()->MountFileSystem(
ProviderId::CreateFromNativeId("smb"), mount_options);
base::File::Error result =
GetProviderService()->MountFileSystem(provider_id_, mount_options);
std::move(callback).Run(result);
}
base::File::Error SmbService::Unmount(
const ProviderId& provider_id,
const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason) const {
return GetProviderService()->UnmountFileSystem(provider_id, file_system_id,
return GetProviderService()->UnmountFileSystem(provider_id_, file_system_id,
reason);
}
......@@ -77,5 +74,9 @@ Service* SmbService::GetProviderService() const {
return file_system_provider::Service::Get(profile_);
}
SmbProviderClient* SmbService::GetSmbProviderClient() const {
return chromeos::DBusThreadManager::Get()->GetSmbProviderClient();
}
} // namespace smb_client
} // namespace chromeos
......@@ -33,7 +33,8 @@ using file_system_provider::ProviderInterface;
using file_system_provider::Service;
// Creates and manages an smb file system.
class SmbService : public KeyedService {
class SmbService : public KeyedService,
public base::SupportsWeakPtr<SmbService> {
public:
using MountResponse = base::OnceCallback<void(base::File::Error error)>;
......@@ -60,15 +61,15 @@ class SmbService : public KeyedService {
private:
// Calls file_system_provider::Service::UnmountFileSystem().
base::File::Error Unmount(
const ProviderId& provider_id,
const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason) const;
Service* GetProviderService() const;
Profile* profile_;
SmbProviderClient* GetSmbProviderClient() const;
base::WeakPtrFactory<SmbService> weak_ptr_factory_;
const ProviderId provider_id_;
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(SmbService);
};
......
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