Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: base/files/file.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/files/file.h ('k') | base/files/file_enumerator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/files/file.h"
6 #include "base/files/file_path.h"
7 #include "base/files/file_tracing.h"
8 #include "base/metrics/histogram.h"
9 #include "base/timer/elapsed_timer.h"
10
11 namespace base {
12
13 File::Info::Info()
14 : size(0),
15 is_directory(false),
16 is_symbolic_link(false) {
17 }
18
19 File::Info::~Info() {
20 }
21
22 File::File()
23 : error_details_(FILE_ERROR_FAILED),
24 created_(false),
25 async_(false) {
26 }
27
28 #if !defined(OS_NACL)
29 File::File(const FilePath& path, uint32 flags)
30 : error_details_(FILE_OK),
31 created_(false),
32 async_(false) {
33 Initialize(path, flags);
34 }
35 #endif
36
37 File::File(PlatformFile platform_file)
38 : file_(platform_file),
39 error_details_(FILE_OK),
40 created_(false),
41 async_(false) {
42 #if defined(OS_POSIX)
43 DCHECK_GE(platform_file, -1);
44 #endif
45 }
46
47 File::File(Error error_details)
48 : error_details_(error_details),
49 created_(false),
50 async_(false) {
51 }
52
53 File::File(RValue other)
54 : file_(other.object->TakePlatformFile()),
55 tracing_path_(other.object->tracing_path_),
56 error_details_(other.object->error_details()),
57 created_(other.object->created()),
58 async_(other.object->async_) {}
59
60 File::~File() {
61 // Go through the AssertIOAllowed logic.
62 Close();
63 }
64
65 // static
66 File File::CreateForAsyncHandle(PlatformFile platform_file) {
67 File file(platform_file);
68 // It would be nice if we could validate that |platform_file| was opened with
69 // FILE_FLAG_OVERLAPPED on Windows but this doesn't appear to be possible.
70 file.async_ = true;
71 return file.Pass();
72 }
73
74 File& File::operator=(RValue other) {
75 if (this != other.object) {
76 Close();
77 SetPlatformFile(other.object->TakePlatformFile());
78 tracing_path_ = other.object->tracing_path_;
79 error_details_ = other.object->error_details();
80 created_ = other.object->created();
81 async_ = other.object->async_;
82 }
83 return *this;
84 }
85
86 #if !defined(OS_NACL)
87 void File::Initialize(const FilePath& path, uint32 flags) {
88 if (path.ReferencesParent()) {
89 error_details_ = FILE_ERROR_ACCESS_DENIED;
90 return;
91 }
92 if (FileTracing::IsCategoryEnabled())
93 tracing_path_ = path;
94 SCOPED_FILE_TRACE("Initialize");
95 DoInitialize(path, flags);
96 }
97 #endif
98
99 std::string File::ErrorToString(Error error) {
100 switch (error) {
101 case FILE_OK:
102 return "FILE_OK";
103 case FILE_ERROR_FAILED:
104 return "FILE_ERROR_FAILED";
105 case FILE_ERROR_IN_USE:
106 return "FILE_ERROR_IN_USE";
107 case FILE_ERROR_EXISTS:
108 return "FILE_ERROR_EXISTS";
109 case FILE_ERROR_NOT_FOUND:
110 return "FILE_ERROR_NOT_FOUND";
111 case FILE_ERROR_ACCESS_DENIED:
112 return "FILE_ERROR_ACCESS_DENIED";
113 case FILE_ERROR_TOO_MANY_OPENED:
114 return "FILE_ERROR_TOO_MANY_OPENED";
115 case FILE_ERROR_NO_MEMORY:
116 return "FILE_ERROR_NO_MEMORY";
117 case FILE_ERROR_NO_SPACE:
118 return "FILE_ERROR_NO_SPACE";
119 case FILE_ERROR_NOT_A_DIRECTORY:
120 return "FILE_ERROR_NOT_A_DIRECTORY";
121 case FILE_ERROR_INVALID_OPERATION:
122 return "FILE_ERROR_INVALID_OPERATION";
123 case FILE_ERROR_SECURITY:
124 return "FILE_ERROR_SECURITY";
125 case FILE_ERROR_ABORT:
126 return "FILE_ERROR_ABORT";
127 case FILE_ERROR_NOT_A_FILE:
128 return "FILE_ERROR_NOT_A_FILE";
129 case FILE_ERROR_NOT_EMPTY:
130 return "FILE_ERROR_NOT_EMPTY";
131 case FILE_ERROR_INVALID_URL:
132 return "FILE_ERROR_INVALID_URL";
133 case FILE_ERROR_IO:
134 return "FILE_ERROR_IO";
135 case FILE_ERROR_MAX:
136 break;
137 }
138
139 NOTREACHED();
140 return "";
141 }
142
143 bool File::Flush() {
144 ElapsedTimer timer;
145 SCOPED_FILE_TRACE("Flush");
146 bool return_value = DoFlush();
147 UMA_HISTOGRAM_TIMES("PlatformFile.FlushTime", timer.Elapsed());
148 return return_value;
149 }
150
151 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file.h ('k') | base/files/file_enumerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698