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

Side by Side Diff: base/platform_file_win.cc

Issue 10701050: net: Implement canceling of all async operations in FileStream. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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
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
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 107
108 return file; 108 return file;
109 } 109 }
110 110
111 bool ClosePlatformFile(PlatformFile file) { 111 bool ClosePlatformFile(PlatformFile file) {
112 base::ThreadRestrictions::AssertIOAllowed(); 112 base::ThreadRestrictions::AssertIOAllowed();
113 return (CloseHandle(file) != 0); 113 return (CloseHandle(file) != 0);
114 } 114 }
115 115
116 int64 SeekPlatformFile(PlatformFile file,
117 PlatformFileWhence whence,
118 int64 offset) {
119 base::ThreadRestrictions::AssertIOAllowed();
120 if (file < 0 || offset < 0)
121 return -1;
122
123 LARGE_INTEGER distance, res;
124 distance.QuadPart = offset;
125 DWORD move_method = static_cast<DWORD>(whence);
126 if (!SetFilePointerEx(file_, distance, &res, move_method))
127 return -1;
128 return res.QuadPart;
129 }
130
116 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { 131 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) {
117 base::ThreadRestrictions::AssertIOAllowed(); 132 base::ThreadRestrictions::AssertIOAllowed();
118 if (file == kInvalidPlatformFileValue) 133 if (file == kInvalidPlatformFileValue)
119 return -1; 134 return -1;
120 135
121 LARGE_INTEGER offset_li; 136 LARGE_INTEGER offset_li;
122 offset_li.QuadPart = offset; 137 offset_li.QuadPart = offset;
123 138
124 OVERLAPPED overlapped = {0}; 139 OVERLAPPED overlapped = {0};
125 overlapped.Offset = offset_li.LowPart; 140 overlapped.Offset = offset_li.LowPart;
(...skipping 10 matching lines...) Expand all
136 151
137 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) { 152 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) {
138 return ReadPlatformFile(file, 0, data, size); 153 return ReadPlatformFile(file, 0, data, size);
139 } 154 }
140 155
141 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, char* data, 156 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, char* data,
142 int size) { 157 int size) {
143 return ReadPlatformFile(file, offset, data, size); 158 return ReadPlatformFile(file, offset, data, size);
144 } 159 }
145 160
161 int ReadPlatformFileCurPosNoBestEffort(PlatformFile file,
162 char* data, int size) {
163 return ReadPlatformFile(file, 0, data, size);
164 }
165
146 int WritePlatformFile(PlatformFile file, int64 offset, 166 int WritePlatformFile(PlatformFile file, int64 offset,
147 const char* data, int size) { 167 const char* data, int size) {
148 base::ThreadRestrictions::AssertIOAllowed(); 168 base::ThreadRestrictions::AssertIOAllowed();
149 if (file == kInvalidPlatformFileValue) 169 if (file == kInvalidPlatformFileValue)
150 return -1; 170 return -1;
151 171
152 LARGE_INTEGER offset_li; 172 LARGE_INTEGER offset_li;
153 offset_li.QuadPart = offset; 173 offset_li.QuadPart = offset;
154 174
155 OVERLAPPED overlapped = {0}; 175 OVERLAPPED overlapped = {0};
156 overlapped.Offset = offset_li.LowPart; 176 overlapped.Offset = offset_li.LowPart;
157 overlapped.OffsetHigh = offset_li.HighPart; 177 overlapped.OffsetHigh = offset_li.HighPart;
158 178
159 DWORD bytes_written; 179 DWORD bytes_written;
160 if (::WriteFile(file, data, size, &bytes_written, &overlapped) != 0) 180 if (::WriteFile(file, data, size, &bytes_written, &overlapped) != 0)
161 return bytes_written; 181 return bytes_written;
162 182
163 return -1; 183 return -1;
164 } 184 }
165 185
166 int WritePlatformFileAtCurrentPos(PlatformFile file, const char* data, 186 int WritePlatformFileAtCurrentPos(PlatformFile file, const char* data,
167 int size) { 187 int size) {
168 return WritePlatformFile(file, 0, data, size); 188 return WritePlatformFile(file, 0, data, size);
169 } 189 }
170 190
191 int WritePlatformFileCurPosNoBestEffort(PlatformFile file,
192 const char* data, int size) {
193 return WritePlatformFile(file, 0, data, size);
194 }
195
171 bool TruncatePlatformFile(PlatformFile file, int64 length) { 196 bool TruncatePlatformFile(PlatformFile file, int64 length) {
172 base::ThreadRestrictions::AssertIOAllowed(); 197 base::ThreadRestrictions::AssertIOAllowed();
173 if (file == kInvalidPlatformFileValue) 198 if (file == kInvalidPlatformFileValue)
174 return false; 199 return false;
175 200
176 // Get the current file pointer. 201 // Get the current file pointer.
177 LARGE_INTEGER file_pointer; 202 LARGE_INTEGER file_pointer;
178 LARGE_INTEGER zero; 203 LARGE_INTEGER zero;
179 zero.QuadPart = 0; 204 zero.QuadPart = 0;
180 if (::SetFilePointerEx(file, zero, &file_pointer, FILE_CURRENT) == 0) 205 if (::SetFilePointerEx(file, zero, &file_pointer, FILE_CURRENT) == 0)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 info->is_directory = 252 info->is_directory =
228 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; 253 (file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
229 info->is_symbolic_link = false; // Windows doesn't have symbolic links. 254 info->is_symbolic_link = false; // Windows doesn't have symbolic links.
230 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime); 255 info->last_modified = base::Time::FromFileTime(file_info.ftLastWriteTime);
231 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime); 256 info->last_accessed = base::Time::FromFileTime(file_info.ftLastAccessTime);
232 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime); 257 info->creation_time = base::Time::FromFileTime(file_info.ftCreationTime);
233 return true; 258 return true;
234 } 259 }
235 260
236 } // namespace base 261 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698