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

Side by Side Diff: base/files/file_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 #include "base/files/file.h" 5 #include "base/files/file.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 <unistd.h> 10 #include <unistd.h>
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 #endif // defined(OS_NACL) 118 #endif // defined(OS_NACL)
119 119
120 } // namespace 120 } // namespace
121 121
122 // NaCl doesn't implement system calls to open files directly. 122 // NaCl doesn't implement system calls to open files directly.
123 #if !defined(OS_NACL) 123 #if !defined(OS_NACL)
124 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here? 124 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here?
125 void File::InitializeUnsafe(const FilePath& name, uint32 flags) { 125 void File::InitializeUnsafe(const FilePath& name, uint32 flags) {
126 base::ThreadRestrictions::AssertIOAllowed(); 126 base::ThreadRestrictions::AssertIOAllowed();
127 DCHECK(!IsValid()); 127 DCHECK(!IsValid());
128 DCHECK(!(flags & FLAG_ASYNC));
129 128
130 int open_flags = 0; 129 int open_flags = 0;
131 if (flags & FLAG_CREATE) 130 if (flags & FLAG_CREATE)
132 open_flags = O_CREAT | O_EXCL; 131 open_flags = O_CREAT | O_EXCL;
133 132
134 created_ = false; 133 created_ = false;
135 134
136 if (flags & FLAG_CREATE_ALWAYS) { 135 if (flags & FLAG_CREATE_ALWAYS) {
137 DCHECK(!open_flags); 136 DCHECK(!open_flags);
138 open_flags = O_CREAT | O_TRUNC; 137 open_flags = O_CREAT | O_TRUNC;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 open_flags |= O_CREAT; 183 open_flags |= O_CREAT;
185 if (flags & FLAG_EXCLUSIVE_READ || flags & FLAG_EXCLUSIVE_WRITE) 184 if (flags & FLAG_EXCLUSIVE_READ || flags & FLAG_EXCLUSIVE_WRITE)
186 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW 185 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW
187 186
188 descriptor = HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); 187 descriptor = HANDLE_EINTR(open(name.value().c_str(), open_flags, mode));
189 if (descriptor >= 0) 188 if (descriptor >= 0)
190 created_ = true; 189 created_ = true;
191 } 190 }
192 } 191 }
193 192
194 if (descriptor >= 0 && (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE))) 193 if (descriptor < 0) {
194 error_details_ = File::OSErrorToFileError(errno);
195 return;
196 }
197
198 if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE))
195 created_ = true; 199 created_ = true;
196 200
197 if ((descriptor >= 0) && (flags & FLAG_DELETE_ON_CLOSE)) 201 if (flags & FLAG_DELETE_ON_CLOSE)
198 unlink(name.value().c_str()); 202 unlink(name.value().c_str());
199 203
200 if (descriptor >= 0) 204 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC);
201 error_details_ = FILE_OK; 205 error_details_ = FILE_OK;
202 else
203 error_details_ = File::OSErrorToFileError(errno);
204
205 file_ = descriptor; 206 file_ = descriptor;
206 } 207 }
207 #endif // !defined(OS_NACL) 208 #endif // !defined(OS_NACL)
208 209
209 bool File::IsValid() const { 210 bool File::IsValid() const {
210 return file_ >= 0; 211 return file_ >= 0;
211 } 212 }
212 213
213 PlatformFile File::TakePlatformFile() { 214 PlatformFile File::TakePlatformFile() {
214 PlatformFile file = file_; 215 PlatformFile file = file_;
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 return FILE_ERROR_FAILED; 472 return FILE_ERROR_FAILED;
472 } 473 }
473 } 474 }
474 475
475 void File::SetPlatformFile(PlatformFile file) { 476 void File::SetPlatformFile(PlatformFile file) {
476 DCHECK_EQ(file_, kInvalidPlatformFileValue); 477 DCHECK_EQ(file_, kInvalidPlatformFileValue);
477 file_ = file; 478 file_ = file;
478 } 479 }
479 480
480 } // namespace base 481 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file.h ('k') | base/files/file_unittest.cc » ('j') | net/base/file_stream.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698