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), |
| 23 | error_(FILE_OK), |
| 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), |
| 31 | error_(FILE_OK), |
| 32 | created_(false), |
| 33 | async_(false) { |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 34 | if (name.ReferencesParent()) { |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame^] | 35 | error_ = FILE_ERROR_ACCESS_DENIED; |
| 36 | return; |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 37 | } |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame^] | 38 | CreateBaseFileUnsafe(name, flags); |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 39 | } |
| 40 | #endif |
| 41 | |
rvargas@chromium.org | 12938d7 | 2013-12-04 09:46:32 +0900 | [diff] [blame^] | 42 | File::File(RValue other) |
| 43 | : file_(other.object->TakePlatformFile()), |
| 44 | error_(other.object->error()), |
| 45 | created_(other.object->created()), |
| 46 | async_(other.object->async_) { |
| 47 | } |
| 48 | |
| 49 | File::~File() { |
| 50 | Close(); |
| 51 | } |
| 52 | |
| 53 | File& File::operator=(RValue other) { |
| 54 | if (this != other.object) { |
| 55 | Close(); |
| 56 | SetPlatformFile(other.object->TakePlatformFile()); |
| 57 | error_ = other.object->error(); |
| 58 | created_ = other.object->created(); |
| 59 | async_ = other.object->async_; |
| 60 | } |
| 61 | return *this; |
| 62 | } |
| 63 | |
rvargas@google.com | b1ae319 | 2013-11-28 10:31:31 +0900 | [diff] [blame] | 64 | } // namespace base |