chromium/storage/browser/blob/write_blob_to_file.cc

// Copyright 2019 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/blob/write_blob_to_file.h"

#include <stdint.h>

#include <algorithm>
#include <limits>
#include <memory>
#include <utility>
#include <vector>

#include "base/containers/span.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/numerics/checked_math.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "components/file_access/scoped_file_access.h"
#include "storage/browser/blob/blob_data_handle.h"
#include "storage/browser/blob/blob_data_item.h"
#include "storage/browser/blob/blob_data_snapshot.h"
#include "storage/browser/blob/shareable_blob_data_item.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_writer_delegate.h"
#include "storage/common/file_system/file_system_mount_option.h"
#include "third_party/blink/public/common/blob/blob_utils.h"

namespace storage {
namespace {
DelegateNoProgressWriteCallback;
CopyCallback;

struct WriteState {};

// Utility function to ignore all progress events returned when running
// FileWriterDelegate::Start. This means that there is either a single call for
// a success or failure. This wrapper also handles owning the lifetime of the
// FileWriterDelegate, which it destructs after receiving a success or error.
FileWriterDelegate::DelegateWriteCallback IgnoreProgressWrapper(
    std::unique_ptr<FileWriterDelegate> delegate,
    DelegateNoProgressWriteCallback callback) {}

// Copied from file_util_posix.cc, with the addition of |offset| and |max_size|
// parameters. The parameters apply to the |infile|. The |bytes_copied|
// parameter keeps track of the number of bytes written to |outfile|.
// Note - this function can still succeed if the size |infile| is less than
// |max_size|. The caller should use |bytes_copied| to know exactly how many
// bytes were copied.
bool CopyFileContentsWithOffsetAndSize(base::File* infile,
                                       base::File* outfile,
                                       int64_t* bytes_copied,
                                       int64_t offset,
                                       int64_t max_size) {}

// Copies the contents of |copy_from| to |copy_to|, with the given |offset| and
// optional |size| applied to the |copy_from| file. The
// |expected_last_modified_copy_from| must match, within a second, the last
// modified time of the |copy_from| file. Afterwards, the |last_modified| date
// is optionally saved as the last modified & last accessed time of |copy_to|.
// If |flush_on_close| is true, then Flush is called on the |copy_to| file
// before it is closed. The `file_access::ScopedFileAccess` parameter is
// expected to allow access to the source file. It has to be kept in scope of
// this function because it must be alive while the copy operation is happening.
mojom::WriteBlobToFileResult CopyFileAndMaybeWriteTimeModified(
    const base::FilePath& copy_from,
    base::Time expected_last_modified_copy_from,
    const base::FilePath& copy_to,
    int64_t offset,
    std::optional<int64_t> size,
    std::optional<base::Time> last_modified,
    bool flush_on_close,
    file_access::ScopedFileAccess) {}

mojom::WriteBlobToFileResult CreateEmptyFileAndMaybeSetModifiedTime(
    base::FilePath file_path,
    std::optional<base::Time> last_modified,
    bool flush_on_write) {}

void HandleModifiedTimeOnBlobFileWriteComplete(
    base::FilePath file_path,
    std::optional<base::Time> last_modified,
    bool flush_on_write,
    mojom::BlobStorageContext::WriteBlobToFileCallback callback,
    base::File::Error rv,
    int64_t bytes_written,
    FileWriterDelegate::WriteProgressStatus write_status) {}

void PostCopyTaskToFileThreadIfAllowed(
    CopyCallback copy_cb,
    mojom::BlobStorageContext::WriteBlobToFileCallback callback,
    file_access::ScopedFileAccess scoped_file_access) {}

void WriteConstructedBlobToFile(
    std::unique_ptr<BlobDataHandle> blob_handle,
    const base::FilePath& file_path,
    bool flush_on_write,
    std::optional<base::Time> last_modified,
    mojom::BlobStorageContext::WriteBlobToFileCallback callback,
    BlobStatus status) {}

}  // namespace

void WriteBlobToFile(
    std::unique_ptr<BlobDataHandle> blob_handle,
    const base::FilePath& file_path,
    bool flush_on_write,
    std::optional<base::Time> last_modified,
    mojom::BlobStorageContext::WriteBlobToFileCallback callback) {}

}  // namespace storage