diff options
Diffstat (limited to 'net/base/file_stream_context.cc')
-rw-r--r-- | net/base/file_stream_context.cc | 101 |
1 files changed, 38 insertions, 63 deletions
diff --git a/net/base/file_stream_context.cc b/net/base/file_stream_context.cc index 092302f..53f3c3d 100644 --- a/net/base/file_stream_context.cc +++ b/net/base/file_stream_context.cc @@ -22,32 +22,6 @@ void CallInt64ToInt(const net::CompletionCallback& callback, int64 result) { namespace net { -FileStream::Context::IOResult::IOResult() - : result(OK), - os_error(0) { -} - -FileStream::Context::IOResult::IOResult(int64 result, int os_error) - : result(result), - os_error(os_error) { -} - -// static -FileStream::Context::IOResult FileStream::Context::IOResult::FromOSError( - int64 os_error) { - return IOResult(MapSystemError(os_error), os_error); -} - -FileStream::Context::OpenResult::OpenResult() - : file(base::kInvalidPlatformFileValue) { -} - -FileStream::Context::OpenResult::OpenResult(base::PlatformFile file, - IOResult error_code) - : file(file), - error_code(error_code) { -} - void FileStream::Context::Orphan() { DCHECK(!orphaned_); @@ -88,14 +62,14 @@ int FileStream::Context::OpenSync(const base::FilePath& path, int open_flags) { OpenResult result = OpenFileImpl(path, open_flags); file_ = result.file; if (file_ == base::kInvalidPlatformFileValue) { - ProcessOpenError(result.error_code); + result.error_code = ProcessOpenError(result.error_code); } else { // TODO(satorux): Remove this once all async clients are migrated to use // Open(). crbug.com/114783 if (open_flags & base::PLATFORM_FILE_ASYNC) OnAsyncFileOpened(); } - return result.error_code.result; + return result.error_code; } void FileStream::Context::CloseSync() { @@ -125,9 +99,9 @@ void FileStream::Context::SeekAsync(Whence whence, } int64 FileStream::Context::SeekSync(Whence whence, int64 offset) { - IOResult result = SeekFileImpl(whence, offset); - RecordError(result, FILE_ERROR_SOURCE_SEEK); - return result.result; + int64 result = SeekFileImpl(whence, offset); + CheckForIOError(&result, FILE_ERROR_SOURCE_SEEK); + return result; } void FileStream::Context::FlushAsync(const CompletionCallback& callback) { @@ -147,32 +121,26 @@ void FileStream::Context::FlushAsync(const CompletionCallback& callback) { } int FileStream::Context::FlushSync() { - IOResult result = FlushFileImpl(); - RecordError(result, FILE_ERROR_SOURCE_FLUSH); - return result.result; + int64 result = FlushFileImpl(); + CheckForIOError(&result, FILE_ERROR_SOURCE_FLUSH); + return result; } -void FileStream::Context::RecordError(const IOResult& result, - FileErrorSource source) const { - if (result.result >= 0) { - // |result| is not an error. - return; - } - +int FileStream::Context::RecordAndMapError(int error, + FileErrorSource source) const { // The following check is against incorrect use or bug. File descriptor // shouldn't ever be closed outside of FileStream while it still tries to do // something with it. - DCHECK_NE(result.result, ERR_INVALID_HANDLE); + DCHECK(error != ERROR_BAD_FILE); + Error net_error = MapSystemError(error); if (!orphaned_) { - bound_net_log_.AddEvent( - NetLog::TYPE_FILE_STREAM_ERROR, - base::Bind(&NetLogFileStreamErrorCallback, - source, result.os_error, - static_cast<net::Error>(result.result))); + bound_net_log_.AddEvent(NetLog::TYPE_FILE_STREAM_ERROR, + base::Bind(&NetLogFileStreamErrorCallback, + source, error, net_error)); } - - RecordFileError(result.os_error, source, record_uma_); + RecordFileError(error, source, record_uma_); + return net_error; } void FileStream::Context::BeginOpenEvent(const base::FilePath& path) { @@ -188,27 +156,28 @@ FileStream::Context::OpenResult FileStream::Context::OpenFileImpl( // delete the file right after FileStream deletion. Thus we are always // adding SHARE_DELETE flag to accommodate such use case. open_flags |= base::PLATFORM_FILE_SHARE_DELETE; - base::PlatformFile file = - base::CreatePlatformFile(path, open_flags, NULL, NULL); - if (file == base::kInvalidPlatformFileValue) - return OpenResult(file, IOResult::FromOSError(GetLastErrno())); + OpenResult result; + result.error_code = OK; + result.file = base::CreatePlatformFile(path, open_flags, NULL, NULL); + if (result.file == base::kInvalidPlatformFileValue) + result.error_code = GetLastErrno(); - return OpenResult(file, IOResult(OK, 0)); + return result; } -void FileStream::Context::ProcessOpenError(const IOResult& error_code) { +int FileStream::Context::ProcessOpenError(int error_code) { bound_net_log_.EndEvent(NetLog::TYPE_FILE_STREAM_OPEN); - RecordError(error_code, FILE_ERROR_SOURCE_OPEN); + return RecordAndMapError(error_code, FILE_ERROR_SOURCE_OPEN); } void FileStream::Context::OnOpenCompleted(const CompletionCallback& callback, - OpenResult open_result) { - file_ = open_result.file; + OpenResult result) { + file_ = result.file; if (file_ == base::kInvalidPlatformFileValue) - ProcessOpenError(open_result.error_code); + result.error_code = ProcessOpenError(result.error_code); else if (!orphaned_) OnAsyncFileOpened(); - OnAsyncCompleted(IntToInt64(callback), open_result.error_code.result); + OnAsyncCompleted(IntToInt64(callback), result.error_code); } void FileStream::Context::CloseAndDelete() { @@ -236,12 +205,18 @@ Int64CompletionCallback FileStream::Context::IntToInt64( return base::Bind(&CallInt64ToInt, callback); } +void FileStream::Context::CheckForIOError(int64* result, + FileErrorSource source) { + if (*result < 0) + *result = RecordAndMapError(static_cast<int>(*result), source); +} + void FileStream::Context::ProcessAsyncResult( const Int64CompletionCallback& callback, FileErrorSource source, - const IOResult& result) { - RecordError(result, source); - OnAsyncCompleted(callback, result.result); + int64 result) { + CheckForIOError(&result, source); + OnAsyncCompleted(callback, result); } void FileStream::Context::OnAsyncCompleted( |