Fix sort order of unlaunched apps on app list start page.
[chromium-blink-merge.git] / base / files / file.cc
bloba997074bec4003b2474287d33785d844a354addb
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"
8 #if defined(OS_POSIX)
9 #include "base/files/file_posix_hooks_internal.h"
10 #endif
12 namespace base {
14 File::Info::Info()
15 : size(0),
16 is_directory(false),
17 is_symbolic_link(false) {
20 File::Info::~Info() {
23 File::File()
24 : error_details_(FILE_ERROR_FAILED),
25 created_(false),
26 async_(false) {
29 #if !defined(OS_NACL)
30 File::File(const FilePath& name, uint32 flags)
31 : error_details_(FILE_OK),
32 created_(false),
33 async_(false) {
34 Initialize(name, flags);
36 #endif
38 File::File(PlatformFile platform_file)
39 : file_(platform_file),
40 error_details_(FILE_OK),
41 created_(false),
42 async_(false) {
43 #if defined(OS_POSIX)
44 DCHECK_GE(platform_file, -1);
45 if (IsValid())
46 ProtectFileDescriptor(platform_file);
47 #endif
50 File::File(Error error_details)
51 : error_details_(error_details),
52 created_(false),
53 async_(false) {
56 File::File(RValue other)
57 : file_(other.object->TakePlatformFile()),
58 error_details_(other.object->error_details()),
59 created_(other.object->created()),
60 async_(other.object->async_) {
61 #if defined(OS_POSIX)
62 if (IsValid())
63 ProtectFileDescriptor(GetPlatformFile());
64 #endif
67 File::~File() {
68 // Go through the AssertIOAllowed logic.
69 Close();
72 File& File::operator=(RValue other) {
73 if (this != other.object) {
74 Close();
75 SetPlatformFile(other.object->TakePlatformFile());
76 error_details_ = other.object->error_details();
77 created_ = other.object->created();
78 async_ = other.object->async_;
80 return *this;
83 #if !defined(OS_NACL)
84 void File::Initialize(const FilePath& name, uint32 flags) {
85 if (name.ReferencesParent()) {
86 error_details_ = FILE_ERROR_ACCESS_DENIED;
87 return;
89 InitializeUnsafe(name, flags);
91 #endif
93 std::string File::ErrorToString(Error error) {
94 switch (error) {
95 case FILE_OK:
96 return "FILE_OK";
97 case FILE_ERROR_FAILED:
98 return "FILE_ERROR_FAILED";
99 case FILE_ERROR_IN_USE:
100 return "FILE_ERROR_IN_USE";
101 case FILE_ERROR_EXISTS:
102 return "FILE_ERROR_EXISTS";
103 case FILE_ERROR_NOT_FOUND:
104 return "FILE_ERROR_NOT_FOUND";
105 case FILE_ERROR_ACCESS_DENIED:
106 return "FILE_ERROR_ACCESS_DENIED";
107 case FILE_ERROR_TOO_MANY_OPENED:
108 return "FILE_ERROR_TOO_MANY_OPENED";
109 case FILE_ERROR_NO_MEMORY:
110 return "FILE_ERROR_NO_MEMORY";
111 case FILE_ERROR_NO_SPACE:
112 return "FILE_ERROR_NO_SPACE";
113 case FILE_ERROR_NOT_A_DIRECTORY:
114 return "FILE_ERROR_NOT_A_DIRECTORY";
115 case FILE_ERROR_INVALID_OPERATION:
116 return "FILE_ERROR_INVALID_OPERATION";
117 case FILE_ERROR_SECURITY:
118 return "FILE_ERROR_SECURITY";
119 case FILE_ERROR_ABORT:
120 return "FILE_ERROR_ABORT";
121 case FILE_ERROR_NOT_A_FILE:
122 return "FILE_ERROR_NOT_A_FILE";
123 case FILE_ERROR_NOT_EMPTY:
124 return "FILE_ERROR_NOT_EMPTY";
125 case FILE_ERROR_INVALID_URL:
126 return "FILE_ERROR_INVALID_URL";
127 case FILE_ERROR_IO:
128 return "FILE_ERROR_IO";
129 case FILE_ERROR_MAX:
130 break;
133 NOTREACHED();
134 return "";
137 } // namespace base