| Index: base/files/file_posix.cc
|
| diff --git a/base/files/file_posix.cc b/base/files/file_posix.cc
|
| index 4c790571e8d6aeb732c6abfa038e51a7191edaa1..e0f0e3b4e77906c9fb026744a461c704f22ccce1 100644
|
| --- a/base/files/file_posix.cc
|
| +++ b/base/files/file_posix.cc
|
| @@ -15,6 +15,7 @@
|
| #include "base/posix/eintr_wrapper.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/threading/thread_restrictions.h"
|
| +#include "base/trace_event/trace_event.h"
|
|
|
| #if defined(OS_ANDROID)
|
| #include "base/os_compat_android.h"
|
| @@ -173,6 +174,7 @@ void File::Close() {
|
| if (!IsValid())
|
| return;
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC0(kTraceGroup, "base::File::Close", this);
|
| ThreadRestrictions::AssertIOAllowed();
|
| file_.reset();
|
| }
|
| @@ -181,6 +183,9 @@ int64 File::Seek(Whence whence, int64 offset) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Seek", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| #if defined(OS_ANDROID)
|
| COMPILE_ASSERT(sizeof(int64) == sizeof(off64_t), off64_t_64_bit);
|
| return lseek64(file_.get(), static_cast<off64_t>(offset),
|
| @@ -198,6 +203,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);
|
| +
|
| int bytes_read = 0;
|
| int rv;
|
| do {
|
| @@ -218,6 +226,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);
|
| +
|
| int bytes_read = 0;
|
| int rv;
|
| do {
|
| @@ -234,7 +245,8 @@ int File::ReadAtCurrentPos(char* data, int size) {
|
| int File::ReadNoBestEffort(int64 offset, char* data, int size) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
| -
|
| + TRACE_EVENT_NESTABLE_ASYNC2(kTraceGroup, "base::File::ReadNoBestEffort", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| return HANDLE_EINTR(pread(file_.get(), data, size, offset));
|
| }
|
|
|
| @@ -244,6 +256,9 @@ int File::ReadAtCurrentPosNoBestEffort(char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(
|
| + kTraceGroup, "base::File::ReadAtCurrentPosNoBestEffort", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| return HANDLE_EINTR(read(file_.get(), data, size));
|
| }
|
|
|
| @@ -257,6 +272,9 @@ int File::Write(int64 offset, const char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(kTraceGroup, "base::File::Write", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| +
|
| int bytes_written = 0;
|
| int rv;
|
| do {
|
| @@ -277,6 +295,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);
|
| +
|
| int bytes_written = 0;
|
| int rv;
|
| do {
|
| @@ -297,12 +319,18 @@ int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) {
|
| if (size < 0)
|
| return -1;
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC2(
|
| + kTraceGroup, "base::File::WriteAtCurrentPosNoBestEffort", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "size", size);
|
| return HANDLE_EINTR(write(file_.get(), data, size));
|
| }
|
|
|
| int64 File::GetLength() {
|
| DCHECK(IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::GetLength", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| stat_wrapper_t file_info;
|
| if (CallFstat(file_.get(), &file_info))
|
| return false;
|
| @@ -313,13 +341,42 @@ int64 File::GetLength() {
|
| bool File::SetLength(int64 length) {
|
| ThreadRestrictions::AssertIOAllowed();
|
| DCHECK(IsValid());
|
| +
|
| + TRACE_EVENT_NESTABLE_ASYNC2(kTraceGroup, "base::File::SetLength", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe(), "length", length);
|
| return !CallFtruncate(file_.get(), length);
|
| }
|
|
|
| +bool File::Flush() {
|
| + ThreadRestrictions::AssertIOAllowed();
|
| + DCHECK(IsValid());
|
| +
|
| +#if defined(OS_NACL)
|
| + NOTIMPLEMENTED(); // NaCl doesn't implement fsync.
|
| + return true;
|
| +#else
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Flush", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +#if defined(OS_LINUX) || defined(OS_ANDROID)
|
| + return !HANDLE_EINTR(fdatasync(file_.get()));
|
| +#else
|
| + return !HANDLE_EINTR(fsync(file_.get()));
|
| +#endif // defined(OS_LINUX) || defined(OS_ANDROID)
|
| +#endif // defined(OS_NACL)
|
| +}
|
| +
|
| +void File::SetPlatformFile(PlatformFile file) {
|
| + DCHECK(!file_.is_valid());
|
| + file_.reset(file);
|
| +}
|
| +
|
| 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());
|
| +
|
| timeval times[2];
|
| times[0] = last_access_time.ToTimeVal();
|
| times[1] = last_modified_time.ToTimeVal();
|
| @@ -330,6 +387,9 @@ bool File::SetTimes(Time last_access_time, Time last_modified_time) {
|
| bool File::GetInfo(Info* info) {
|
| DCHECK(IsValid());
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::GetInfo", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| stat_wrapper_t file_info;
|
| if (CallFstat(file_.get(), &file_info))
|
| return false;
|
| @@ -339,10 +399,14 @@ bool File::GetInfo(Info* info) {
|
| }
|
|
|
| File::Error File::Lock() {
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Lock", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| return CallFctnlFlock(file_.get(), true);
|
| }
|
|
|
| File::Error File::Unlock() {
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Unlock", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| return CallFctnlFlock(file_.get(), false);
|
| }
|
|
|
| @@ -350,6 +414,9 @@ File File::Duplicate() {
|
| if (!IsValid())
|
| return File();
|
|
|
| + TRACE_EVENT_NESTABLE_ASYNC1(kTraceGroup, "base::File::Duplicate", this,
|
| + "path", unsafe_path_.AsUTF8Unsafe());
|
| +
|
| PlatformFile other_fd = dup(GetPlatformFile());
|
| if (other_fd == -1)
|
| return File(OSErrorToFileError(errno));
|
| @@ -442,10 +509,13 @@ void File::MemoryCheckingScopedFD::UpdateChecksum() {
|
| // NaCl doesn't implement system calls to open files directly.
|
| #if !defined(OS_NACL)
|
| // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here?
|
| -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());
|
| +
|
| int open_flags = 0;
|
| if (flags & FLAG_CREATE)
|
| open_flags = O_CREAT | O_EXCL;
|
| @@ -497,7 +567,8 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
|
| mode |= S_IRGRP | S_IROTH;
|
| #endif
|
|
|
| - int descriptor = HANDLE_EINTR(open(name.value().c_str(), open_flags, mode));
|
| + int descriptor =
|
| + HANDLE_EINTR(open(unsafe_path_.value().c_str(), open_flags, mode));
|
|
|
| if (flags & FLAG_OPEN_ALWAYS) {
|
| if (descriptor < 0) {
|
| @@ -505,7 +576,8 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
|
| if (flags & FLAG_EXCLUSIVE_READ || flags & FLAG_EXCLUSIVE_WRITE)
|
| open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW
|
|
|
| - descriptor = HANDLE_EINTR(open(name.value().c_str(), open_flags, mode));
|
| + descriptor =
|
| + HANDLE_EINTR(open(unsafe_path_.value().c_str(), open_flags, mode));
|
| if (descriptor >= 0)
|
| created_ = true;
|
| }
|
| @@ -520,7 +592,7 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
|
| created_ = true;
|
|
|
| if (flags & FLAG_DELETE_ON_CLOSE)
|
| - unlink(name.value().c_str());
|
| + unlink(unsafe_path_.value().c_str());
|
|
|
| async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC);
|
| error_details_ = FILE_OK;
|
| @@ -528,22 +600,4 @@ void File::DoInitialize(const FilePath& name, uint32 flags) {
|
| }
|
| #endif // !defined(OS_NACL)
|
|
|
| -bool File::DoFlush() {
|
| - ThreadRestrictions::AssertIOAllowed();
|
| - DCHECK(IsValid());
|
| -#if defined(OS_NACL)
|
| - NOTIMPLEMENTED(); // NaCl doesn't implement fsync.
|
| - return true;
|
| -#elif defined(OS_LINUX) || defined(OS_ANDROID)
|
| - return !HANDLE_EINTR(fdatasync(file_.get()));
|
| -#else
|
| - return !HANDLE_EINTR(fsync(file_.get()));
|
| -#endif
|
| -}
|
| -
|
| -void File::SetPlatformFile(PlatformFile file) {
|
| - DCHECK(!file_.is_valid());
|
| - file_.reset(file);
|
| -}
|
| -
|
| } // namespace base
|
|
|