Skip to content

Commit

Permalink
FS: Rename FileSystemFileStreamReader to SandboxFileStreamReader.
Browse files Browse the repository at this point in the history
Despite the name and comment for this class, the implementation didn't
actually support arbitrary file backends anymore, so renaming the class
makes it more obvious what the class is used for. This is also more in
line with the similarly named SandboxFileStreamWriter class.

Change-Id: Ic765c5ced831b25d249da1a60d2ca5b4a187b97b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2827420
Reviewed-by: Austin Sullivan <asully@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#872886}
  • Loading branch information
mkruisselbrink authored and Chromium LUCI CQ committed Apr 15, 2021
1 parent ba6ef97 commit d696dd1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 40 deletions.
6 changes: 3 additions & 3 deletions storage/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ component("browser") {
"file_system/file_system_context.h",
"file_system/file_system_features.cc",
"file_system/file_system_features.h",
"file_system/file_system_file_stream_reader.cc",
"file_system/file_system_file_stream_reader.h",
"file_system/file_system_file_util.cc",
"file_system/file_system_file_util.h",
"file_system/file_system_operation.h",
Expand Down Expand Up @@ -162,6 +160,8 @@ component("browser") {
"file_system/remove_operation_delegate.h",
"file_system/sandbox_directory_database.cc",
"file_system/sandbox_directory_database.h",
"file_system/sandbox_file_stream_reader.cc",
"file_system/sandbox_file_stream_reader.h",
"file_system/sandbox_file_stream_writer.cc",
"file_system/sandbox_file_stream_writer.h",
"file_system/sandbox_file_system_backend.cc",
Expand Down Expand Up @@ -295,7 +295,6 @@ source_set("unittests") {
"file_system/file_stream_writer_test.cc",
"file_system/file_stream_writer_test.h",
"file_system/file_system_context_unittest.cc",
"file_system/file_system_file_stream_reader_unittest.cc",
"file_system/file_system_operation_impl_unittest.cc",
"file_system/file_system_operation_impl_write_unittest.cc",
"file_system/file_system_quota_client_unittest.cc",
Expand All @@ -317,6 +316,7 @@ source_set("unittests") {
"file_system/quota/quota_reservation_manager_unittest.cc",
"file_system/recursive_operation_delegate_unittest.cc",
"file_system/sandbox_directory_database_unittest.cc",
"file_system/sandbox_file_stream_reader_unittest.cc",
"file_system/sandbox_file_stream_writer_unittest.cc",
"file_system/sandbox_file_system_backend_delegate_unittest.cc",
"file_system/sandbox_file_system_backend_unittest.cc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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/file_system_file_stream_reader.h"
#include "storage/browser/file_system/sandbox_file_stream_reader.h"

#include <stdint.h>

Expand All @@ -28,11 +28,11 @@ std::unique_ptr<FileStreamReader> FileStreamReader::CreateForFileSystemFile(
const FileSystemURL& url,
int64_t initial_offset,
const base::Time& expected_modification_time) {
return base::WrapUnique(new FileSystemFileStreamReader(
return base::WrapUnique(new SandboxFileStreamReader(
file_system_context, url, initial_offset, expected_modification_time));
}

FileSystemFileStreamReader::FileSystemFileStreamReader(
SandboxFileStreamReader::SandboxFileStreamReader(
FileSystemContext* file_system_context,
const FileSystemURL& url,
int64_t initial_offset,
Expand All @@ -45,11 +45,11 @@ FileSystemFileStreamReader::FileSystemFileStreamReader(
expected_modification_time_(expected_modification_time),
has_pending_create_snapshot_(false) {}

FileSystemFileStreamReader::~FileSystemFileStreamReader() = default;
SandboxFileStreamReader::~SandboxFileStreamReader() = default;

int FileSystemFileStreamReader::Read(net::IOBuffer* buf,
int buf_len,
net::CompletionOnceCallback callback) {
int SandboxFileStreamReader::Read(net::IOBuffer* buf,
int buf_len,
net::CompletionOnceCallback callback) {
if (file_reader_)
return file_reader_->Read(buf, buf_len, std::move(callback));

Expand All @@ -59,7 +59,7 @@ int FileSystemFileStreamReader::Read(net::IOBuffer* buf,
return CreateSnapshot();
}

int64_t FileSystemFileStreamReader::GetLength(
int64_t SandboxFileStreamReader::GetLength(
net::Int64CompletionOnceCallback callback) {
if (file_reader_)
return file_reader_->GetLength(std::move(callback));
Expand All @@ -68,16 +68,16 @@ int64_t FileSystemFileStreamReader::GetLength(
return CreateSnapshot();
}

int FileSystemFileStreamReader::CreateSnapshot() {
int SandboxFileStreamReader::CreateSnapshot() {
DCHECK(!has_pending_create_snapshot_);
has_pending_create_snapshot_ = true;
file_system_context_->operation_runner()->CreateSnapshotFile(
url_, base::BindOnce(&FileSystemFileStreamReader::DidCreateSnapshot,
url_, base::BindOnce(&SandboxFileStreamReader::DidCreateSnapshot,
weak_factory_.GetWeakPtr()));
return net::ERR_IO_PENDING;
}

void FileSystemFileStreamReader::DidCreateSnapshot(
void SandboxFileStreamReader::DidCreateSnapshot(
base::File::Error file_error,
const base::File::Info& file_info,
const base::FilePath& platform_path,
Expand Down Expand Up @@ -124,24 +124,24 @@ void FileSystemFileStreamReader::DidCreateSnapshot(
if (read_callback_) {
DCHECK(!get_length_callback_);
int rv = Read(read_buf_, read_buf_len_,
base::BindOnce(&FileSystemFileStreamReader::OnRead,
base::BindOnce(&SandboxFileStreamReader::OnRead,
weak_factory_.GetWeakPtr()));
if (rv != net::ERR_IO_PENDING)
std::move(read_callback_).Run(rv);
return;
}

int64_t rv = file_reader_->GetLength(base::BindOnce(
&FileSystemFileStreamReader::OnGetLength, weak_factory_.GetWeakPtr()));
&SandboxFileStreamReader::OnGetLength, weak_factory_.GetWeakPtr()));
if (rv != net::ERR_IO_PENDING)
std::move(get_length_callback_).Run(rv);
}

void FileSystemFileStreamReader::OnRead(int rv) {
void SandboxFileStreamReader::OnRead(int rv) {
std::move(read_callback_).Run(rv);
}

void FileSystemFileStreamReader::OnGetLength(int64_t rv) {
void SandboxFileStreamReader::OnGetLength(int64_t rv) {
std::move(get_length_callback_).Run(rv);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_FILE_STREAM_READER_H_
#define STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_FILE_STREAM_READER_H_
#ifndef STORAGE_BROWSER_FILE_SYSTEM_SANDBOX_FILE_STREAM_READER_H_
#define STORAGE_BROWSER_FILE_SYSTEM_SANDBOX_FILE_STREAM_READER_H_

#include <stdint.h>

Expand All @@ -28,15 +28,17 @@ namespace storage {

class FileSystemContext;

// Generic FileStreamReader implementation for FileSystem files.
// Note: This generic implementation would work for any filesystems but
// remote filesystem should implement its own reader rather than relying
// on FileSystemOperation::GetSnapshotFile() which may force downloading
// the entire contents for remote files.
class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemFileStreamReader
// FileStreamReader implementation for Sandboxed FileSystem files.
// This wraps either a LocalFileStreamReader or a MemoryFileStreamReader,
// depending on if we're in an incognito profile or not.
class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxFileStreamReader
: public FileStreamReader {
public:
~FileSystemFileStreamReader() override;
SandboxFileStreamReader(FileSystemContext* file_system_context,
const FileSystemURL& url,
int64_t initial_offset,
const base::Time& expected_modification_time);
~SandboxFileStreamReader() override;

// FileStreamReader overrides.
int Read(net::IOBuffer* buf,
Expand All @@ -46,12 +48,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemFileStreamReader

private:
friend class FileStreamReader;
friend class FileSystemFileStreamReaderTest;

FileSystemFileStreamReader(FileSystemContext* file_system_context,
const FileSystemURL& url,
int64_t initial_offset,
const base::Time& expected_modification_time);

int CreateSnapshot();
void DidCreateSnapshot(base::File::Error file_error,
Expand All @@ -72,11 +68,11 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemFileStreamReader
std::unique_ptr<FileStreamReader> file_reader_;
scoped_refptr<ShareableFileReference> snapshot_ref_;
bool has_pending_create_snapshot_;
base::WeakPtrFactory<FileSystemFileStreamReader> weak_factory_{this};
base::WeakPtrFactory<SandboxFileStreamReader> weak_factory_{this};

DISALLOW_COPY_AND_ASSIGN(FileSystemFileStreamReader);
DISALLOW_COPY_AND_ASSIGN(SandboxFileStreamReader);
};

} // namespace storage

#endif // STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_FILE_STREAM_READER_H_
#endif // STORAGE_BROWSER_FILE_SYSTEM_SANDBOX_FILE_STREAM_READER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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/file_system_file_stream_reader.h"
#include "storage/browser/file_system/sandbox_file_stream_reader.h"

#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -38,9 +38,9 @@ namespace {
const char kURLOrigin[] = "http://remote/";
} // namespace

class FileSystemFileStreamReaderTest : public FileStreamReaderTest {
class SandboxFileStreamReaderTest : public FileStreamReaderTest {
public:
FileSystemFileStreamReaderTest() = default;
SandboxFileStreamReaderTest() = default;

void SetUp() override {
ASSERT_TRUE(dir_.CreateUniqueTempDir());
Expand Down Expand Up @@ -113,6 +113,6 @@ class FileSystemFileStreamReaderTest : public FileStreamReaderTest {

INSTANTIATE_TYPED_TEST_SUITE_P(FileSystem,
FileStreamReaderTypedTest,
FileSystemFileStreamReaderTest);
SandboxFileStreamReaderTest);

} // namespace storage

0 comments on commit d696dd1

Please sign in to comment.