| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "components/filesystem/file_impl.h" | 16 #include "components/filesystem/file_impl.h" |
| 17 #include "components/filesystem/lock_table.h" | 17 #include "components/filesystem/lock_table.h" |
| 18 #include "components/filesystem/util.h" | 18 #include "components/filesystem/util.h" |
| 19 #include "mojo/common/common_type_converters.h" | |
| 20 #include "mojo/public/cpp/bindings/strong_binding.h" | 19 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 21 | 20 |
| 22 namespace filesystem { | 21 namespace filesystem { |
| 23 | 22 |
| 24 DirectoryImpl::DirectoryImpl(base::FilePath directory_path, | 23 DirectoryImpl::DirectoryImpl(base::FilePath directory_path, |
| 25 scoped_refptr<SharedTempDir> temp_dir, | 24 scoped_refptr<SharedTempDir> temp_dir, |
| 26 scoped_refptr<LockTable> lock_table) | 25 scoped_refptr<LockTable> lock_table) |
| 27 : directory_path_(directory_path), | 26 : directory_path_(directory_path), |
| 28 temp_dir_(std::move(temp_dir)), | 27 temp_dir_(std::move(temp_dir)), |
| 29 lock_table_(std::move(lock_table)) {} | 28 lock_table_(std::move(lock_table)) {} |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 callback.Run(mojom::FileError::NOT_A_FILE, std::vector<uint8_t>()); | 283 callback.Run(mojom::FileError::NOT_A_FILE, std::vector<uint8_t>()); |
| 285 return; | 284 return; |
| 286 } | 285 } |
| 287 | 286 |
| 288 base::File base_file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 287 base::File base_file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 289 if (!base_file.IsValid()) { | 288 if (!base_file.IsValid()) { |
| 290 callback.Run(GetError(base_file), std::vector<uint8_t>()); | 289 callback.Run(GetError(base_file), std::vector<uint8_t>()); |
| 291 return; | 290 return; |
| 292 } | 291 } |
| 293 | 292 |
| 294 std::string contents; | 293 std::vector<uint8_t> contents; |
| 295 const int kBufferSize = 1 << 16; | 294 const int kBufferSize = 1 << 16; |
| 296 std::unique_ptr<char[]> buf(new char[kBufferSize]); | 295 std::unique_ptr<char[]> buf(new char[kBufferSize]); |
| 297 int len; | 296 int len; |
| 298 while ((len = base_file.ReadAtCurrentPos(buf.get(), kBufferSize)) > 0) | 297 while ((len = base_file.ReadAtCurrentPos(buf.get(), kBufferSize)) > 0) |
| 299 contents.append(buf.get(), len); | 298 contents.insert(contents.end(), buf.get(), buf.get() + len); |
| 300 | 299 |
| 301 callback.Run(mojom::FileError::OK, mojo::Array<uint8_t>::From(contents)); | 300 callback.Run(mojom::FileError::OK, contents); |
| 302 } | 301 } |
| 303 | 302 |
| 304 void DirectoryImpl::WriteFile(const std::string& raw_path, | 303 void DirectoryImpl::WriteFile(const std::string& raw_path, |
| 305 const std::vector<uint8_t>& data, | 304 const std::vector<uint8_t>& data, |
| 306 const WriteFileCallback& callback) { | 305 const WriteFileCallback& callback) { |
| 307 base::FilePath path; | 306 base::FilePath path; |
| 308 mojom::FileError error = ValidatePath(raw_path, directory_path_, &path); | 307 mojom::FileError error = ValidatePath(raw_path, directory_path_, &path); |
| 309 if (error != mojom::FileError::OK) { | 308 if (error != mojom::FileError::OK) { |
| 310 callback.Run(error); | 309 callback.Run(error); |
| 311 return; | 310 return; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 // We must not return directories as files. In the file abstraction, we | 346 // We must not return directories as files. In the file abstraction, we |
| 348 // can fetch raw file descriptors over mojo pipes, and passing a file | 347 // can fetch raw file descriptors over mojo pipes, and passing a file |
| 349 // descriptor to a directory is a sandbox escape on Windows. | 348 // descriptor to a directory is a sandbox escape on Windows. |
| 350 return base::File(base::File::FILE_ERROR_NOT_A_FILE); | 349 return base::File(base::File::FILE_ERROR_NOT_A_FILE); |
| 351 } | 350 } |
| 352 | 351 |
| 353 return base::File(path, open_flags); | 352 return base::File(path, open_flags); |
| 354 } | 353 } |
| 355 | 354 |
| 356 } // namespace filesystem | 355 } // namespace filesystem |
| OLD | NEW |