Commit 22f9e2e1 authored by Bailey Berro's avatar Bailey Berro Committed by Commit Bot

Refactoring out SmbProvider from SmbService.

This change removes the multiple inheritance from the SmbService class
so that the SmbService class no longer has to register itself as a
provider.

Bug: 
Change-Id: Ie1eb3642f68f5f4f537e1c6c6caa5b471d0680f5
Reviewed-on: https://chromium-review.googlesource.com/820640Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Commit-Queue: Bailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523327}
parent deb41c4e
...@@ -1484,6 +1484,8 @@ source_set("chromeos") { ...@@ -1484,6 +1484,8 @@ source_set("chromeos") {
"settings/token_encryptor.h", "settings/token_encryptor.h",
"smb_client/smb_file_system.cc", "smb_client/smb_file_system.cc",
"smb_client/smb_file_system.h", "smb_client/smb_file_system.h",
"smb_client/smb_provider.cc",
"smb_client/smb_provider.h",
"smb_client/smb_service.cc", "smb_client/smb_service.cc",
"smb_client/smb_service.h", "smb_client/smb_service.h",
"smb_client/smb_service_factory.cc", "smb_client/smb_service_factory.cc",
......
// Copyright 2017 The Chromium 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 "chrome/browser/chromeos/smb_client/smb_provider.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/smb_client/smb_file_system.h"
#include "chrome/browser/profiles/profile.h"
namespace chromeos {
namespace smb_client {
SmbProvider::SmbProvider()
: provider_id_(ProviderId::CreateFromNativeId("smb")),
capabilities_(false /* configurable */,
false /* watchable */,
false /* multiple_mounts */,
extensions::SOURCE_NETWORK),
// TODO(baileyberro): Localize this string, so it shows correctly in all
// languages. See l10n_util::GetStringUTF8.
name_("SMB Shares") {}
std::unique_ptr<ProvidedFileSystemInterface>
SmbProvider::CreateProvidedFileSystem(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info) {
DCHECK(profile);
return std::make_unique<SmbFileSystem>(file_system_info);
}
const Capabilities& SmbProvider::GetCapabilities() const {
return capabilities_;
}
const ProviderId& SmbProvider::GetId() const {
return provider_id_;
}
const std::string& SmbProvider::GetName() const {
return name_;
}
} // namespace smb_client
} // namespace chromeos
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_SMB_CLIENT_SMB_PROVIDER_H_
#define CHROME_BROWSER_CHROMEOS_SMB_CLIENT_SMB_PROVIDER_H_
#include <memory>
#include <string>
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/provider_interface.h"
class Profile;
namespace chromeos {
namespace smb_client {
using file_system_provider::ProviderId;
using file_system_provider::Capabilities;
using file_system_provider::ProvidedFileSystemInfo;
using file_system_provider::ProviderInterface;
using file_system_provider::ProvidedFileSystemInterface;
class SmbProvider : public ProviderInterface {
public:
SmbProvider();
// ProviderInterface overrides.
std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info) override;
const Capabilities& GetCapabilities() const override;
const ProviderId& GetId() const override;
const std::string& GetName() const override;
private:
ProviderId provider_id_;
Capabilities capabilities_;
std::string name_;
DISALLOW_COPY_AND_ASSIGN(SmbProvider);
};
} // namespace smb_client
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SMB_CLIENT_SMB_PROVIDER_H_
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/smb_client/smb_file_system.h" #include "chrome/browser/chromeos/smb_client/smb_file_system.h"
#include "chrome/browser/chromeos/smb_client/smb_provider.h"
#include "chrome/browser/chromeos/smb_client/smb_service_factory.h" #include "chrome/browser/chromeos/smb_client/smb_service_factory.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/smb_provider_client.h" #include "chromeos/dbus/smb_provider_client.h"
...@@ -19,13 +20,8 @@ namespace smb_client { ...@@ -19,13 +20,8 @@ namespace smb_client {
SmbService::SmbService(Profile* profile) SmbService::SmbService(Profile* profile)
: profile_(profile), : profile_(profile),
provider_id_(ProviderId::CreateFromNativeId("smb")),
capabilities_(false, false, false, extensions::SOURCE_NETWORK),
// TODO(baileyberro): Localize this string, so it shows correctly in all
// languages. See l10n_util::GetStringUTF8.
name_("SMB Shares"),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
GetProviderService()->RegisterProvider(std::make_unique<SmbService>(profile)); GetProviderService()->RegisterProvider(std::make_unique<SmbProvider>());
} }
SmbService::~SmbService() {} SmbService::~SmbService() {}
...@@ -50,43 +46,24 @@ void SmbService::OnMountResponse( ...@@ -50,43 +46,24 @@ void SmbService::OnMountResponse(
smbprovider::ErrorType error, smbprovider::ErrorType error,
int32_t mount_id) { int32_t mount_id) {
if (error != smbprovider::ERROR_OK) { if (error != smbprovider::ERROR_OK) {
DCHECK(mount_id >= 0);
std::move(callback).Run(SmbFileSystem::TranslateError(error)); std::move(callback).Run(SmbFileSystem::TranslateError(error));
return; return;
} }
DCHECK_GT(mount_id, 0);
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 providerServiceMountResult = base::File::Error result = GetProviderService()->MountFileSystem(
GetProviderService()->MountFileSystem(GetId(), mount_options); ProviderId::CreateFromNativeId("smb"), mount_options);
std::move(callback).Run(providerServiceMountResult); std::move(callback).Run(result);
} }
Service* SmbService::GetProviderService() const { Service* SmbService::GetProviderService() const {
return file_system_provider::Service::Get(profile_); return file_system_provider::Service::Get(profile_);
} }
std::unique_ptr<ProvidedFileSystemInterface>
SmbService::CreateProvidedFileSystem(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info) {
DCHECK(profile);
return std::make_unique<SmbFileSystem>(file_system_info);
}
const Capabilities& SmbService::GetCapabilities() const {
return capabilities_;
}
const ProviderId& SmbService::GetId() const {
return provider_id_;
}
const std::string& SmbService::GetName() const {
return name_;
}
} // namespace smb_client } // namespace smb_client
} // namespace chromeos } // namespace chromeos
...@@ -33,7 +33,7 @@ using file_system_provider::ProviderInterface; ...@@ -33,7 +33,7 @@ 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, public ProviderInterface { class SmbService : public KeyedService {
public: public:
using MountResponse = base::OnceCallback<void(base::File::Error error)>; using MountResponse = base::OnceCallback<void(base::File::Error error)>;
...@@ -57,21 +57,10 @@ class SmbService : public KeyedService, public ProviderInterface { ...@@ -57,21 +57,10 @@ class SmbService : public KeyedService, public ProviderInterface {
smbprovider::ErrorType error, smbprovider::ErrorType error,
int32_t mount_id); int32_t mount_id);
// ProviderInterface overrides.
std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info) override;
const Capabilities& GetCapabilities() const override;
const ProviderId& GetId() const override;
const std::string& GetName() const override;
private: private:
Service* GetProviderService() const; Service* GetProviderService() const;
Profile* profile_; Profile* profile_;
ProviderId provider_id_;
Capabilities capabilities_;
std::string name_;
base::WeakPtrFactory<SmbService> weak_ptr_factory_; base::WeakPtrFactory<SmbService> weak_ptr_factory_;
......
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