Commit 8b27c88d authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by Commit Bot

Create ExtensionProvider per each extension.

To match semantics of ExtensionProvider.

Test: All current FSP tests pass.
Bug: 790836
Change-Id: I6948086c234319031a4ae95664d9216c2fb5f55c
Reviewed-on: https://chromium-review.googlesource.com/802836
Commit-Queue: Tomasz Mikolajewski <mtomasz@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521608}
parent 5577210e
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include <stddef.h> #include <stddef.h>
#include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "base/macros.h" #include "base/macros.h"
...@@ -16,7 +18,6 @@ ...@@ -16,7 +18,6 @@
#include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h" #include "chrome/browser/chromeos/file_manager/fake_disk_mount_manager.h"
#include "chrome/browser/chromeos/file_manager/volume_manager_observer.h" #include "chrome/browser/chromeos/file_manager/volume_manager_observer.h"
#include "chrome/browser/chromeos/file_system_provider/fake_extension_provider.h" #include "chrome/browser/chromeos/file_system_provider/fake_extension_provider.h"
#include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h"
#include "chrome/browser/chromeos/file_system_provider/service.h" #include "chrome/browser/chromeos/file_system_provider/service.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -182,9 +183,6 @@ class VolumeManagerTest : public testing::Test { ...@@ -182,9 +183,6 @@ class VolumeManagerTest : public testing::Test {
file_system_provider_service_.get(), file_system_provider_service_.get(),
base::Bind(&ProfileEnvironment::GetFakeMtpStorageInfo, base::Bind(&ProfileEnvironment::GetFakeMtpStorageInfo,
base::Unretained(this)))) { base::Unretained(this)))) {
file_system_provider_service_->SetExtensionProviderForTesting(
std::make_unique<
chromeos::file_system_provider::FakeExtensionProvider>());
} }
Profile* profile() const { return profile_.get(); } Profile* profile() const { return profile_.get(); }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
#include "chrome/browser/chromeos/file_system_provider/service.h"
#include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h" #include "chrome/browser/chromeos/file_system_provider/throttled_file_system.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
...@@ -23,12 +22,10 @@ namespace { ...@@ -23,12 +22,10 @@ namespace {
// Returns boolean indicating success. result->capabilities contains the // Returns boolean indicating success. result->capabilities contains the
// capabilites of the extension. // capabilites of the extension.
bool GetProvidingExtensionInfo(const std::string& extension_id, bool GetProvidingExtensionInfo(const extensions::ExtensionId& extension_id,
ProvidingExtensionInfo* result, ProvidingExtensionInfo* result,
Profile* profile) { extensions::ExtensionRegistry* registry) {
DCHECK(result); DCHECK(result);
extensions::ExtensionRegistry* const registry =
extensions::ExtensionRegistry::Get(profile);
DCHECK(registry); DCHECK(registry);
const extensions::Extension* const extension = registry->GetExtensionById( const extensions::Extension* const extension = registry->GetExtensionById(
...@@ -50,6 +47,22 @@ bool GetProvidingExtensionInfo(const std::string& extension_id, ...@@ -50,6 +47,22 @@ bool GetProvidingExtensionInfo(const std::string& extension_id,
} // namespace } // namespace
ProvidingExtensionInfo::ProvidingExtensionInfo() = default;
ProvidingExtensionInfo::~ProvidingExtensionInfo() = default;
// static
std::unique_ptr<ProviderInterface> ExtensionProvider::Create(
extensions::ExtensionRegistry* registry,
const extensions::ExtensionId& extension_id) {
ProvidingExtensionInfo info;
if (!GetProvidingExtensionInfo(extension_id, &info, registry))
return nullptr;
return std::unique_ptr<ProviderInterface>(
new ExtensionProvider(extension_id, info));
}
std::unique_ptr<ProvidedFileSystemInterface> std::unique_ptr<ProvidedFileSystemInterface>
ExtensionProvider::CreateProvidedFileSystem( ExtensionProvider::CreateProvidedFileSystem(
Profile* profile, Profile* profile,
...@@ -59,24 +72,23 @@ ExtensionProvider::CreateProvidedFileSystem( ...@@ -59,24 +72,23 @@ ExtensionProvider::CreateProvidedFileSystem(
std::make_unique<ProvidedFileSystem>(profile, file_system_info)); std::make_unique<ProvidedFileSystem>(profile, file_system_info));
} }
bool ExtensionProvider::GetCapabilities(Profile* profile, const Capabilities& ExtensionProvider::GetCapabilities() const {
const ProviderId& provider_id, return capabilities_;
Capabilities& result) { }
ProvidingExtensionInfo providing_extension_info;
const ProviderId& ExtensionProvider::GetId() const {
// TODO(baileyberro): Change this so error is not swallowed once return provider_id_;
// bug is resolved (crrev.com/c/767629).
bool success = GetProvidingExtensionInfo(provider_id.GetExtensionId(),
&providing_extension_info, profile);
result = Capabilities(providing_extension_info.capabilities.configurable(),
providing_extension_info.capabilities.watchable(),
providing_extension_info.capabilities.multiple_mounts(),
providing_extension_info.capabilities.source());
return success;
} }
ExtensionProvider::ExtensionProvider() {} ExtensionProvider::ExtensionProvider(
const extensions::ExtensionId& extension_id,
const ProvidingExtensionInfo& info)
: provider_id_(ProviderId::CreateFromExtensionId(extension_id)) {
capabilities_.configurable = info.capabilities.configurable();
capabilities_.watchable = info.capabilities.watchable();
capabilities_.multiple_mounts = info.capabilities.multiple_mounts();
capabilities_.source = info.capabilities.source();
}
} // namespace file_system_provider } // namespace file_system_provider
} // namespace chromeos } // namespace chromeos
...@@ -6,30 +6,55 @@ ...@@ -6,30 +6,55 @@
#define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_EXTENSION_PROVIDER_H_ #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_EXTENSION_PROVIDER_H_
#include <memory> #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/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/provider_interface.h" #include "chrome/browser/chromeos/file_system_provider/provider_interface.h"
#include "extensions/common/extension_id.h"
class Profile; class Profile;
namespace extensions {
class ExtensionRegistry;
} // namespace extensions
namespace chromeos { namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
class ProvidedFileSystemInfo; // Holds information for a providing extension.
class ProviderId; struct ProvidingExtensionInfo {
ProvidingExtensionInfo();
~ProvidingExtensionInfo();
extensions::ExtensionId extension_id;
std::string name;
extensions::FileSystemProviderCapabilities capabilities;
};
class ExtensionProvider : public ProviderInterface { class ExtensionProvider : public ProviderInterface {
public: public:
ExtensionProvider();
~ExtensionProvider() override {} ~ExtensionProvider() override {}
// Returns a provider instance for the specified extension. If the extension
// cannot be a providing extension, returns nullptr.
static std::unique_ptr<ProviderInterface> Create(
extensions::ExtensionRegistry* registry,
const extensions::ExtensionId& extension_id);
// ProviderInterface overrides. // ProviderInterface overrides.
std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem( std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem(
Profile* profile, Profile* profile,
const ProvidedFileSystemInfo& file_system_info) override; const ProvidedFileSystemInfo& file_system_info) override;
bool GetCapabilities(Profile* profile, const Capabilities& GetCapabilities() const override;
const ProviderId& provider_id, const ProviderId& GetId() const override;
Capabilities& result) override;
private:
ExtensionProvider(const extensions::ExtensionId& extension_id,
const ProvidingExtensionInfo& info);
ProviderId provider_id_;
Capabilities capabilities_;
}; };
} // namespace file_system_provider } // namespace file_system_provider
......
...@@ -12,13 +12,21 @@ ...@@ -12,13 +12,21 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h" #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h"
#include "chrome/browser/chromeos/file_system_provider/service.h" #include "chrome/browser/chromeos/file_system_provider/service.h"
#include "chrome/browser/profiles/profile.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/common/permissions/permissions_data.h" #include "extensions/common/permissions/permissions_data.h"
namespace chromeos { namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
// static
std::unique_ptr<ProviderInterface> FakeExtensionProvider::Create(
const extensions::ExtensionId& extension_id) {
Capabilities default_capabilities(false, false, false,
extensions::SOURCE_NETWORK);
return std::unique_ptr<ProviderInterface>(
new FakeExtensionProvider(extension_id, default_capabilities));
}
// Factory callback, to be used in Service::SetFileSystemFactory(). The // Factory callback, to be used in Service::SetFileSystemFactory(). The
// |event_router| argument can be NULL. // |event_router| argument can be NULL.
std::unique_ptr<ProvidedFileSystemInterface> std::unique_ptr<ProvidedFileSystemInterface>
...@@ -29,7 +37,19 @@ FakeExtensionProvider::CreateProvidedFileSystem( ...@@ -29,7 +37,19 @@ FakeExtensionProvider::CreateProvidedFileSystem(
return std::make_unique<FakeProvidedFileSystem>(file_system_info); return std::make_unique<FakeProvidedFileSystem>(file_system_info);
} }
FakeExtensionProvider::FakeExtensionProvider() {} const Capabilities& FakeExtensionProvider::GetCapabilities() const {
return capabilities_;
}
const ProviderId& FakeExtensionProvider::GetId() const {
return provider_id_;
}
FakeExtensionProvider::FakeExtensionProvider(
const extensions::ExtensionId& extension_id,
const Capabilities& capabilities)
: provider_id_(ProviderId::CreateFromExtensionId(extension_id)),
capabilities_(capabilities) {}
} // namespace file_system_provider } // namespace file_system_provider
} // namespace chromeos } // namespace chromeos
...@@ -10,23 +10,35 @@ ...@@ -10,23 +10,35 @@
#include "chrome/browser/chromeos/file_system_provider/extension_provider.h" #include "chrome/browser/chromeos/file_system_provider/extension_provider.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/provider_interface.h" #include "chrome/browser/chromeos/file_system_provider/provider_interface.h"
#include "extensions/common/extension_id.h"
class Profile; class Profile;
namespace chromeos { namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
class ProvidedFileSystemInfo; class FakeExtensionProvider : public ProviderInterface {
class FakeExtensionProvider : public ExtensionProvider {
public: public:
FakeExtensionProvider();
~FakeExtensionProvider() override {} ~FakeExtensionProvider() override {}
// ExtensionProvider override. // Returns a fake provider instance for the specified extension. The extension
// doesn't have to exist.
static std::unique_ptr<ProviderInterface> Create(
const extensions::ExtensionId& extension_id);
// ProviderInterface overrides.
std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem( std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem(
Profile* profile, Profile* profile,
const ProvidedFileSystemInfo& file_system_info) override; const ProvidedFileSystemInfo& file_system_info) override;
const Capabilities& GetCapabilities() const override;
const ProviderId& GetId() const override;
protected:
FakeExtensionProvider(const extensions::ExtensionId& extension_id,
const Capabilities& capabilities);
ProviderId provider_id_;
Capabilities capabilities_;
}; };
} // namespace file_system_provider } // namespace file_system_provider
......
...@@ -92,8 +92,7 @@ class FileSystemProviderFileStreamReader : public testing::Test { ...@@ -92,8 +92,7 @@ class FileSystemProviderFileStreamReader : public testing::Test {
profile_ = profile_manager_->CreateTestingProfile("testing-profile"); profile_ = profile_manager_->CreateTestingProfile("testing-profile");
Service* service = Service::Get(profile_); // Owned by its factory. Service* service = Service::Get(profile_); // Owned by its factory.
service->SetExtensionProviderForTesting( service->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
std::make_unique<FakeExtensionProvider>());
const base::File::Error result = service->MountFileSystem( const base::File::Error result = service->MountFileSystem(
kProviderId, MountOptions(kFileSystemId, "Testing File System")); kProviderId, MountOptions(kFileSystemId, "Testing File System"));
......
...@@ -74,8 +74,7 @@ class FileSystemProviderFileStreamWriter : public testing::Test { ...@@ -74,8 +74,7 @@ class FileSystemProviderFileStreamWriter : public testing::Test {
profile_ = profile_manager_->CreateTestingProfile("testing-profile"); profile_ = profile_manager_->CreateTestingProfile("testing-profile");
Service* service = Service::Get(profile_); // Owned by its factory. Service* service = Service::Get(profile_); // Owned by its factory.
service->SetExtensionProviderForTesting( service->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
std::make_unique<FakeExtensionProvider>());
const base::File::Error result = service->MountFileSystem( const base::File::Error result = service->MountFileSystem(
kProviderId, MountOptions(kFileSystemId, "Testing File System")); kProviderId, MountOptions(kFileSystemId, "Testing File System"));
......
...@@ -130,8 +130,7 @@ class FileSystemProviderProviderAsyncFileUtilTest : public testing::Test { ...@@ -130,8 +130,7 @@ class FileSystemProviderProviderAsyncFileUtilTest : public testing::Test {
content::CreateFileSystemContextForTesting(NULL, data_dir_.GetPath()); content::CreateFileSystemContextForTesting(NULL, data_dir_.GetPath());
Service* service = Service::Get(profile_); // Owned by its factory. Service* service = Service::Get(profile_); // Owned by its factory.
service->SetExtensionProviderForTesting( service->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
std::make_unique<FakeExtensionProvider>());
const base::File::Error result = service->MountFileSystem( const base::File::Error result = service->MountFileSystem(
kProviderId, MountOptions(kFileSystemId, "Testing File System")); kProviderId, MountOptions(kFileSystemId, "Testing File System"));
......
...@@ -77,8 +77,8 @@ class FileSystemProviderMountPathUtilTest : public testing::Test { ...@@ -77,8 +77,8 @@ class FileSystemProviderMountPathUtilTest : public testing::Test {
user_manager_->AddUser( user_manager_->AddUser(
AccountId::FromUserEmail(profile_->GetProfileUserName())); AccountId::FromUserEmail(profile_->GetProfileUserName()));
file_system_provider_service_ = Service::Get(profile_); file_system_provider_service_ = Service::Get(profile_);
file_system_provider_service_->SetExtensionProviderForTesting( file_system_provider_service_->RegisterProvider(
std::make_unique<FakeExtensionProvider>()); FakeExtensionProvider::Create(kExtensionId));
} }
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
......
...@@ -61,6 +61,11 @@ bool ProviderId::operator==(const ProviderId& other) const { ...@@ -61,6 +61,11 @@ bool ProviderId::operator==(const ProviderId& other) const {
return type_ == other.GetType() && internal_id_ == other.GetIdUnsafe(); return type_ == other.GetType() && internal_id_ == other.GetIdUnsafe();
} }
bool ProviderId::operator<(const ProviderId& other) const {
return std::tie(type_, internal_id_) <
std::tie(other.type_, other.internal_id_);
}
MountOptions::MountOptions() MountOptions::MountOptions()
: writable(false), : writable(false),
supports_notify_tag(false), supports_notify_tag(false),
......
...@@ -46,6 +46,7 @@ class ProviderId { ...@@ -46,6 +46,7 @@ class ProviderId {
ProviderType GetType() const; ProviderType GetType() const;
bool operator==(const ProviderId& other) const; bool operator==(const ProviderId& other) const;
bool operator<(const ProviderId& other) const;
private: private:
ProviderId(const std::string& internal_id, ProviderType provider_type); ProviderId(const std::string& internal_id, ProviderType provider_type);
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h" #include "chrome/common/extensions/api/file_system_provider_capabilities/file_system_provider_capabilities_handler.h"
class Profile; class Profile;
...@@ -15,7 +17,6 @@ namespace chromeos { ...@@ -15,7 +17,6 @@ namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
class ProvidedFileSystemInterface; class ProvidedFileSystemInterface;
class ProvidedFileSystemInfo;
class ProviderId; class ProviderId;
struct Capabilities { struct Capabilities {
...@@ -27,7 +28,12 @@ struct Capabilities { ...@@ -27,7 +28,12 @@ struct Capabilities {
watchable(watchable), watchable(watchable),
multiple_mounts(multiple_mounts), multiple_mounts(multiple_mounts),
source(source) {} source(source) {}
Capabilities() = default; Capabilities()
: configurable(false),
watchable(false),
multiple_mounts(false),
source(extensions::SOURCE_NETWORK) {}
bool configurable; bool configurable;
bool watchable; bool watchable;
bool multiple_mounts; bool multiple_mounts;
...@@ -43,10 +49,11 @@ class ProviderInterface { ...@@ -43,10 +49,11 @@ class ProviderInterface {
Profile* profile, Profile* profile,
const ProvidedFileSystemInfo& file_system_info) = 0; const ProvidedFileSystemInfo& file_system_info) = 0;
// Returns the capabilites of file system with |provider_id|. // Returns the capabilites of the provider.
virtual bool GetCapabilities(Profile* profile, virtual const Capabilities& GetCapabilities() const = 0;
const ProviderId& provider_id,
Capabilities& result) = 0; // Returns id of this provider.
virtual const ProviderId& GetId() const = 0;
}; };
} // namespace file_system_provider } // namespace file_system_provider
......
...@@ -38,19 +38,11 @@ const size_t kMaxFileSystems = 16; ...@@ -38,19 +38,11 @@ const size_t kMaxFileSystems = 16;
} // namespace } // namespace
ProvidingExtensionInfo::ProvidingExtensionInfo() {
}
ProvidingExtensionInfo::~ProvidingExtensionInfo() {
}
Service::Service(Profile* profile, Service::Service(Profile* profile,
extensions::ExtensionRegistry* extension_registry) extensions::ExtensionRegistry* extension_registry)
: profile_(profile), : profile_(profile),
extension_registry_(extension_registry), extension_registry_(extension_registry),
registry_(new Registry(profile)), registry_(new Registry(profile)),
extension_provider_(
std::make_unique<ExtensionProvider>(ExtensionProvider())),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
extension_registry_->AddObserver(this); extension_registry_->AddObserver(this);
} }
...@@ -94,12 +86,6 @@ void Service::RemoveObserver(Observer* observer) { ...@@ -94,12 +86,6 @@ void Service::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer); observers_.RemoveObserver(observer);
} }
void Service::SetExtensionProviderForTesting(
std::unique_ptr<ProviderInterface> provider) {
DCHECK(provider);
extension_provider_ = std::move(provider);
}
void Service::SetRegistryForTesting( void Service::SetRegistryForTesting(
std::unique_ptr<RegistryInterface> registry) { std::unique_ptr<RegistryInterface> registry) {
DCHECK(registry); DCHECK(registry);
...@@ -117,17 +103,23 @@ base::File::Error Service::MountFileSystemInternal( ...@@ -117,17 +103,23 @@ base::File::Error Service::MountFileSystemInternal(
MountContext context) { MountContext context) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
ProviderInterface* const provider = GetProvider(provider_id);
if (!provider) {
for (auto& observer : observers_) {
observer.OnProvidedFileSystemMount(
ProvidedFileSystemInfo(), context,
base::File::FILE_ERROR_INVALID_OPERATION);
}
return base::File::FILE_ERROR_INVALID_OPERATION;
}
// The mount point path and name are unique per system, since they are system // The mount point path and name are unique per system, since they are system
// wide. This is necessary for copying between profiles. // wide. This is necessary for copying between profiles.
const base::FilePath& mount_path = const base::FilePath& mount_path =
util::GetMountPath(profile_, provider_id, options.file_system_id); util::GetMountPath(profile_, provider_id, options.file_system_id);
const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe();
ProvidingExtensionInfo provider_info; Capabilities capabilities = provider->GetCapabilities();
// TODO(mtomasz): Set up a testing extension in unit tests.
ProviderInterface* provider = GetProvider(provider_id);
Capabilities capabilities;
provider->GetCapabilities(profile_, provider_id, capabilities);
// Store the file system descriptor. Use the mount point name as the file // Store the file system descriptor. Use the mount point name as the file
// system provider file system id. // system provider file system id.
// Examples: // Examples:
...@@ -357,7 +349,17 @@ bool Service::GetProvidingExtensionInfo(const std::string& extension_id, ...@@ -357,7 +349,17 @@ bool Service::GetProvidingExtensionInfo(const std::string& extension_id,
void Service::OnExtensionUnloaded(content::BrowserContext* browser_context, void Service::OnExtensionUnloaded(content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) { extensions::UnloadedExtensionReason reason) {
// Unmount all of the provided file systems associated with this extension. ProviderId provider_id = ProviderId::CreateFromExtensionId(extension->id());
UnregisterProvider(
provider_id,
reason == extensions::UnloadedExtensionReason::PROFILE_SHUTDOWN
? UNMOUNT_REASON_SHUTDOWN
: UNMOUNT_REASON_USER);
}
void Service::UnmountFileSystems(const ProviderId& provider_id,
UnmountReason reason) {
// Unmount all of the provided file systems associated with this provider.
auto it = file_system_map_.begin(); auto it = file_system_map_.begin();
while (it != file_system_map_.end()) { while (it != file_system_map_.end()) {
const ProvidedFileSystemInfo& file_system_info = const ProvidedFileSystemInfo& file_system_info =
...@@ -365,20 +367,31 @@ void Service::OnExtensionUnloaded(content::BrowserContext* browser_context, ...@@ -365,20 +367,31 @@ void Service::OnExtensionUnloaded(content::BrowserContext* browser_context,
// Advance the iterator beforehand, otherwise it will become invalidated // Advance the iterator beforehand, otherwise it will become invalidated
// by the UnmountFileSystem() call. // by the UnmountFileSystem() call.
++it; ++it;
if (file_system_info.provider_id().GetExtensionId() == extension->id()) { if (file_system_info.provider_id() == provider_id) {
const base::File::Error unmount_result = UnmountFileSystem( const base::File::Error unmount_result =
file_system_info.provider_id(), file_system_info.file_system_id(), UnmountFileSystem(file_system_info.provider_id(),
reason == extensions::UnloadedExtensionReason::PROFILE_SHUTDOWN file_system_info.file_system_id(), reason);
? UNMOUNT_REASON_SHUTDOWN
: UNMOUNT_REASON_USER);
DCHECK_EQ(base::File::FILE_OK, unmount_result); DCHECK_EQ(base::File::FILE_OK, unmount_result);
} }
} }
} }
void Service::UnregisterProvider(const ProviderId& provider_id,
UnmountReason reason) {
UnmountFileSystems(provider_id, reason);
provider_map_.erase(provider_id);
}
void Service::OnExtensionLoaded(content::BrowserContext* browser_context, void Service::OnExtensionLoaded(content::BrowserContext* browser_context,
const extensions::Extension* extension) { const extensions::Extension* extension) {
ProviderId provider_id = ProviderId::CreateFromExtensionId(extension->id()); // If the extension is a provider, then register it.
std::unique_ptr<ProviderInterface> provider =
ExtensionProvider::Create(extension_registry_, extension->id());
if (provider)
RegisterProvider(std::move(provider));
}
void Service::RestoreFileSystems(const ProviderId& provider_id) {
std::unique_ptr<RegistryInterface::RestoredFileSystems> std::unique_ptr<RegistryInterface::RestoredFileSystems>
restored_file_systems = registry_->RestoreFileSystems(provider_id); restored_file_systems = registry_->RestoreFileSystems(provider_id);
...@@ -457,21 +470,17 @@ void Service::OnWatcherListChanged( ...@@ -457,21 +470,17 @@ void Service::OnWatcherListChanged(
registry_->RememberFileSystem(file_system_info, watchers); registry_->RememberFileSystem(file_system_info, watchers);
} }
void Service::RegisterNativeProvider( void Service::RegisterProvider(std::unique_ptr<ProviderInterface> provider) {
const ProviderId& provider_id, ProviderId provider_id = provider->GetId();
std::unique_ptr<ProviderInterface> provider) { provider_map_[provider_id] = std::move(provider);
DCHECK_EQ(ProviderId::NATIVE, provider_id.GetType()); RestoreFileSystems(provider_id);
native_provider_map_[provider_id.GetNativeId()] = std::move(provider);
} }
ProviderInterface* Service::GetProvider(const ProviderId& provider_id) { ProviderInterface* Service::GetProvider(const ProviderId& provider_id) {
DCHECK_NE(ProviderId::INVALID, provider_id.GetType()); DCHECK_NE(ProviderId::INVALID, provider_id.GetType());
auto it = provider_map_.find(provider_id);
if (provider_id.GetType() == ProviderId::EXTENSION) if (it == provider_map_.end())
return extension_provider_.get(); return nullptr;
auto it = native_provider_map_.find(provider_id.GetNativeId());
DCHECK(it != native_provider_map_.end());
return it->second.get(); return it->second.get();
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "extensions/browser/extension_registry_observer.h" #include "extensions/browser/extension_registry_observer.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "storage/browser/fileapi/watcher_manager.h" #include "storage/browser/fileapi/watcher_manager.h"
namespace extensions { namespace extensions {
...@@ -55,27 +56,12 @@ struct MountOptions; ...@@ -55,27 +56,12 @@ struct MountOptions;
// Registers preferences to remember registered file systems between reboots. // Registers preferences to remember registered file systems between reboots.
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// Holds information for a providing extension.
struct ProvidingExtensionInfo {
ProvidingExtensionInfo();
~ProvidingExtensionInfo();
std::string extension_id;
std::string name;
extensions::FileSystemProviderCapabilities capabilities;
};
// Manages and registers the file system provider service. Maintains provided // Manages and registers the file system provider service. Maintains provided
// file systems. // file systems.
class Service : public KeyedService, class Service : public KeyedService,
public extensions::ExtensionRegistryObserver, public extensions::ExtensionRegistryObserver,
public ProvidedFileSystemObserver { public ProvidedFileSystemObserver {
public: public:
typedef base::Callback<std::unique_ptr<ProvidedFileSystemInterface>(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info)>
FileSystemFactoryCallback;
// Reason for unmounting. In case of UNMOUNT_REASON_SHUTDOWN, the file system // Reason for unmounting. In case of UNMOUNT_REASON_SHUTDOWN, the file system
// will be remounted automatically after a reboot. In case of // will be remounted automatically after a reboot. In case of
// UNMOUNT_REASON_USER it will be permanently unmounted. // UNMOUNT_REASON_USER it will be permanently unmounted.
...@@ -90,11 +76,6 @@ class Service : public KeyedService, ...@@ -90,11 +76,6 @@ class Service : public KeyedService,
// KeyedService: // KeyedService:
void Shutdown() override; void Shutdown() override;
// Sets a custom ProvidedFileSystemInterface factory. Used by unit tests,
// where an event router is not available.
void SetExtensionProviderForTesting(
std::unique_ptr<ProviderInterface> provider);
// Sets a custom Registry implementation. Used by unit tests. // Sets a custom Registry implementation. Used by unit tests.
void SetRegistryForTesting(std::unique_ptr<RegistryInterface> registry); void SetRegistryForTesting(std::unique_ptr<RegistryInterface> registry);
...@@ -171,9 +152,13 @@ class Service : public KeyedService, ...@@ -171,9 +152,13 @@ class Service : public KeyedService,
void OnWatcherListChanged(const ProvidedFileSystemInfo& file_system_info, void OnWatcherListChanged(const ProvidedFileSystemInfo& file_system_info,
const Watchers& watchers) override; const Watchers& watchers) override;
// Registers a FileSystemFactory for the passed |provider_id|. // Registers a provider. Restores all remembered mounts.
void RegisterNativeProvider(const ProviderId& provider_id, void RegisterProvider(std::unique_ptr<ProviderInterface> provider);
std::unique_ptr<ProviderInterface> provider);
// Unregisters a provider. Unmounts all currently mounted file systems.
// If the reason is UNMOUNT_REASON_USER then they will not be automatically
// restored on the next registration.
void UnregisterProvider(const ProviderId& provider_id, UnmountReason reason);
private: private:
FRIEND_TEST_ALL_PREFIXES(FileSystemProviderServiceTest, RememberFileSystem); FRIEND_TEST_ALL_PREFIXES(FileSystemProviderServiceTest, RememberFileSystem);
...@@ -207,7 +192,13 @@ class Service : public KeyedService, ...@@ -207,7 +192,13 @@ class Service : public KeyedService,
// |provider_id| provided file system. // |provider_id| provided file system.
void RestoreFileSystems(const ProviderId& provider_id); void RestoreFileSystems(const ProviderId& provider_id);
// Returns a file system provider for the passed |provider_id|. // Unmounts all currently mounted file systems for this provider. If
// reason is UNMOUNT_REASON_USER then the file systems will not be remembered
// for automagical remount in the future.
void UnmountFileSystems(const ProviderId& provider_id, UnmountReason reason);
// Returns a file system provider for the passed |provider_id|. If not found
// then returns nullptr.
ProviderInterface* GetProvider(const ProviderId& provider_id); ProviderInterface* GetProvider(const ProviderId& provider_id);
Profile* profile_; Profile* profile_;
...@@ -218,9 +209,7 @@ class Service : public KeyedService, ...@@ -218,9 +209,7 @@ class Service : public KeyedService,
std::map<std::string, FileSystemKey> mount_point_name_to_key_map_; std::map<std::string, FileSystemKey> mount_point_name_to_key_map_;
std::unique_ptr<RegistryInterface> registry_; std::unique_ptr<RegistryInterface> registry_;
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
std::unordered_map<std::string, std::unique_ptr<ProviderInterface>> std::map<ProviderId, std::unique_ptr<ProviderInterface>> provider_map_;
native_provider_map_;
std::unique_ptr<ProviderInterface> extension_provider_;
base::WeakPtrFactory<Service> weak_ptr_factory_; base::WeakPtrFactory<Service> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(Service); DISALLOW_COPY_AND_ASSIGN(Service);
......
...@@ -42,8 +42,8 @@ namespace chromeos { ...@@ -42,8 +42,8 @@ namespace chromeos {
namespace file_system_provider { namespace file_system_provider {
namespace { namespace {
const ProviderId kProviderId = const extensions::ExtensionId kExtensionId = "mbflcebpggnecokmikipoihdbecnjfoj";
ProviderId::CreateFromExtensionId("mbflcebpggnecokmikipoihdbecnjfoj"); const ProviderId kProviderId = ProviderId::CreateFromExtensionId(kExtensionId);
const char kDisplayName[] = "Camera Pictures"; const char kDisplayName[] = "Camera Pictures";
const ProviderId kCustomProviderId = const ProviderId kCustomProviderId =
ProviderId::CreateFromNativeId("custom provider id"); ProviderId::CreateFromNativeId("custom provider id");
...@@ -54,54 +54,35 @@ const ProviderId kCustomProviderId = ...@@ -54,54 +54,35 @@ const ProviderId kCustomProviderId =
const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+"; const char kFileSystemId[] = "camera/pictures/id .!@#$%^&*()_+";
// Creates a fake extension with the specified |extension_id|. // Creates a fake extension with the specified |extension_id|.
// TODO(mtomasz): Use the extension builder.
scoped_refptr<extensions::Extension> CreateFakeExtension( scoped_refptr<extensions::Extension> CreateFakeExtension(
const std::string& extension_id) { const std::string& extension_id) {
base::DictionaryValue manifest; base::DictionaryValue manifest;
std::string error; std::string error;
manifest.SetKey(extensions::manifest_keys::kVersion, base::Value("1.0.0.0")); manifest.SetKey(extensions::manifest_keys::kVersion, base::Value("1.0.0.0"));
manifest.SetKey(extensions::manifest_keys::kName, base::Value("unused")); manifest.SetKey(extensions::manifest_keys::kName, base::Value("unused"));
return extensions::Extension::Create(base::FilePath(),
extensions::Manifest::UNPACKED, std::unique_ptr<base::ListValue> permissions_list(new base::ListValue());
manifest, permissions_list->AppendString("fileSystemProvider");
extensions::Extension::NO_FLAGS, manifest.Set(extensions::manifest_keys::kPermissions,
extension_id, std::move(permissions_list));
&error);
std::unique_ptr<base::DictionaryValue> capabilities(
new base::DictionaryValue);
capabilities->SetString("source", "network");
manifest.Set(extensions::manifest_keys::kFileSystemProviderCapabilities,
std::move(capabilities));
scoped_refptr<extensions::Extension> extension =
extensions::Extension::Create(
base::FilePath(), extensions::Manifest::UNPACKED, manifest,
extensions::Extension::NO_FLAGS, extension_id, &error);
EXPECT_TRUE(extension) << error;
return extension;
} }
} // namespace } // namespace
class FakeDefaultExtensionProvider : public FakeExtensionProvider {
public:
std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info) override {
called_default_factory = true;
return std::make_unique<FakeProvidedFileSystem>(file_system_info);
}
static bool called_default_factory;
};
bool FakeDefaultExtensionProvider::called_default_factory = false;
class FakeNativeProvider : public ProviderInterface {
public:
// ProviderInterface overrides
std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem(
Profile* profile,
const ProvidedFileSystemInfo& file_system_info) override {
called_custom_factory = true;
return std::make_unique<FakeProvidedFileSystem>(file_system_info);
}
bool GetCapabilities(Profile* profile,
const ProviderId& provider_id,
Capabilities& result) override {
result = Capabilities(false, false, false, extensions::SOURCE_NETWORK);
return true;
}
static bool called_custom_factory;
};
bool FakeNativeProvider::called_custom_factory = false;
class FileSystemProviderServiceTest : public testing::Test { class FileSystemProviderServiceTest : public testing::Test {
protected: protected:
FileSystemProviderServiceTest() : profile_(NULL) {} FileSystemProviderServiceTest() : profile_(NULL) {}
...@@ -119,14 +100,8 @@ class FileSystemProviderServiceTest : public testing::Test { ...@@ -119,14 +100,8 @@ class FileSystemProviderServiceTest : public testing::Test {
user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>( user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
base::WrapUnique(user_manager_)); base::WrapUnique(user_manager_));
extension_registry_.reset(new extensions::ExtensionRegistry(profile_)); extension_registry_.reset(new extensions::ExtensionRegistry(profile_));
service_.reset(new Service(profile_, extension_registry_.get())); service_.reset(new Service(profile_, extension_registry_.get()));
service_->SetExtensionProviderForTesting(
std::make_unique<FakeExtensionProvider>());
extension_ = CreateFakeExtension(kProviderId.GetExtensionId());
registry_ = new FakeRegistry; registry_ = new FakeRegistry;
// Passes ownership to the service instance. // Passes ownership to the service instance.
service_->SetRegistryForTesting(base::WrapUnique(registry_)); service_->SetRegistryForTesting(base::WrapUnique(registry_));
...@@ -147,38 +122,14 @@ class FileSystemProviderServiceTest : public testing::Test { ...@@ -147,38 +122,14 @@ class FileSystemProviderServiceTest : public testing::Test {
std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_; std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_;
std::unique_ptr<extensions::ExtensionRegistry> extension_registry_; std::unique_ptr<extensions::ExtensionRegistry> extension_registry_;
std::unique_ptr<Service> service_; std::unique_ptr<Service> service_;
scoped_refptr<extensions::Extension> extension_;
FakeRegistry* registry_; // Owned by Service. FakeRegistry* registry_; // Owned by Service.
Watcher fake_watcher_; Watcher fake_watcher_;
bool called_default_factory_;
bool called_custom_factory_;
}; };
TEST_F(FileSystemProviderServiceTest, RegisterFileSystemProvider) {
service_->RegisterNativeProvider(kCustomProviderId,
std::make_unique<FakeNativeProvider>());
service_->SetExtensionProviderForTesting(
std::make_unique<FakeDefaultExtensionProvider>());
FakeNativeProvider::called_custom_factory = false;
FakeDefaultExtensionProvider::called_default_factory = false;
EXPECT_EQ(base::File::FILE_OK,
service_->MountFileSystem(
kProviderId, MountOptions(kFileSystemId, kDisplayName)));
EXPECT_TRUE(FakeDefaultExtensionProvider::called_default_factory);
EXPECT_EQ(base::File::FILE_OK,
service_->MountFileSystem(
kCustomProviderId, MountOptions(kFileSystemId, kDisplayName)));
EXPECT_TRUE(FakeNativeProvider::called_custom_factory);
}
TEST_F(FileSystemProviderServiceTest, MountFileSystem) { TEST_F(FileSystemProviderServiceTest, MountFileSystem) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
EXPECT_EQ(base::File::FILE_OK, EXPECT_EQ(base::File::FILE_OK,
service_->MountFileSystem( service_->MountFileSystem(
...@@ -210,6 +161,7 @@ TEST_F(FileSystemProviderServiceTest, ...@@ -210,6 +161,7 @@ TEST_F(FileSystemProviderServiceTest,
MountFileSystem_WritableAndSupportsNotifyTag) { MountFileSystem_WritableAndSupportsNotifyTag) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
MountOptions options(kFileSystemId, kDisplayName); MountOptions options(kFileSystemId, kDisplayName);
options.writable = true; options.writable = true;
...@@ -231,6 +183,7 @@ TEST_F(FileSystemProviderServiceTest, ...@@ -231,6 +183,7 @@ TEST_F(FileSystemProviderServiceTest,
TEST_F(FileSystemProviderServiceTest, MountFileSystem_UniqueIds) { TEST_F(FileSystemProviderServiceTest, MountFileSystem_UniqueIds) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
EXPECT_EQ(base::File::FILE_OK, EXPECT_EQ(base::File::FILE_OK,
service_->MountFileSystem( service_->MountFileSystem(
...@@ -253,6 +206,7 @@ TEST_F(FileSystemProviderServiceTest, MountFileSystem_UniqueIds) { ...@@ -253,6 +206,7 @@ TEST_F(FileSystemProviderServiceTest, MountFileSystem_UniqueIds) {
TEST_F(FileSystemProviderServiceTest, MountFileSystem_StressTest) { TEST_F(FileSystemProviderServiceTest, MountFileSystem_StressTest) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
const size_t kMaxFileSystems = 16; const size_t kMaxFileSystems = 16;
for (size_t i = 0; i < kMaxFileSystems; ++i) { for (size_t i = 0; i < kMaxFileSystems; ++i) {
...@@ -284,6 +238,8 @@ TEST_F(FileSystemProviderServiceTest, UnmountFileSystem) { ...@@ -284,6 +238,8 @@ TEST_F(FileSystemProviderServiceTest, UnmountFileSystem) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
EXPECT_EQ(base::File::FILE_OK, EXPECT_EQ(base::File::FILE_OK,
service_->MountFileSystem( service_->MountFileSystem(
kProviderId, MountOptions(kFileSystemId, kDisplayName))); kProviderId, MountOptions(kFileSystemId, kDisplayName)));
...@@ -310,13 +266,18 @@ TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) { ...@@ -310,13 +266,18 @@ TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
scoped_refptr<extensions::Extension> extension =
CreateFakeExtension(kExtensionId);
extension_registry_->AddEnabled(extension);
service_->OnExtensionLoaded(profile_, extension.get());
EXPECT_EQ(base::File::FILE_OK, EXPECT_EQ(base::File::FILE_OK,
service_->MountFileSystem( service_->MountFileSystem(
kProviderId, MountOptions(kFileSystemId, kDisplayName))); kProviderId, MountOptions(kFileSystemId, kDisplayName)));
ASSERT_EQ(1u, observer.mounts.size()); ASSERT_EQ(1u, observer.mounts.size());
// Directly call the observer's method. // Directly call the observer's method.
service_->OnExtensionUnloaded(profile_, extension_.get(), service_->OnExtensionUnloaded(profile_, extension.get(),
extensions::UnloadedExtensionReason::DISABLE); extensions::UnloadedExtensionReason::DISABLE);
ASSERT_EQ(1u, observer.unmounts.size()); ASSERT_EQ(1u, observer.unmounts.size());
...@@ -336,6 +297,7 @@ TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) { ...@@ -336,6 +297,7 @@ TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_OnExtensionUnload) {
TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_WrongExtensionId) { TEST_F(FileSystemProviderServiceTest, UnmountFileSystem_WrongExtensionId) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
const ProviderId kWrongProviderId = const ProviderId kWrongProviderId =
ProviderId::CreateFromExtensionId("helloworldhelloworldhelloworldhe"); ProviderId::CreateFromExtensionId("helloworldhelloworldhelloworldhe");
...@@ -377,8 +339,12 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) { ...@@ -377,8 +339,12 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) {
EXPECT_EQ(0u, observer.mounts.size()); EXPECT_EQ(0u, observer.mounts.size());
scoped_refptr<extensions::Extension> extension =
CreateFakeExtension(kExtensionId);
extension_registry_->AddEnabled(extension);
// Directly call the observer's method. // Directly call the observer's method.
service_->OnExtensionLoaded(profile_, extension_.get()); service_->OnExtensionLoaded(profile_, extension.get());
ASSERT_EQ(1u, observer.mounts.size()); ASSERT_EQ(1u, observer.mounts.size());
EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error()); EXPECT_EQ(base::File::FILE_OK, observer.mounts[0].error());
...@@ -419,6 +385,7 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) { ...@@ -419,6 +385,7 @@ TEST_F(FileSystemProviderServiceTest, RestoreFileSystem_OnExtensionLoad) {
TEST_F(FileSystemProviderServiceTest, DoNotRememberNonPersistent) { TEST_F(FileSystemProviderServiceTest, DoNotRememberNonPersistent) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
EXPECT_FALSE(registry_->watchers()); EXPECT_FALSE(registry_->watchers());
...@@ -437,6 +404,7 @@ TEST_F(FileSystemProviderServiceTest, DoNotRememberNonPersistent) { ...@@ -437,6 +404,7 @@ TEST_F(FileSystemProviderServiceTest, DoNotRememberNonPersistent) {
TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) { TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
EXPECT_FALSE(registry_->watchers()); EXPECT_FALSE(registry_->watchers());
...@@ -462,6 +430,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) { ...@@ -462,6 +430,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnMount) {
TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) { TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
{ {
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
...@@ -491,6 +460,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) { ...@@ -491,6 +460,7 @@ TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountOnShutdown) {
TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountByUser) { TEST_F(FileSystemProviderServiceTest, RememberFileSystem_OnUnmountByUser) {
LoggingObserver observer; LoggingObserver observer;
service_->AddObserver(&observer); service_->AddObserver(&observer);
service_->RegisterProvider(FakeExtensionProvider::Create(kExtensionId));
{ {
EXPECT_FALSE(registry_->file_system_info()); EXPECT_FALSE(registry_->file_system_info());
......
...@@ -12,19 +12,18 @@ using chromeos::file_system_provider::Service; ...@@ -12,19 +12,18 @@ using chromeos::file_system_provider::Service;
namespace chromeos { namespace chromeos {
namespace smb_client { namespace smb_client {
file_system_provider::ProviderId kSmbProviderId = SmbService::SmbService(Profile* profile)
ProviderId::CreateFromNativeId("smb"); : profile_(profile),
provider_id_(ProviderId::CreateFromNativeId("smb")),
SmbService::SmbService(Profile* profile) : profile_(profile) { capabilities_(false, false, false, extensions::SOURCE_NETWORK) {
GetProviderService()->RegisterNativeProvider( GetProviderService()->RegisterProvider(std::make_unique<SmbService>(profile));
kSmbProviderId, std::make_unique<SmbService>(profile));
} }
SmbService::~SmbService() {} SmbService::~SmbService() {}
base::File::Error SmbService::Mount( base::File::Error SmbService::Mount(
const file_system_provider::MountOptions& options) { const file_system_provider::MountOptions& options) {
return GetProviderService()->MountFileSystem(kSmbProviderId, options); return GetProviderService()->MountFileSystem(provider_id_, options);
} }
Service* SmbService::GetProviderService() const { Service* SmbService::GetProviderService() const {
...@@ -39,11 +38,12 @@ SmbService::CreateProvidedFileSystem( ...@@ -39,11 +38,12 @@ SmbService::CreateProvidedFileSystem(
return std::make_unique<SmbFileSystem>(file_system_info); return std::make_unique<SmbFileSystem>(file_system_info);
} }
bool SmbService::GetCapabilities(Profile* profile, const Capabilities& SmbService::GetCapabilities() const {
const ProviderId& provider_id, return capabilities_;
Capabilities& result) { }
result = Capabilities(false, false, false, extensions::SOURCE_NETWORK);
return true; const ProviderId& SmbService::GetId() const {
return provider_id_;
} }
} // namespace smb_client } // namespace smb_client
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_CHROMEOS_SMB_CLIENT_SMB_SERVICE_H_ #ifndef CHROME_BROWSER_CHROMEOS_SMB_CLIENT_SMB_SERVICE_H_
#define CHROME_BROWSER_CHROMEOS_SMB_CLIENT_SMB_SERVICE_H_ #define CHROME_BROWSER_CHROMEOS_SMB_CLIENT_SMB_SERVICE_H_
#include <memory>
#include "base/files/file.h" #include "base/files/file.h"
#include "base/macros.h" #include "base/macros.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"
...@@ -33,18 +35,19 @@ class SmbService : public KeyedService, public ProviderInterface { ...@@ -33,18 +35,19 @@ class SmbService : public KeyedService, public ProviderInterface {
// file_system_provider::Service::MountFileSystem(). // file_system_provider::Service::MountFileSystem().
base::File::Error Mount(const file_system_provider::MountOptions& options); base::File::Error Mount(const file_system_provider::MountOptions& options);
// ProviderInterface overrides // ProviderInterface overrides.
std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem( std::unique_ptr<ProvidedFileSystemInterface> CreateProvidedFileSystem(
Profile* profile, Profile* profile,
const ProvidedFileSystemInfo& file_system_info) override; const ProvidedFileSystemInfo& file_system_info) override;
bool GetCapabilities(Profile* profile, const Capabilities& GetCapabilities() const override;
const ProviderId& provider_id, const ProviderId& GetId() const override;
Capabilities& result) override;
private: private:
Service* GetProviderService() const; Service* GetProviderService() const;
Profile* profile_; Profile* profile_;
ProviderId provider_id_;
Capabilities capabilities_;
DISALLOW_COPY_AND_ASSIGN(SmbService); DISALLOW_COPY_AND_ASSIGN(SmbService);
}; };
......
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
#include "chrome/browser/chromeos/smb_client/smb_service.h" #include "chrome/browser/chromeos/smb_client/smb_service.h"
#include <stddef.h> #include <stddef.h>
#include <memory> #include <memory>
#include <utility>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chrome/browser/chromeos/file_system_provider/fake_extension_provider.h"
#include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h" #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h"
#include "chrome/browser/chromeos/file_system_provider/fake_registry.h" #include "chrome/browser/chromeos/file_system_provider/fake_registry.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"
...@@ -47,8 +48,6 @@ class SmbServiceTest : public testing::Test { ...@@ -47,8 +48,6 @@ class SmbServiceTest : public testing::Test {
std::make_unique<extensions::ExtensionRegistry>(profile_); std::make_unique<extensions::ExtensionRegistry>(profile_);
fsp_service_ = std::make_unique<file_system_provider::Service>( fsp_service_ = std::make_unique<file_system_provider::Service>(
profile_, extension_registry_.get()); profile_, extension_registry_.get());
fsp_service_->SetExtensionProviderForTesting(
std::make_unique<file_system_provider::FakeExtensionProvider>());
fsp_service_->SetRegistryForTesting( fsp_service_->SetRegistryForTesting(
std::make_unique<file_system_provider::FakeRegistry>()); std::make_unique<file_system_provider::FakeRegistry>());
......
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