#include "storage/browser/file_system/copy_or_move_operation_delegate.h"
#include <cstdint>
#include <memory>
#include <tuple>
#include <utility>
#include "base/auto_reset.h"
#include "base/check_is_test.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "components/file_access/file_access_copy_or_move_delegate_factory.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "storage/browser/blob/shareable_file_reference.h"
#include "storage/browser/file_system/copy_or_move_file_validator.h"
#include "storage/browser/file_system/copy_or_move_hook_delegate.h"
#include "storage/browser/file_system/copy_or_move_hook_delegate_composite.h"
#include "storage/browser/file_system/file_observers.h"
#include "storage/browser/file_system/file_stream_reader.h"
#include "storage/browser/file_system/file_stream_writer.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_operation.h"
#include "storage/browser/file_system/file_system_operation_runner.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/common/file_system/file_system_util.h"
namespace storage {
const int64_t kFlushIntervalInBytes = …;
namespace {
base::File::Error MaybeSuppressError(
base::File::Error error,
CopyOrMoveHookDelegate::ErrorAction error_action) { … }
CopyOrMoveHookDelegate::ErrorCallback CreateErrorSuppressCallback(
CopyOrMoveHookDelegate::StatusCallback callback,
base::File::Error error) { … }
}
class CopyOrMoveOperationDelegate::CopyOrMoveImpl { … };
namespace {
const FileSystemURL* g_error_url_for_test = …;
class CopyOrMoveOnSameFileSystemImpl
: public CopyOrMoveOperationDelegate::CopyOrMoveImpl { … };
class SnapshotCopyOrMoveImpl
: public CopyOrMoveOperationDelegate::CopyOrMoveImpl { … };
const int kReadBufferSize = …;
const int kMinProgressCallbackInvocationSpanInMilliseconds = …;
class StreamCopyOrMoveImpl
: public CopyOrMoveOperationDelegate::CopyOrMoveImpl { … };
}
CopyOrMoveOperationDelegate::StreamCopyHelper::StreamCopyHelper(
std::unique_ptr<FileStreamReader> reader,
std::unique_ptr<FileStreamWriter> writer,
FlushPolicy flush_policy,
int buffer_size,
FileSystemOperation::CopyFileProgressCallback file_progress_callback,
const base::TimeDelta& min_progress_callback_invocation_span)
: … { … }
CopyOrMoveOperationDelegate::StreamCopyHelper::~StreamCopyHelper() = default;
void CopyOrMoveOperationDelegate::StreamCopyHelper::Run(
StatusCallback callback) { … }
void CopyOrMoveOperationDelegate::StreamCopyHelper::Cancel() { … }
void CopyOrMoveOperationDelegate::StreamCopyHelper::Read() { … }
void CopyOrMoveOperationDelegate::StreamCopyHelper::DidRead(int result) { … }
void CopyOrMoveOperationDelegate::StreamCopyHelper::Write(
scoped_refptr<net::DrainableIOBuffer> buffer) { … }
void CopyOrMoveOperationDelegate::StreamCopyHelper::DidWrite(
scoped_refptr<net::DrainableIOBuffer> buffer,
int result) { … }
void CopyOrMoveOperationDelegate::StreamCopyHelper::Flush(
FlushMode flush_mode) { … }
void CopyOrMoveOperationDelegate::StreamCopyHelper::DidFlush(
FlushMode flush_mode,
int result) { … }
CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate(
FileSystemContext* file_system_context,
const FileSystemURL& src_root,
const FileSystemURL& dest_root,
OperationType operation_type,
CopyOrMoveOptionSet options,
ErrorBehavior error_behavior,
std::unique_ptr<CopyOrMoveHookDelegate> copy_or_move_hook_delegate,
StatusCallback callback)
: … { … }
CopyOrMoveOperationDelegate::~CopyOrMoveOperationDelegate() = default;
void CopyOrMoveOperationDelegate::Run() { … }
void CopyOrMoveOperationDelegate::RunRecursively() { … }
void CopyOrMoveOperationDelegate::FinishOperation(base::File::Error error) { … }
void CopyOrMoveOperationDelegate::ProcessFile(const FileSystemURL& src_url,
StatusCallback callback) { … }
void CopyOrMoveOperationDelegate::DoProcessFile(const FileSystemURL& src_url,
FileSystemURL dest_url,
StatusCallback callback,
base::File::Error error) { … }
void CopyOrMoveOperationDelegate::ProcessDirectory(const FileSystemURL& src_url,
StatusCallback callback) { … }
void CopyOrMoveOperationDelegate::PostProcessDirectory(
const FileSystemURL& src_url,
StatusCallback callback) { … }
base::WeakPtr<RecursiveOperationDelegate>
CopyOrMoveOperationDelegate::AsWeakPtr() { … }
void CopyOrMoveOperationDelegate::SetErrorUrlForTest(const FileSystemURL* url) { … }
void CopyOrMoveOperationDelegate::OnCancel() { … }
void CopyOrMoveOperationDelegate::DidCopyOrMoveFile(StatusCallback callback,
CopyOrMoveImpl* impl,
base::File::Error error) { … }
void CopyOrMoveOperationDelegate::DidTryRemoveDestRoot(
StatusCallback callback,
base::File::Error error) { … }
void CopyOrMoveOperationDelegate::ProcessDirectoryInternal(
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
StatusCallback callback,
base::File::Error error) { … }
void CopyOrMoveOperationDelegate::DidCreateDirectory(
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
StatusCallback callback,
base::File::Error error) { … }
void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterGetMetadata(
const FileSystemURL& src_url,
StatusCallback callback,
base::File::Error error,
const base::File::Info& file_info) { … }
void CopyOrMoveOperationDelegate::PostProcessDirectoryAfterTouchFile(
const FileSystemURL& src_url,
StatusCallback callback,
base::File::Error error) { … }
void CopyOrMoveOperationDelegate::DidRemoveSourceForMove(
const FileSystemURL& src_url,
StatusCallback callback,
base::File::Error error) { … }
FileSystemURL CopyOrMoveOperationDelegate::CreateDestURL(
const FileSystemURL& src_url) const { … }
}