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( ...@@ -203,9 +203,9 @@ void SmbFileSystem::HandleRequestUnmountCallback(
task_queue_.TaskFinished(); task_queue_.TaskFinished();
base::File::Error result = TranslateError(error); base::File::Error result = TranslateError(error);
if (result == base::File::FILE_OK) { if (result == base::File::FILE_OK) {
result = RunUnmountCallback( result =
file_system_info_.provider_id(), file_system_info_.file_system_id(), RunUnmountCallback(file_system_info_.file_system_id(),
file_system_provider::Service::UNMOUNT_REASON_USER); file_system_provider::Service::UNMOUNT_REASON_USER);
} }
std::move(callback).Run(result); std::move(callback).Run(result);
} }
...@@ -575,11 +575,10 @@ void SmbFileSystem::HandleRequestGetMetadataEntryCallback( ...@@ -575,11 +575,10 @@ void SmbFileSystem::HandleRequestGetMetadataEntryCallback(
} }
base::File::Error SmbFileSystem::RunUnmountCallback( base::File::Error SmbFileSystem::RunUnmountCallback(
const ProviderId& provider_id,
const std::string& file_system_id, const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason) { file_system_provider::Service::UnmountReason reason) {
base::File::Error error = 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; return error;
} }
......
...@@ -46,7 +46,6 @@ class SmbFileSystem : public file_system_provider::ProvidedFileSystemInterface, ...@@ -46,7 +46,6 @@ class SmbFileSystem : public file_system_provider::ProvidedFileSystemInterface,
public base::SupportsWeakPtr<SmbFileSystem> { public base::SupportsWeakPtr<SmbFileSystem> {
public: public:
using UnmountCallback = base::OnceCallback<base::File::Error( using UnmountCallback = base::OnceCallback<base::File::Error(
const ProviderId&,
const std::string&, const std::string&,
file_system_provider::Service::UnmountReason)>; file_system_provider::Service::UnmountReason)>;
...@@ -204,7 +203,6 @@ class SmbFileSystem : public file_system_provider::ProvidedFileSystemInterface, ...@@ -204,7 +203,6 @@ class SmbFileSystem : public file_system_provider::ProvidedFileSystemInterface,
smbprovider::ErrorType error) const; smbprovider::ErrorType error) const;
base::File::Error RunUnmountCallback( base::File::Error RunUnmountCallback(
const ProviderId& provider_id,
const std::string& file_system_id, const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason); file_system_provider::Service::UnmountReason reason);
......
...@@ -29,7 +29,6 @@ using file_system_provider::ProviderInterface; ...@@ -29,7 +29,6 @@ using file_system_provider::ProviderInterface;
class SmbProvider : public ProviderInterface { class SmbProvider : public ProviderInterface {
public: public:
using UnmountCallback = base::RepeatingCallback<base::File::Error( using UnmountCallback = base::RepeatingCallback<base::File::Error(
const ProviderId&,
const std::string&, const std::string&,
file_system_provider::Service::UnmountReason)>; file_system_provider::Service::UnmountReason)>;
......
...@@ -21,8 +21,7 @@ namespace chromeos { ...@@ -21,8 +21,7 @@ namespace chromeos {
namespace smb_client { namespace smb_client {
SmbService::SmbService(Profile* profile) SmbService::SmbService(Profile* profile)
: profile_(profile), : provider_id_(ProviderId::CreateFromNativeId("smb")), profile_(profile) {
weak_ptr_factory_(this) {
if (base::FeatureList::IsEnabled(features::kNativeSmb)) if (base::FeatureList::IsEnabled(features::kNativeSmb))
GetProviderService()->RegisterProvider(std::make_unique<SmbProvider>( GetProviderService()->RegisterProvider(std::make_unique<SmbProvider>(
base::BindRepeating(&SmbService::Unmount, base::Unretained(this)))); base::BindRepeating(&SmbService::Unmount, base::Unretained(this))));
...@@ -38,9 +37,8 @@ SmbService* SmbService::Get(content::BrowserContext* context) { ...@@ -38,9 +37,8 @@ SmbService* SmbService::Get(content::BrowserContext* context) {
void SmbService::Mount(const file_system_provider::MountOptions& options, void SmbService::Mount(const file_system_provider::MountOptions& options,
const base::FilePath& share_path, const base::FilePath& share_path,
MountResponse callback) { MountResponse callback) {
chromeos::DBusThreadManager::Get()->GetSmbProviderClient()->Mount( GetSmbProviderClient()->Mount(
share_path, base::BindOnce(&SmbService::OnMountResponse, share_path, base::BindOnce(&SmbService::OnMountResponse, AsWeakPtr(),
weak_ptr_factory_.GetWeakPtr(),
base::Passed(&callback), options)); base::Passed(&callback), options));
} }
...@@ -59,17 +57,16 @@ void SmbService::OnMountResponse( ...@@ -59,17 +57,16 @@ void SmbService::OnMountResponse(
file_system_provider::MountOptions mount_options(options); file_system_provider::MountOptions mount_options(options);
mount_options.file_system_id = base::NumberToString(mount_id); mount_options.file_system_id = base::NumberToString(mount_id);
base::File::Error result = GetProviderService()->MountFileSystem( base::File::Error result =
ProviderId::CreateFromNativeId("smb"), mount_options); GetProviderService()->MountFileSystem(provider_id_, mount_options);
std::move(callback).Run(result); std::move(callback).Run(result);
} }
base::File::Error SmbService::Unmount( base::File::Error SmbService::Unmount(
const ProviderId& provider_id,
const std::string& file_system_id, const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason) const { file_system_provider::Service::UnmountReason reason) const {
return GetProviderService()->UnmountFileSystem(provider_id, file_system_id, return GetProviderService()->UnmountFileSystem(provider_id_, file_system_id,
reason); reason);
} }
...@@ -77,5 +74,9 @@ Service* SmbService::GetProviderService() const { ...@@ -77,5 +74,9 @@ Service* SmbService::GetProviderService() const {
return file_system_provider::Service::Get(profile_); return file_system_provider::Service::Get(profile_);
} }
SmbProviderClient* SmbService::GetSmbProviderClient() const {
return chromeos::DBusThreadManager::Get()->GetSmbProviderClient();
}
} // namespace smb_client } // namespace smb_client
} // namespace chromeos } // namespace chromeos
...@@ -33,7 +33,8 @@ using file_system_provider::ProviderInterface; ...@@ -33,7 +33,8 @@ using file_system_provider::ProviderInterface;
using file_system_provider::Service; using file_system_provider::Service;
// Creates and manages an smb file system. // Creates and manages an smb file system.
class SmbService : public KeyedService { class SmbService : public KeyedService,
public base::SupportsWeakPtr<SmbService> {
public: public:
using MountResponse = base::OnceCallback<void(base::File::Error error)>; using MountResponse = base::OnceCallback<void(base::File::Error error)>;
...@@ -60,15 +61,15 @@ class SmbService : public KeyedService { ...@@ -60,15 +61,15 @@ class SmbService : public KeyedService {
private: private:
// Calls file_system_provider::Service::UnmountFileSystem(). // Calls file_system_provider::Service::UnmountFileSystem().
base::File::Error Unmount( base::File::Error Unmount(
const ProviderId& provider_id,
const std::string& file_system_id, const std::string& file_system_id,
file_system_provider::Service::UnmountReason reason) const; file_system_provider::Service::UnmountReason reason) const;
Service* GetProviderService() 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); 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