| 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_resource_handler.h" | 5 #include "content/browser/download/download_resource_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; | 342 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; |
| 343 break; | 343 break; |
| 344 default: | 344 default: |
| 345 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; | 345 reason = content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; |
| 346 break; | 346 break; |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 | 350 |
| 351 download_stats::RecordAcceptsRanges(accept_ranges_, bytes_read_); | 351 download_stats::RecordAcceptsRanges(accept_ranges_, bytes_read_); |
| 352 download_stats::RecordNetworkBlockage( |
| 353 base::TimeTicks::Now() - download_start_time_, total_pause_time_); |
| 352 | 354 |
| 353 CallStartedCB(DownloadId(), error_code); | 355 CallStartedCB(DownloadId(), error_code); |
| 354 | 356 |
| 355 // Send the info down the stream. Conditional is in case we get | 357 // Send the info down the stream. Conditional is in case we get |
| 356 // OnResponseCompleted without OnResponseStarted. | 358 // OnResponseCompleted without OnResponseStarted. |
| 357 if (stream_writer_.get()) | 359 if (stream_writer_.get()) |
| 358 stream_writer_->Close(reason); | 360 stream_writer_->Close(reason); |
| 359 | 361 |
| 360 stream_writer_.reset(); // We no longer need the stream. | 362 stream_writer_.reset(); // We no longer need the stream. |
| 361 read_buffer_ = NULL; | 363 read_buffer_ = NULL; |
| 362 | 364 |
| 363 // Stats | |
| 364 download_stats::RecordNetworkBandwidth( | |
| 365 bytes_read_, base::TimeTicks::Now() - download_start_time_, | |
| 366 total_pause_time_); | |
| 367 | |
| 368 return true; | 365 return true; |
| 369 } | 366 } |
| 370 | 367 |
| 371 // If the content-length header is not present (or contains something other | 368 // If the content-length header is not present (or contains something other |
| 372 // than numbers), the incoming content_length is -1 (unknown size). | 369 // than numbers), the incoming content_length is -1 (unknown size). |
| 373 // Set the content length to 0 to indicate unknown size to DownloadManager. | 370 // Set the content length to 0 to indicate unknown size to DownloadManager. |
| 374 void DownloadResourceHandler::SetContentLength(const int64& content_length) { | 371 void DownloadResourceHandler::SetContentLength(const int64& content_length) { |
| 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 376 content_length_ = 0; | 373 content_length_ = 0; |
| 377 if (content_length > 0) | 374 if (content_length > 0) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 // false somewhere in the chain of resource handlers. | 443 // false somewhere in the chain of resource handlers. |
| 447 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); | 444 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); |
| 448 | 445 |
| 449 // Remove output stream callback if a stream exists. | 446 // Remove output stream callback if a stream exists. |
| 450 if (stream_writer_.get()) | 447 if (stream_writer_.get()) |
| 451 stream_writer_->RegisterCallback(base::Closure()); | 448 stream_writer_->RegisterCallback(base::Closure()); |
| 452 | 449 |
| 453 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 450 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
| 454 base::TimeTicks::Now() - download_start_time_); | 451 base::TimeTicks::Now() - download_start_time_); |
| 455 } | 452 } |
| OLD | NEW |