Add R_8 GPU memory buffers format.
[chromium-blink-merge.git] / base / files / file.cc
blob86fdbc9ec07ff9d1f45bbfab02b51b71985d8c5e
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"
10 #if defined(OS_POSIX)
11 #include "base/files/file_posix_hooks_internal.h"
12 #endif
14 namespace base {
16 File::Info::Info()
17 : size(0),
18 is_directory(false),
19 is_symbolic_link(false) {
22 File::Info::~Info() {
25 File::File()
26 : error_details_(FILE_ERROR_FAILED),
27 created_(false),
28 async_(false) {
31 #if !defined(OS_NACL)
32 File::File(const FilePath& name, uint32 flags)
33 : error_details_(FILE_OK),
34 created_(false),
35 async_(false) {
36 Initialize(name, flags);
38 #endif
40 File::File(PlatformFile platform_file)
41 : file_(platform_file),
42 error_details_(FILE_OK),
43 created_(false),
44 async_(false) {
45 #if defined(OS_POSIX)
46 DCHECK_GE(platform_file, -1);
47 if (IsValid())
48 ProtectFileDescriptor(platform_file);
49 #endif
52 File::File(Error error_details)
53 : error_details_(error_details),
54 created_(false),
55 async_(false) {
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_) {
63 #if defined(OS_POSIX)
64 if (IsValid())
65 ProtectFileDescriptor(GetPlatformFile());
66 #endif
69 File::~File() {
70 // Go through the AssertIOAllowed logic.
71 Close();
74 File& File::operator=(RValue other) {
75 if (this != other.object) {
76 Close();
77 SetPlatformFile(other.object->TakePlatformFile());
78 error_details_ = other.object->error_details();
79 created_ = other.object->created();
80 async_ = other.object->async_;
82 return *this;
85 #if !defined(OS_NACL)
86 void File::Initialize(const FilePath& name, uint32 flags) {
87 if (name.ReferencesParent()) {
88 error_details_ = FILE_ERROR_ACCESS_DENIED;
89 return;
91 InitializeUnsafe(name, flags);
93 #endif
95 std::string File::ErrorToString(Error error) {
96 switch (error) {
97 case FILE_OK:
98 return "FILE_OK";
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";
129 case FILE_ERROR_IO:
130 return "FILE_ERROR_IO";
131 case FILE_ERROR_MAX:
132 break;
135 NOTREACHED();
136 return "";
139 bool File::Flush() {
140 ElapsedTimer timer;
141 bool return_value = DoFlush();
142 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed());
143 return return_value;
146 } // namespace base