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 } | 59 } |
60 | 60 |
61 File::~File() { | 61 File::~File() { |
62 // Go through the AssertIOAllowed logic. | 62 // Go through the AssertIOAllowed logic. |
63 Close(); | 63 Close(); |
64 } | 64 } |
65 | 65 |
66 // static | 66 // static |
67 File File::CreateForAsyncHandle(PlatformFile platform_file) { | 67 File File::CreateForAsyncHandle(PlatformFile platform_file) { |
68 File file(platform_file); | 68 File file(platform_file); |
69 // It would be nice if we could validate that |platform_file| was opened with | 69 // It would be nice if we could validate that |platform_file| was opened with |
70 // FILE_FLAG_OVERLAPPED on Windows but this doesn't appear to be possible. | 70 // FILE_FLAG_OVERLAPPED on Windows but this doesn't appear to be possible. |
71 file.async_ = true; | 71 file.async_ = true; |
72 return file.Pass(); | 72 return file.Pass(); |
73 } | 73 } |
74 | 74 |
75 File& File::operator=(RValue other) { | 75 File& File::operator=(RValue other) { |
76 if (this != other.object) { | 76 if (this != other.object) { |
77 Close(); | 77 Close(); |
78 SetPlatformFile(other.object->TakePlatformFile()); | 78 SetPlatformFile(other.object->TakePlatformFile()); |
79 path_ = other.object->path_; | 79 tracing_path_ = other.object->tracing_path_; |
80 error_details_ = other.object->error_details(); | 80 error_details_ = other.object->error_details(); |
81 created_ = other.object->created(); | 81 created_ = other.object->created(); |
82 async_ = other.object->async_; | 82 async_ = other.object->async_; |
83 } | 83 } |
84 return *this; | 84 return *this; |
85 } | 85 } |
86 | 86 |
87 #if !defined(OS_NACL) | 87 #if !defined(OS_NACL) |
88 void File::Initialize(const FilePath& path, uint32 flags) { | 88 void File::Initialize(const FilePath& path, uint32 flags) { |
89 if (path.ReferencesParent()) { | 89 if (path.ReferencesParent()) { |
90 error_details_ = FILE_ERROR_ACCESS_DENIED; | 90 error_details_ = FILE_ERROR_ACCESS_DENIED; |
91 return; | 91 return; |
92 } | 92 } |
93 path_ = path; | 93 if (FileTracing::IsCategoryEnabled()) |
| 94 tracing_path_ = path; |
94 SCOPED_FILE_TRACE("Initialize"); | 95 SCOPED_FILE_TRACE("Initialize"); |
95 DoInitialize(flags); | 96 DoInitialize(path, flags); |
96 } | 97 } |
97 #endif | 98 #endif |
98 | 99 |
99 std::string File::ErrorToString(Error error) { | 100 std::string File::ErrorToString(Error error) { |
100 switch (error) { | 101 switch (error) { |
101 case FILE_OK: | 102 case FILE_OK: |
102 return "FILE_OK"; | 103 return "FILE_OK"; |
103 case FILE_ERROR_FAILED: | 104 case FILE_ERROR_FAILED: |
104 return "FILE_ERROR_FAILED"; | 105 return "FILE_ERROR_FAILED"; |
105 case FILE_ERROR_IN_USE: | 106 case FILE_ERROR_IN_USE: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 143 |
143 bool File::Flush() { | 144 bool File::Flush() { |
144 ElapsedTimer timer; | 145 ElapsedTimer timer; |
145 SCOPED_FILE_TRACE("Flush"); | 146 SCOPED_FILE_TRACE("Flush"); |
146 bool return_value = DoFlush(); | 147 bool return_value = DoFlush(); |
147 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); | 148 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); |
148 return return_value; | 149 return return_value; |
149 } | 150 } |
150 | 151 |
151 } // namespace base | 152 } // namespace base |
OLD | NEW |