| 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 "content/browser/download/download_file_impl.h" | 5 #include "content/browser/download/download_file_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 switch (state) { | 176 switch (state) { |
| 177 case content::ByteStreamReader::STREAM_EMPTY: | 177 case content::ByteStreamReader::STREAM_EMPTY: |
| 178 break; | 178 break; |
| 179 case content::ByteStreamReader::STREAM_HAS_DATA: | 179 case content::ByteStreamReader::STREAM_HAS_DATA: |
| 180 { | 180 { |
| 181 ++num_buffers; | 181 ++num_buffers; |
| 182 base::TimeTicks write_start(base::TimeTicks::Now()); | 182 base::TimeTicks write_start(base::TimeTicks::Now()); |
| 183 result = AppendDataToFile( | 183 result = AppendDataToFile( |
| 184 incoming_data.get()->data(), incoming_data_size); | 184 incoming_data.get()->data(), incoming_data_size); |
| 185 disk_writes_time_ += (base::TimeTicks::Now() - write_start); | 185 disk_writes_time_ += (base::TimeTicks::Now() - write_start); |
| 186 bytes_seen_ += incoming_data_size; |
| 186 total_incoming_data_size += incoming_data_size; | 187 total_incoming_data_size += incoming_data_size; |
| 187 reason = content::ConvertNetErrorToInterruptReason( | 188 reason = content::ConvertNetErrorToInterruptReason( |
| 188 result, content::DOWNLOAD_INTERRUPT_FROM_DISK); | 189 result, content::DOWNLOAD_INTERRUPT_FROM_DISK); |
| 189 } | 190 } |
| 190 break; | 191 break; |
| 191 case content::ByteStreamReader::STREAM_COMPLETE: | 192 case content::ByteStreamReader::STREAM_COMPLETE: |
| 192 { | 193 { |
| 193 reason = stream_reader_->GetStatus(); | 194 reason = stream_reader_->GetStatus(); |
| 194 SendUpdate(); | 195 SendUpdate(); |
| 195 base::TimeTicks close_start(base::TimeTicks::Now()); | 196 base::TimeTicks close_start(base::TimeTicks::Now()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 214 if (state == content::ByteStreamReader::STREAM_HAS_DATA && | 215 if (state == content::ByteStreamReader::STREAM_HAS_DATA && |
| 215 now - start > delta) { | 216 now - start > delta) { |
| 216 BrowserThread::PostTask( | 217 BrowserThread::PostTask( |
| 217 BrowserThread::FILE, FROM_HERE, | 218 BrowserThread::FILE, FROM_HERE, |
| 218 base::Bind(&DownloadFileImpl::StreamActive, | 219 base::Bind(&DownloadFileImpl::StreamActive, |
| 219 weak_factory_.GetWeakPtr())); | 220 weak_factory_.GetWeakPtr())); |
| 220 } | 221 } |
| 221 | 222 |
| 222 if (total_incoming_data_size) | 223 if (total_incoming_data_size) |
| 223 download_stats::RecordFileThreadReceiveBuffers(num_buffers); | 224 download_stats::RecordFileThreadReceiveBuffers(num_buffers); |
| 224 bytes_seen_ += total_incoming_data_size; | |
| 225 | 225 |
| 226 download_stats::RecordContiguousWriteTime(now - start); | 226 download_stats::RecordContiguousWriteTime(now - start); |
| 227 | 227 |
| 228 // Take care of communication with our controller. | 228 // Take care of communication with our controller. |
| 229 if (reason != content::DOWNLOAD_INTERRUPT_REASON_NONE) { | 229 if (reason != content::DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 230 // Error case for both upstream source and file write. | 230 // Error case for both upstream source and file write. |
| 231 // Shut down processing and signal an error to our controller. | 231 // Shut down processing and signal an error to our controller. |
| 232 // Our controller will clean us up. | 232 // Our controller will clean us up. |
| 233 stream_reader_->RegisterCallback(base::Closure()); | 233 stream_reader_->RegisterCallback(base::Closure()); |
| 234 weak_factory_.InvalidateWeakPtrs(); | 234 weak_factory_.InvalidateWeakPtrs(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 264 | 264 |
| 265 void DownloadFileImpl::SendUpdate() { | 265 void DownloadFileImpl::SendUpdate() { |
| 266 if (download_manager_.get()) { | 266 if (download_manager_.get()) { |
| 267 BrowserThread::PostTask( | 267 BrowserThread::PostTask( |
| 268 BrowserThread::UI, FROM_HERE, | 268 BrowserThread::UI, FROM_HERE, |
| 269 base::Bind(&DownloadManager::UpdateDownload, | 269 base::Bind(&DownloadManager::UpdateDownload, |
| 270 download_manager_, id_.local(), | 270 download_manager_, id_.local(), |
| 271 BytesSoFar(), CurrentSpeed(), GetHashState())); | 271 BytesSoFar(), CurrentSpeed(), GetHashState())); |
| 272 } | 272 } |
| 273 } | 273 } |
| OLD | NEW |