| 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/macros.h" |
| 7 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 8 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 10 #include "chrome/browser/chromeos/file_system_provider/abort_callback.h" | 11 #include "chrome/browser/chromeos/file_system_provider/abort_callback.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" | 12 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 13 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/scoped_file_opener.h" | 15 #include "chrome/browser/chromeos/file_system_provider/scoped_file_opener.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 file_opener_.reset(new ScopedFileOpener( | 50 file_opener_.reset(new ScopedFileOpener( |
| 50 parser.file_system(), parser.file_path(), OPEN_FILE_MODE_WRITE, | 51 parser.file_system(), parser.file_path(), OPEN_FILE_MODE_WRITE, |
| 51 base::Bind(&OperationRunner::OnOpenFileCompletedOnUIThread, this, | 52 base::Bind(&OperationRunner::OnOpenFileCompletedOnUIThread, this, |
| 52 callback))); | 53 callback))); |
| 53 } | 54 } |
| 54 | 55 |
| 55 // Requests writing bytes to the file. In case of either success or a failure | 56 // Requests writing bytes to the file. In case of either success or a failure |
| 56 // |callback| is executed. Must be called on UI thread. | 57 // |callback| is executed. Must be called on UI thread. |
| 57 void WriteFileOnUIThread( | 58 void WriteFileOnUIThread( |
| 58 scoped_refptr<net::IOBuffer> buffer, | 59 scoped_refptr<net::IOBuffer> buffer, |
| 59 int64 offset, | 60 int64_t offset, |
| 60 int length, | 61 int length, |
| 61 const storage::AsyncFileUtil::StatusCallback& callback) { | 62 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 62 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 63 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 63 DCHECK(abort_callback_.is_null()); | 64 DCHECK(abort_callback_.is_null()); |
| 64 | 65 |
| 65 // If the file system got unmounted, then abort the writing operation. | 66 // If the file system got unmounted, then abort the writing operation. |
| 66 if (!file_system_.get()) { | 67 if (!file_system_.get()) { |
| 67 BrowserThread::PostTask( | 68 BrowserThread::PostTask( |
| 68 BrowserThread::IO, | 69 BrowserThread::IO, |
| 69 FROM_HERE, | 70 FROM_HERE, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 132 |
| 132 AbortCallback abort_callback_; | 133 AbortCallback abort_callback_; |
| 133 base::WeakPtr<ProvidedFileSystemInterface> file_system_; | 134 base::WeakPtr<ProvidedFileSystemInterface> file_system_; |
| 134 scoped_ptr<ScopedFileOpener> file_opener_; | 135 scoped_ptr<ScopedFileOpener> file_opener_; |
| 135 int file_handle_; | 136 int file_handle_; |
| 136 | 137 |
| 137 DISALLOW_COPY_AND_ASSIGN(OperationRunner); | 138 DISALLOW_COPY_AND_ASSIGN(OperationRunner); |
| 138 }; | 139 }; |
| 139 | 140 |
| 140 FileStreamWriter::FileStreamWriter(const storage::FileSystemURL& url, | 141 FileStreamWriter::FileStreamWriter(const storage::FileSystemURL& url, |
| 141 int64 initial_offset) | 142 int64_t initial_offset) |
| 142 : url_(url), | 143 : url_(url), |
| 143 current_offset_(initial_offset), | 144 current_offset_(initial_offset), |
| 144 runner_(new OperationRunner), | 145 runner_(new OperationRunner), |
| 145 state_(NOT_INITIALIZED), | 146 state_(NOT_INITIALIZED), |
| 146 weak_ptr_factory_(this) { | 147 weak_ptr_factory_(this) {} |
| 147 } | |
| 148 | 148 |
| 149 FileStreamWriter::~FileStreamWriter() { | 149 FileStreamWriter::~FileStreamWriter() { |
| 150 // Close the runner explicitly if the file streamer is | 150 // Close the runner explicitly if the file streamer is |
| 151 if (state_ != CANCELLING) { | 151 if (state_ != CANCELLING) { |
| 152 BrowserThread::PostTask( | 152 BrowserThread::PostTask( |
| 153 BrowserThread::UI, FROM_HERE, | 153 BrowserThread::UI, FROM_HERE, |
| 154 base::Bind(&OperationRunner::CloseRunnerOnUIThread, runner_)); | 154 base::Bind(&OperationRunner::CloseRunnerOnUIThread, runner_)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // If a write is in progress, mark it as completed. | 157 // If a write is in progress, mark it as completed. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 current_offset_, | 335 current_offset_, |
| 336 buffer_length, | 336 buffer_length, |
| 337 base::Bind(&FileStreamWriter::OnWriteFileCompleted, | 337 base::Bind(&FileStreamWriter::OnWriteFileCompleted, |
| 338 weak_ptr_factory_.GetWeakPtr(), | 338 weak_ptr_factory_.GetWeakPtr(), |
| 339 buffer_length, | 339 buffer_length, |
| 340 callback))); | 340 callback))); |
| 341 } | 341 } |
| 342 | 342 |
| 343 } // namespace file_system_provider | 343 } // namespace file_system_provider |
| 344 } // namespace chromeos | 344 } // namespace chromeos |
| OLD | NEW |