OLD | NEW |
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/directory_impl.h" | 5 #include "components/filesystem/directory_impl.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 bool recursive = delete_flags & kDeleteFlagRecursive; | 165 bool recursive = delete_flags & kDeleteFlagRecursive; |
166 if (!base::DeleteFile(path, recursive)) { | 166 if (!base::DeleteFile(path, recursive)) { |
167 callback.Run(FILE_ERROR_FAILED); | 167 callback.Run(FILE_ERROR_FAILED); |
168 return; | 168 return; |
169 } | 169 } |
170 | 170 |
171 callback.Run(FILE_ERROR_OK); | 171 callback.Run(FILE_ERROR_OK); |
172 } | 172 } |
173 | 173 |
| 174 void DirectoryImpl::Exists(const mojo::String& raw_path, |
| 175 const ExistsCallback& callback) { |
| 176 base::FilePath path; |
| 177 if (FileError error = ValidatePath(raw_path, directory_path_, &path)) { |
| 178 callback.Run(error, false); |
| 179 return; |
| 180 } |
| 181 |
| 182 bool exists = base::PathExists(path); |
| 183 callback.Run(FILE_ERROR_OK, exists); |
| 184 } |
| 185 |
| 186 void DirectoryImpl::IsWritable(const mojo::String& raw_path, |
| 187 const IsWritableCallback& callback) { |
| 188 base::FilePath path; |
| 189 if (FileError error = ValidatePath(raw_path, directory_path_, &path)) { |
| 190 callback.Run(error, false); |
| 191 return; |
| 192 } |
| 193 |
| 194 callback.Run(FILE_ERROR_OK, base::PathIsWritable(path)); |
| 195 } |
| 196 |
| 197 void DirectoryImpl::Flush(const FlushCallback& callback) { |
| 198 base::File file(directory_path_, base::File::FLAG_READ); |
| 199 if (!file.IsValid()) { |
| 200 callback.Run(FILE_ERROR_FAILED); |
| 201 return; |
| 202 } |
| 203 |
| 204 if (!file.Flush()) { |
| 205 callback.Run(FILE_ERROR_FAILED); |
| 206 return; |
| 207 } |
| 208 |
| 209 callback.Run(FILE_ERROR_OK); |
| 210 } |
| 211 |
174 } // namespace filesystem | 212 } // namespace filesystem |
OLD | NEW |