| 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/file_impl.h" | 5 #include "components/filesystem/file_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_file.h" | 13 #include "base/files/scoped_file.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "components/filesystem/lock_table.h" | 16 #include "components/filesystem/lock_table.h" |
| 17 #include "components/filesystem/shared_temp_dir.h" | 17 #include "components/filesystem/shared_temp_dir.h" |
| 18 #include "components/filesystem/util.h" | 18 #include "components/filesystem/util.h" |
| 19 #include "mojo/common/common_type_converters.h" | 19 #include "mojo/common/common_type_converters.h" |
| 20 #include "mojo/public/cpp/bindings/strong_binding.h" | 20 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 21 #include "mojo/public/cpp/system/platform_handle.h" | |
| 22 | 21 |
| 23 static_assert(sizeof(off_t) <= sizeof(int64_t), "off_t too big"); | 22 static_assert(sizeof(off_t) <= sizeof(int64_t), "off_t too big"); |
| 24 static_assert(sizeof(size_t) >= sizeof(uint32_t), "size_t too small"); | 23 static_assert(sizeof(size_t) >= sizeof(uint32_t), "size_t too small"); |
| 25 | 24 |
| 26 using base::Time; | 25 using base::Time; |
| 27 using mojo::ScopedHandle; | |
| 28 | 26 |
| 29 namespace filesystem { | 27 namespace filesystem { |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 const size_t kMaxReadSize = 1 * 1024 * 1024; // 1 MB. | 30 const size_t kMaxReadSize = 1 * 1024 * 1024; // 1 MB. |
| 33 | 31 |
| 34 } // namespace | 32 } // namespace |
| 35 | 33 |
| 36 FileImpl::FileImpl(const base::FilePath& path, | 34 FileImpl::FileImpl(const base::FilePath& path, |
| 37 uint32_t flags, | 35 uint32_t flags, |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 static_cast<filesystem::mojom::FileError>(lock_table_->LockFile(this))); | 318 static_cast<filesystem::mojom::FileError>(lock_table_->LockFile(this))); |
| 321 } | 319 } |
| 322 | 320 |
| 323 void FileImpl::Unlock(const UnlockCallback& callback) { | 321 void FileImpl::Unlock(const UnlockCallback& callback) { |
| 324 callback.Run( | 322 callback.Run( |
| 325 static_cast<filesystem::mojom::FileError>(lock_table_->UnlockFile(this))); | 323 static_cast<filesystem::mojom::FileError>(lock_table_->UnlockFile(this))); |
| 326 } | 324 } |
| 327 | 325 |
| 328 void FileImpl::AsHandle(const AsHandleCallback& callback) { | 326 void FileImpl::AsHandle(const AsHandleCallback& callback) { |
| 329 if (!file_.IsValid()) { | 327 if (!file_.IsValid()) { |
| 330 callback.Run(GetError(file_), ScopedHandle()); | 328 callback.Run(GetError(file_), base::File()); |
| 331 return; | 329 return; |
| 332 } | 330 } |
| 333 | 331 |
| 334 base::File new_file = file_.Duplicate(); | 332 base::File new_file = file_.Duplicate(); |
| 335 if (!new_file.IsValid()) { | 333 if (!new_file.IsValid()) { |
| 336 callback.Run(GetError(new_file), ScopedHandle()); | 334 callback.Run(GetError(new_file), base::File()); |
| 337 return; | 335 return; |
| 338 } | 336 } |
| 339 | 337 |
| 340 base::File::Info info; | 338 base::File::Info info; |
| 341 if (!new_file.GetInfo(&info)) { | 339 if (!new_file.GetInfo(&info)) { |
| 342 callback.Run(mojom::FileError::FAILED, ScopedHandle()); | 340 callback.Run(mojom::FileError::FAILED, base::File()); |
| 343 return; | 341 return; |
| 344 } | 342 } |
| 345 | 343 |
| 346 // Perform one additional check right before we send the file's file | 344 // Perform one additional check right before we send the file's file |
| 347 // descriptor over mojo. This is theoretically redundant, but given that | 345 // descriptor over mojo. This is theoretically redundant, but given that |
| 348 // passing a file descriptor to a directory is a sandbox escape on Windows, | 346 // passing a file descriptor to a directory is a sandbox escape on Windows, |
| 349 // we should be absolutely paranoid. | 347 // we should be absolutely paranoid. |
| 350 if (info.is_directory) { | 348 if (info.is_directory) { |
| 351 callback.Run(mojom::FileError::NOT_A_FILE, ScopedHandle()); | 349 callback.Run(mojom::FileError::NOT_A_FILE, base::File()); |
| 352 return; | 350 return; |
| 353 } | 351 } |
| 354 | 352 |
| 355 callback.Run(mojom::FileError::OK, | 353 callback.Run(mojom::FileError::OK, std::move(new_file)); |
| 356 mojo::WrapPlatformFile(new_file.TakePlatformFile())); | |
| 357 } | 354 } |
| 358 | 355 |
| 359 } // namespace filesystem | 356 } // namespace filesystem |
| OLD | NEW |