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

Side by Side Diff: components/filesystem/util.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 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 | « components/filesystem/files_test_base.cc ('k') | components/font_service/font_service_app.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/filesystem/util.h" 5 #include "components/filesystem/util.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <time.h> 10 #include <time.h>
(...skipping 30 matching lines...) Expand all
41 static_cast<uint32_t>(base::File::FLAG_READ), 41 static_cast<uint32_t>(base::File::FLAG_READ),
42 ""); 42 "");
43 static_assert(filesystem::kFlagWrite == 43 static_assert(filesystem::kFlagWrite ==
44 static_cast<uint32_t>(base::File::FLAG_WRITE), 44 static_cast<uint32_t>(base::File::FLAG_WRITE),
45 ""); 45 "");
46 static_assert(filesystem::kFlagAppend == 46 static_assert(filesystem::kFlagAppend ==
47 static_cast<uint32_t>(base::File::FLAG_APPEND), 47 static_cast<uint32_t>(base::File::FLAG_APPEND),
48 ""); 48 "");
49 49
50 // filesystem.Error in types.mojom must be the same as base::File::Error. 50 // filesystem.Error in types.mojom must be the same as base::File::Error.
51 static_assert(static_cast<int>(filesystem::FILE_ERROR_OK) == 51 static_assert(static_cast<int>(filesystem::FileError::OK) ==
52 static_cast<int>(base::File::FILE_OK), 52 static_cast<int>(base::File::FILE_OK),
53 ""); 53 "");
54 static_assert(static_cast<int>(filesystem::FILE_ERROR_FAILED) == 54 static_assert(static_cast<int>(filesystem::FileError::FAILED) ==
55 static_cast<int>(base::File::FILE_ERROR_FAILED), 55 static_cast<int>(base::File::FILE_ERROR_FAILED),
56 ""); 56 "");
57 static_assert(static_cast<int>(filesystem::FILE_ERROR_IN_USE) == 57 static_assert(static_cast<int>(filesystem::FileError::IN_USE) ==
58 static_cast<int>(base::File::FILE_ERROR_IN_USE), 58 static_cast<int>(base::File::FILE_ERROR_IN_USE),
59 ""); 59 "");
60 static_assert(static_cast<int>(filesystem::FILE_ERROR_EXISTS) == 60 static_assert(static_cast<int>(filesystem::FileError::EXISTS) ==
61 static_cast<int>(base::File::FILE_ERROR_EXISTS), 61 static_cast<int>(base::File::FILE_ERROR_EXISTS),
62 ""); 62 "");
63 static_assert(static_cast<int>(filesystem::FILE_ERROR_NOT_FOUND) == 63 static_assert(static_cast<int>(filesystem::FileError::NOT_FOUND) ==
64 static_cast<int>(base::File::FILE_ERROR_NOT_FOUND), 64 static_cast<int>(base::File::FILE_ERROR_NOT_FOUND),
65 ""); 65 "");
66 static_assert(static_cast<int>(filesystem::FILE_ERROR_ACCESS_DENIED) == 66 static_assert(static_cast<int>(filesystem::FileError::ACCESS_DENIED) ==
67 static_cast<int>(base::File::FILE_ERROR_ACCESS_DENIED), 67 static_cast<int>(base::File::FILE_ERROR_ACCESS_DENIED),
68 ""); 68 "");
69 static_assert(static_cast<int>(filesystem::FILE_ERROR_TOO_MANY_OPENED) == 69 static_assert(static_cast<int>(filesystem::FileError::TOO_MANY_OPENED) ==
70 static_cast<int>(base::File::FILE_ERROR_TOO_MANY_OPENED), 70 static_cast<int>(base::File::FILE_ERROR_TOO_MANY_OPENED),
71 ""); 71 "");
72 static_assert(static_cast<int>(filesystem::FILE_ERROR_NO_MEMORY) == 72 static_assert(static_cast<int>(filesystem::FileError::NO_MEMORY) ==
73 static_cast<int>(base::File::FILE_ERROR_NO_MEMORY), 73 static_cast<int>(base::File::FILE_ERROR_NO_MEMORY),
74 ""); 74 "");
75 static_assert(static_cast<int>(filesystem::FILE_ERROR_NO_SPACE) == 75 static_assert(static_cast<int>(filesystem::FileError::NO_SPACE) ==
76 static_cast<int>(base::File::FILE_ERROR_NO_SPACE), 76 static_cast<int>(base::File::FILE_ERROR_NO_SPACE),
77 ""); 77 "");
78 static_assert(static_cast<int>(filesystem::FILE_ERROR_NOT_A_DIRECTORY) == 78 static_assert(static_cast<int>(filesystem::FileError::NOT_A_DIRECTORY) ==
79 static_cast<int>(base::File::FILE_ERROR_NOT_A_DIRECTORY), 79 static_cast<int>(base::File::FILE_ERROR_NOT_A_DIRECTORY),
80 ""); 80 "");
81 static_assert(static_cast<int>(filesystem::FILE_ERROR_INVALID_OPERATION) == 81 static_assert(static_cast<int>(filesystem::FileError::INVALID_OPERATION) ==
82 static_cast<int>(base::File::FILE_ERROR_INVALID_OPERATION), 82 static_cast<int>(base::File::FILE_ERROR_INVALID_OPERATION),
83 ""); 83 "");
84 static_assert(static_cast<int>(filesystem::FILE_ERROR_SECURITY) == 84 static_assert(static_cast<int>(filesystem::FileError::SECURITY) ==
85 static_cast<int>(base::File::FILE_ERROR_SECURITY), 85 static_cast<int>(base::File::FILE_ERROR_SECURITY),
86 ""); 86 "");
87 static_assert(static_cast<int>(filesystem::FILE_ERROR_ABORT) == 87 static_assert(static_cast<int>(filesystem::FileError::ABORT) ==
88 static_cast<int>(base::File::FILE_ERROR_ABORT), 88 static_cast<int>(base::File::FILE_ERROR_ABORT),
89 ""); 89 "");
90 static_assert(static_cast<int>(filesystem::FILE_ERROR_NOT_A_FILE) == 90 static_assert(static_cast<int>(filesystem::FileError::NOT_A_FILE) ==
91 static_cast<int>(base::File::FILE_ERROR_NOT_A_FILE), 91 static_cast<int>(base::File::FILE_ERROR_NOT_A_FILE),
92 ""); 92 "");
93 static_assert(static_cast<int>(filesystem::FILE_ERROR_NOT_EMPTY) == 93 static_assert(static_cast<int>(filesystem::FileError::NOT_EMPTY) ==
94 static_cast<int>(base::File::FILE_ERROR_NOT_EMPTY), 94 static_cast<int>(base::File::FILE_ERROR_NOT_EMPTY),
95 ""); 95 "");
96 static_assert(static_cast<int>(filesystem::FILE_ERROR_INVALID_URL) == 96 static_assert(static_cast<int>(filesystem::FileError::INVALID_URL) ==
97 static_cast<int>(base::File::FILE_ERROR_INVALID_URL), 97 static_cast<int>(base::File::FILE_ERROR_INVALID_URL),
98 ""); 98 "");
99 static_assert(static_cast<int>(filesystem::FILE_ERROR_IO) == 99 static_assert(static_cast<int>(filesystem::FileError::IO) ==
100 static_cast<int>(base::File::FILE_ERROR_IO), 100 static_cast<int>(base::File::FILE_ERROR_IO),
101 ""); 101 "");
102 102
103 // filesystem.Whence in types.mojom must be the same as base::File::Whence. 103 // filesystem.Whence in types.mojom must be the same as base::File::Whence.
104 static_assert(static_cast<int>(filesystem::WHENCE_FROM_BEGIN) == 104 static_assert(static_cast<int>(filesystem::Whence::FROM_BEGIN) ==
105 static_cast<int>(base::File::FROM_BEGIN), 105 static_cast<int>(base::File::FROM_BEGIN),
106 ""); 106 "");
107 static_assert(static_cast<int>(filesystem::WHENCE_FROM_CURRENT) == 107 static_assert(static_cast<int>(filesystem::Whence::FROM_CURRENT) ==
108 static_cast<int>(base::File::FROM_CURRENT), 108 static_cast<int>(base::File::FROM_CURRENT),
109 ""); 109 "");
110 static_assert(static_cast<int>(filesystem::WHENCE_FROM_END) == 110 static_assert(static_cast<int>(filesystem::Whence::FROM_END) ==
111 static_cast<int>(base::File::FROM_END), 111 static_cast<int>(base::File::FROM_END),
112 ""); 112 "");
113 113
114 namespace filesystem { 114 namespace filesystem {
115 115
116 FileError IsWhenceValid(Whence whence) { 116 FileError IsWhenceValid(Whence whence) {
117 return (whence == WHENCE_FROM_CURRENT || whence == WHENCE_FROM_BEGIN || 117 return (whence == Whence::FROM_CURRENT || whence == Whence::FROM_BEGIN ||
118 whence == WHENCE_FROM_END) 118 whence == Whence::FROM_END)
119 ? FILE_ERROR_OK 119 ? FileError::OK
120 : FILE_ERROR_INVALID_OPERATION; 120 : FileError::INVALID_OPERATION;
121 } 121 }
122 122
123 FileError IsOffsetValid(int64_t offset) { 123 FileError IsOffsetValid(int64_t offset) {
124 return (offset >= std::numeric_limits<off_t>::min() && 124 return (offset >= std::numeric_limits<off_t>::min() &&
125 offset <= std::numeric_limits<off_t>::max()) 125 offset <= std::numeric_limits<off_t>::max())
126 ? FILE_ERROR_OK 126 ? FileError::OK
127 : FILE_ERROR_INVALID_OPERATION; 127 : FileError::INVALID_OPERATION;
128 } 128 }
129 129
130 FileError GetError(const base::File& file) { 130 FileError GetError(const base::File& file) {
131 return static_cast<filesystem::FileError>(file.error_details()); 131 return static_cast<filesystem::FileError>(file.error_details());
132 } 132 }
133 133
134 FileInformationPtr MakeFileInformation(const base::File::Info& info) { 134 FileInformationPtr MakeFileInformation(const base::File::Info& info) {
135 FileInformationPtr file_info(FileInformation::New()); 135 FileInformationPtr file_info(FileInformation::New());
136 file_info->type = 136 file_info->type =
137 info.is_directory ? FS_FILE_TYPE_DIRECTORY : FS_FILE_TYPE_REGULAR_FILE; 137 info.is_directory ? FsFileType::DIRECTORY : FsFileType::REGULAR_FILE;
138 file_info->size = info.size; 138 file_info->size = info.size;
139 139
140 file_info->atime = info.last_accessed.ToDoubleT(); 140 file_info->atime = info.last_accessed.ToDoubleT();
141 file_info->mtime = info.last_modified.ToDoubleT(); 141 file_info->mtime = info.last_modified.ToDoubleT();
142 file_info->ctime = info.creation_time.ToDoubleT(); 142 file_info->ctime = info.creation_time.ToDoubleT();
143 143
144 return file_info; 144 return file_info;
145 } 145 }
146 146
147 FileError ValidatePath(const mojo::String& raw_path, 147 FileError ValidatePath(const mojo::String& raw_path,
148 const base::FilePath& filesystem_base, 148 const base::FilePath& filesystem_base,
149 base::FilePath* out) { 149 base::FilePath* out) {
150 DCHECK(!raw_path.is_null()); 150 DCHECK(!raw_path.is_null());
151 if (!base::IsStringUTF8(raw_path.get())) 151 if (!base::IsStringUTF8(raw_path.get()))
152 return FILE_ERROR_INVALID_OPERATION; 152 return FileError::INVALID_OPERATION;
153 153
154 #if defined(OS_POSIX) 154 #if defined(OS_POSIX)
155 base::FilePath::StringType path = raw_path; 155 base::FilePath::StringType path = raw_path;
156 #elif defined(OS_WIN) 156 #elif defined(OS_WIN)
157 base::FilePath::StringType path = base::UTF8ToUTF16(raw_path.get()); 157 base::FilePath::StringType path = base::UTF8ToUTF16(raw_path.get());
158 #endif 158 #endif
159 159
160 // TODO(erg): This isn't really what we want. FilePath::AppendRelativePath() 160 // TODO(erg): This isn't really what we want. FilePath::AppendRelativePath()
161 // is closer. We need to deal with entirely hostile apps trying to bust this 161 // is closer. We need to deal with entirely hostile apps trying to bust this
162 // function to use a possibly maliciously provided |raw_path| to bust out of 162 // function to use a possibly maliciously provided |raw_path| to bust out of
163 // |filesystem_base|. 163 // |filesystem_base|.
164 base::FilePath full_path = filesystem_base.Append(path); 164 base::FilePath full_path = filesystem_base.Append(path);
165 if (full_path.ReferencesParent()) { 165 if (full_path.ReferencesParent()) {
166 // TODO(erg): For now, if it references a parent, we'll consider this bad. 166 // TODO(erg): For now, if it references a parent, we'll consider this bad.
167 return FILE_ERROR_ACCESS_DENIED; 167 return FileError::ACCESS_DENIED;
168 } 168 }
169 169
170 *out = full_path; 170 *out = full_path;
171 return FILE_ERROR_OK; 171 return FileError::OK;
172 } 172 }
173 173
174 } // namespace filesystem 174 } // namespace filesystem
OLDNEW
« no previous file with comments | « components/filesystem/files_test_base.cc ('k') | components/font_service/font_service_app.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698