| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_write
r.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_write
r.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" | 9 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
| 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 ProvidedFileSystemInterface::OPEN_FILE_MODE_WRITE, | 52 ProvidedFileSystemInterface::OPEN_FILE_MODE_WRITE, |
| 53 base::Bind( | 53 base::Bind( |
| 54 &OperationRunner::OnOpenFileCompletedOnUIThread, this, callback)); | 54 &OperationRunner::OnOpenFileCompletedOnUIThread, this, callback)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Closes a file. Ignores result, since outlives the caller. Must be called on | 57 // Closes a file. Ignores result, since outlives the caller. Must be called on |
| 58 // UI thread. | 58 // UI thread. |
| 59 void CloseFileOnUIThread() { | 59 void CloseFileOnUIThread() { |
| 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 60 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 61 if (file_system_.get() && file_handle_ != -1) { | 61 if (file_system_.get() && file_handle_ != -1) { |
| 62 abort_callback_ = file_system_->CloseFile( | 62 // Closing a file must not be aborted, since we could end up on files |
| 63 file_handle_, base::Bind(&EmptyStatusCallback)); | 63 // which are never closed. |
| 64 file_system_->CloseFile(file_handle_, base::Bind(&EmptyStatusCallback)); |
| 65 abort_callback_ = ProvidedFileSystemInterface::AbortCallback(); |
| 64 } | 66 } |
| 65 } | 67 } |
| 66 | 68 |
| 67 // Requests writing bytes to the file. In case of either success or a failure | 69 // Requests writing bytes to the file. In case of either success or a failure |
| 68 // |callback| is executed. Must be called on UI thread. | 70 // |callback| is executed. Must be called on UI thread. |
| 69 void WriteFileOnUIThread( | 71 void WriteFileOnUIThread( |
| 70 scoped_refptr<net::IOBuffer> buffer, | 72 scoped_refptr<net::IOBuffer> buffer, |
| 71 int64 offset, | 73 int64 offset, |
| 72 int length, | 74 int length, |
| 73 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 75 const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 89 length, | 91 length, |
| 90 base::Bind( | 92 base::Bind( |
| 91 &OperationRunner::OnWriteFileCompletedOnUIThread, this, callback)); | 93 &OperationRunner::OnWriteFileCompletedOnUIThread, this, callback)); |
| 92 } | 94 } |
| 93 | 95 |
| 94 // Aborts the most recent operation (if exists), and calls the callback. | 96 // Aborts the most recent operation (if exists), and calls the callback. |
| 95 void AbortOnUIThread(const fileapi::AsyncFileUtil::StatusCallback& callback) { | 97 void AbortOnUIThread(const fileapi::AsyncFileUtil::StatusCallback& callback) { |
| 96 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 98 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 97 | 99 |
| 98 if (abort_callback_.is_null()) { | 100 if (abort_callback_.is_null()) { |
| 99 // No operation on the file system being performed. At most a callback | 101 // No operation to be cancelled. At most a callback call, which will be |
| 100 // call, which will be discarded. | 102 // discarded. |
| 101 BrowserThread::PostTask( | 103 BrowserThread::PostTask(BrowserThread::IO, |
| 102 BrowserThread::IO, | 104 FROM_HERE, |
| 103 FROM_HERE, | 105 base::Bind(callback, base::File::FILE_OK)); |
| 104 base::Bind(callback, base::File::FILE_ERROR_ABORT)); | |
| 105 return; | 106 return; |
| 106 } | 107 } |
| 107 | 108 |
| 108 const ProvidedFileSystemInterface::AbortCallback abort_callback = | 109 const ProvidedFileSystemInterface::AbortCallback abort_callback = |
| 109 abort_callback_; | 110 abort_callback_; |
| 110 abort_callback_ = ProvidedFileSystemInterface::AbortCallback(); | 111 abort_callback_ = ProvidedFileSystemInterface::AbortCallback(); |
| 111 abort_callback.Run(base::Bind( | 112 abort_callback.Run(base::Bind( |
| 112 &OperationRunner::OnAbortCompletedOnUIThread, this, callback)); | 113 &OperationRunner::OnAbortCompletedOnUIThread, this, callback)); |
| 113 } | 114 } |
| 114 | 115 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 current_offset_, | 330 current_offset_, |
| 330 buffer_length, | 331 buffer_length, |
| 331 base::Bind(&FileStreamWriter::OnWriteFileCompleted, | 332 base::Bind(&FileStreamWriter::OnWriteFileCompleted, |
| 332 weak_ptr_factory_.GetWeakPtr(), | 333 weak_ptr_factory_.GetWeakPtr(), |
| 333 buffer_length, | 334 buffer_length, |
| 334 callback))); | 335 callback))); |
| 335 } | 336 } |
| 336 | 337 |
| 337 } // namespace file_system_provider | 338 } // namespace file_system_provider |
| 338 } // namespace chromeos | 339 } // namespace chromeos |
| OLD | NEW |