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

Side by Side Diff: services/files/file_impl.cc

Issue 1355403002: enum class fixups - testing non-zero (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « services/files/directory_impl.cc ('k') | services/files/shared_impl.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "services/files/file_impl.h" 5 #include "services/files/file_impl.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 Whence whence, 64 Whence whence,
65 const ReadCallback& callback) { 65 const ReadCallback& callback) {
66 if (!file_fd_.is_valid()) { 66 if (!file_fd_.is_valid()) {
67 callback.Run(ERROR_CLOSED, Array<uint8_t>()); 67 callback.Run(ERROR_CLOSED, Array<uint8_t>());
68 return; 68 return;
69 } 69 }
70 if (num_bytes_to_read > kMaxReadSize) { 70 if (num_bytes_to_read > kMaxReadSize) {
71 callback.Run(ERROR_OUT_OF_RANGE, Array<uint8_t>()); 71 callback.Run(ERROR_OUT_OF_RANGE, Array<uint8_t>());
72 return; 72 return;
73 } 73 }
74 if (Error error = IsOffsetValid(offset)) { 74
75 Error error = IsOffsetValid(offset);
76 if (error != ERROR_OK) {
75 callback.Run(error, Array<uint8_t>()); 77 callback.Run(error, Array<uint8_t>());
76 return; 78 return;
77 } 79 }
78 if (Error error = IsWhenceValid(whence)) { 80
81 error = IsWhenceValid(whence);
82 if (error != ERROR_OK) {
79 callback.Run(error, Array<uint8_t>()); 83 callback.Run(error, Array<uint8_t>());
80 return; 84 return;
81 } 85 }
82 86
83 if (offset != 0 || whence != WHENCE_FROM_CURRENT) { 87 if (offset != 0 || whence != WHENCE_FROM_CURRENT) {
84 // TODO(vtl): Use |pread()| below in the |WHENCE_FROM_START| case. This 88 // TODO(vtl): Use |pread()| below in the |WHENCE_FROM_START| case. This
85 // implementation is obviously not atomic. (If someone seeks simultaneously, 89 // implementation is obviously not atomic. (If someone seeks simultaneously,
86 // we'll end up writing somewhere else. Or, well, we would if we were 90 // we'll end up writing somewhere else. Or, well, we would if we were
87 // multithreaded.) Maybe we should do an |ftell()| and always use |pread()|. 91 // multithreaded.) Maybe we should do an |ftell()| and always use |pread()|.
88 // TODO(vtl): Possibly, at least sometimes we should not change the file 92 // TODO(vtl): Possibly, at least sometimes we should not change the file
(...skipping 29 matching lines...) Expand all
118 callback.Run(ERROR_CLOSED, 0); 122 callback.Run(ERROR_CLOSED, 0);
119 return; 123 return;
120 } 124 }
121 // Who knows what |write()| would return if the size is that big (and it 125 // Who knows what |write()| would return if the size is that big (and it
122 // actually wrote that much). 126 // actually wrote that much).
123 if (bytes_to_write.size() > 127 if (bytes_to_write.size() >
124 static_cast<size_t>(std::numeric_limits<ssize_t>::max())) { 128 static_cast<size_t>(std::numeric_limits<ssize_t>::max())) {
125 callback.Run(ERROR_OUT_OF_RANGE, 0); 129 callback.Run(ERROR_OUT_OF_RANGE, 0);
126 return; 130 return;
127 } 131 }
128 if (Error error = IsOffsetValid(offset)) { 132
133 Error error = IsOffsetValid(offset);
134 if (error != ERROR_OK) {
129 callback.Run(error, 0); 135 callback.Run(error, 0);
130 return; 136 return;
131 } 137 }
132 if (Error error = IsWhenceValid(whence)) { 138
139 error = IsWhenceValid(whence);
140 if (error != ERROR_OK) {
133 callback.Run(error, 0); 141 callback.Run(error, 0);
134 return; 142 return;
135 } 143 }
136 144
137 if (offset != 0 || whence != WHENCE_FROM_CURRENT) { 145 if (offset != 0 || whence != WHENCE_FROM_CURRENT) {
138 // TODO(vtl): Use |pwrite()| below in the |WHENCE_FROM_START| case. This 146 // TODO(vtl): Use |pwrite()| below in the |WHENCE_FROM_START| case. This
139 // implementation is obviously not atomic. (If someone seeks simultaneously, 147 // implementation is obviously not atomic. (If someone seeks simultaneously,
140 // we'll end up writing somewhere else. Or, well, we would if we were 148 // we'll end up writing somewhere else. Or, well, we would if we were
141 // multithreaded.) Maybe we should do an |ftell()| and always use 149 // multithreaded.) Maybe we should do an |ftell()| and always use
142 // |pwrite()|. 150 // |pwrite()|.
(...skipping 22 matching lines...) Expand all
165 173
166 void FileImpl::ReadToStream(ScopedDataPipeProducerHandle source, 174 void FileImpl::ReadToStream(ScopedDataPipeProducerHandle source,
167 int64_t offset, 175 int64_t offset,
168 Whence whence, 176 Whence whence,
169 int64_t num_bytes_to_read, 177 int64_t num_bytes_to_read,
170 const ReadToStreamCallback& callback) { 178 const ReadToStreamCallback& callback) {
171 if (!file_fd_.is_valid()) { 179 if (!file_fd_.is_valid()) {
172 callback.Run(ERROR_CLOSED); 180 callback.Run(ERROR_CLOSED);
173 return; 181 return;
174 } 182 }
175 if (Error error = IsOffsetValid(offset)) { 183
184 Error error = IsOffsetValid(offset);
185 if (error != ERROR_OK) {
176 callback.Run(error); 186 callback.Run(error);
177 return; 187 return;
178 } 188 }
179 if (Error error = IsWhenceValid(whence)) { 189
190 error = IsWhenceValid(whence);
191 if (error != ERROR_OK) {
180 callback.Run(error); 192 callback.Run(error);
181 return; 193 return;
182 } 194 }
183 195
184 // TODO(vtl): FIXME soon 196 // TODO(vtl): FIXME soon
185 NOTIMPLEMENTED(); 197 NOTIMPLEMENTED();
186 callback.Run(ERROR_UNIMPLEMENTED); 198 callback.Run(ERROR_UNIMPLEMENTED);
187 } 199 }
188 200
189 void FileImpl::WriteFromStream(ScopedDataPipeConsumerHandle sink, 201 void FileImpl::WriteFromStream(ScopedDataPipeConsumerHandle sink,
190 int64_t offset, 202 int64_t offset,
191 Whence whence, 203 Whence whence,
192 const WriteFromStreamCallback& callback) { 204 const WriteFromStreamCallback& callback) {
193 if (!file_fd_.is_valid()) { 205 if (!file_fd_.is_valid()) {
194 callback.Run(ERROR_CLOSED); 206 callback.Run(ERROR_CLOSED);
195 return; 207 return;
196 } 208 }
197 if (Error error = IsOffsetValid(offset)) { 209
210 Error error = IsOffsetValid(offset);
211 if (error != ERROR_OK) {
198 callback.Run(error); 212 callback.Run(error);
199 return; 213 return;
200 } 214 }
201 if (Error error = IsWhenceValid(whence)) { 215
216 error = IsWhenceValid(whence);
217 if (error != ERROR_OK) {
202 callback.Run(error); 218 callback.Run(error);
203 return; 219 return;
204 } 220 }
205 221
206 // TODO(vtl): FIXME soon 222 // TODO(vtl): FIXME soon
207 NOTIMPLEMENTED(); 223 NOTIMPLEMENTED();
208 callback.Run(ERROR_UNIMPLEMENTED); 224 callback.Run(ERROR_UNIMPLEMENTED);
209 } 225 }
210 226
211 void FileImpl::Tell(const TellCallback& callback) { 227 void FileImpl::Tell(const TellCallback& callback) {
212 Seek(0, WHENCE_FROM_CURRENT, callback); 228 Seek(0, WHENCE_FROM_CURRENT, callback);
213 } 229 }
214 230
215 void FileImpl::Seek(int64_t offset, 231 void FileImpl::Seek(int64_t offset,
216 Whence whence, 232 Whence whence,
217 const SeekCallback& callback) { 233 const SeekCallback& callback) {
218 if (!file_fd_.is_valid()) { 234 if (!file_fd_.is_valid()) {
219 callback.Run(ERROR_CLOSED, 0); 235 callback.Run(ERROR_CLOSED, 0);
220 return; 236 return;
221 } 237 }
222 if (Error error = IsOffsetValid(offset)) { 238
239 Error error = IsOffsetValid(offset);
240 if (error != ERROR_OK) {
223 callback.Run(error, 0); 241 callback.Run(error, 0);
224 return; 242 return;
225 } 243 }
226 if (Error error = IsWhenceValid(whence)) { 244
245 error = IsWhenceValid(whence);
246 if (error != ERROR_OK) {
227 callback.Run(error, 0); 247 callback.Run(error, 0);
228 return; 248 return;
229 } 249 }
230 250
231 off_t position = lseek(file_fd_.get(), static_cast<off_t>(offset), 251 off_t position = lseek(file_fd_.get(), static_cast<off_t>(offset),
232 WhenceToStandardWhence(whence)); 252 WhenceToStandardWhence(whence));
233 if (position < 0) { 253 if (position < 0) {
234 callback.Run(ErrnoToError(errno), 0); 254 callback.Run(ErrnoToError(errno), 0);
235 return; 255 return;
236 } 256 }
(...skipping 11 matching lines...) Expand all
248 268
249 void FileImpl::Truncate(int64_t size, const TruncateCallback& callback) { 269 void FileImpl::Truncate(int64_t size, const TruncateCallback& callback) {
250 if (!file_fd_.is_valid()) { 270 if (!file_fd_.is_valid()) {
251 callback.Run(ERROR_CLOSED); 271 callback.Run(ERROR_CLOSED);
252 return; 272 return;
253 } 273 }
254 if (size < 0) { 274 if (size < 0) {
255 callback.Run(ERROR_INVALID_ARGUMENT); 275 callback.Run(ERROR_INVALID_ARGUMENT);
256 return; 276 return;
257 } 277 }
258 if (Error error = IsOffsetValid(size)) { 278
279 Error error = IsOffsetValid(size);
280 if (error != ERROR_OK) {
259 callback.Run(error); 281 callback.Run(error);
260 return; 282 return;
261 } 283 }
262 284
263 if (ftruncate(file_fd_.get(), static_cast<off_t>(size)) != 0) { 285 if (ftruncate(file_fd_.get(), static_cast<off_t>(size)) != 0) {
264 callback.Run(ErrnoToError(errno)); 286 callback.Run(ErrnoToError(errno));
265 return; 287 return;
266 } 288 }
267 289
268 callback.Run(ERROR_OK); 290 callback.Run(ERROR_OK);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return; 348 return;
327 } 349 }
328 350
329 // TODO(vtl): The "correct" error code should be one that can be translated to 351 // TODO(vtl): The "correct" error code should be one that can be translated to
330 // ENOTTY! 352 // ENOTTY!
331 callback.Run(ERROR_UNAVAILABLE, Array<uint32_t>()); 353 callback.Run(ERROR_UNAVAILABLE, Array<uint32_t>());
332 } 354 }
333 355
334 } // namespace files 356 } // namespace files
335 } // namespace mojo 357 } // namespace mojo
OLDNEW
« no previous file with comments | « services/files/directory_impl.cc ('k') | services/files/shared_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698