summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-04 00:00:54 +0000
committerahendrickson@chromium.org <ahendrickson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-04 00:00:54 +0000
commit33c6d3f12211d716768ab195be90d598cd2bd364 (patch)
tree58af1d1690f995e8e4bf0e03fab379b9940f9946 /net
parentdeac4290c3fd825f6f3000e89d67d4ac8a190371 (diff)
downloadchromium_src-33c6d3f12211d716768ab195be90d598cd2bd364.zip
chromium_src-33c6d3f12211d716768ab195be90d598cd2bd364.tar.gz
chromium_src-33c6d3f12211d716768ab195be90d598cd2bd364.tar.bz2
Make BaseFile member functions return net::Error's.
Moving towards giving the user feedback when a file system error occurs during a download. Split from CL 7134019. rdsmith: downloads phajdan.jr: downloads, base wtc: net brettw: base BUG=None TEST=None Review URL: http://codereview.chromium.org/7778003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/file_stream_posix.cc33
-rw-r--r--net/base/file_stream_win.cc31
-rw-r--r--net/base/net_error_list.h12
-rw-r--r--net/base/net_errors_posix.cc53
-rw-r--r--net/base/net_errors_win.cc59
5 files changed, 140 insertions, 48 deletions
diff --git a/net/base/file_stream_posix.cc b/net/base/file_stream_posix.cc
index 68732e3..ed0f4d6 100644
--- a/net/base/file_stream_posix.cc
+++ b/net/base/file_stream_posix.cc
@@ -47,21 +47,8 @@ COMPILE_ASSERT(FROM_BEGIN == SEEK_SET &&
namespace {
-// Map from errno to net error codes.
-int64 MapErrorCode(int err) {
- switch (err) {
- case ENOENT:
- return ERR_FILE_NOT_FOUND;
- case EACCES:
- return ERR_ACCESS_DENIED;
- default:
- LOG(WARNING) << "Unknown error " << err << " mapped to net::ERR_FAILED";
- return ERR_FAILED;
- }
-}
-
// ReadFile() is a simple wrapper around read() that handles EINTR signals and
-// calls MapErrorCode() to map errno to net error codes.
+// calls MapSystemError() to map errno to net error codes.
int ReadFile(base::PlatformFile file, char* buf, int buf_len) {
base::ThreadRestrictions::AssertIOAllowed();
// read(..., 0) returns 0 to indicate end-of-file.
@@ -69,7 +56,7 @@ int ReadFile(base::PlatformFile file, char* buf, int buf_len) {
// Loop in the case of getting interrupted by a signal.
ssize_t res = HANDLE_EINTR(read(file, buf, static_cast<size_t>(buf_len)));
if (res == static_cast<ssize_t>(-1))
- return MapErrorCode(errno);
+ return MapSystemError(errno);
return static_cast<int>(res);
}
@@ -81,13 +68,13 @@ void ReadFileTask(base::PlatformFile file,
}
// WriteFile() is a simple wrapper around write() that handles EINTR signals and
-// calls MapErrorCode() to map errno to net error codes. It tries to write to
+// calls MapSystemError() to map errno to net error codes. It tries to write to
// completion.
int WriteFile(base::PlatformFile file, const char* buf, int buf_len) {
base::ThreadRestrictions::AssertIOAllowed();
ssize_t res = HANDLE_EINTR(write(file, buf, buf_len));
if (res == -1)
- return MapErrorCode(errno);
+ return MapSystemError(errno);
return res;
}
@@ -99,13 +86,13 @@ void WriteFileTask(base::PlatformFile file,
}
// FlushFile() is a simple wrapper around fsync() that handles EINTR signals and
-// calls MapErrorCode() to map errno to net error codes. It tries to flush to
+// calls MapSystemError() to map errno to net error codes. It tries to flush to
// completion.
int FlushFile(base::PlatformFile file) {
base::ThreadRestrictions::AssertIOAllowed();
ssize_t res = HANDLE_EINTR(fsync(file));
if (res == -1)
- return MapErrorCode(errno);
+ return MapSystemError(errno);
return res;
}
@@ -315,7 +302,7 @@ int FileStream::Open(const FilePath& path, int open_flags) {
open_flags_ = open_flags;
file_ = base::CreatePlatformFile(path, open_flags_, NULL, NULL);
if (file_ == base::kInvalidPlatformFileValue) {
- return MapErrorCode(errno);
+ return MapSystemError(errno);
}
if (open_flags_ & base::PLATFORM_FILE_ASYNC) {
@@ -341,7 +328,7 @@ int64 FileStream::Seek(Whence whence, int64 offset) {
off_t res = lseek(file_, static_cast<off_t>(offset),
static_cast<int>(whence));
if (res == static_cast<off_t>(-1))
- return MapErrorCode(errno);
+ return MapSystemError(errno);
return res;
}
@@ -358,7 +345,7 @@ int64 FileStream::Available() {
struct stat info;
if (fstat(file_, &info) != 0)
- return MapErrorCode(errno);
+ return MapSystemError(errno);
int64 size = static_cast<int64>(info.st_size);
DCHECK_GT(size, cur_pos);
@@ -442,7 +429,7 @@ int64 FileStream::Truncate(int64 bytes) {
// And truncate the file.
int result = ftruncate(file_, bytes);
- return result == 0 ? seek_position : MapErrorCode(errno);
+ return result == 0 ? seek_position : MapSystemError(errno);
}
int FileStream::Flush() {
diff --git a/net/base/file_stream_win.cc b/net/base/file_stream_win.cc
index c08521e..314687e 100644
--- a/net/base/file_stream_win.cc
+++ b/net/base/file_stream_win.cc
@@ -33,21 +33,6 @@ static void IncrementOffset(OVERLAPPED* overlapped, DWORD count) {
SetOffset(overlapped, offset);
}
-static int MapErrorCode(DWORD err) {
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- return ERR_FILE_NOT_FOUND;
- case ERROR_ACCESS_DENIED:
- return ERR_ACCESS_DENIED;
- case ERROR_SUCCESS:
- return OK;
- default:
- LOG(WARNING) << "Unknown error " << err << " mapped to net::ERR_FAILED";
- return ERR_FAILED;
- }
-}
-
// FileStream::AsyncContext ----------------------------------------------
class FileStream::AsyncContext : public MessageLoopForIO::IOHandler {
@@ -106,7 +91,7 @@ void FileStream::AsyncContext::OnIOCompleted(
int result = static_cast<int>(bytes_read);
if (error && error != ERROR_HANDLE_EOF)
- result = MapErrorCode(error);
+ result = MapSystemError(error);
if (bytes_read)
IncrementOffset(&context->overlapped, bytes_read);
@@ -164,7 +149,7 @@ int FileStream::Open(const FilePath& path, int open_flags) {
if (file_ == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
LOG(WARNING) << "Failed to open file: " << error;
- return MapErrorCode(error);
+ return MapSystemError(error);
}
if (open_flags_ & base::PLATFORM_FILE_ASYNC) {
@@ -191,7 +176,7 @@ int64 FileStream::Seek(Whence whence, int64 offset) {
if (!SetFilePointerEx(file_, distance, &result, move_method)) {
DWORD error = GetLastError();
LOG(WARNING) << "SetFilePointerEx failed: " << error;
- return MapErrorCode(error);
+ return MapSystemError(error);
}
if (async_context_.get())
SetOffset(async_context_->overlapped(), result);
@@ -212,7 +197,7 @@ int64 FileStream::Available() {
if (!GetFileSizeEx(file_, &file_size)) {
DWORD error = GetLastError();
LOG(WARNING) << "GetFileSizeEx failed: " << error;
- return MapErrorCode(error);
+ return MapSystemError(error);
}
return file_size.QuadPart - cur_pos;
@@ -246,7 +231,7 @@ int FileStream::Read(
rv = 0; // Report EOF by returning 0 bytes read.
} else {
LOG(WARNING) << "ReadFile failed: " << error;
- rv = MapErrorCode(error);
+ rv = MapSystemError(error);
}
} else if (overlapped) {
async_context_->IOCompletionIsPending(callback);
@@ -303,7 +288,7 @@ int FileStream::Write(
rv = ERR_IO_PENDING;
} else {
LOG(WARNING) << "WriteFile failed: " << error;
- rv = MapErrorCode(error);
+ rv = MapSystemError(error);
}
} else if (overlapped) {
async_context_->IOCompletionIsPending(callback);
@@ -327,7 +312,7 @@ int FileStream::Flush() {
int rv;
DWORD error = GetLastError();
- rv = MapErrorCode(error);
+ rv = MapSystemError(error);
return rv;
}
@@ -350,7 +335,7 @@ int64 FileStream::Truncate(int64 bytes) {
if (!result) {
DWORD error = GetLastError();
LOG(WARNING) << "SetEndOfFile failed: " << error;
- return MapErrorCode(error);
+ return MapSystemError(error);
}
// Success.
diff --git a/net/base/net_error_list.h b/net/base/net_error_list.h
index 5481933..8ef5fde 100644
--- a/net/base/net_error_list.h
+++ b/net/base/net_error_list.h
@@ -69,6 +69,18 @@ NET_ERROR(UPLOAD_FILE_CHANGED, -14)
// The socket is not connected.
NET_ERROR(SOCKET_NOT_CONNECTED, -15)
+// The file already exists.
+NET_ERROR(FILE_EXISTS, -16)
+
+// The path or file name is too long.
+NET_ERROR(FILE_PATH_TOO_LONG, -17)
+
+// Not enough room left on the disk.
+NET_ERROR(FILE_NO_SPACE, -18)
+
+// The file has a virus.
+NET_ERROR(FILE_VIRUS_INFECTED, -19)
+
// A connection was closed (corresponding to a TCP FIN).
NET_ERROR(CONNECTION_CLOSED, -100)
diff --git a/net/base/net_errors_posix.cc b/net/base/net_errors_posix.cc
index 31450f9..143912c 100644
--- a/net/base/net_errors_posix.cc
+++ b/net/base/net_errors_posix.cc
@@ -26,7 +26,7 @@ Error MapSystemError(int os_error) {
case ETIMEDOUT:
return ERR_TIMED_OUT;
case ECONNRESET:
- case ENETRESET: // Related to keep-alive
+ case ENETRESET: // Related to keep-alive.
case EPIPE:
return ERR_CONNECTION_RESET;
case ECONNABORTED:
@@ -48,6 +48,57 @@ Error MapSystemError(int os_error) {
return ERR_INVALID_ARGUMENT;
case EADDRINUSE:
return ERR_ADDRESS_IN_USE;
+ case E2BIG: // Argument list too long.
+ return ERR_INVALID_ARGUMENT;
+ case EBADF: // Bad file descriptor.
+ return ERR_INVALID_HANDLE;
+ case EBUSY: // Device or resource busy.
+ return ERR_INSUFFICIENT_RESOURCES;
+ case ECANCELED: // Operation canceled.
+ return ERR_ABORTED;
+ case EDEADLK: // Resource deadlock avoided.
+ return ERR_INSUFFICIENT_RESOURCES;
+ case EDQUOT: // Disk quota exceeded.
+ return ERR_FILE_NO_SPACE;
+ case EEXIST: // File exists.
+ return ERR_FILE_EXISTS;
+ case EFAULT: // Bad address.
+ return ERR_INVALID_ARGUMENT;
+ case EFBIG: // File too large.
+ return ERR_FILE_TOO_BIG;
+ case EISDIR: // Is a directory.
+ return ERR_FILE_NOT_FOUND;
+ case ENAMETOOLONG: // Filename too long.
+ return ERR_FILE_PATH_TOO_LONG;
+ case ENFILE: // Too many open files in system.
+ return ERR_INSUFFICIENT_RESOURCES;
+ case ENOBUFS: // No buffer space available.
+ return ERR_OUT_OF_MEMORY;
+ case ENODEV: // No such device.
+ return ERR_INVALID_ARGUMENT;
+ case ENOENT: // No such file or directory.
+ return ERR_FILE_NOT_FOUND;
+ case ENOLCK: // No locks available.
+ return ERR_INSUFFICIENT_RESOURCES;
+ case ENOMEM: // Not enough space.
+ return ERR_OUT_OF_MEMORY;
+ case ENOSPC: // No space left on device.
+ return ERR_FILE_NO_SPACE;
+ case ENOSYS: // Function not implemented.
+ return ERR_NOT_IMPLEMENTED;
+ case ENOTDIR: // Not a directory.
+ return ERR_FILE_NOT_FOUND;
+ case ENOTSUP: // Operation not supported.
+ return ERR_NOT_IMPLEMENTED;
+ case EPERM: // Operation not permitted.
+ return ERR_ACCESS_DENIED;
+ case EROFS: // Read-only file system.
+ return ERR_ACCESS_DENIED;
+ case ETXTBSY: // Text file busy.
+ return ERR_ACCESS_DENIED;
+ case EUSERS: // Too many users.
+ return ERR_INSUFFICIENT_RESOURCES;
+
case 0:
return OK;
default:
diff --git a/net/base/net_errors_win.cc b/net/base/net_errors_win.cc
index c290020..fcede60 100644
--- a/net/base/net_errors_win.cc
+++ b/net/base/net_errors_win.cc
@@ -10,7 +10,7 @@
namespace net {
-// Map winsock error to Chromium error.
+// Map winsock and system errors to Chromium errors.
Error MapSystemError(int os_error) {
// There are numerous Winsock error codes, but these are the ones we thus far
// find interesting.
@@ -48,6 +48,63 @@ Error MapSystemError(int os_error) {
return ERR_INVALID_ARGUMENT;
case WSAEADDRINUSE:
return ERR_ADDRESS_IN_USE;
+
+ // System errors.
+ case ERROR_FILE_NOT_FOUND: // The system cannot find the file specified.
+ return ERR_FILE_NOT_FOUND;
+ case ERROR_PATH_NOT_FOUND: // The system cannot find the path specified.
+ return ERR_FILE_NOT_FOUND;
+ case ERROR_TOO_MANY_OPEN_FILES: // The system cannot open the file.
+ return ERR_INSUFFICIENT_RESOURCES;
+ case ERROR_ACCESS_DENIED: // Access is denied.
+ return ERR_ACCESS_DENIED;
+ case ERROR_INVALID_HANDLE: // The handle is invalid.
+ return ERR_INVALID_HANDLE;
+ case ERROR_NOT_ENOUGH_MEMORY: // Not enough storage is available to
+ return ERR_OUT_OF_MEMORY; // process this command.
+ case ERROR_OUTOFMEMORY: // Not enough storage is available to complete
+ return ERR_OUT_OF_MEMORY; // this operation.
+ case ERROR_WRITE_PROTECT: // The media is write protected.
+ return ERR_ACCESS_DENIED;
+ case ERROR_SHARING_VIOLATION: // Cannot access the file because it is
+ return ERR_ACCESS_DENIED; // being used by another process.
+ case ERROR_LOCK_VIOLATION: // The process cannot access the file because
+ return ERR_ACCESS_DENIED; // another process has locked the file.
+ case ERROR_HANDLE_EOF: // Reached the end of the file.
+ return ERR_FAILED;
+ case ERROR_HANDLE_DISK_FULL: // The disk is full.
+ return ERR_FILE_NO_SPACE;
+ case ERROR_FILE_EXISTS: // The file exists.
+ return ERR_FILE_EXISTS;
+ case ERROR_INVALID_PARAMETER: // The parameter is incorrect.
+ return ERR_INVALID_ARGUMENT;
+ case ERROR_BUFFER_OVERFLOW: // The file name is too long.
+ return ERR_FILE_PATH_TOO_LONG;
+ case ERROR_DISK_FULL: // There is not enough space on the disk.
+ return ERR_FILE_NO_SPACE;
+ case ERROR_CALL_NOT_IMPLEMENTED: // This function is not supported on
+ return ERR_NOT_IMPLEMENTED; // this system.
+ case ERROR_INVALID_NAME: // The filename, directory name, or volume
+ return ERR_INVALID_ARGUMENT; // label syntax is incorrect.
+ case ERROR_DIR_NOT_EMPTY: // The directory is not empty.
+ return ERR_FAILED;
+ case ERROR_BUSY: // The requested resource is in use.
+ return ERR_ACCESS_DENIED;
+ case ERROR_ALREADY_EXISTS: // Cannot create a file when that file
+ return ERR_FILE_EXISTS; // already exists.
+ case ERROR_FILENAME_EXCED_RANGE: // The filename or extension is too long.
+ return ERR_FILE_PATH_TOO_LONG;
+ case ERROR_FILE_TOO_LARGE: // The file size exceeds the limit allowed
+ return ERR_FILE_NO_SPACE; // and cannot be saved.
+ case ERROR_VIRUS_INFECTED: // Operation failed because the file
+ return ERR_FILE_VIRUS_INFECTED; // contains a virus.
+ case ERROR_IO_DEVICE: // The request could not be performed
+ return ERR_ACCESS_DENIED; // because of an I/O device error.
+ case ERROR_POSSIBLE_DEADLOCK: // A potential deadlock condition has
+ return ERR_ACCESS_DENIED; // been detected.
+ case ERROR_BAD_DEVICE: // The specified device name is invalid.
+ return ERR_INVALID_ARGUMENT;
+
case ERROR_SUCCESS:
return OK;
default: