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

Side by Side Diff: base/files/file_posix.cc

Issue 737943002: Update from https://crrev.com/304715 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 | « base/files/file.cc ('k') | base/files/file_posix_hooks_internal.h » ('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/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>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_posix_hooks_internal.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
15 #include "base/posix/eintr_wrapper.h" 16 #include "base/posix/eintr_wrapper.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread_restrictions.h" 18 #include "base/threading/thread_restrictions.h"
18 19
19 #if defined(OS_ANDROID) 20 #if defined(OS_ANDROID)
20 #include "base/os_compat_android.h" 21 #include "base/os_compat_android.h"
21 #endif 22 #endif
22 23
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 Time::FromTimeT(last_accessed_sec) + 160 Time::FromTimeT(last_accessed_sec) +
160 TimeDelta::FromMicroseconds(last_accessed_nsec / 161 TimeDelta::FromMicroseconds(last_accessed_nsec /
161 Time::kNanosecondsPerMicrosecond); 162 Time::kNanosecondsPerMicrosecond);
162 163
163 creation_time = 164 creation_time =
164 Time::FromTimeT(creation_time_sec) + 165 Time::FromTimeT(creation_time_sec) +
165 TimeDelta::FromMicroseconds(creation_time_nsec / 166 TimeDelta::FromMicroseconds(creation_time_nsec /
166 Time::kNanosecondsPerMicrosecond); 167 Time::kNanosecondsPerMicrosecond);
167 } 168 }
168 169
170 // Default implementations of Protect/Unprotect hooks defined as weak symbols
171 // where possible.
172 void ProtectFileDescriptor(int fd) {
173 }
174
175 void UnprotectFileDescriptor(int fd) {
176 }
177
169 // NaCl doesn't implement system calls to open files directly. 178 // NaCl doesn't implement system calls to open files directly.
170 #if !defined(OS_NACL) 179 #if !defined(OS_NACL)
171 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here? 180 // TODO(erikkay): does it make sense to support FLAG_EXCLUSIVE_* here?
172 void File::InitializeUnsafe(const FilePath& name, uint32 flags) { 181 void File::InitializeUnsafe(const FilePath& name, uint32 flags) {
173 base::ThreadRestrictions::AssertIOAllowed(); 182 base::ThreadRestrictions::AssertIOAllowed();
174 DCHECK(!IsValid()); 183 DCHECK(!IsValid());
175 184
176 int open_flags = 0; 185 int open_flags = 0;
177 if (flags & FLAG_CREATE) 186 if (flags & FLAG_CREATE)
178 open_flags = O_CREAT | O_EXCL; 187 open_flags = O_CREAT | O_EXCL;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 254
246 if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE)) 255 if (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE))
247 created_ = true; 256 created_ = true;
248 257
249 if (flags & FLAG_DELETE_ON_CLOSE) 258 if (flags & FLAG_DELETE_ON_CLOSE)
250 unlink(name.value().c_str()); 259 unlink(name.value().c_str());
251 260
252 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC); 261 async_ = ((flags & FLAG_ASYNC) == FLAG_ASYNC);
253 error_details_ = FILE_OK; 262 error_details_ = FILE_OK;
254 file_.reset(descriptor); 263 file_.reset(descriptor);
264 ProtectFileDescriptor(descriptor);
255 } 265 }
256 #endif // !defined(OS_NACL) 266 #endif // !defined(OS_NACL)
257 267
258 bool File::IsValid() const { 268 bool File::IsValid() const {
259 return file_.is_valid(); 269 return file_.is_valid();
260 } 270 }
261 271
262 PlatformFile File::GetPlatformFile() const { 272 PlatformFile File::GetPlatformFile() const {
263 return file_.get(); 273 return file_.get();
264 } 274 }
265 275
266 PlatformFile File::TakePlatformFile() { 276 PlatformFile File::TakePlatformFile() {
277 if (IsValid())
278 UnprotectFileDescriptor(GetPlatformFile());
267 return file_.release(); 279 return file_.release();
268 } 280 }
269 281
270 void File::Close() { 282 void File::Close() {
271 if (!IsValid()) 283 if (!IsValid())
272 return; 284 return;
273 285
274 base::ThreadRestrictions::AssertIOAllowed(); 286 base::ThreadRestrictions::AssertIOAllowed();
287 UnprotectFileDescriptor(GetPlatformFile());
275 file_.reset(); 288 file_.reset();
276 } 289 }
277 290
278 int64 File::Seek(Whence whence, int64 offset) { 291 int64 File::Seek(Whence whence, int64 offset) {
279 base::ThreadRestrictions::AssertIOAllowed(); 292 base::ThreadRestrictions::AssertIOAllowed();
280 DCHECK(IsValid()); 293 DCHECK(IsValid());
281 294
282 #if defined(OS_ANDROID) 295 #if defined(OS_ANDROID)
283 COMPILE_ASSERT(sizeof(int64) == sizeof(off64_t), off64_t_64_bit); 296 COMPILE_ASSERT(sizeof(int64) == sizeof(off64_t), off64_t_64_bit);
284 return lseek64(file_.get(), static_cast<off64_t>(offset), 297 return lseek64(file_.get(), static_cast<off64_t>(offset),
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 unsigned int computed_checksum; 533 unsigned int computed_checksum;
521 ComputeMemoryChecksum(&computed_checksum); 534 ComputeMemoryChecksum(&computed_checksum);
522 CHECK_EQ(file_memory_checksum_, computed_checksum) << "corrupted fd memory"; 535 CHECK_EQ(file_memory_checksum_, computed_checksum) << "corrupted fd memory";
523 } 536 }
524 537
525 void File::MemoryCheckingScopedFD::UpdateChecksum() { 538 void File::MemoryCheckingScopedFD::UpdateChecksum() {
526 ComputeMemoryChecksum(&file_memory_checksum_); 539 ComputeMemoryChecksum(&file_memory_checksum_);
527 } 540 }
528 541
529 void File::SetPlatformFile(PlatformFile file) { 542 void File::SetPlatformFile(PlatformFile file) {
530 DCHECK(!file_.is_valid()); 543 CHECK(!file_.is_valid());
531 file_.reset(file); 544 file_.reset(file);
545 if (file_.is_valid())
546 ProtectFileDescriptor(GetPlatformFile());
532 } 547 }
533 548
534 } // namespace base 549 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file.cc ('k') | base/files/file_posix_hooks_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698