| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/files/file_util_proxy.h" | 5 #include "base/files/file_util_proxy.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 ~CreateTemporaryHelper() { | 70 ~CreateTemporaryHelper() { |
| 71 if (file_handle_ != kInvalidPlatformFileValue) { | 71 if (file_handle_ != kInvalidPlatformFileValue) { |
| 72 FileUtilProxy::Close( | 72 FileUtilProxy::Close( |
| 73 task_runner_.get(), file_handle_, FileUtilProxy::StatusCallback()); | 73 task_runner_.get(), file_handle_, FileUtilProxy::StatusCallback()); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 void RunWork(int additional_file_flags) { | 77 void RunWork(int additional_file_flags) { |
| 78 // TODO(darin): file_util should have a variant of CreateTemporaryFile | 78 // TODO(darin): file_util should have a variant of CreateTemporaryFile |
| 79 // that returns a FilePath and a PlatformFile. | 79 // that returns a FilePath and a PlatformFile. |
| 80 base::CreateTemporaryFile(&file_path_); | 80 if (!base::CreateTemporaryFile(&file_path_)) { |
| 81 // TODO(davidben): base::CreateTemporaryFile should preserve the error |
| 82 // code. |
| 83 error_ = File::FILE_ERROR_FAILED; |
| 84 return; |
| 85 } |
| 81 | 86 |
| 82 int file_flags = | 87 int file_flags = |
| 83 PLATFORM_FILE_WRITE | | 88 PLATFORM_FILE_WRITE | |
| 84 PLATFORM_FILE_TEMPORARY | | 89 PLATFORM_FILE_TEMPORARY | |
| 85 PLATFORM_FILE_CREATE_ALWAYS | | 90 PLATFORM_FILE_CREATE_ALWAYS | |
| 86 additional_file_flags; | 91 additional_file_flags; |
| 87 | 92 |
| 88 error_ = File::FILE_OK; | 93 error_ = File::FILE_OK; |
| 89 // TODO(rvargas): Convert this code to use File. | 94 // TODO(rvargas): Convert this code to use File. |
| 90 file_handle_ = | 95 file_handle_ = |
| 91 CreatePlatformFile(file_path_, file_flags, NULL, | 96 CreatePlatformFile(file_path_, file_flags, NULL, |
| 92 reinterpret_cast<PlatformFileError*>(&error_)); | 97 reinterpret_cast<PlatformFileError*>(&error_)); |
| 98 if (error_ != File::FILE_OK) { |
| 99 base::DeleteFile(file_path_, false); |
| 100 file_path_.clear(); |
| 101 } |
| 93 } | 102 } |
| 94 | 103 |
| 95 void Reply(const FileUtilProxy::CreateTemporaryCallback& callback) { | 104 void Reply(const FileUtilProxy::CreateTemporaryCallback& callback) { |
| 96 DCHECK(!callback.is_null()); | 105 DCHECK(!callback.is_null()); |
| 97 callback.Run(error_, PassPlatformFile(&file_handle_), file_path_); | 106 callback.Run(error_, PassPlatformFile(&file_handle_), file_path_); |
| 98 } | 107 } |
| 99 | 108 |
| 100 private: | 109 private: |
| 101 scoped_refptr<TaskRunner> task_runner_; | 110 scoped_refptr<TaskRunner> task_runner_; |
| 102 PlatformFile file_handle_; | 111 PlatformFile file_handle_; |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 bool FileUtilProxy::RelayClose( | 422 bool FileUtilProxy::RelayClose( |
| 414 TaskRunner* task_runner, | 423 TaskRunner* task_runner, |
| 415 const CloseTask& close_task, | 424 const CloseTask& close_task, |
| 416 PlatformFile file_handle, | 425 PlatformFile file_handle, |
| 417 const StatusCallback& callback) { | 426 const StatusCallback& callback) { |
| 418 return base::PostTaskAndReplyWithResult( | 427 return base::PostTaskAndReplyWithResult( |
| 419 task_runner, FROM_HERE, Bind(close_task, file_handle), callback); | 428 task_runner, FROM_HERE, Bind(close_task, file_handle), callback); |
| 420 } | 429 } |
| 421 | 430 |
| 422 } // namespace base | 431 } // namespace base |
| OLD | NEW |