Index: base/files/file_win.cc |
diff --git a/base/files/file_win.cc b/base/files/file_win.cc |
index 9f3033c845bb5a8e1469765c9b01c9b330167c7e..200ea296644a06238e21642313e831a1845a6596 100644 |
--- a/base/files/file_win.cc |
+++ b/base/files/file_win.cc |
@@ -18,90 +18,6 @@ COMPILE_ASSERT(File::FROM_BEGIN == FILE_BEGIN && |
File::FROM_CURRENT == FILE_CURRENT && |
File::FROM_END == FILE_END, whence_matches_system); |
-void File::InitializeUnsafe(const FilePath& name, uint32 flags) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
- DCHECK(!IsValid()); |
- |
- DWORD disposition = 0; |
- |
- if (flags & FLAG_OPEN) |
- disposition = OPEN_EXISTING; |
- |
- if (flags & FLAG_CREATE) { |
- DCHECK(!disposition); |
- disposition = CREATE_NEW; |
- } |
- |
- if (flags & FLAG_OPEN_ALWAYS) { |
- DCHECK(!disposition); |
- disposition = OPEN_ALWAYS; |
- } |
- |
- if (flags & FLAG_CREATE_ALWAYS) { |
- DCHECK(!disposition); |
- DCHECK(flags & FLAG_WRITE); |
- disposition = CREATE_ALWAYS; |
- } |
- |
- if (flags & FLAG_OPEN_TRUNCATED) { |
- DCHECK(!disposition); |
- DCHECK(flags & FLAG_WRITE); |
- disposition = TRUNCATE_EXISTING; |
- } |
- |
- if (!disposition) { |
- NOTREACHED(); |
- return; |
- } |
- |
- DWORD access = 0; |
- if (flags & FLAG_WRITE) |
- access = GENERIC_WRITE; |
- if (flags & FLAG_APPEND) { |
- DCHECK(!access); |
- access = FILE_APPEND_DATA; |
- } |
- if (flags & FLAG_READ) |
- access |= GENERIC_READ; |
- if (flags & FLAG_WRITE_ATTRIBUTES) |
- access |= FILE_WRITE_ATTRIBUTES; |
- if (flags & FLAG_EXECUTE) |
- access |= GENERIC_EXECUTE; |
- |
- DWORD sharing = (flags & FLAG_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; |
- if (!(flags & FLAG_EXCLUSIVE_WRITE)) |
- sharing |= FILE_SHARE_WRITE; |
- if (flags & FLAG_SHARE_DELETE) |
- sharing |= FILE_SHARE_DELETE; |
- |
- DWORD create_flags = 0; |
- if (flags & FLAG_ASYNC) |
- create_flags |= FILE_FLAG_OVERLAPPED; |
- if (flags & FLAG_TEMPORARY) |
- create_flags |= FILE_ATTRIBUTE_TEMPORARY; |
- if (flags & FLAG_HIDDEN) |
- create_flags |= FILE_ATTRIBUTE_HIDDEN; |
- if (flags & FLAG_DELETE_ON_CLOSE) |
- create_flags |= FILE_FLAG_DELETE_ON_CLOSE; |
- if (flags & FLAG_BACKUP_SEMANTICS) |
- create_flags |= FILE_FLAG_BACKUP_SEMANTICS; |
- |
- file_.Set(CreateFile(name.value().c_str(), access, sharing, NULL, |
- disposition, create_flags, NULL)); |
- |
- if (file_.IsValid()) { |
- error_details_ = FILE_OK; |
- async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); |
- |
- if (flags & (FLAG_OPEN_ALWAYS)) |
- created_ = (ERROR_ALREADY_EXISTS != GetLastError()); |
- else if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) |
- created_ = true; |
- } else { |
- error_details_ = OSErrorToFileError(GetLastError()); |
- } |
-} |
- |
bool File::IsValid() const { |
return file_.IsValid(); |
} |
@@ -116,13 +32,13 @@ PlatformFile File::TakePlatformFile() { |
void File::Close() { |
if (file_.IsValid()) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
file_.Close(); |
} |
} |
int64 File::Seek(Whence whence, int64 offset) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
LARGE_INTEGER distance, res; |
@@ -134,7 +50,7 @@ int64 File::Seek(Whence whence, int64 offset) { |
} |
int File::Read(int64 offset, char* data, int size) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
DCHECK(!async_); |
if (size < 0) |
@@ -157,7 +73,7 @@ int File::Read(int64 offset, char* data, int size) { |
} |
int File::ReadAtCurrentPos(char* data, int size) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
DCHECK(!async_); |
if (size < 0) |
@@ -181,7 +97,7 @@ int File::ReadAtCurrentPosNoBestEffort(char* data, int size) { |
} |
int File::Write(int64 offset, const char* data, int size) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
DCHECK(!async_); |
@@ -200,7 +116,7 @@ int File::Write(int64 offset, const char* data, int size) { |
} |
int File::WriteAtCurrentPos(const char* data, int size) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
DCHECK(!async_); |
if (size < 0) |
@@ -218,7 +134,7 @@ int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { |
} |
int64 File::GetLength() { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
LARGE_INTEGER size; |
if (!::GetFileSizeEx(file_.Get(), &size)) |
@@ -228,7 +144,7 @@ int64 File::GetLength() { |
} |
bool File::SetLength(int64 length) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
// Get the current file pointer. |
@@ -256,14 +172,8 @@ bool File::SetLength(int64 length) { |
FALSE)); |
} |
-bool File::Flush() { |
- base::ThreadRestrictions::AssertIOAllowed(); |
- DCHECK(IsValid()); |
- return ::FlushFileBuffers(file_.Get()) != FALSE; |
-} |
- |
bool File::SetTimes(Time last_access_time, Time last_modified_time) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
FILETIME last_access_filetime = last_access_time.ToFileTime(); |
@@ -273,7 +183,7 @@ bool File::SetTimes(Time last_access_time, Time last_modified_time) { |
} |
bool File::GetInfo(Info* info) { |
- base::ThreadRestrictions::AssertIOAllowed(); |
+ ThreadRestrictions::AssertIOAllowed(); |
DCHECK(IsValid()); |
BY_HANDLE_FILE_INFORMATION file_info; |
@@ -287,13 +197,13 @@ bool File::GetInfo(Info* info) { |
info->is_directory = |
(file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
info->is_symbolic_link = false; // Windows doesn't have symbolic links. |
- info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); |
- info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); |
- info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); |
+ info->last_modified = Time::FromFileTime(file_info.ftLastWriteTime); |
+ info->last_accessed = Time::FromFileTime(file_info.ftLastAccessTime); |
+ info->creation_time = Time::FromFileTime(file_info.ftCreationTime); |
return true; |
} |
-File::Error base::File::Lock() { |
+File::Error File::Lock() { |
DCHECK(IsValid()); |
BOOL result = LockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); |
if (!result) |
@@ -368,6 +278,96 @@ File::Error File::OSErrorToFileError(DWORD last_error) { |
} |
} |
+void File::DoInitialize(const FilePath& name, uint32 flags) { |
+ ThreadRestrictions::AssertIOAllowed(); |
+ DCHECK(!IsValid()); |
+ |
+ DWORD disposition = 0; |
+ |
+ if (flags & FLAG_OPEN) |
+ disposition = OPEN_EXISTING; |
+ |
+ if (flags & FLAG_CREATE) { |
+ DCHECK(!disposition); |
+ disposition = CREATE_NEW; |
+ } |
+ |
+ if (flags & FLAG_OPEN_ALWAYS) { |
+ DCHECK(!disposition); |
+ disposition = OPEN_ALWAYS; |
+ } |
+ |
+ if (flags & FLAG_CREATE_ALWAYS) { |
+ DCHECK(!disposition); |
+ DCHECK(flags & FLAG_WRITE); |
+ disposition = CREATE_ALWAYS; |
+ } |
+ |
+ if (flags & FLAG_OPEN_TRUNCATED) { |
+ DCHECK(!disposition); |
+ DCHECK(flags & FLAG_WRITE); |
+ disposition = TRUNCATE_EXISTING; |
+ } |
+ |
+ if (!disposition) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ DWORD access = 0; |
+ if (flags & FLAG_WRITE) |
+ access = GENERIC_WRITE; |
+ if (flags & FLAG_APPEND) { |
+ DCHECK(!access); |
+ access = FILE_APPEND_DATA; |
+ } |
+ if (flags & FLAG_READ) |
+ access |= GENERIC_READ; |
+ if (flags & FLAG_WRITE_ATTRIBUTES) |
+ access |= FILE_WRITE_ATTRIBUTES; |
+ if (flags & FLAG_EXECUTE) |
+ access |= GENERIC_EXECUTE; |
+ |
+ DWORD sharing = (flags & FLAG_EXCLUSIVE_READ) ? 0 : FILE_SHARE_READ; |
+ if (!(flags & FLAG_EXCLUSIVE_WRITE)) |
+ sharing |= FILE_SHARE_WRITE; |
+ if (flags & FLAG_SHARE_DELETE) |
+ sharing |= FILE_SHARE_DELETE; |
+ |
+ DWORD create_flags = 0; |
+ if (flags & FLAG_ASYNC) |
+ create_flags |= FILE_FLAG_OVERLAPPED; |
+ if (flags & FLAG_TEMPORARY) |
+ create_flags |= FILE_ATTRIBUTE_TEMPORARY; |
+ if (flags & FLAG_HIDDEN) |
+ create_flags |= FILE_ATTRIBUTE_HIDDEN; |
+ if (flags & FLAG_DELETE_ON_CLOSE) |
+ create_flags |= FILE_FLAG_DELETE_ON_CLOSE; |
+ if (flags & FLAG_BACKUP_SEMANTICS) |
+ create_flags |= FILE_FLAG_BACKUP_SEMANTICS; |
+ |
+ file_.Set(CreateFile(name.value().c_str(), access, sharing, NULL, |
+ disposition, create_flags, NULL)); |
+ |
+ if (file_.IsValid()) { |
+ error_details_ = FILE_OK; |
+ async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); |
+ |
+ if (flags & (FLAG_OPEN_ALWAYS)) |
+ created_ = (ERROR_ALREADY_EXISTS != GetLastError()); |
+ else if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) |
+ created_ = true; |
+ } else { |
+ error_details_ = OSErrorToFileError(GetLastError()); |
+ } |
+} |
+ |
+bool File::DoFlush() { |
+ ThreadRestrictions::AssertIOAllowed(); |
+ DCHECK(IsValid()); |
+ return ::FlushFileBuffers(file_.Get()) != FALSE; |
+} |
+ |
void File::SetPlatformFile(PlatformFile file) { |
file_.Set(file); |
} |