| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 bool recursive = delete_flags & kDeleteFlagRecursive; | 159 bool recursive = delete_flags & kDeleteFlagRecursive; |
| 160 if (!base::DeleteFile(path, recursive)) { | 160 if (!base::DeleteFile(path, recursive)) { |
| 161 callback.Run(FILE_ERROR_FAILED); | 161 callback.Run(FILE_ERROR_FAILED); |
| 162 return; | 162 return; |
| 163 } | 163 } |
| 164 | 164 |
| 165 callback.Run(FILE_ERROR_OK); | 165 callback.Run(FILE_ERROR_OK); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void DirectoryImpl::Exists(const mojo::String& raw_path, |
| 169 const ExistsCallback& callback) { |
| 170 base::FilePath path; |
| 171 if (FileError error = ValidatePath(raw_path, directory_path_, &path)) { |
| 172 callback.Run(error, false); |
| 173 return; |
| 174 } |
| 175 |
| 176 bool exists = base::PathExists(path); |
| 177 callback.Run(FILE_ERROR_OK, exists); |
| 178 } |
| 179 |
| 180 void DirectoryImpl::IsWritable(const mojo::String& raw_path, |
| 181 const IsWritableCallback& callback) { |
| 182 base::FilePath path; |
| 183 if (FileError error = ValidatePath(raw_path, directory_path_, &path)) { |
| 184 callback.Run(error, false); |
| 185 return; |
| 186 } |
| 187 |
| 188 callback.Run(FILE_ERROR_OK, base::PathIsWritable(path)); |
| 189 } |
| 190 |
| 191 void DirectoryImpl::Flush(const FlushCallback& callback) { |
| 192 base::File file(directory_path_, base::File::FLAG_READ); |
| 193 if (!file.IsValid()) { |
| 194 callback.Run(FILE_ERROR_FAILED); |
| 195 return; |
| 196 } |
| 197 |
| 198 if (!file.Flush()) { |
| 199 callback.Run(FILE_ERROR_FAILED); |
| 200 return; |
| 201 } |
| 202 |
| 203 callback.Run(FILE_ERROR_OK); |
| 204 } |
| 205 |
| 168 } // namespace filesystem | 206 } // namespace filesystem |
| OLD | NEW |