| Index: base/files/file_win.cc
|
| diff --git a/base/files/file_win.cc b/base/files/file_win.cc
|
| index 200ea296644a06238e21642313e831a1845a6596..643c359e56779e97ca175f01b4f7098e1d14d269 100644
|
| --- a/base/files/file_win.cc
|
| +++ b/base/files/file_win.cc
|
| @@ -6,10 +6,10 @@
|
|
|
| #include <io.h>
|
|
|
| -#include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| #include "base/metrics/sparse_histogram.h"
|
| #include "base/threading/thread_restrictions.h"
|
| +#include "base/trace_event/trace_event.h"
|
|
|
| namespace base {
|
|
|
| @@ -31,16 +31,21 @@ PlatformFile File::TakePlatformFile() {
|
| }
|
|
|
| void File::Close() {
|
| - if (file_.IsValid()) {
|
| - ThreadRestrictions::AssertIOAllowed();
|
| - file_.Close();
|
| - }
|
| + if (!file_.IsValid())
|
| + return;
|
| +
|
| + ThreadRestrictions::AssertIOAllowed();
|
| + TRACE_EVENT_NESTABLE_ASYNC0(kTraceGroup, "base::File::Close", this);
|
| + file_.Close();
|
| }
|
|
|
| int64 File::Seek(Whence whence, int64 offset) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Seek", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| LARGE_INTEGER distance, res;
|
| distance.QuadPart = offset;
|
| DWORD move_method = static_cast<DWORD>(whence);
|
| @@ -56,6 +61,9 @@ int File::Read(int64 offset, char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(kTraceGroup, "base::File::Read", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| +
|
| LARGE_INTEGER offset_li;
|
| offset_li.QuadPart = offset;
|
|
|
| @@ -79,6 +87,9 @@ int File::ReadAtCurrentPos(char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(kTraceGroup, "base::File::ReadAtCurrentPos", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| +
|
| DWORD bytes_read;
|
| if (::ReadFile(file_.Get(), data, size, &bytes_read, NULL))
|
| return bytes_read;
|
| @@ -89,10 +100,12 @@ int File::ReadAtCurrentPos(char* data, int size) {
|
| }
|
|
|
| int File::ReadNoBestEffort(int64 offset, char* data, int size) {
|
| + // TODO(dbeam): trace this separately?
|
| return Read(offset, data, size);
|
| }
|
|
|
| int File::ReadAtCurrentPosNoBestEffort(char* data, int size) {
|
| + // TODO(dbeam): trace this separately?
|
| return ReadAtCurrentPos(data, size);
|
| }
|
|
|
| @@ -101,6 +114,9 @@ int File::Write(int64 offset, const char* data, int size) {
|
| DCHECK(IsValid());
|
| DCHECK(!async_);
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(kTraceGroup, "base::File::Write", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| +
|
| LARGE_INTEGER offset_li;
|
| offset_li.QuadPart = offset;
|
|
|
| @@ -122,6 +138,10 @@ int File::WriteAtCurrentPos(const char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(
|
| + kTraceGroup, "base::File::WriteAtCurrentPos", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| +
|
| DWORD bytes_written;
|
| if (::WriteFile(file_.Get(), data, size, &bytes_written, NULL))
|
| return bytes_written;
|
| @@ -136,6 +156,10 @@ int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) {
|
| int64 File::GetLength() {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
| +
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::GetLength", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| LARGE_INTEGER size;
|
| if (!::GetFileSizeEx(file_.Get(), &size))
|
| return -1;
|
| @@ -147,6 +171,9 @@ bool File::SetLength(int64 length) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(kTraceGroup, "base::File::SetLength", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "length", length);
|
| +
|
| // Get the current file pointer.
|
| LARGE_INTEGER file_pointer;
|
| LARGE_INTEGER zero;
|
| @@ -172,10 +199,22 @@ bool File::SetLength(int64 length) {
|
| FALSE));
|
| }
|
|
|
| +bool File::Flush() {
|
| + ThreadRestrictions::AssertIOAllowed();
|
| + DCHECK(IsValid());
|
| +
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Flush", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| + return ::FlushFileBuffers(file_.Get()) != FALSE;
|
| +}
|
| +
|
| bool File::SetTimes(Time last_access_time, Time last_modified_time) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::SetTimes", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| FILETIME last_access_filetime = last_access_time.ToFileTime();
|
| FILETIME last_modified_filetime = last_modified_time.ToFileTime();
|
| return (::SetFileTime(file_.Get(), NULL, &last_access_filetime,
|
| @@ -186,6 +225,9 @@ bool File::GetInfo(Info* info) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::GetInfo", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| BY_HANDLE_FILE_INFORMATION file_info;
|
| if (!GetFileInformationByHandle(file_.Get(), &file_info))
|
| return false;
|
| @@ -205,6 +247,10 @@ bool File::GetInfo(Info* info) {
|
|
|
| File::Error File::Lock() {
|
| DCHECK(IsValid());
|
| +
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Lock", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| BOOL result = LockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD);
|
| if (!result)
|
| return OSErrorToFileError(GetLastError());
|
| @@ -213,6 +259,10 @@ File::Error File::Lock() {
|
|
|
| File::Error File::Unlock() {
|
| DCHECK(IsValid());
|
| +
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Unlock", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| BOOL result = UnlockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD);
|
| if (!result)
|
| return OSErrorToFileError(GetLastError());
|
| @@ -223,6 +273,9 @@ File File::Duplicate() {
|
| if (!IsValid())
|
| return File();
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Duplicate", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| HANDLE other_handle = nullptr;
|
|
|
| if (!::DuplicateHandle(GetCurrentProcess(), // hSourceProcessHandle
|
| @@ -278,10 +331,13 @@ File::Error File::OSErrorToFileError(DWORD last_error) {
|
| }
|
| }
|
|
|
| -void File::DoInitialize(const FilePath& name, uint32 flags) {
|
| +void File::DoInitialize(uint32 flags) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(!IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Initialize", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| DWORD disposition = 0;
|
|
|
| if (flags & FLAG_OPEN)
|
| @@ -346,7 +402,7 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
|
| if (flags & FLAG_BACKUP_SEMANTICS)
|
| create_flags |= FILE_FLAG_BACKUP_SEMANTICS;
|
|
|
| - file_.Set(CreateFile(name.value().c_str(), access, sharing, NULL,
|
| + file_.Set(CreateFile(unsafe_path_.value().c_str(), access, sharing, NULL,
|
| disposition, create_flags, NULL));
|
|
|
| if (file_.IsValid()) {
|
| @@ -362,12 +418,6 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
|
| }
|
| }
|
|
|
| -bool File::DoFlush() {
|
| - ThreadRestrictions::AssertIOAllowed();
|
| - DCHECK(IsValid());
|
| - return ::FlushFileBuffers(file_.Get()) != FALSE;
|
| -}
|
| -
|
| void File::SetPlatformFile(PlatformFile file) {
|
| file_.Set(file);
|
| }
|
|
|