| 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 "storage/browser/fileapi/file_writer_delegate.h" | 5 #include "storage/browser/fileapi/file_writer_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/files/file_util_proxy.h" | 12 #include "base/files/file_util_proxy.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 14 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "storage/browser/fileapi/file_stream_writer.h" | 17 #include "storage/browser/fileapi/file_stream_writer.h" |
| 17 #include "storage/browser/fileapi/file_system_context.h" | 18 #include "storage/browser/fileapi/file_system_context.h" |
| 18 #include "storage/common/fileapi/file_system_mount_option.h" | 19 #include "storage/common/fileapi/file_system_mount_option.h" |
| 19 #include "storage/common/fileapi/file_system_util.h" | 20 #include "storage/common/fileapi/file_system_util.h" |
| 20 | 21 |
| 21 namespace storage { | 22 namespace storage { |
| 22 | 23 |
| 23 static const int kReadBufSize = 32768; | 24 static const int kReadBufSize = 32768; |
| 24 | 25 |
| 25 FileWriterDelegate::FileWriterDelegate( | 26 FileWriterDelegate::FileWriterDelegate( |
| 26 scoped_ptr<FileStreamWriter> file_stream_writer, | 27 scoped_ptr<FileStreamWriter> file_stream_writer, |
| 27 FlushPolicy flush_policy) | 28 FlushPolicy flush_policy) |
| 28 : file_stream_writer_(file_stream_writer.Pass()), | 29 : file_stream_writer_(std::move(file_stream_writer)), |
| 29 writing_started_(false), | 30 writing_started_(false), |
| 30 flush_policy_(flush_policy), | 31 flush_policy_(flush_policy), |
| 31 bytes_written_backlog_(0), | 32 bytes_written_backlog_(0), |
| 32 bytes_written_(0), | 33 bytes_written_(0), |
| 33 bytes_read_(0), | 34 bytes_read_(0), |
| 34 io_buffer_(new net::IOBufferWithSize(kReadBufSize)), | 35 io_buffer_(new net::IOBufferWithSize(kReadBufSize)), |
| 35 weak_factory_(this) { | 36 weak_factory_(this) {} |
| 36 } | |
| 37 | 37 |
| 38 FileWriterDelegate::~FileWriterDelegate() { | 38 FileWriterDelegate::~FileWriterDelegate() { |
| 39 } | 39 } |
| 40 | 40 |
| 41 void FileWriterDelegate::Start(scoped_ptr<net::URLRequest> request, | 41 void FileWriterDelegate::Start(scoped_ptr<net::URLRequest> request, |
| 42 const DelegateWriteCallback& write_callback) { | 42 const DelegateWriteCallback& write_callback) { |
| 43 write_callback_ = write_callback; | 43 write_callback_ = write_callback; |
| 44 request_ = request.Pass(); | 44 request_ = std::move(request); |
| 45 request_->Start(); | 45 request_->Start(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void FileWriterDelegate::Cancel() { | 48 void FileWriterDelegate::Cancel() { |
| 49 // Destroy the request to prevent it from invoking any callbacks. | 49 // Destroy the request to prevent it from invoking any callbacks. |
| 50 request_.reset(); | 50 request_.reset(); |
| 51 | 51 |
| 52 const int status = file_stream_writer_->Cancel( | 52 const int status = file_stream_writer_->Cancel( |
| 53 base::Bind(&FileWriterDelegate::OnWriteCancelled, | 53 base::Bind(&FileWriterDelegate::OnWriteCancelled, |
| 54 weak_factory_.GetWeakPtr())); | 54 weak_factory_.GetWeakPtr())); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 if (error == base::File::FILE_OK && flush_error != net::OK) { | 233 if (error == base::File::FILE_OK && flush_error != net::OK) { |
| 234 // If the Flush introduced an error, overwrite the status. | 234 // If the Flush introduced an error, overwrite the status. |
| 235 // Otherwise, keep the original error status. | 235 // Otherwise, keep the original error status. |
| 236 error = NetErrorToFileError(flush_error); | 236 error = NetErrorToFileError(flush_error); |
| 237 progress_status = GetCompletionStatusOnError(); | 237 progress_status = GetCompletionStatusOnError(); |
| 238 } | 238 } |
| 239 write_callback_.Run(error, bytes_written, progress_status); | 239 write_callback_.Run(error, bytes_written, progress_status); |
| 240 } | 240 } |
| 241 | 241 |
| 242 } // namespace storage | 242 } // namespace storage |
| OLD | NEW |