| 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/util.h" | 18 #include "components/filesystem/util.h" |
| 18 #include "mojo/common/common_type_converters.h" | 19 #include "mojo/common/common_type_converters.h" |
| 19 #include "mojo/platform_handle/platform_handle_functions.h" | 20 #include "mojo/platform_handle/platform_handle_functions.h" |
| 20 | 21 |
| 21 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"); |
| 22 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"); |
| 23 | 24 |
| 24 using base::Time; | 25 using base::Time; |
| 25 using mojo::ScopedHandle; | 26 using mojo::ScopedHandle; |
| 26 | 27 |
| 27 namespace filesystem { | 28 namespace filesystem { |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 const size_t kMaxReadSize = 1 * 1024 * 1024; // 1 MB. | 31 const size_t kMaxReadSize = 1 * 1024 * 1024; // 1 MB. |
| 31 | 32 |
| 32 } // namespace | 33 } // namespace |
| 33 | 34 |
| 34 FileImpl::FileImpl(mojo::InterfaceRequest<File> request, | 35 FileImpl::FileImpl(mojo::InterfaceRequest<File> request, |
| 35 const base::FilePath& path, | 36 const base::FilePath& path, |
| 36 uint32_t flags, | 37 uint32_t flags, |
| 38 scoped_refptr<SharedTempDir> temp_dir, |
| 37 scoped_refptr<LockTable> lock_table) | 39 scoped_refptr<LockTable> lock_table) |
| 38 : binding_(this, std::move(request)), | 40 : binding_(this, std::move(request)), |
| 39 file_(path, flags), | 41 file_(path, flags), |
| 40 path_(path), | 42 path_(path), |
| 43 temp_dir_(std::move(temp_dir)), |
| 41 lock_table_(std::move(lock_table)) { | 44 lock_table_(std::move(lock_table)) { |
| 42 DCHECK(file_.IsValid()); | 45 DCHECK(file_.IsValid()); |
| 43 } | 46 } |
| 44 | 47 |
| 45 FileImpl::FileImpl(mojo::InterfaceRequest<File> request, | 48 FileImpl::FileImpl(mojo::InterfaceRequest<File> request, |
| 46 const base::FilePath& path, | 49 const base::FilePath& path, |
| 47 base::File file, | 50 base::File file, |
| 51 scoped_refptr<SharedTempDir> temp_dir, |
| 48 scoped_refptr<LockTable> lock_table) | 52 scoped_refptr<LockTable> lock_table) |
| 49 : binding_(this, std::move(request)), | 53 : binding_(this, std::move(request)), |
| 50 file_(std::move(file)), | 54 file_(std::move(file)), |
| 51 path_(path), | 55 path_(path), |
| 56 temp_dir_(std::move(temp_dir)), |
| 52 lock_table_(std::move(lock_table)) { | 57 lock_table_(std::move(lock_table)) { |
| 53 DCHECK(file_.IsValid()); | 58 DCHECK(file_.IsValid()); |
| 54 } | 59 } |
| 55 | 60 |
| 56 FileImpl::~FileImpl() { | 61 FileImpl::~FileImpl() { |
| 57 if (file_.IsValid()) | 62 if (file_.IsValid()) |
| 58 lock_table_->RemoveFromLockTable(path_); | 63 lock_table_->RemoveFromLockTable(path_); |
| 59 } | 64 } |
| 60 | 65 |
| 61 bool FileImpl::IsValid() const { | 66 bool FileImpl::IsValid() const { |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 return; | 295 return; |
| 291 } | 296 } |
| 292 | 297 |
| 293 base::File new_file = file_.Duplicate(); | 298 base::File new_file = file_.Duplicate(); |
| 294 if (!new_file.IsValid()) { | 299 if (!new_file.IsValid()) { |
| 295 callback.Run(GetError(new_file)); | 300 callback.Run(GetError(new_file)); |
| 296 return; | 301 return; |
| 297 } | 302 } |
| 298 | 303 |
| 299 if (file.is_pending()) | 304 if (file.is_pending()) |
| 300 new FileImpl(std::move(file), path_, std::move(new_file), lock_table_); | 305 new FileImpl(std::move(file), path_, std::move(new_file), temp_dir_, |
| 306 lock_table_); |
| 301 callback.Run(FileError::OK); | 307 callback.Run(FileError::OK); |
| 302 } | 308 } |
| 303 | 309 |
| 304 void FileImpl::Flush(const FlushCallback& callback) { | 310 void FileImpl::Flush(const FlushCallback& callback) { |
| 305 if (!file_.IsValid()) { | 311 if (!file_.IsValid()) { |
| 306 callback.Run(GetError(file_)); | 312 callback.Run(GetError(file_)); |
| 307 return; | 313 return; |
| 308 } | 314 } |
| 309 | 315 |
| 310 bool ret = file_.Flush(); | 316 bool ret = file_.Flush(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 new_file.TakePlatformFile(), &mojo_handle); | 358 new_file.TakePlatformFile(), &mojo_handle); |
| 353 if (create_result != MOJO_RESULT_OK) { | 359 if (create_result != MOJO_RESULT_OK) { |
| 354 callback.Run(FileError::FAILED, ScopedHandle()); | 360 callback.Run(FileError::FAILED, ScopedHandle()); |
| 355 return; | 361 return; |
| 356 } | 362 } |
| 357 | 363 |
| 358 callback.Run(FileError::OK, ScopedHandle(mojo::Handle(mojo_handle))); | 364 callback.Run(FileError::OK, ScopedHandle(mojo::Handle(mojo_handle))); |
| 359 } | 365 } |
| 360 | 366 |
| 361 } // namespace filesystem | 367 } // namespace filesystem |
| OLD | NEW |