Commit 7694c364 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Introduce a filesystem backend delegate for smbfs

This delegate will be used to implement server-side copy/move, and
to intercept certain operations (eg. read directory) to provide UI in
error cases.

Bug: 1054704, 1054689
Change-Id: I506a8e606c3fdf40d9a0016dfde1b9954c1b4f39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2106039Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751180}
parent 1a7048ca
......@@ -384,6 +384,7 @@
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h"
#include "chrome/browser/chromeos/system/input_device_settings.h"
#include "chrome/browser/speech/tts_chromeos.h"
#include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h"
......@@ -3538,6 +3539,8 @@ void ChromeContentBrowserClient::GetAdditionalFileSystemBackends(
std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(),
std::make_unique<drive::DriveFsFileSystemBackendDelegate>(
Profile::FromBrowserContext(browser_context)),
std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>(
Profile::FromBrowserContext(browser_context)),
external_mount_points, storage::ExternalMountPoints::GetSystemInstance());
backend->AddSystemMountPoints();
DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal));
......
......@@ -2223,6 +2223,10 @@ source_set("chromeos") {
"smb_client/discovery/netbios_host_locator.h",
"smb_client/discovery/network_scanner.cc",
"smb_client/discovery/network_scanner.h",
"smb_client/fileapi/smbfs_async_file_util.cc",
"smb_client/fileapi/smbfs_async_file_util.h",
"smb_client/fileapi/smbfs_file_system_backend_delegate.cc",
"smb_client/fileapi/smbfs_file_system_backend_delegate.h",
"smb_client/smb_constants.cc",
"smb_client/smb_constants.h",
"smb_client/smb_errors.cc",
......
......@@ -69,6 +69,7 @@ FileSystemBackend::FileSystemBackend(
std::unique_ptr<FileSystemBackendDelegate> arc_content_delegate,
std::unique_ptr<FileSystemBackendDelegate> arc_documents_provider_delegate,
std::unique_ptr<FileSystemBackendDelegate> drivefs_delegate,
std::unique_ptr<FileSystemBackendDelegate> smbfs_delegate,
scoped_refptr<storage::ExternalMountPoints> mount_points,
storage::ExternalMountPoints* system_mount_points)
: file_access_permissions_(new FileAccessPermissions()),
......@@ -79,6 +80,7 @@ FileSystemBackend::FileSystemBackend(
arc_documents_provider_delegate_(
std::move(arc_documents_provider_delegate)),
drivefs_delegate_(std::move(drivefs_delegate)),
smbfs_delegate_(std::move(smbfs_delegate)),
mount_points_(mount_points),
system_mount_points_(system_mount_points) {}
......@@ -282,7 +284,6 @@ storage::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil(
return file_system_provider_delegate_->GetAsyncFileUtil(type);
case storage::kFileSystemTypeNativeLocal:
case storage::kFileSystemTypeRestrictedNativeLocal:
case storage::kFileSystemTypeSmbFs:
return local_file_util_.get();
case storage::kFileSystemTypeDeviceMediaAsFileStorage:
return mtp_delegate_->GetAsyncFileUtil(type);
......@@ -292,6 +293,8 @@ storage::AsyncFileUtil* FileSystemBackend::GetAsyncFileUtil(
return arc_documents_provider_delegate_->GetAsyncFileUtil(type);
case storage::kFileSystemTypeDriveFs:
return drivefs_delegate_->GetAsyncFileUtil(type);
case storage::kFileSystemTypeSmbFs:
return smbfs_delegate_->GetAsyncFileUtil(type);
default:
NOTREACHED();
}
......
......@@ -79,6 +79,7 @@ class FileSystemBackend : public storage::ExternalFileSystemBackend {
std::unique_ptr<FileSystemBackendDelegate>
arc_documents_provider_delegate,
std::unique_ptr<FileSystemBackendDelegate> drivefs_delegate,
std::unique_ptr<FileSystemBackendDelegate> smbfs_delegate,
scoped_refptr<storage::ExternalMountPoints> mount_points,
storage::ExternalMountPoints* system_mount_points);
~FileSystemBackend() override;
......@@ -163,6 +164,9 @@ class FileSystemBackend : public storage::ExternalFileSystemBackend {
// The delegate instance for the DriveFS file system related operations.
std::unique_ptr<FileSystemBackendDelegate> drivefs_delegate_;
// The delegate instance for the SmbFs file system related operations.
std::unique_ptr<FileSystemBackendDelegate> smbfs_delegate_;
// Mount points specific to the owning context (i.e. per-profile mount
// points).
//
......
......@@ -45,6 +45,7 @@ TEST(ChromeOSFileSystemBackendTest, DefaultMountPoints) {
nullptr, // arc_content_delegate
nullptr, // arc_documents_provider_delegate
nullptr, // drivefs_delegate
nullptr, // smbfs_delegate
mount_points.get(), storage::ExternalMountPoints::GetSystemInstance());
backend.AddSystemMountPoints();
std::vector<base::FilePath> root_dirs = backend.GetRootDirectories();
......@@ -73,6 +74,7 @@ TEST(ChromeOSFileSystemBackendTest, GetRootDirectories) {
nullptr, // arc_content_delegate
nullptr, // arc_documents_provider_delegate
nullptr, // drivefs_delegate
nullptr, // smbfs_delegate
mount_points.get(), system_mount_points.get());
const size_t initial_root_dirs_size = backend.GetRootDirectories().size();
......@@ -117,6 +119,7 @@ TEST(ChromeOSFileSystemBackendTest, AccessPermissions) {
nullptr, // arc_content_delegate
nullptr, // arc_documents_provider_delegate
nullptr, // drivefs_delegate
nullptr, // smbfs_delegate
mount_points.get(), system_mount_points.get());
std::string extension("ddammdhioacbehjngdmkjcjbnfginlla");
......@@ -187,6 +190,7 @@ TEST(ChromeOSFileSystemBackendTest, GetVirtualPathConflictWithSystemPoints) {
nullptr, // arc_content_delegate
nullptr, // arc_documents_provider_delegate
nullptr, // drivefs_delegate
nullptr, // smbfs_delegate
mount_points.get(), system_mount_points.get());
const storage::FileSystemType type = storage::kFileSystemTypeNativeLocal;
......
// Copyright 2020 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/fileapi/smbfs_async_file_util.h"
#include "base/logging.h"
#include "storage/browser/file_system/local_file_util.h"
namespace chromeos {
namespace smb_client {
SmbFsAsyncFileUtil::SmbFsAsyncFileUtil(Profile* profile)
: AsyncFileUtilAdapter(new storage::LocalFileUtil), profile_(profile) {
DCHECK(profile_);
}
SmbFsAsyncFileUtil::~SmbFsAsyncFileUtil() = default;
} // namespace smb_client
} // namespace chromeos
// Copyright 2020 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_FILEAPI_SMBFS_ASYNC_FILE_UTIL_H_
#define CHROME_BROWSER_CHROMEOS_SMB_CLIENT_FILEAPI_SMBFS_ASYNC_FILE_UTIL_H_
#include "storage/browser/file_system/async_file_util_adapter.h"
class Profile;
namespace chromeos {
namespace smb_client {
class SmbFsAsyncFileUtil : public storage::AsyncFileUtilAdapter {
public:
explicit SmbFsAsyncFileUtil(Profile* profile);
~SmbFsAsyncFileUtil() override;
SmbFsAsyncFileUtil() = delete;
SmbFsAsyncFileUtil(const SmbFsAsyncFileUtil&) = delete;
SmbFsAsyncFileUtil& operator=(const SmbFsAsyncFileUtil&) = delete;
private:
Profile* const profile_;
};
} // namespace smb_client
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SMB_CLIENT_FILEAPI_SMBFS_ASYNC_FILE_UTIL_H_
// Copyright 2020 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/fileapi/smbfs_file_system_backend_delegate.h"
#include "base/logging.h"
#include "chrome/browser/chromeos/smb_client/fileapi/smbfs_async_file_util.h"
#include "content/public/browser/browser_thread.h"
#include "storage/browser/file_system/file_stream_reader.h"
#include "storage/browser/file_system/file_stream_writer.h"
namespace chromeos {
namespace smb_client {
SmbFsFileSystemBackendDelegate::SmbFsFileSystemBackendDelegate(Profile* profile)
: async_file_util_(std::make_unique<SmbFsAsyncFileUtil>(profile)) {}
SmbFsFileSystemBackendDelegate::~SmbFsFileSystemBackendDelegate() = default;
storage::AsyncFileUtil* SmbFsFileSystemBackendDelegate::GetAsyncFileUtil(
storage::FileSystemType type) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
DCHECK_EQ(storage::kFileSystemTypeSmbFs, type);
return async_file_util_.get();
}
std::unique_ptr<storage::FileStreamReader>
SmbFsFileSystemBackendDelegate::CreateFileStreamReader(
const storage::FileSystemURL& url,
int64_t offset,
int64_t max_bytes_to_read,
const base::Time& expected_modification_time,
storage::FileSystemContext* context) {
NOTREACHED();
return nullptr;
}
std::unique_ptr<storage::FileStreamWriter>
SmbFsFileSystemBackendDelegate::CreateFileStreamWriter(
const storage::FileSystemURL& url,
int64_t offset,
storage::FileSystemContext* context) {
NOTREACHED();
return nullptr;
}
storage::WatcherManager* SmbFsFileSystemBackendDelegate::GetWatcherManager(
storage::FileSystemType type) {
NOTREACHED();
return nullptr;
}
void SmbFsFileSystemBackendDelegate::GetRedirectURLForContents(
const storage::FileSystemURL& url,
storage::URLCallback callback) {
NOTREACHED();
}
} // namespace smb_client
} // namespace chromeos
// Copyright 2020 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_FILEAPI_SMBFS_FILE_SYSTEM_BACKEND_DELEGATE_H_
#define CHROME_BROWSER_CHROMEOS_SMB_CLIENT_FILEAPI_SMBFS_FILE_SYSTEM_BACKEND_DELEGATE_H_
#include <memory>
#include "chrome/browser/chromeos/fileapi/file_system_backend_delegate.h"
class Profile;
namespace chromeos {
namespace smb_client {
class SmbFsAsyncFileUtil;
class SmbFsFileSystemBackendDelegate
: public chromeos::FileSystemBackendDelegate {
public:
explicit SmbFsFileSystemBackendDelegate(Profile* profile);
~SmbFsFileSystemBackendDelegate() override;
// FileSystemBackend::Delegate overrides.
storage::AsyncFileUtil* GetAsyncFileUtil(
storage::FileSystemType type) override;
std::unique_ptr<storage::FileStreamReader> CreateFileStreamReader(
const storage::FileSystemURL& url,
int64_t offset,
int64_t max_bytes_to_read,
const base::Time& expected_modification_time,
storage::FileSystemContext* context) override;
std::unique_ptr<storage::FileStreamWriter> CreateFileStreamWriter(
const storage::FileSystemURL& url,
int64_t offset,
storage::FileSystemContext* context) override;
storage::WatcherManager* GetWatcherManager(
storage::FileSystemType type) override;
void GetRedirectURLForContents(const storage::FileSystemURL& url,
storage::URLCallback callback) override;
private:
std::unique_ptr<SmbFsAsyncFileUtil> async_file_util_;
};
} // namespace smb_client
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SMB_CLIENT_FILEAPI_SMBFS_FILE_SYSTEM_BACKEND_DELEGATE_H_
......@@ -58,7 +58,8 @@ class PlatformUtilTestContentBrowserClient : public ChromeContentBrowserClient {
// New FileSystemBackend that uses our MockSpecialStoragePolicy.
additional_backends->push_back(
std::make_unique<chromeos::FileSystemBackend>(
nullptr, nullptr, nullptr, nullptr, nullptr, external_mount_points,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
external_mount_points,
storage::ExternalMountPoints::GetSystemInstance()));
}
};
......
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