| 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 "net/base/upload_file_element_reader.h" | 5 #include "net/base/upload_file_element_reader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 uint64 UploadFileElementReader::BytesRemaining() const { | 72 uint64 UploadFileElementReader::BytesRemaining() const { |
| 73 return bytes_remaining_; | 73 return bytes_remaining_; |
| 74 } | 74 } |
| 75 | 75 |
| 76 int UploadFileElementReader::Read(IOBuffer* buf, | 76 int UploadFileElementReader::Read(IOBuffer* buf, |
| 77 int buf_length, | 77 int buf_length, |
| 78 const CompletionCallback& callback) { | 78 const CompletionCallback& callback) { |
| 79 DCHECK(!callback.is_null()); | 79 DCHECK(!callback.is_null()); |
| 80 | 80 |
| 81 uint64 num_bytes_to_read = | 81 int num_bytes_to_read = static_cast<int>( |
| 82 std::min(BytesRemaining(), static_cast<uint64>(buf_length)); | 82 std::min(BytesRemaining(), static_cast<uint64>(buf_length))); |
| 83 if (num_bytes_to_read == 0) | 83 if (num_bytes_to_read == 0) |
| 84 return 0; | 84 return 0; |
| 85 | 85 |
| 86 int result = file_stream_->Read( | 86 int result = file_stream_->Read( |
| 87 buf, num_bytes_to_read, | 87 buf, num_bytes_to_read, |
| 88 base::Bind(base::IgnoreResult(&UploadFileElementReader::OnReadCompleted), | 88 base::Bind(base::IgnoreResult(&UploadFileElementReader::OnReadCompleted), |
| 89 weak_ptr_factory_.GetWeakPtr(), | 89 weak_ptr_factory_.GetWeakPtr(), |
| 90 callback)); | 90 callback)); |
| 91 // Even in async mode, FileStream::Read() may return the result synchronously. | 91 // Even in async mode, FileStream::Read() may return the result synchronously. |
| 92 if (result != ERR_IO_PENDING) | 92 if (result != ERR_IO_PENDING) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 void UploadFileElementReader::OnSeekCompleted( | 135 void UploadFileElementReader::OnSeekCompleted( |
| 136 const CompletionCallback& callback, | 136 const CompletionCallback& callback, |
| 137 int64 result) { | 137 int64 result) { |
| 138 DCHECK(!callback.is_null()); | 138 DCHECK(!callback.is_null()); |
| 139 | 139 |
| 140 if (result < 0) { | 140 if (result < 0) { |
| 141 DLOG(WARNING) << "Failed to seek \"" << path_.value() | 141 DLOG(WARNING) << "Failed to seek \"" << path_.value() |
| 142 << "\" to offset: " << range_offset_ << " (" << result << ")"; | 142 << "\" to offset: " << range_offset_ << " (" << result << ")"; |
| 143 callback.Run(result); | 143 callback.Run(static_cast<int>(result)); |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 | 146 |
| 147 base::File::Info* file_info = new base::File::Info; | 147 base::File::Info* file_info = new base::File::Info; |
| 148 bool posted = base::PostTaskAndReplyWithResult( | 148 bool posted = base::PostTaskAndReplyWithResult( |
| 149 task_runner_.get(), | 149 task_runner_.get(), |
| 150 FROM_HERE, | 150 FROM_HERE, |
| 151 base::Bind(&base::GetFileInfo, path_, file_info), | 151 base::Bind(&base::GetFileInfo, path_, file_info), |
| 152 base::Bind(&UploadFileElementReader::OnGetFileInfoCompleted, | 152 base::Bind(&UploadFileElementReader::OnGetFileInfoCompleted, |
| 153 weak_ptr_factory_.GetWeakPtr(), | 153 weak_ptr_factory_.GetWeakPtr(), |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 ScopedOverridingContentLengthForTests(uint64 value) { | 209 ScopedOverridingContentLengthForTests(uint64 value) { |
| 210 overriding_content_length = value; | 210 overriding_content_length = value; |
| 211 } | 211 } |
| 212 | 212 |
| 213 UploadFileElementReader::ScopedOverridingContentLengthForTests:: | 213 UploadFileElementReader::ScopedOverridingContentLengthForTests:: |
| 214 ~ScopedOverridingContentLengthForTests() { | 214 ~ScopedOverridingContentLengthForTests() { |
| 215 overriding_content_length = 0; | 215 overriding_content_length = 0; |
| 216 } | 216 } |
| 217 | 217 |
| 218 } // namespace net | 218 } // namespace net |
| OLD | NEW |