Commit bf8a1b65 authored by Adrienne Walker's avatar Adrienne Walker Committed by Commit Bot

Refactor LocalFileStreamReader to look like the FilesystemProxy version

This is a followup to this patch:
https://chromium-review.googlesource.com/c/chromium/src/+/2412834

...to make the same changes to LocalFileStreamReader that were requested
for the FilesystemProxyFileStreamReader in that review.

Bug: 1119547
Change-Id: Ibaccd858c807969eb185012add8ab01fed4aad33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422271
Auto-Submit: enne <enne@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: enne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809428}
parent 439ce5f9
......@@ -26,29 +26,15 @@ namespace {
const int kOpenFlagsForRead =
base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_ASYNC;
struct GetFileInfoResults {
base::File::Error error;
base::File::Info info;
};
using GetFileInfoCallback =
base::OnceCallback<void(base::File::Error, const base::File::Info&)>;
GetFileInfoResults DoGetFileInfo(const base::FilePath& path) {
GetFileInfoResults results;
if (!base::PathExists(path)) {
results.error = base::File::FILE_ERROR_NOT_FOUND;
return results;
}
results.error = base::GetFileInfo(path, &results.info)
? base::File::FILE_OK
: base::File::FILE_ERROR_FAILED;
return results;
}
FileErrorOr<base::File::Info> DoGetFileInfo(const base::FilePath& path) {
if (!base::PathExists(path))
return base::File::FILE_ERROR_NOT_FOUND;
void SendGetFileInfoResults(GetFileInfoCallback callback,
const GetFileInfoResults& results) {
std::move(callback).Run(results.error, results.info);
base::File::Info info;
bool success = base::GetFileInfo(path, &info);
if (!success)
return base::File::FILE_ERROR_FAILED;
return info;
}
} // namespace
......@@ -84,10 +70,8 @@ int64_t LocalFileStreamReader::GetLength(
net::Int64CompletionOnceCallback callback) {
bool posted = base::PostTaskAndReplyWithResult(
task_runner_.get(), FROM_HERE, base::BindOnce(&DoGetFileInfo, file_path_),
base::BindOnce(
&SendGetFileInfoResults,
base::BindOnce(&LocalFileStreamReader::DidGetFileInfoForGetLength,
weak_factory_.GetWeakPtr(), std::move(callback))));
weak_factory_.GetWeakPtr(), std::move(callback)));
DCHECK(posted);
return net::ERR_IO_PENDING;
}
......@@ -182,14 +166,14 @@ void LocalFileStreamReader::DidOpenForRead(net::IOBuffer* buf,
void LocalFileStreamReader::DidGetFileInfoForGetLength(
net::Int64CompletionOnceCallback callback,
base::File::Error error,
const base::File::Info& file_info) {
if (file_info.is_directory) {
std::move(callback).Run(net::ERR_FILE_NOT_FOUND);
FileErrorOr<base::File::Info> result) {
if (result.is_error()) {
std::move(callback).Run(net::FileErrorToNetError(result.error()));
return;
}
if (error != base::File::FILE_OK) {
std::move(callback).Run(net::FileErrorToNetError(error));
const auto& file_info = result.value();
if (file_info.is_directory) {
std::move(callback).Run(net::ERR_FILE_NOT_FOUND);
return;
}
if (!VerifySnapshotTime(expected_modification_time_, file_info)) {
......
......@@ -63,8 +63,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) LocalFileStreamReader
void OnRead(int read_result);
void DidGetFileInfoForGetLength(net::Int64CompletionOnceCallback callback,
base::File::Error error,
const base::File::Info& file_info);
FileErrorOr<base::File::Info> result);
net::CompletionOnceCallback callback_;
scoped_refptr<base::TaskRunner> task_runner_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment