OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/files/file_tracing.h" | 7 #include "base/files/file_tracing.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/timer/elapsed_timer.h" | 9 #include "base/timer/elapsed_timer.h" |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 File::File(Error error_details) | 47 File::File(Error error_details) |
48 : error_details_(error_details), | 48 : error_details_(error_details), |
49 created_(false), | 49 created_(false), |
50 async_(false) { | 50 async_(false) { |
51 } | 51 } |
52 | 52 |
53 File::File(RValue other) | 53 File::File(RValue other) |
54 : file_(other.object->TakePlatformFile()), | 54 : file_(other.object->TakePlatformFile()), |
55 path_(other.object->path_), | 55 tracing_path_(other.object->tracing_path_), |
56 error_details_(other.object->error_details()), | 56 error_details_(other.object->error_details()), |
57 created_(other.object->created()), | 57 created_(other.object->created()), |
58 async_(other.object->async_) { | 58 async_(other.object->async_) {} |
59 } | |
60 | 59 |
61 File::~File() { | 60 File::~File() { |
62 // Go through the AssertIOAllowed logic. | 61 // Go through the AssertIOAllowed logic. |
63 Close(); | 62 Close(); |
64 } | 63 } |
65 | 64 |
| 65 // static |
| 66 File File::CreateForAsyncHandle(PlatformFile platform_file) { |
| 67 File file(platform_file); |
| 68 // It would be nice if we could validate that |platform_file| was opened with |
| 69 // FILE_FLAG_OVERLAPPED on Windows but this doesn't appear to be possible. |
| 70 file.async_ = true; |
| 71 return file.Pass(); |
| 72 } |
| 73 |
66 File& File::operator=(RValue other) { | 74 File& File::operator=(RValue other) { |
67 if (this != other.object) { | 75 if (this != other.object) { |
68 Close(); | 76 Close(); |
69 SetPlatformFile(other.object->TakePlatformFile()); | 77 SetPlatformFile(other.object->TakePlatformFile()); |
70 path_ = other.object->path_; | 78 tracing_path_ = other.object->tracing_path_; |
71 error_details_ = other.object->error_details(); | 79 error_details_ = other.object->error_details(); |
72 created_ = other.object->created(); | 80 created_ = other.object->created(); |
73 async_ = other.object->async_; | 81 async_ = other.object->async_; |
74 } | 82 } |
75 return *this; | 83 return *this; |
76 } | 84 } |
77 | 85 |
78 #if !defined(OS_NACL) | 86 #if !defined(OS_NACL) |
79 void File::Initialize(const FilePath& path, uint32 flags) { | 87 void File::Initialize(const FilePath& path, uint32 flags) { |
80 if (path.ReferencesParent()) { | 88 if (path.ReferencesParent()) { |
81 error_details_ = FILE_ERROR_ACCESS_DENIED; | 89 error_details_ = FILE_ERROR_ACCESS_DENIED; |
82 return; | 90 return; |
83 } | 91 } |
84 path_ = path; | 92 if (FileTracing::IsCategoryEnabled()) |
| 93 tracing_path_ = path; |
85 SCOPED_FILE_TRACE("Initialize"); | 94 SCOPED_FILE_TRACE("Initialize"); |
86 DoInitialize(flags); | 95 DoInitialize(path, flags); |
87 } | 96 } |
88 #endif | 97 #endif |
89 | 98 |
90 std::string File::ErrorToString(Error error) { | 99 std::string File::ErrorToString(Error error) { |
91 switch (error) { | 100 switch (error) { |
92 case FILE_OK: | 101 case FILE_OK: |
93 return "FILE_OK"; | 102 return "FILE_OK"; |
94 case FILE_ERROR_FAILED: | 103 case FILE_ERROR_FAILED: |
95 return "FILE_ERROR_FAILED"; | 104 return "FILE_ERROR_FAILED"; |
96 case FILE_ERROR_IN_USE: | 105 case FILE_ERROR_IN_USE: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 142 |
134 bool File::Flush() { | 143 bool File::Flush() { |
135 ElapsedTimer timer; | 144 ElapsedTimer timer; |
136 SCOPED_FILE_TRACE("Flush"); | 145 SCOPED_FILE_TRACE("Flush"); |
137 bool return_value = DoFlush(); | 146 bool return_value = DoFlush(); |
138 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); | 147 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); |
139 return return_value; | 148 return return_value; |
140 } | 149 } |
141 | 150 |
142 } // namespace base | 151 } // namespace base |
OLD | NEW |