| Index: net/base/file_stream_win.cc
|
| diff --git a/net/base/file_stream_win.cc b/net/base/file_stream_win.cc
|
| index c08521e913a47c1ee3adcf9b77ea969365d28f54..82583f139e5ac20518c6130c01159a799c21f9ed 100644
|
| --- a/net/base/file_stream_win.cc
|
| +++ b/net/base/file_stream_win.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/message_loop.h"
|
| #include "base/metrics/histogram.h"
|
| #include "base/threading/thread_restrictions.h"
|
| +#include "net/base/file_stream_metrics.h"
|
| #include "net/base/net_errors.h"
|
|
|
| namespace net {
|
| @@ -48,12 +49,22 @@ static int MapErrorCode(DWORD err) {
|
| }
|
| }
|
|
|
| +namespace {
|
| +
|
| +int RecordAndMapError(int error, FileErrorSource source, bool record_uma) {
|
| + RecordFileError(error, source, record_uma);
|
| + return MapErrorCode(error);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // FileStream::AsyncContext ----------------------------------------------
|
|
|
| class FileStream::AsyncContext : public MessageLoopForIO::IOHandler {
|
| public:
|
| AsyncContext(FileStream* owner)
|
| - : owner_(owner), context_(), callback_(NULL), is_closing_(false) {
|
| + : owner_(owner), context_(), callback_(NULL), is_closing_(false),
|
| + record_uma_(false), error_source_(FILE_ERROR_SOURCE_COUNT) {
|
| context_.handler = this;
|
| }
|
| ~AsyncContext();
|
| @@ -63,6 +74,12 @@ class FileStream::AsyncContext : public MessageLoopForIO::IOHandler {
|
| OVERLAPPED* overlapped() { return &context_.overlapped; }
|
| CompletionCallback* callback() const { return callback_; }
|
|
|
| + void set_error_source(FileErrorSource source) { error_source_ = source; }
|
| +
|
| + void EnableErrorStatistics() {
|
| + record_uma_ = true;
|
| + }
|
| +
|
| private:
|
| virtual void OnIOCompleted(MessageLoopForIO::IOContext* context,
|
| DWORD bytes_read, DWORD error);
|
| @@ -71,6 +88,8 @@ class FileStream::AsyncContext : public MessageLoopForIO::IOHandler {
|
| MessageLoopForIO::IOContext context_;
|
| CompletionCallback* callback_;
|
| bool is_closing_;
|
| + bool record_uma_;
|
| + FileErrorSource error_source_;
|
| };
|
|
|
| FileStream::AsyncContext::~AsyncContext() {
|
| @@ -106,7 +125,7 @@ void FileStream::AsyncContext::OnIOCompleted(
|
|
|
| int result = static_cast<int>(bytes_read);
|
| if (error && error != ERROR_HANDLE_EOF)
|
| - result = MapErrorCode(error);
|
| + result = RecordAndMapError(error, error_source_, record_uma_);
|
|
|
| if (bytes_read)
|
| IncrementOffset(&context->overlapped, bytes_read);
|
| @@ -121,13 +140,15 @@ void FileStream::AsyncContext::OnIOCompleted(
|
| FileStream::FileStream()
|
| : file_(INVALID_HANDLE_VALUE),
|
| open_flags_(0),
|
| - auto_closed_(true) {
|
| + auto_closed_(true),
|
| + record_uma_(false) {
|
| }
|
|
|
| FileStream::FileStream(base::PlatformFile file, int flags)
|
| : file_(file),
|
| open_flags_(flags),
|
| - auto_closed_(false) {
|
| + auto_closed_(false),
|
| + record_uma_(false) {
|
| // If the file handle is opened with base::PLATFORM_FILE_ASYNC, we need to
|
| // make sure we will perform asynchronous File IO to it.
|
| if (flags & base::PLATFORM_FILE_ASYNC) {
|
| @@ -164,11 +185,13 @@ 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 RecordAndMapError(error, FILE_ERROR_SOURCE_OPEN, record_uma_);
|
| }
|
|
|
| if (open_flags_ & base::PLATFORM_FILE_ASYNC) {
|
| async_context_.reset(new AsyncContext(this));
|
| + if (record_uma_)
|
| + async_context_->EnableErrorStatistics();
|
| MessageLoopForIO::current()->RegisterIOHandler(file_,
|
| async_context_.get());
|
| }
|
| @@ -183,6 +206,7 @@ bool FileStream::IsOpen() const {
|
| int64 FileStream::Seek(Whence whence, int64 offset) {
|
| if (!IsOpen())
|
| return ERR_UNEXPECTED;
|
| +
|
| DCHECK(!async_context_.get() || !async_context_->callback());
|
|
|
| LARGE_INTEGER distance, result;
|
| @@ -191,10 +215,12 @@ 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 RecordAndMapError(error, FILE_ERROR_SOURCE_SEEK, record_uma_);
|
| }
|
| - if (async_context_.get())
|
| + if (async_context_.get()) {
|
| + async_context_->set_error_source(FILE_ERROR_SOURCE_SEEK);
|
| SetOffset(async_context_->overlapped(), result);
|
| + }
|
| return result.QuadPart;
|
| }
|
|
|
| @@ -212,7 +238,7 @@ int64 FileStream::Available() {
|
| if (!GetFileSizeEx(file_, &file_size)) {
|
| DWORD error = GetLastError();
|
| LOG(WARNING) << "GetFileSizeEx failed: " << error;
|
| - return MapErrorCode(error);
|
| + return RecordAndMapError(error, FILE_ERROR_SOURCE_GET_SIZE, record_uma_);
|
| }
|
|
|
| return file_size.QuadPart - cur_pos;
|
| @@ -222,6 +248,7 @@ int FileStream::Read(
|
| char* buf, int buf_len, CompletionCallback* callback) {
|
| if (!IsOpen())
|
| return ERR_UNEXPECTED;
|
| +
|
| DCHECK(open_flags_ & base::PLATFORM_FILE_READ);
|
|
|
| OVERLAPPED* overlapped = NULL;
|
| @@ -229,6 +256,7 @@ int FileStream::Read(
|
| DCHECK(callback);
|
| DCHECK(!async_context_->callback());
|
| overlapped = async_context_->overlapped();
|
| + async_context_->set_error_source(FILE_ERROR_SOURCE_READ);
|
| } else {
|
| DCHECK(!callback);
|
| base::ThreadRestrictions::AssertIOAllowed();
|
| @@ -246,7 +274,7 @@ int FileStream::Read(
|
| rv = 0; // Report EOF by returning 0 bytes read.
|
| } else {
|
| LOG(WARNING) << "ReadFile failed: " << error;
|
| - rv = MapErrorCode(error);
|
| + rv = RecordAndMapError(error, FILE_ERROR_SOURCE_READ, record_uma_);
|
| }
|
| } else if (overlapped) {
|
| async_context_->IOCompletionIsPending(callback);
|
| @@ -282,6 +310,7 @@ int FileStream::Write(
|
| const char* buf, int buf_len, CompletionCallback* callback) {
|
| if (!IsOpen())
|
| return ERR_UNEXPECTED;
|
| +
|
| DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
|
|
|
| OVERLAPPED* overlapped = NULL;
|
| @@ -289,6 +318,7 @@ int FileStream::Write(
|
| DCHECK(callback);
|
| DCHECK(!async_context_->callback());
|
| overlapped = async_context_->overlapped();
|
| + async_context_->set_error_source(FILE_ERROR_SOURCE_WRITE);
|
| } else {
|
| DCHECK(!callback);
|
| base::ThreadRestrictions::AssertIOAllowed();
|
| @@ -303,7 +333,7 @@ int FileStream::Write(
|
| rv = ERR_IO_PENDING;
|
| } else {
|
| LOG(WARNING) << "WriteFile failed: " << error;
|
| - rv = MapErrorCode(error);
|
| + rv = RecordAndMapError(error, FILE_ERROR_SOURCE_WRITE, record_uma_);
|
| }
|
| } else if (overlapped) {
|
| async_context_->IOCompletionIsPending(callback);
|
| @@ -325,10 +355,9 @@ int FileStream::Flush() {
|
| return OK;
|
| }
|
|
|
| - int rv;
|
| - DWORD error = GetLastError();
|
| - rv = MapErrorCode(error);
|
| - return rv;
|
| + return RecordAndMapError(GetLastError(),
|
| + FILE_ERROR_SOURCE_FLUSH,
|
| + record_uma_);
|
| }
|
|
|
| int64 FileStream::Truncate(int64 bytes) {
|
| @@ -350,11 +379,18 @@ int64 FileStream::Truncate(int64 bytes) {
|
| if (!result) {
|
| DWORD error = GetLastError();
|
| LOG(WARNING) << "SetEndOfFile failed: " << error;
|
| - return MapErrorCode(error);
|
| + return RecordAndMapError(error, FILE_ERROR_SOURCE_SET_EOF, record_uma_);
|
| }
|
|
|
| // Success.
|
| return seek_position;
|
| }
|
|
|
| +void FileStream::EnableErrorStatistics() {
|
| + record_uma_ = true;
|
| +
|
| + if (async_context_.get())
|
| + async_context_->EnableErrorStatistics();
|
| +}
|
| +
|
| } // namespace net
|
|
|