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.
5 #include "base/files/file.h"
6 #include "base/files/file_path.h"
7 #include "base/metrics/histogram.h"
8 #include "base/timer/elapsed_timer.h"
11 #include "base/files/file_posix_hooks_internal.h"
19 is_symbolic_link(false) {
26 : error_details_(FILE_ERROR_FAILED
),
32 File::File(const FilePath
& name
, uint32 flags
)
33 : error_details_(FILE_OK
),
36 Initialize(name
, flags
);
40 File::File(PlatformFile platform_file
)
41 : file_(platform_file
),
42 error_details_(FILE_OK
),
46 DCHECK_GE(platform_file
, -1);
48 ProtectFileDescriptor(platform_file
);
52 File::File(Error error_details
)
53 : error_details_(error_details
),
58 File::File(RValue other
)
59 : file_(other
.object
->TakePlatformFile()),
60 error_details_(other
.object
->error_details()),
61 created_(other
.object
->created()),
62 async_(other
.object
->async_
) {
65 ProtectFileDescriptor(GetPlatformFile());
70 // Go through the AssertIOAllowed logic.
74 File
& File::operator=(RValue other
) {
75 if (this != other
.object
) {
77 SetPlatformFile(other
.object
->TakePlatformFile());
78 error_details_
= other
.object
->error_details();
79 created_
= other
.object
->created();
80 async_
= other
.object
->async_
;
86 void File::Initialize(const FilePath
& name
, uint32 flags
) {
87 if (name
.ReferencesParent()) {
88 error_details_
= FILE_ERROR_ACCESS_DENIED
;
91 InitializeUnsafe(name
, flags
);
95 std::string
File::ErrorToString(Error error
) {
99 case FILE_ERROR_FAILED
:
100 return "FILE_ERROR_FAILED";
101 case FILE_ERROR_IN_USE
:
102 return "FILE_ERROR_IN_USE";
103 case FILE_ERROR_EXISTS
:
104 return "FILE_ERROR_EXISTS";
105 case FILE_ERROR_NOT_FOUND
:
106 return "FILE_ERROR_NOT_FOUND";
107 case FILE_ERROR_ACCESS_DENIED
:
108 return "FILE_ERROR_ACCESS_DENIED";
109 case FILE_ERROR_TOO_MANY_OPENED
:
110 return "FILE_ERROR_TOO_MANY_OPENED";
111 case FILE_ERROR_NO_MEMORY
:
112 return "FILE_ERROR_NO_MEMORY";
113 case FILE_ERROR_NO_SPACE
:
114 return "FILE_ERROR_NO_SPACE";
115 case FILE_ERROR_NOT_A_DIRECTORY
:
116 return "FILE_ERROR_NOT_A_DIRECTORY";
117 case FILE_ERROR_INVALID_OPERATION
:
118 return "FILE_ERROR_INVALID_OPERATION";
119 case FILE_ERROR_SECURITY
:
120 return "FILE_ERROR_SECURITY";
121 case FILE_ERROR_ABORT
:
122 return "FILE_ERROR_ABORT";
123 case FILE_ERROR_NOT_A_FILE
:
124 return "FILE_ERROR_NOT_A_FILE";
125 case FILE_ERROR_NOT_EMPTY
:
126 return "FILE_ERROR_NOT_EMPTY";
127 case FILE_ERROR_INVALID_URL
:
128 return "FILE_ERROR_INVALID_URL";
130 return "FILE_ERROR_IO";
141 bool return_value
= DoFlush();
142 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer
.Elapsed());