Update strings for turning off Smart Lock.
[chromium-blink-merge.git] / base / files / file.cc
blobea8dbf27ac1770d88fc6ce933a4bdd331820d2d9
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 namespace base {
10 File::Info::Info()
11 : size(0),
12 is_directory(false),
13 is_symbolic_link(false) {
16 File::Info::~Info() {
19 File::File()
20 : error_details_(FILE_ERROR_FAILED),
21 created_(false),
22 async_(false) {
25 #if !defined(OS_NACL)
26 File::File(const FilePath& name, uint32 flags)
27 : error_details_(FILE_OK),
28 created_(false),
29 async_(false) {
30 Initialize(name, flags);
32 #endif
34 File::File(PlatformFile platform_file)
35 : file_(platform_file),
36 error_details_(FILE_OK),
37 created_(false),
38 async_(false) {
39 #if defined(OS_POSIX)
40 DCHECK_GE(platform_file, -1);
41 #endif
44 File::File(Error error_details)
45 : error_details_(error_details),
46 created_(false),
47 async_(false) {
50 File::File(RValue other)
51 : file_(other.object->TakePlatformFile()),
52 error_details_(other.object->error_details()),
53 created_(other.object->created()),
54 async_(other.object->async_) {
57 File::~File() {
58 // Go through the AssertIOAllowed logic.
59 Close();
62 File& File::operator=(RValue other) {
63 if (this != other.object) {
64 Close();
65 SetPlatformFile(other.object->TakePlatformFile());
66 error_details_ = other.object->error_details();
67 created_ = other.object->created();
68 async_ = other.object->async_;
70 return *this;
73 #if !defined(OS_NACL)
74 void File::Initialize(const FilePath& name, uint32 flags) {
75 if (name.ReferencesParent()) {
76 error_details_ = FILE_ERROR_ACCESS_DENIED;
77 return;
79 InitializeUnsafe(name, flags);
81 #endif
83 std::string File::ErrorToString(Error error) {
84 switch (error) {
85 case FILE_OK:
86 return "FILE_OK";
87 case FILE_ERROR_FAILED:
88 return "FILE_ERROR_FAILED";
89 case FILE_ERROR_IN_USE:
90 return "FILE_ERROR_IN_USE";
91 case FILE_ERROR_EXISTS:
92 return "FILE_ERROR_EXISTS";
93 case FILE_ERROR_NOT_FOUND:
94 return "FILE_ERROR_NOT_FOUND";
95 case FILE_ERROR_ACCESS_DENIED:
96 return "FILE_ERROR_ACCESS_DENIED";
97 case FILE_ERROR_TOO_MANY_OPENED:
98 return "FILE_ERROR_TOO_MANY_OPENED";
99 case FILE_ERROR_NO_MEMORY:
100 return "FILE_ERROR_NO_MEMORY";
101 case FILE_ERROR_NO_SPACE:
102 return "FILE_ERROR_NO_SPACE";
103 case FILE_ERROR_NOT_A_DIRECTORY:
104 return "FILE_ERROR_NOT_A_DIRECTORY";
105 case FILE_ERROR_INVALID_OPERATION:
106 return "FILE_ERROR_INVALID_OPERATION";
107 case FILE_ERROR_SECURITY:
108 return "FILE_ERROR_SECURITY";
109 case FILE_ERROR_ABORT:
110 return "FILE_ERROR_ABORT";
111 case FILE_ERROR_NOT_A_FILE:
112 return "FILE_ERROR_NOT_A_FILE";
113 case FILE_ERROR_NOT_EMPTY:
114 return "FILE_ERROR_NOT_EMPTY";
115 case FILE_ERROR_INVALID_URL:
116 return "FILE_ERROR_INVALID_URL";
117 case FILE_ERROR_IO:
118 return "FILE_ERROR_IO";
119 case FILE_ERROR_MAX:
120 break;
123 NOTREACHED();
124 return "";
127 } // namespace base