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

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

Issue 2492283002: Mojo C++ bindings: switch components/filesystem mojom target to use STL types. (Closed)
Patch Set: Created 4 years, 1 month 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/util.h ('k') | components/leveldb/env_mojo.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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 : mojom::FsFileType::REGULAR_FILE; 139 : mojom::FsFileType::REGULAR_FILE;
140 file_info->size = info.size; 140 file_info->size = info.size;
141 141
142 file_info->atime = info.last_accessed.ToDoubleT(); 142 file_info->atime = info.last_accessed.ToDoubleT();
143 file_info->mtime = info.last_modified.ToDoubleT(); 143 file_info->mtime = info.last_modified.ToDoubleT();
144 file_info->ctime = info.creation_time.ToDoubleT(); 144 file_info->ctime = info.creation_time.ToDoubleT();
145 145
146 return file_info; 146 return file_info;
147 } 147 }
148 148
149 mojom::FileError ValidatePath(const mojo::String& raw_path, 149 mojom::FileError ValidatePath(const std::string& raw_path,
150 const base::FilePath& filesystem_base, 150 const base::FilePath& filesystem_base,
151 base::FilePath* out) { 151 base::FilePath* out) {
152 DCHECK(!raw_path.is_null()); 152 if (!base::IsStringUTF8(raw_path))
153 if (!base::IsStringUTF8(raw_path.get()))
154 return mojom::FileError::INVALID_OPERATION; 153 return mojom::FileError::INVALID_OPERATION;
155 154
156 #if defined(OS_POSIX) 155 #if defined(OS_POSIX)
157 base::FilePath::StringType path = raw_path; 156 base::FilePath::StringType path = raw_path;
158 #elif defined(OS_WIN) 157 #elif defined(OS_WIN)
159 base::FilePath::StringType path = base::UTF8ToUTF16(raw_path.get()); 158 base::FilePath::StringType path = base::UTF8ToUTF16(raw_path);
160 #endif 159 #endif
161 160
162 // TODO(erg): This isn't really what we want. FilePath::AppendRelativePath() 161 // TODO(erg): This isn't really what we want. FilePath::AppendRelativePath()
163 // is closer. We need to deal with entirely hostile apps trying to bust this 162 // is closer. We need to deal with entirely hostile apps trying to bust this
164 // function to use a possibly maliciously provided |raw_path| to bust out of 163 // function to use a possibly maliciously provided |raw_path| to bust out of
165 // |filesystem_base|. 164 // |filesystem_base|.
166 base::FilePath full_path = filesystem_base.Append(path); 165 base::FilePath full_path = filesystem_base.Append(path);
167 if (full_path.ReferencesParent()) { 166 if (full_path.ReferencesParent()) {
168 // TODO(erg): For now, if it references a parent, we'll consider this bad. 167 // TODO(erg): For now, if it references a parent, we'll consider this bad.
169 return mojom::FileError::ACCESS_DENIED; 168 return mojom::FileError::ACCESS_DENIED;
170 } 169 }
171 170
172 *out = full_path; 171 *out = full_path;
173 return mojom::FileError::OK; 172 return mojom::FileError::OK;
174 } 173 }
175 174
176 } // namespace filesystem 175 } // namespace filesystem
OLDNEW
« no previous file with comments | « components/filesystem/util.h ('k') | components/leveldb/env_mojo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698