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/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/timer/elapsed_timer.h" | 8 #include "base/timer/elapsed_timer.h" |
| 9 #include "base/trace_event/trace_event.h" |
9 | 10 |
10 namespace base { | 11 namespace base { |
11 | 12 |
12 File::Info::Info() | 13 File::Info::Info() |
13 : size(0), | 14 : size(0), |
14 is_directory(false), | 15 is_directory(false), |
15 is_symbolic_link(false) { | 16 is_symbolic_link(false) { |
16 } | 17 } |
17 | 18 |
18 File::Info::~Info() { | 19 File::Info::~Info() { |
19 } | 20 } |
20 | 21 |
21 File::File() | 22 File::File() |
22 : error_details_(FILE_ERROR_FAILED), | 23 : error_details_(FILE_ERROR_FAILED), |
23 created_(false), | 24 created_(false), |
24 async_(false) { | 25 async_(false) { |
| 26 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this); |
25 } | 27 } |
26 | 28 |
27 #if !defined(OS_NACL) | 29 #if !defined(OS_NACL) |
28 File::File(const FilePath& name, uint32 flags) | 30 File::File(const FilePath& path, uint32 flags) |
29 : error_details_(FILE_OK), | 31 : error_details_(FILE_OK), |
30 created_(false), | 32 created_(false), |
31 async_(false) { | 33 async_(false) { |
32 Initialize(name, flags); | 34 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this); |
| 35 Initialize(path, flags); |
33 } | 36 } |
34 #endif | 37 #endif |
35 | 38 |
36 File::File(PlatformFile platform_file) | 39 File::File(PlatformFile platform_file) |
37 : file_(platform_file), | 40 : file_(platform_file), |
38 error_details_(FILE_OK), | 41 error_details_(FILE_OK), |
39 created_(false), | 42 created_(false), |
40 async_(false) { | 43 async_(false) { |
41 #if defined(OS_POSIX) | 44 #if defined(OS_POSIX) |
42 DCHECK_GE(platform_file, -1); | 45 DCHECK_GE(platform_file, -1); |
43 #endif | 46 #endif |
| 47 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this); |
44 } | 48 } |
45 | 49 |
46 File::File(Error error_details) | 50 File::File(Error error_details) |
47 : error_details_(error_details), | 51 : error_details_(error_details), |
48 created_(false), | 52 created_(false), |
49 async_(false) { | 53 async_(false) { |
| 54 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this); |
50 } | 55 } |
51 | 56 |
52 File::File(RValue other) | 57 File::File(RValue other) |
53 : file_(other.object->TakePlatformFile()), | 58 : file_(other.object->TakePlatformFile()), |
| 59 path_(other.object->path_), |
54 error_details_(other.object->error_details()), | 60 error_details_(other.object->error_details()), |
55 created_(other.object->created()), | 61 created_(other.object->created()), |
56 async_(other.object->async_) { | 62 async_(other.object->async_) { |
| 63 TRACE_EVENT_ASYNC_BEGIN0(kTraceGroup, "File", this); |
57 } | 64 } |
58 | 65 |
59 File::~File() { | 66 File::~File() { |
60 // Go through the AssertIOAllowed logic. | 67 // Go through the AssertIOAllowed logic. |
61 Close(); | 68 Close(); |
| 69 TRACE_EVENT_ASYNC_END0(kTraceGroup, "File", this); |
62 } | 70 } |
63 | 71 |
64 File& File::operator=(RValue other) { | 72 File& File::operator=(RValue other) { |
65 if (this != other.object) { | 73 if (this != other.object) { |
66 Close(); | 74 Close(); |
67 SetPlatformFile(other.object->TakePlatformFile()); | 75 SetPlatformFile(other.object->TakePlatformFile()); |
| 76 path_ = other.object->path_; |
68 error_details_ = other.object->error_details(); | 77 error_details_ = other.object->error_details(); |
69 created_ = other.object->created(); | 78 created_ = other.object->created(); |
70 async_ = other.object->async_; | 79 async_ = other.object->async_; |
71 } | 80 } |
72 return *this; | 81 return *this; |
73 } | 82 } |
74 | 83 |
75 #if !defined(OS_NACL) | 84 #if !defined(OS_NACL) |
76 void File::Initialize(const FilePath& name, uint32 flags) { | 85 void File::Initialize(const FilePath& path, uint32 flags) { |
77 if (name.ReferencesParent()) { | 86 path_ = path; |
| 87 if (path_.ReferencesParent()) { |
78 error_details_ = FILE_ERROR_ACCESS_DENIED; | 88 error_details_ = FILE_ERROR_ACCESS_DENIED; |
79 return; | 89 return; |
80 } | 90 } |
81 DoInitialize(name, flags); | 91 TRACE_EVENT1(kTraceGroup, "Initialize", "path", path_.AsUTF8Unsafe()); |
| 92 DoInitialize(flags); |
82 } | 93 } |
83 #endif | 94 #endif |
84 | 95 |
85 std::string File::ErrorToString(Error error) { | 96 std::string File::ErrorToString(Error error) { |
86 switch (error) { | 97 switch (error) { |
87 case FILE_OK: | 98 case FILE_OK: |
88 return "FILE_OK"; | 99 return "FILE_OK"; |
89 case FILE_ERROR_FAILED: | 100 case FILE_ERROR_FAILED: |
90 return "FILE_ERROR_FAILED"; | 101 return "FILE_ERROR_FAILED"; |
91 case FILE_ERROR_IN_USE: | 102 case FILE_ERROR_IN_USE: |
(...skipping 27 matching lines...) Expand all Loading... |
119 case FILE_ERROR_IO: | 130 case FILE_ERROR_IO: |
120 return "FILE_ERROR_IO"; | 131 return "FILE_ERROR_IO"; |
121 case FILE_ERROR_MAX: | 132 case FILE_ERROR_MAX: |
122 break; | 133 break; |
123 } | 134 } |
124 | 135 |
125 NOTREACHED(); | 136 NOTREACHED(); |
126 return ""; | 137 return ""; |
127 } | 138 } |
128 | 139 |
| 140 // static |
| 141 const char File::kTraceGroup[] = TRACE_DISABLED_BY_DEFAULT("file"); |
| 142 |
129 bool File::Flush() { | 143 bool File::Flush() { |
130 ElapsedTimer timer; | 144 ElapsedTimer timer; |
131 bool return_value = DoFlush(); | 145 bool return_value = DoFlush(); |
132 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); | 146 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed()); |
133 return return_value; | 147 return return_value; |
134 } | 148 } |
135 | 149 |
136 } // namespace base | 150 } // namespace base |
OLD | NEW |