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

Side by Side Diff: net/base/file_stream_context_posix.cc

Issue 189393002: net: Update FileStream to use base::File instead of PlatformFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 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
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 // For 64-bit file access (off_t = off64_t, lseek64, etc). 5 // For 64-bit file access (off_t = off64_t, lseek64, etc).
6 #define _FILE_OFFSET_BITS 64 6 #define _FILE_OFFSET_BITS 64
7 7
8 #include "net/base/file_stream_context.h" 8 #include "net/base/file_stream_context.h"
9 9
10 #include <errno.h> 10 #include <errno.h>
(...skipping 28 matching lines...) Expand all
39 // We cast back and forth, so make sure it's the size we're expecting. 39 // We cast back and forth, so make sure it's the size we're expecting.
40 COMPILE_ASSERT(sizeof(int64) == sizeof(off_t), off_t_64_bit); 40 COMPILE_ASSERT(sizeof(int64) == sizeof(off_t), off_t_64_bit);
41 41
42 // Make sure our Whence mappings match the system headers. 42 // Make sure our Whence mappings match the system headers.
43 COMPILE_ASSERT(FROM_BEGIN == SEEK_SET && 43 COMPILE_ASSERT(FROM_BEGIN == SEEK_SET &&
44 FROM_CURRENT == SEEK_CUR && 44 FROM_CURRENT == SEEK_CUR &&
45 FROM_END == SEEK_END, whence_matches_system); 45 FROM_END == SEEK_END, whence_matches_system);
46 46
47 FileStream::Context::Context(const BoundNetLog& bound_net_log, 47 FileStream::Context::Context(const BoundNetLog& bound_net_log,
48 const scoped_refptr<base::TaskRunner>& task_runner) 48 const scoped_refptr<base::TaskRunner>& task_runner)
49 : file_(base::kInvalidPlatformFileValue), 49 : record_uma_(false),
50 record_uma_(false),
51 async_in_progress_(false), 50 async_in_progress_(false),
52 orphaned_(false), 51 orphaned_(false),
52 async_(false),
53 bound_net_log_(bound_net_log), 53 bound_net_log_(bound_net_log),
54 task_runner_(task_runner) { 54 task_runner_(task_runner) {
55 } 55 }
56 56
57 FileStream::Context::Context(base::PlatformFile file, 57 FileStream::Context::Context(base::File file,
58 const BoundNetLog& bound_net_log, 58 const BoundNetLog& bound_net_log,
59 int /* open_flags */,
60 const scoped_refptr<base::TaskRunner>& task_runner) 59 const scoped_refptr<base::TaskRunner>& task_runner)
61 : file_(file), 60 : file_(file.Pass()),
62 record_uma_(false), 61 record_uma_(false),
63 async_in_progress_(false), 62 async_in_progress_(false),
64 orphaned_(false), 63 orphaned_(false),
64 async_(false),
65 bound_net_log_(bound_net_log), 65 bound_net_log_(bound_net_log),
66 task_runner_(task_runner) { 66 task_runner_(task_runner) {
67 } 67 }
68
69 FileStream::Context::Context(base::File file,
70 int flags,
71 const BoundNetLog& bound_net_log,
72 const scoped_refptr<base::TaskRunner>& task_runner)
73 : file_(file.Pass()),
74 record_uma_(false),
75 async_in_progress_(false),
76 orphaned_(false),
77 async_((flags & base::File::FLAG_ASYNC) == base::File::FLAG_ASYNC),
78 bound_net_log_(bound_net_log),
79 task_runner_(task_runner) {
80 }
68 81
69 FileStream::Context::~Context() { 82 FileStream::Context::~Context() {
70 } 83 }
71 84
72 int64 FileStream::Context::GetFileSize() const { 85 int64 FileStream::Context::GetFileSize() const {
73 struct stat info; 86 struct stat info;
74 if (fstat(file_, &info) != 0) { 87 if (fstat(file_.GetPlatformFile(), &info) != 0) {
75 IOResult result = IOResult::FromOSError(errno); 88 IOResult result = IOResult::FromOSError(errno);
76 RecordError(result, FILE_ERROR_SOURCE_GET_SIZE); 89 RecordError(result, FILE_ERROR_SOURCE_GET_SIZE);
77 return result.result; 90 return result.result;
78 } 91 }
79 92
80 return static_cast<int64>(info.st_size); 93 return static_cast<int64>(info.st_size);
81 } 94 }
82 95
83 int FileStream::Context::ReadAsync(IOBuffer* in_buf, 96 int FileStream::Context::ReadAsync(IOBuffer* in_buf,
84 int buf_len, 97 int buf_len,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 141 }
129 142
130 int FileStream::Context::WriteSync(const char* in_buf, int buf_len) { 143 int FileStream::Context::WriteSync(const char* in_buf, int buf_len) {
131 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf); 144 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf);
132 IOResult result = WriteFileImpl(buf, buf_len); 145 IOResult result = WriteFileImpl(buf, buf_len);
133 RecordError(result, FILE_ERROR_SOURCE_WRITE); 146 RecordError(result, FILE_ERROR_SOURCE_WRITE);
134 return result.result; 147 return result.result;
135 } 148 }
136 149
137 int FileStream::Context::Truncate(int64 bytes) { 150 int FileStream::Context::Truncate(int64 bytes) {
138 if (ftruncate(file_, bytes) != 0) { 151 if (ftruncate(file_.GetPlatformFile(), bytes) != 0) {
139 IOResult result = IOResult::FromOSError(errno); 152 IOResult result = IOResult::FromOSError(errno);
140 RecordError(result, FILE_ERROR_SOURCE_SET_EOF); 153 RecordError(result, FILE_ERROR_SOURCE_SET_EOF);
141 return result.result; 154 return result.result;
142 } 155 }
143 156
144 return bytes; 157 return bytes;
145 } 158 }
146 159
147 FileStream::Context::IOResult FileStream::Context::SeekFileImpl(Whence whence, 160 FileStream::Context::IOResult FileStream::Context::SeekFileImpl(Whence whence,
148 int64 offset) { 161 int64 offset) {
149 off_t res = lseek(file_, static_cast<off_t>(offset), 162 off_t res = lseek(file_.GetPlatformFile(), static_cast<off_t>(offset),
150 static_cast<int>(whence)); 163 static_cast<int>(whence));
151 if (res == static_cast<off_t>(-1)) 164 if (res == static_cast<off_t>(-1))
152 return IOResult::FromOSError(errno); 165 return IOResult::FromOSError(errno);
153 166
154 return IOResult(res, 0); 167 return IOResult(res, 0);
155 } 168 }
156 169
157 FileStream::Context::IOResult FileStream::Context::FlushFileImpl() { 170 FileStream::Context::IOResult FileStream::Context::FlushFileImpl() {
158 ssize_t res = HANDLE_EINTR(fsync(file_)); 171 ssize_t res = HANDLE_EINTR(fsync(file_.GetPlatformFile()));
159 if (res == -1) 172 if (res == -1)
160 return IOResult::FromOSError(errno); 173 return IOResult::FromOSError(errno);
161 174
162 return IOResult(res, 0); 175 return IOResult(res, 0);
163 } 176 }
164 177
165 FileStream::Context::IOResult FileStream::Context::ReadFileImpl( 178 FileStream::Context::IOResult FileStream::Context::ReadFileImpl(
166 scoped_refptr<IOBuffer> buf, 179 scoped_refptr<IOBuffer> buf,
167 int buf_len) { 180 int buf_len) {
168 // Loop in the case of getting interrupted by a signal. 181 // Loop in the case of getting interrupted by a signal.
169 ssize_t res = HANDLE_EINTR(read(file_, buf->data(), 182 ssize_t res = HANDLE_EINTR(read(file_.GetPlatformFile(), buf->data(),
170 static_cast<size_t>(buf_len))); 183 static_cast<size_t>(buf_len)));
171 if (res == -1) 184 if (res == -1)
172 return IOResult::FromOSError(errno); 185 return IOResult::FromOSError(errno);
173 186
174 return IOResult(res, 0); 187 return IOResult(res, 0);
175 } 188 }
176 189
177 FileStream::Context::IOResult FileStream::Context::WriteFileImpl( 190 FileStream::Context::IOResult FileStream::Context::WriteFileImpl(
178 scoped_refptr<IOBuffer> buf, 191 scoped_refptr<IOBuffer> buf,
179 int buf_len) { 192 int buf_len) {
180 ssize_t res = HANDLE_EINTR(write(file_, buf->data(), buf_len)); 193 ssize_t res = HANDLE_EINTR(write(file_.GetPlatformFile(), buf->data(),
194 buf_len));
181 if (res == -1) 195 if (res == -1)
182 return IOResult::FromOSError(errno); 196 return IOResult::FromOSError(errno);
183 197
184 return IOResult(res, 0); 198 return IOResult(res, 0);
185 } 199 }
186 200
187 FileStream::Context::IOResult FileStream::Context::CloseFileImpl() {
188 bool success = base::ClosePlatformFile(file_);
189 file_ = base::kInvalidPlatformFileValue;
190 if (!success)
191 return IOResult::FromOSError(errno);
192
193 return IOResult(OK, 0);
194 }
195
196 } // namespace net 201 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698