chromium/storage/browser/file_system/copy_or_move_operation_delegate.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 =;  // 10MB.

namespace {

base::File::Error MaybeSuppressError(
    base::File::Error error,
    CopyOrMoveHookDelegate::ErrorAction error_action) {}

CopyOrMoveHookDelegate::ErrorCallback CreateErrorSuppressCallback(
    CopyOrMoveHookDelegate::StatusCallback callback,
    base::File::Error error) {}

}  // namespace

class CopyOrMoveOperationDelegate::CopyOrMoveImpl {};

namespace {

// A non-owning pointer. Whoever calls `SetErrorUrlForTest` of
// `CopyOrMoveOperationDelegate` should take care of its lifespan.
const FileSystemURL* g_error_url_for_test =;

// Copies or moves a file on a (same) file system. Just delegate the operation
// to |operation_runner|.
class CopyOrMoveOnSameFileSystemImpl
    : public CopyOrMoveOperationDelegate::CopyOrMoveImpl {};

// Specifically for cross file system copy/move operation, this class creates
// a snapshot file, validates it if necessary, runs copying process,
// validates the created file, and removes source file for move (noop for
// copy).
class SnapshotCopyOrMoveImpl
    : public CopyOrMoveOperationDelegate::CopyOrMoveImpl {};

// The size of buffer for StreamCopyHelper.
const int kReadBufferSize =;

// To avoid too many progress callbacks, it should be called less
// frequently than 50ms.
const int kMinProgressCallbackInvocationSpanInMilliseconds =;

// Specifically for cross file system copy/move operation, this class uses
// stream reader and writer for copying. Validator is not supported, so if
// necessary SnapshotCopyOrMoveImpl should be used.
class StreamCopyOrMoveImpl
    : public CopyOrMoveOperationDelegate::CopyOrMoveImpl {};

}  // namespace

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() {}

// static
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 {}

}  // namespace storage