Skip to content
Permalink
Browse files

[NativeFS] Interact with FileSystemOperationRunner via base::Sequence…

…Bound.

This is in preparation for migrating native file system code to the UI
thread, and decoupling it from whatever thread file system backend code
actually wants to be called on.

Bug: 1011534
Change-Id: I9d956dac5761380654842cdd07b67e1c7c2000d3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841764
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: Olivier Yiptong <oyiptong@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704907}
  • Loading branch information
mkruisselbrink authored and Commit Bot committed Oct 11, 2019
1 parent e84fbe9 commit 7ee94745224ecff9840fc0237b2a8971d446f049
@@ -24,6 +24,7 @@ using blink::mojom::NativeFileSystemEntryPtr;
using blink::mojom::NativeFileSystemHandle;
using blink::mojom::NativeFileSystemStatus;
using blink::mojom::NativeFileSystemTransferToken;
using storage::FileSystemOperationRunner;

namespace content {

@@ -116,11 +117,12 @@ void NativeFileSystemDirectoryHandleImpl::GetFile(const std::string& basename,
}),
std::move(callback));
} else {
operation_runner()->FileExists(
child_url,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::FileExists,
base::BindOnce(&NativeFileSystemDirectoryHandleImpl::DidGetFile,
weak_factory_.GetWeakPtr(), child_url,
std::move(callback)));
std::move(callback)),
child_url);
}
}

@@ -162,23 +164,26 @@ void NativeFileSystemDirectoryHandleImpl::GetDirectory(
}),
std::move(callback));
} else {
operation_runner()->DirectoryExists(
child_url,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::DirectoryExists,
base::BindOnce(&NativeFileSystemDirectoryHandleImpl::DidGetDirectory,
weak_factory_.GetWeakPtr(), child_url,
std::move(callback)));
std::move(callback)),
child_url);
}
}

void NativeFileSystemDirectoryHandleImpl::GetEntries(
GetEntriesCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

operation_runner()->ReadDirectory(
url(), base::BindRepeating(
&NativeFileSystemDirectoryHandleImpl::DidReadDirectory,
weak_factory_.GetWeakPtr(),
base::Owned(new ReadDirectoryState{std::move(callback)})));
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::ReadDirectory,
base::BindRepeating(
&NativeFileSystemDirectoryHandleImpl::DidReadDirectory,
weak_factory_.GetWeakPtr(),
base::Owned(new ReadDirectoryState{std::move(callback)})),
url());
}

void NativeFileSystemDirectoryHandleImpl::RemoveEntry(
@@ -219,11 +224,13 @@ void NativeFileSystemDirectoryHandleImpl::GetFileWithWritePermission(
DCHECK_EQ(GetWritePermissionStatus(),
blink::mojom::PermissionStatus::GRANTED);

operation_runner()->CreateFile(
child_url, /*exclusive=*/false,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::CreateFile,
base::BindOnce(&NativeFileSystemDirectoryHandleImpl::DidGetFile,
weak_factory_.GetWeakPtr(), child_url,
std::move(callback)));
std::move(callback)),
child_url,
/*exclusive=*/false);
}

void NativeFileSystemDirectoryHandleImpl::DidGetFile(
@@ -250,11 +257,13 @@ void NativeFileSystemDirectoryHandleImpl::GetDirectoryWithWritePermission(
DCHECK_EQ(GetWritePermissionStatus(),
blink::mojom::PermissionStatus::GRANTED);

operation_runner()->CreateDirectory(
child_url, /*exclusive=*/false, /*recursive=*/false,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::CreateDirectory,
base::BindOnce(&NativeFileSystemDirectoryHandleImpl::DidGetDirectory,
weak_factory_.GetWeakPtr(), child_url,
std::move(callback)));
std::move(callback)),
child_url,
/*exclusive=*/false, /*recursive=*/false);
}

void NativeFileSystemDirectoryHandleImpl::DidGetDirectory(
@@ -320,14 +329,15 @@ void NativeFileSystemDirectoryHandleImpl::RemoveEntryImpl(
DCHECK_EQ(GetWritePermissionStatus(),
blink::mojom::PermissionStatus::GRANTED);

operation_runner()->Remove(
url, recurse,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::Remove,
base::BindOnce(
[](RemoveEntryCallback callback, base::File::Error result) {
std::move(callback).Run(
native_file_system_error::FromFileError(result));
},
std::move(callback)));
std::move(callback)),
url, recurse);
}

blink::mojom::NativeFileSystemErrorPtr
@@ -23,6 +23,7 @@ using blink::mojom::NativeFileSystemStatus;
using storage::BlobDataHandle;
using storage::BlobImpl;
using storage::FileSystemOperation;
using storage::FileSystemOperationRunner;
using storage::IsolatedContext;

namespace content {
@@ -63,13 +64,14 @@ void NativeFileSystemFileHandleImpl::AsBlob(AsBlobCallback callback) {

// TODO(mek): Check backend::SupportsStreaming and create snapshot file if
// streaming is not supported.
operation_runner()->GetMetadata(
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::GetMetadata,
base::BindOnce(&NativeFileSystemFileHandleImpl::DidGetMetaDataForBlob,
weak_factory_.GetWeakPtr(), std::move(callback)),
url(),
FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY |
FileSystemOperation::GET_METADATA_FIELD_SIZE |
FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED,
base::BindOnce(&NativeFileSystemFileHandleImpl::DidGetMetaDataForBlob,
weak_factory_.GetWeakPtr(), std::move(callback)));
FileSystemOperation::GET_METADATA_FIELD_LAST_MODIFIED);
}

void NativeFileSystemFileHandleImpl::CreateFileWriter(
@@ -229,13 +231,13 @@ void NativeFileSystemFileHandleImpl::CreateSwapFile(
swap_file_system = std::move(handle.file_system);
}

operation_runner()->CreateFile(
swap_url,
/*exclusive=*/true,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::CreateFile,
base::BindOnce(&NativeFileSystemFileHandleImpl::DidCreateSwapFile,
weak_factory_.GetWeakPtr(), count, swap_url,
swap_file_system, keep_existing_data,
std::move(callback)));
swap_file_system, keep_existing_data, std::move(callback)),
swap_url,
/*exclusive=*/true);
}

void NativeFileSystemFileHandleImpl::DidCreateSwapFile(
@@ -273,14 +275,15 @@ void NativeFileSystemFileHandleImpl::DidCreateSwapFile(
return;
}

operation_runner()->Copy(
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::Copy,
base::BindOnce(&NativeFileSystemFileHandleImpl::DidCopySwapFile,
weak_factory_.GetWeakPtr(), swap_url, swap_file_system,
std::move(callback)),
url(), swap_url,
storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED,
storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT,
storage::FileSystemOperation::CopyProgressCallback(),
base::BindOnce(&NativeFileSystemFileHandleImpl::DidCopySwapFile,
weak_factory_.GetWeakPtr(), swap_url, swap_file_system,
std::move(callback)));
storage::FileSystemOperation::CopyProgressCallback());
}

void NativeFileSystemFileHandleImpl::DidCopySwapFile(
@@ -72,6 +72,8 @@ class NativeFileSystemFileHandleImplTest : public testing::Test {
allow_grant_, allow_grant_, /*file_system=*/{}));
}

void TearDown() override { task_environment_.RunUntilIdle(); }

std::string ReadFile(const FileSystemURL& url) {
std::unique_ptr<storage::FileStreamReader> reader =
file_system_context_->CreateFileStreamReader(
@@ -20,6 +20,7 @@
using blink::mojom::NativeFileSystemStatus;
using storage::BlobDataHandle;
using storage::FileSystemOperation;
using storage::FileSystemOperationRunner;

namespace {

@@ -98,17 +99,19 @@ NativeFileSystemFileWriterImpl::NativeFileSystemFileWriterImpl(

NativeFileSystemFileWriterImpl::~NativeFileSystemFileWriterImpl() {
if (can_purge()) {
manager()->operation_runner()->RemoveFile(
swap_url(), base::BindOnce(
[](const storage::FileSystemURL& swap_url,
base::File::Error result) {
if (result != base::File::FILE_OK) {
DLOG(ERROR) << "Error Deleting Swap File, status: "
<< base::File::ErrorToString(result)
<< " path: " << swap_url.path();
}
},
swap_url()));
DoFileSystemOperation(FROM_HERE, &FileSystemOperationRunner::RemoveFile,
base::BindOnce(
[](const storage::FileSystemURL& swap_url,
base::File::Error result) {
if (result != base::File::FILE_OK) {
DLOG(ERROR)
<< "Error Deleting Swap File, status: "
<< base::File::ErrorToString(result)
<< " path: " << swap_url.path();
}
},
swap_url()),
swap_url());
}
}

@@ -210,11 +213,12 @@ void NativeFileSystemFileWriterImpl::DoWriteBlob(
return;
}

operation_runner()->Write(
swap_url(), std::move(blob), position,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::Write,
base::BindRepeating(&NativeFileSystemFileWriterImpl::DidWrite,
weak_factory_.GetWeakPtr(),
base::Owned(new WriteState{std::move(callback)})));
base::Owned(new WriteState{std::move(callback)})),
swap_url(), std::move(blob), position);
}

void NativeFileSystemFileWriterImpl::WriteStreamImpl(
@@ -234,11 +238,12 @@ void NativeFileSystemFileWriterImpl::WriteStreamImpl(
return;
}

operation_runner()->Write(
swap_url(), std::move(stream), offset,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::WriteStream,
base::BindRepeating(&NativeFileSystemFileWriterImpl::DidWrite,
weak_factory_.GetWeakPtr(),
base::Owned(new WriteState{std::move(callback)})));
base::Owned(new WriteState{std::move(callback)})),
swap_url(), std::move(stream), offset);
}

void NativeFileSystemFileWriterImpl::DidWrite(WriteState* state,
@@ -269,14 +274,15 @@ void NativeFileSystemFileWriterImpl::TruncateImpl(uint64_t length,
return;
}

operation_runner()->Truncate(
swap_url(), length,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::Truncate,
base::BindOnce(
[](TruncateCallback callback, base::File::Error result) {
std::move(callback).Run(
native_file_system_error::FromFileError(result));
},
std::move(callback)));
std::move(callback)),
swap_url(), length);
}

void NativeFileSystemFileWriterImpl::CloseImpl(CloseCallback callback) {
@@ -372,11 +378,12 @@ void NativeFileSystemFileWriterImpl::DidPassAfterWriteCheck(
// will not exist anymore.
// In case of error, the swap file URL will point to a valid filesystem
// location. The file at this URL will be deleted when the mojo pipe closes.
operation_runner()->Move(
swap_url(), url(),
storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED,
DoFileSystemOperation(
FROM_HERE, &FileSystemOperationRunner::Move,
base::BindOnce(&NativeFileSystemFileWriterImpl::DidSwapFileBeforeClose,
weak_factory_.GetWeakPtr(), std::move(callback)));
weak_factory_.GetWeakPtr(), std::move(callback)),
swap_url(), url(),
storage::FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED);
}

void NativeFileSystemFileWriterImpl::DidSwapFileBeforeClose(
@@ -109,6 +109,9 @@ class NativeFileSystemFileWriterImplTest : public testing::Test {
}

void TearDown() override {
handle_.reset();
manager_.reset();

task_environment_.RunUntilIdle();
EXPECT_TRUE(dir_.Delete());
}

0 comments on commit 7ee9474

Please sign in to comment.
You can’t perform that action at this time.