Chromium Code Reviews| Index: net/base/file_stream_win.cc |
| diff --git a/net/base/file_stream_win.cc b/net/base/file_stream_win.cc |
| index 07d365f0597b1ef6178f7dd742a92263d8c46d66..e7e7f71f4a7543208c158787995e4e9baf851024 100644 |
| --- a/net/base/file_stream_win.cc |
| +++ b/net/base/file_stream_win.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/metrics/histogram.h" |
| #include "base/threading/thread_restrictions.h" |
| #include "net/base/file_stream_metrics.h" |
| +#include "net/base/file_stream_net_log_parameters.h" |
| #include "net/base/net_errors.h" |
| namespace net { |
| @@ -36,7 +37,16 @@ static void IncrementOffset(OVERLAPPED* overlapped, DWORD count) { |
| namespace { |
| -int RecordAndMapError(int error, FileErrorSource source, bool record_uma) { |
| +int RecordAndMapError(int error, |
| + FileErrorSource source, |
| + bool record_uma, |
| + const net::BoundNetLog& log) { |
| + log.AddEvent(net::NetLog::TYPE_FILE_STREAM_ERROR, |
| + make_scoped_refptr( |
|
rvargas (doing something else)
2012/01/30 23:11:38
nit: indent
ahendrickson
2012/01/31 20:12:40
Done.
|
| + new FileStreamErrorParameters( |
| + GetFileErrorSourceName(source), |
| + error))); |
|
mmenke
2012/01/30 22:38:39
You should log the network error code (MapSystemEr
ahendrickson
2012/01/31 20:12:40
Done.
|
| + |
| RecordFileError(error, source, record_uma); |
| return MapSystemError(error); |
| } |
| @@ -49,7 +59,8 @@ class FileStream::AsyncContext : public MessageLoopForIO::IOHandler { |
| public: |
| AsyncContext(FileStream* owner) |
| : owner_(owner), context_(), is_closing_(false), |
| - record_uma_(false), error_source_(FILE_ERROR_SOURCE_COUNT) { |
| + record_uma_(false), |
| + error_source_(FILE_ERROR_SOURCE_COUNT) { |
| context_.handler = this; |
| } |
| ~AsyncContext(); |
| @@ -60,6 +71,7 @@ class FileStream::AsyncContext : public MessageLoopForIO::IOHandler { |
| const CompletionCallback& callback() const { return callback_; } |
| void set_error_source(FileErrorSource source) { error_source_ = source; } |
| + void set_bound_net_log(const net::BoundNetLog& log) { net_log_ = log; } |
| void EnableErrorStatistics() { |
| record_uma_ = true; |
| @@ -74,6 +86,7 @@ class FileStream::AsyncContext : public MessageLoopForIO::IOHandler { |
| CompletionCallback callback_; |
| bool is_closing_; |
| bool record_uma_; |
| + net::BoundNetLog net_log_; |
| FileErrorSource error_source_; |
| }; |
| @@ -110,7 +123,7 @@ void FileStream::AsyncContext::OnIOCompleted( |
| int result = static_cast<int>(bytes_read); |
| if (error && error != ERROR_HANDLE_EOF) |
| - result = RecordAndMapError(error, error_source_, record_uma_); |
| + result = RecordAndMapError(error, error_source_, record_uma_, net_log_); |
| if (bytes_read) |
| IncrementOffset(&context->overlapped, bytes_read); |
| @@ -123,10 +136,20 @@ void FileStream::AsyncContext::OnIOCompleted( |
| // FileStream ------------------------------------------------------------ |
| FileStream::FileStream() |
| - : file_(INVALID_HANDLE_VALUE), |
| + : file_(base::kInvalidPlatformFileValue), |
| + open_flags_(0), |
| + auto_closed_(true), |
| + record_uma_(false) { |
| +} |
| + |
| +FileStream::FileStream(net::NetLog* log) |
| + : file_(base::kInvalidPlatformFileValue), |
| open_flags_(0), |
| auto_closed_(true), |
| record_uma_(false) { |
| + net_log_ = net::BoundNetLog::Make(log, net::NetLog::SOURCE_FILESTREAM); |
|
mmenke
2012/01/30 22:38:39
nit: Can just add this to the initialized list.
ahendrickson
2012/01/31 20:12:40
Done.
|
| + |
| + net_log_.BeginEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL); |
| } |
| FileStream::FileStream(base::PlatformFile file, int flags) |
| @@ -146,9 +169,12 @@ FileStream::FileStream(base::PlatformFile file, int flags) |
| FileStream::~FileStream() { |
| if (auto_closed_) |
| Close(); |
| + |
| + net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_ALIVE, NULL); |
| } |
| void FileStream::Close() { |
| + net_log_.AddEvent(net::NetLog::TYPE_FILE_STREAM_CLOSE, NULL); |
| if (file_ != INVALID_HANDLE_VALUE) |
| CancelIo(file_); |
| @@ -156,10 +182,18 @@ void FileStream::Close() { |
| if (file_ != INVALID_HANDLE_VALUE) { |
| CloseHandle(file_); |
| file_ = INVALID_HANDLE_VALUE; |
| + |
| + net_log_.EndEvent(net::NetLog::TYPE_FILE_STREAM_OPEN, NULL); |
| } |
| } |
| int FileStream::Open(const FilePath& path, int open_flags) { |
| + net_log_.BeginEvent( |
|
rvargas (doing something else)
2012/01/30 23:11:38
Same thing here ("leaked" events)
ahendrickson
2012/01/31 20:12:40
Done.
|
| + net::NetLog::TYPE_FILE_STREAM_OPEN, |
| + make_scoped_refptr( |
| + new net::NetLogStringParameter("file_name", |
| + path.AsUTF8Unsafe()))); |
| + |
| if (IsOpen()) { |
| DLOG(FATAL) << "File is already open!"; |
| return ERR_UNEXPECTED; |
| @@ -170,7 +204,10 @@ 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 RecordAndMapError(error, FILE_ERROR_SOURCE_OPEN, record_uma_); |
| + return RecordAndMapError(error, |
| + FILE_ERROR_SOURCE_OPEN, |
| + record_uma_, |
| + net_log_); |
| } |
| if (open_flags_ & base::PLATFORM_FILE_ASYNC) { |
| @@ -200,10 +237,14 @@ int64 FileStream::Seek(Whence whence, int64 offset) { |
| if (!SetFilePointerEx(file_, distance, &result, move_method)) { |
| DWORD error = GetLastError(); |
| LOG(WARNING) << "SetFilePointerEx failed: " << error; |
| - return RecordAndMapError(error, FILE_ERROR_SOURCE_SEEK, record_uma_); |
| + return RecordAndMapError(error, |
| + FILE_ERROR_SOURCE_SEEK, |
| + record_uma_, |
| + net_log_); |
| } |
| if (async_context_.get()) { |
| async_context_->set_error_source(FILE_ERROR_SOURCE_SEEK); |
| + async_context_->set_bound_net_log(net_log_); |
| SetOffset(async_context_->overlapped(), result); |
| } |
| return result.QuadPart; |
| @@ -223,7 +264,10 @@ int64 FileStream::Available() { |
| if (!GetFileSizeEx(file_, &file_size)) { |
| DWORD error = GetLastError(); |
| LOG(WARNING) << "GetFileSizeEx failed: " << error; |
| - return RecordAndMapError(error, FILE_ERROR_SOURCE_GET_SIZE, record_uma_); |
| + return RecordAndMapError(error, |
| + FILE_ERROR_SOURCE_GET_SIZE, |
| + record_uma_, |
| + net_log_); |
| } |
| return file_size.QuadPart - cur_pos; |
| @@ -242,6 +286,7 @@ int FileStream::Read( |
| DCHECK(async_context_->callback().is_null()); |
| overlapped = async_context_->overlapped(); |
| async_context_->set_error_source(FILE_ERROR_SOURCE_READ); |
| + async_context_->set_bound_net_log(net_log_); |
| } else { |
| DCHECK(callback.is_null()); |
| base::ThreadRestrictions::AssertIOAllowed(); |
| @@ -259,7 +304,10 @@ int FileStream::Read( |
| rv = 0; // Report EOF by returning 0 bytes read. |
| } else { |
| LOG(WARNING) << "ReadFile failed: " << error; |
| - rv = RecordAndMapError(error, FILE_ERROR_SOURCE_READ, record_uma_); |
| + rv = RecordAndMapError(error, |
| + FILE_ERROR_SOURCE_READ, |
| + record_uma_, |
| + net_log_); |
| } |
| } else if (overlapped) { |
| async_context_->IOCompletionIsPending(callback); |
| @@ -304,6 +352,7 @@ int FileStream::Write( |
| DCHECK(async_context_->callback().is_null()); |
| overlapped = async_context_->overlapped(); |
| async_context_->set_error_source(FILE_ERROR_SOURCE_WRITE); |
| + async_context_->set_bound_net_log(net_log_); |
| } else { |
| DCHECK(callback.is_null()); |
| base::ThreadRestrictions::AssertIOAllowed(); |
| @@ -318,7 +367,10 @@ int FileStream::Write( |
| rv = ERR_IO_PENDING; |
| } else { |
| LOG(WARNING) << "WriteFile failed: " << error; |
| - rv = RecordAndMapError(error, FILE_ERROR_SOURCE_WRITE, record_uma_); |
| + rv = RecordAndMapError(error, |
| + FILE_ERROR_SOURCE_WRITE, |
| + record_uma_, |
| + net_log_); |
| } |
| } else if (overlapped) { |
| async_context_->IOCompletionIsPending(callback); |
| @@ -342,7 +394,8 @@ int FileStream::Flush() { |
| return RecordAndMapError(GetLastError(), |
| FILE_ERROR_SOURCE_FLUSH, |
| - record_uma_); |
| + record_uma_, |
| + net_log_); |
| } |
| int64 FileStream::Truncate(int64 bytes) { |
| @@ -351,7 +404,7 @@ int64 FileStream::Truncate(int64 bytes) { |
| if (!IsOpen()) |
| return ERR_UNEXPECTED; |
| - // We better be open for reading. |
| + // We'd better be open for reading. |
| DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE); |
| // Seek to the position to truncate from. |
| @@ -364,7 +417,10 @@ int64 FileStream::Truncate(int64 bytes) { |
| if (!result) { |
| DWORD error = GetLastError(); |
| LOG(WARNING) << "SetEndOfFile failed: " << error; |
| - return RecordAndMapError(error, FILE_ERROR_SOURCE_SET_EOF, record_uma_); |
| + return RecordAndMapError(error, |
| + FILE_ERROR_SOURCE_SET_EOF, |
| + record_uma_, |
| + net_log_); |
| } |
| // Success. |
| @@ -378,4 +434,24 @@ void FileStream::EnableErrorStatistics() { |
| async_context_->EnableErrorStatistics(); |
| } |
| +void FileStream::SetBoundNetLogSource(const net::BoundNetLog& log) { |
| + if (log.source().id == net::NetLog::Source::kInvalidId) |
| + return; |
| + |
| + if (log.source().id == net_log_.source().id) |
| + return; |
| + |
| + net_log_.AddEvent( |
| + net::NetLog::TYPE_FILE_STREAM_BOUND_TO_OWNER, |
| + make_scoped_refptr( |
| + new net::NetLogSourceParameter("source_dependency", |
| + log.source()))); |
| + |
| + log.AddEvent( |
| + net::NetLog::TYPE_FILE_STREAM_SOURCE, |
| + make_scoped_refptr( |
| + new net::NetLogSourceParameter("source_dependency", |
| + net_log_.source()))); |
| +} |
| + |
| } // namespace net |