#include "content/browser/file_system/file_system_manager_impl.h"
#include <utility>
#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/services/filesystem/public/mojom/types.mojom.h"
#include "content/browser/blob_storage/chrome_blob_storage_context.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/file_system/browser_file_system_helper.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_impl.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/blob/shareable_file_reference.h"
#include "storage/browser/file_system/copy_or_move_hook_delegate.h"
#include "storage/browser/file_system/file_observers.h"
#include "storage/browser/file_system/file_permission_policy.h"
#include "storage/browser/file_system/file_system_backend.h"
#include "storage/browser/file_system/file_system_context.h"
#include "storage/browser/file_system/file_system_file_util.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/browser/file_system/isolated_context.h"
#include "storage/common/file_system/file_system_info.h"
#include "storage/common/file_system/file_system_types.h"
#include "storage/common/file_system/file_system_util.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/blob/blob.mojom.h"
#include "third_party/blink/public/mojom/blob/serialized_blob.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
BlobDataBuilder;
BlobStorageContext;
FileSystemBackend;
FileSystemFileUtil;
FileSystemOperation;
FileSystemURL;
namespace content {
namespace {
void RevokeFilePermission(int child_id, const base::FilePath& path) { … }
storage::FileSystemType ToStorageFileSystemType(
blink::mojom::FileSystemType type) { … }
blink::mojom::FileSystemType ToMojoFileSystemType(
storage::FileSystemType type) { … }
blink::mojom::FileSystemInfoPtr ToMojoFileSystemInfo(
const storage::FileSystemInfo& info) { … }
}
class FileSystemManagerImpl::FileSystemCancellableOperationImpl
: public blink::mojom::FileSystemCancellableOperation { … };
class FileSystemManagerImpl::ReceivedSnapshotListenerImpl
: public blink::mojom::ReceivedSnapshotListener { … };
struct FileSystemManagerImpl::WriteSyncCallbackEntry { … };
struct FileSystemManagerImpl::ReadDirectorySyncCallbackEntry { … };
FileSystemManagerImpl::FileSystemManagerImpl(
int process_id,
scoped_refptr<storage::FileSystemContext> file_system_context,
scoped_refptr<ChromeBlobStorageContext> blob_storage_context)
: … { … }
FileSystemManagerImpl::~FileSystemManagerImpl() { … }
base::WeakPtr<FileSystemManagerImpl> FileSystemManagerImpl::GetWeakPtr() { … }
void FileSystemManagerImpl::BindReceiver(
const blink::StorageKey& storage_key,
mojo::PendingReceiver<blink::mojom::FileSystemManager> receiver) { … }
void FileSystemManagerImpl::Open(const url::Origin& origin,
blink::mojom::FileSystemType file_system_type,
OpenCallback callback) { … }
void FileSystemManagerImpl::ContinueOpen(
const url::Origin& origin,
blink::mojom::FileSystemType file_system_type,
mojo::ReportBadMessageCallback bad_message_callback,
OpenCallback callback,
const blink::StorageKey& storage_key,
bool security_check_success) { … }
void FileSystemManagerImpl::ResolveURL(const GURL& filesystem_url,
ResolveURLCallback callback) { … }
void FileSystemManagerImpl::ContinueResolveURL(
const storage::FileSystemURL& url,
ResolveURLCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::Move(const GURL& src_path,
const GURL& dest_path,
MoveCallback callback) { … }
void FileSystemManagerImpl::ContinueMove(const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url,
MoveCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::Copy(const GURL& src_path,
const GURL& dest_path,
CopyCallback callback) { … }
void FileSystemManagerImpl::ContinueCopy(const storage::FileSystemURL& src_url,
const storage::FileSystemURL& dest_url,
CopyCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::Remove(const GURL& path,
bool recursive,
RemoveCallback callback) { … }
void FileSystemManagerImpl::ContinueRemove(const storage::FileSystemURL& url,
bool recursive,
RemoveCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::ReadMetadata(const GURL& path,
ReadMetadataCallback callback) { … }
void FileSystemManagerImpl::ContinueReadMetadata(
const storage::FileSystemURL& url,
ReadMetadataCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::Create(const GURL& path,
bool exclusive,
bool is_directory,
bool recursive,
CreateCallback callback) { … }
void FileSystemManagerImpl::ContinueCreate(const storage::FileSystemURL& url,
bool exclusive,
bool is_directory,
bool recursive,
CreateCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::Exists(const GURL& path,
bool is_directory,
ExistsCallback callback) { … }
void FileSystemManagerImpl::ContinueExists(const storage::FileSystemURL& url,
bool is_directory,
ExistsCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::ReadDirectory(
const GURL& path,
mojo::PendingRemote<blink::mojom::FileSystemOperationListener>
pending_listener) { … }
void FileSystemManagerImpl::ContinueReadDirectory(
const storage::FileSystemURL& url,
mojo::Remote<blink::mojom::FileSystemOperationListener> listener,
bool security_check_success) { … }
void FileSystemManagerImpl::ReadDirectorySync(
const GURL& path,
ReadDirectorySyncCallback callback) { … }
void FileSystemManagerImpl::ContinueReadDirectorySync(
const storage::FileSystemURL& url,
ReadDirectorySyncCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::Write(
const GURL& file_path,
mojo::PendingRemote<blink::mojom::Blob> blob,
int64_t position,
mojo::PendingReceiver<blink::mojom::FileSystemCancellableOperation>
op_receiver,
mojo::PendingRemote<blink::mojom::FileSystemOperationListener>
pending_listener) { … }
void FileSystemManagerImpl::ResolveBlobForWrite(
mojo::PendingRemote<blink::mojom::Blob> blob,
base::OnceCallback<void(std::unique_ptr<storage::BlobDataHandle>)> callback,
bool security_check_success) { … }
void FileSystemManagerImpl::ContinueWrite(
const storage::FileSystemURL& url,
int64_t position,
mojo::PendingReceiver<blink::mojom::FileSystemCancellableOperation>
op_receiver,
mojo::Remote<blink::mojom::FileSystemOperationListener> listener,
std::unique_ptr<storage::BlobDataHandle> blob) { … }
void FileSystemManagerImpl::WriteSync(
const GURL& file_path,
mojo::PendingRemote<blink::mojom::Blob> blob,
int64_t position,
WriteSyncCallback callback) { … }
void FileSystemManagerImpl::ContinueWriteSync(
const storage::FileSystemURL& url,
int64_t position,
WriteSyncCallback callback,
std::unique_ptr<storage::BlobDataHandle> blob) { … }
void FileSystemManagerImpl::Truncate(
const GURL& file_path,
int64_t length,
mojo::PendingReceiver<blink::mojom::FileSystemCancellableOperation>
op_receiver,
TruncateCallback callback) { … }
void FileSystemManagerImpl::ContinueTruncate(
const storage::FileSystemURL& url,
int64_t length,
mojo::PendingReceiver<blink::mojom::FileSystemCancellableOperation>
op_receiver,
TruncateCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::TruncateSync(const GURL& file_path,
int64_t length,
TruncateSyncCallback callback) { … }
void FileSystemManagerImpl::ContinueTruncateSync(
const storage::FileSystemURL& url,
int64_t length,
TruncateSyncCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::CreateSnapshotFile(
const GURL& file_path,
CreateSnapshotFileCallback callback) { … }
void FileSystemManagerImpl::ContinueCreateSnapshotFile(
const storage::FileSystemURL& url,
CreateSnapshotFileCallback callback,
bool security_check_success) { … }
void FileSystemManagerImpl::GetPlatformPath(const GURL& path,
GetPlatformPathCallback callback) { … }
void FileSystemManagerImpl::RegisterBlob(
const std::string& content_type,
const GURL& url,
uint64_t length,
std::optional<base::Time> expected_modification_time,
RegisterBlobCallback callback) { … }
void FileSystemManagerImpl::ContinueRegisterBlob(
const std::string& content_type,
const GURL& url,
uint64_t length,
std::optional<base::Time> expected_modification_time,
RegisterBlobCallback callback,
storage::FileSystemURL crack_url,
bool security_check_success) { … }
void FileSystemManagerImpl::Cancel(
OperationID op_id,
FileSystemCancellableOperationImpl::CancelCallback callback) { … }
void FileSystemManagerImpl::DidReceiveSnapshotFile(int snapshot_id) { … }
void FileSystemManagerImpl::OnConnectionError() { … }
void FileSystemManagerImpl::DidFinish(
base::OnceCallback<void(base::File::Error)> callback,
base::File::Error error_code) { … }
void FileSystemManagerImpl::DidGetMetadata(ReadMetadataCallback callback,
base::File::Error result,
const base::File::Info& info) { … }
void FileSystemManagerImpl::DidGetMetadataForStreaming(
CreateSnapshotFileCallback callback,
base::File::Error result,
const base::File::Info& info) { … }
void FileSystemManagerImpl::DidReadDirectory(
OperationListenerID listener_id,
base::File::Error result,
std::vector<filesystem::mojom::DirectoryEntry> entries,
bool has_more) { … }
void FileSystemManagerImpl::DidReadDirectorySync(
ReadDirectorySyncCallbackEntry* callback_entry,
base::File::Error result,
std::vector<filesystem::mojom::DirectoryEntry> entries,
bool has_more) { … }
void FileSystemManagerImpl::DidWrite(OperationListenerID listener_id,
base::File::Error result,
int64_t bytes,
bool complete) { … }
void FileSystemManagerImpl::DidWriteSync(WriteSyncCallbackEntry* entry,
base::File::Error result,
int64_t bytes,
bool complete) { … }
void FileSystemManagerImpl::DidOpenFileSystem(
OpenCallback callback,
const FileSystemURL& root,
const std::string& filesystem_name,
base::File::Error result) { … }
void FileSystemManagerImpl::DidResolveURL(
ResolveURLCallback callback,
base::File::Error result,
const storage::FileSystemInfo& info,
const base::FilePath& file_path,
storage::FileSystemContext::ResolvedEntryType type) { … }
void FileSystemManagerImpl::DidCreateSnapshot(
CreateSnapshotFileCallback callback,
const storage::FileSystemURL& url,
base::File::Error result,
const base::File::Info& info,
const base::FilePath& platform_path,
scoped_refptr<storage::ShareableFileReference> ) { … }
void FileSystemManagerImpl::ContinueDidCreateSnapshot(
CreateSnapshotFileCallback callback,
const storage::FileSystemURL& url,
base::File::Error result,
const base::File::Info& info,
const base::FilePath& platform_path,
bool security_check_success) { … }
void FileSystemManagerImpl::DidGetPlatformPath(
scoped_refptr<storage::FileSystemContext> ,
GetPlatformPathCallback callback,
base::FilePath platform_path) { … }
void FileSystemManagerImpl::GetPlatformPathOnFileThread(
const GURL& path,
int process_id,
scoped_refptr<storage::FileSystemContext> context,
base::WeakPtr<FileSystemManagerImpl> file_system_manager,
const blink::StorageKey& storage_key,
GetPlatformPathCallback callback) { … }
std::optional<base::File::Error> FileSystemManagerImpl::ValidateFileSystemURL(
const storage::FileSystemURL& url) { … }
FileSystemManagerImpl::OperationListenerID FileSystemManagerImpl::AddOpListener(
mojo::Remote<blink::mojom::FileSystemOperationListener> listener) { … }
void FileSystemManagerImpl::RemoveOpListener(OperationListenerID listener_id) { … }
blink::mojom::FileSystemOperationListener* FileSystemManagerImpl::GetOpListener(
OperationListenerID listener_id) { … }
void FileSystemManagerImpl::OnConnectionErrorForOpListeners(
OperationListenerID listener_id) { … }
}