rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 5 | #include "base/files/file.h" |
| 6 | |
| 7 | // TODO(rvargas): remove this (needed for kInvalidPlatformFileValue). |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 8 | #include "base/platform_file.h" |
| 9 | |
| 10 | namespace base { |
| 11 | |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 12 | File::Info::Info() |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 13 | : size(0), |
| 14 | is_directory(false), |
| 15 | is_symbolic_link(false) { |
| 16 | } |
| 17 | |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 18 | File::Info::~Info() { |
| 19 | } |
| 20 | |
| 21 | File::File() |
| 22 | : file_(kInvalidPlatformFileValue), |
rvargas@chromium.org | ca704f4 | 2014-03-26 18:59:31 +0900 | [diff] [blame^] | 23 | error_details_(FILE_ERROR_FAILED), |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 24 | created_(false), |
| 25 | async_(false) { |
| 26 | } |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 27 | |
| 28 | #if !defined(OS_NACL) |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 29 | File::File(const FilePath& name, uint32 flags) |
| 30 | : file_(kInvalidPlatformFileValue), |
rvargas@chromium.org | 9cce032 | 2014-01-09 07:30:21 +0900 | [diff] [blame] | 31 | error_details_(FILE_OK), |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 32 | created_(false), |
| 33 | async_(false) { |
rvargas@chromium.org | e207eae | 2014-01-04 07:14:15 +0900 | [diff] [blame] | 34 | Initialize(name, flags); |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 35 | } |
| 36 | #endif |
| 37 | |
rvargas@chromium.org | e207eae | 2014-01-04 07:14:15 +0900 | [diff] [blame] | 38 | File::File(PlatformFile platform_file) |
| 39 | : file_(platform_file), |
rvargas@chromium.org | 9cce032 | 2014-01-09 07:30:21 +0900 | [diff] [blame] | 40 | error_details_(FILE_OK), |
rvargas@chromium.org | e207eae | 2014-01-04 07:14:15 +0900 | [diff] [blame] | 41 | created_(false), |
| 42 | async_(false) { |
zmo@chromium.org | 536b9a9 | 2014-03-18 11:39:03 +0900 | [diff] [blame] | 43 | #if defined(OS_POSIX) |
| 44 | DCHECK_GE(platform_file, -1); |
| 45 | #endif |
rvargas@chromium.org | e207eae | 2014-01-04 07:14:15 +0900 | [diff] [blame] | 46 | } |
| 47 | |
rvargas@chromium.org | ca704f4 | 2014-03-26 18:59:31 +0900 | [diff] [blame^] | 48 | File::File(Error error_details) |
| 49 | : file_(kInvalidPlatformFileValue), |
| 50 | error_details_(error_details), |
| 51 | created_(false), |
| 52 | async_(false) { |
| 53 | } |
| 54 | |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 55 | File::File(RValue other) |
| 56 | : file_(other.object->TakePlatformFile()), |
rvargas@chromium.org | 9cce032 | 2014-01-09 07:30:21 +0900 | [diff] [blame] | 57 | error_details_(other.object->error_details()), |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 58 | created_(other.object->created()), |
| 59 | async_(other.object->async_) { |
| 60 | } |
| 61 | |
| 62 | File::~File() { |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | File& File::operator=(RValue other) { |
| 66 | if (this != other.object) { |
| 67 | Close(); |
| 68 | SetPlatformFile(other.object->TakePlatformFile()); |
rvargas@chromium.org | 9cce032 | 2014-01-09 07:30:21 +0900 | [diff] [blame] | 69 | error_details_ = other.object->error_details(); |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame] | 70 | created_ = other.object->created(); |
| 71 | async_ = other.object->async_; |
| 72 | } |
| 73 | return *this; |
| 74 | } |
| 75 | |
rvargas@chromium.org | e207eae | 2014-01-04 07:14:15 +0900 | [diff] [blame] | 76 | #if !defined(OS_NACL) |
| 77 | void File::Initialize(const FilePath& name, uint32 flags) { |
| 78 | if (name.ReferencesParent()) { |
rvargas@chromium.org | 9cce032 | 2014-01-09 07:30:21 +0900 | [diff] [blame] | 79 | error_details_ = FILE_ERROR_ACCESS_DENIED; |
rvargas@chromium.org | e207eae | 2014-01-04 07:14:15 +0900 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | InitializeUnsafe(name, flags); |
| 83 | } |
| 84 | #endif |
| 85 | |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 86 | } // namespace base |