Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Side by Side Diff: base/platform_file_win.cc

Issue 12095045: Merge 175642 (also includes 175980) (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1364/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/platform_file_posix.cc ('k') | chrome/test/base/v8_unit_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/platform_file.h" 5 #include "base/platform_file.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 10
11 namespace base { 11 namespace base {
12 12 PlatformFile CreatePlatformFileUnsafe(const FilePath& name,
13 PlatformFile CreatePlatformFile(const FilePath& name, 13 int flags,
14 int flags, 14 bool* created,
15 bool* created, 15 PlatformFileError* error) {
16 PlatformFileError* error_code) {
17 base::ThreadRestrictions::AssertIOAllowed(); 16 base::ThreadRestrictions::AssertIOAllowed();
18 17
19 DWORD disposition = 0; 18 DWORD disposition = 0;
20 if (created) 19 if (created)
21 *created = false; 20 *created = false;
22 21
23 if (flags & PLATFORM_FILE_OPEN) 22 if (flags & PLATFORM_FILE_OPEN)
24 disposition = OPEN_EXISTING; 23 disposition = OPEN_EXISTING;
25 24
26 if (flags & PLATFORM_FILE_CREATE) { 25 if (flags & PLATFORM_FILE_CREATE) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 HANDLE file = CreateFile(name.value().c_str(), access, sharing, NULL, 75 HANDLE file = CreateFile(name.value().c_str(), access, sharing, NULL,
77 disposition, create_flags, NULL); 76 disposition, create_flags, NULL);
78 77
79 if (created && (INVALID_HANDLE_VALUE != file)) { 78 if (created && (INVALID_HANDLE_VALUE != file)) {
80 if (flags & (PLATFORM_FILE_OPEN_ALWAYS)) 79 if (flags & (PLATFORM_FILE_OPEN_ALWAYS))
81 *created = (ERROR_ALREADY_EXISTS != GetLastError()); 80 *created = (ERROR_ALREADY_EXISTS != GetLastError());
82 else if (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE)) 81 else if (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE))
83 *created = true; 82 *created = true;
84 } 83 }
85 84
86 if (error_code) { 85 if (error) {
87 if (file != kInvalidPlatformFileValue) 86 if (file != kInvalidPlatformFileValue)
88 *error_code = PLATFORM_FILE_OK; 87 *error = PLATFORM_FILE_OK;
89 else { 88 else {
90 DWORD last_error = GetLastError(); 89 DWORD last_error = GetLastError();
91 switch (last_error) { 90 switch (last_error) {
92 case ERROR_SHARING_VIOLATION: 91 case ERROR_SHARING_VIOLATION:
93 *error_code = PLATFORM_FILE_ERROR_IN_USE; 92 *error = PLATFORM_FILE_ERROR_IN_USE;
94 break; 93 break;
95 case ERROR_FILE_EXISTS: 94 case ERROR_FILE_EXISTS:
96 *error_code = PLATFORM_FILE_ERROR_EXISTS; 95 *error = PLATFORM_FILE_ERROR_EXISTS;
97 break; 96 break;
98 case ERROR_FILE_NOT_FOUND: 97 case ERROR_FILE_NOT_FOUND:
99 *error_code = PLATFORM_FILE_ERROR_NOT_FOUND; 98 *error = PLATFORM_FILE_ERROR_NOT_FOUND;
100 break; 99 break;
101 case ERROR_ACCESS_DENIED: 100 case ERROR_ACCESS_DENIED:
102 *error_code = PLATFORM_FILE_ERROR_ACCESS_DENIED; 101 *error = PLATFORM_FILE_ERROR_ACCESS_DENIED;
103 break; 102 break;
104 default: 103 default:
105 *error_code = PLATFORM_FILE_ERROR_FAILED; 104 *error = PLATFORM_FILE_ERROR_FAILED;
106 } 105 }
107 } 106 }
108 } 107 }
109 108
110 return file; 109 return file;
111 } 110 }
112 111
113 bool ClosePlatformFile(PlatformFile file) { 112 bool ClosePlatformFile(PlatformFile file) {
114 base::ThreadRestrictions::AssertIOAllowed(); 113 base::ThreadRestrictions::AssertIOAllowed();
115 return (CloseHandle(file) != 0); 114 return (CloseHandle(file) != 0);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 info->is_directory = 253 info->is_directory =
255 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; 254 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
256 info->is_symbolic_link = false; // Windows doesn't have symbolic links. 255 info->is_symbolic_link = false; // Windows doesn't have symbolic links.
257 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); 256 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime);
258 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); 257 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime);
259 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); 258 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime);
260 return true; 259 return true;
261 } 260 }
262 261
263 } // namespace base 262 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file_posix.cc ('k') | chrome/test/base/v8_unit_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698