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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 // Send the download creation information to the download thread. | 150 // Send the download creation information to the download thread. |
151 bool DownloadResourceHandler::OnResponseStarted( | 151 bool DownloadResourceHandler::OnResponseStarted( |
152 ResourceResponse* response, | 152 ResourceResponse* response, |
153 bool* defer) { | 153 bool* defer) { |
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
155 // There can be only one (call) | 155 // There can be only one (call) |
156 DCHECK(!on_response_started_called_); | 156 DCHECK(!on_response_started_called_); |
157 on_response_started_called_ = true; | 157 on_response_started_called_ = true; |
158 | 158 |
159 VLOG(20) << __FUNCTION__ << "()" << DebugString(); | 159 DVLOG(20) << __FUNCTION__ << "()" << DebugString(); |
160 download_start_time_ = base::TimeTicks::Now(); | 160 download_start_time_ = base::TimeTicks::Now(); |
161 | 161 |
162 // If it's a download, we don't want to poison the cache with it. | 162 // If it's a download, we don't want to poison the cache with it. |
163 request()->StopCaching(); | 163 request()->StopCaching(); |
164 | 164 |
165 // Lower priority as well, so downloads don't contend for resources | 165 // Lower priority as well, so downloads don't contend for resources |
166 // with main frames. | 166 // with main frames. |
167 request()->SetPriority(net::IDLE); | 167 request()->SetPriority(net::IDLE); |
168 | 168 |
169 // If the content-length header is not present (or contains something other | 169 // If the content-length header is not present (or contains something other |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 336 |
337 return true; | 337 return true; |
338 } | 338 } |
339 | 339 |
340 void DownloadResourceHandler::OnResponseCompleted( | 340 void DownloadResourceHandler::OnResponseCompleted( |
341 const net::URLRequestStatus& status, | 341 const net::URLRequestStatus& status, |
342 const std::string& security_info, | 342 const std::string& security_info, |
343 bool* defer) { | 343 bool* defer) { |
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
345 int response_code = status.is_success() ? request()->GetResponseCode() : 0; | 345 int response_code = status.is_success() ? request()->GetResponseCode() : 0; |
346 VLOG(20) << __FUNCTION__ << "()" << DebugString() | 346 DVLOG(20) << __FUNCTION__ << "()" << DebugString() |
347 << " status.status() = " << status.status() | 347 << " status.status() = " << status.status() |
348 << " status.error() = " << status.error() | 348 << " status.error() = " << status.error() |
349 << " response_code = " << response_code; | 349 << " response_code = " << response_code; |
350 | 350 |
351 net::Error error_code = net::OK; | 351 net::Error error_code = net::OK; |
352 if (status.status() == net::URLRequestStatus::FAILED || | 352 if (status.status() == net::URLRequestStatus::FAILED || |
353 // Note cancels as failures too. | 353 // Note cancels as failures too. |
354 status.status() == net::URLRequestStatus::CANCELED) { | 354 status.status() == net::URLRequestStatus::CANCELED) { |
355 error_code = static_cast<net::Error>(status.error()); // Normal case. | 355 error_code = static_cast<net::Error>(status.error()); // Normal case. |
356 // Make sure that at least the fact of failure comes through. | 356 // Make sure that at least the fact of failure comes through. |
357 if (error_code == net::OK) | 357 if (error_code == net::OK) |
358 error_code = net::ERR_FAILED; | 358 error_code = net::ERR_FAILED; |
359 } | 359 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 // tab_info_ must be destroyed on UI thread, since | 532 // tab_info_ must be destroyed on UI thread, since |
533 // InitializeDownloadTabInfoOnUIThread might still be using it. | 533 // InitializeDownloadTabInfoOnUIThread might still be using it. |
534 if (tab_info_) | 534 if (tab_info_) |
535 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, tab_info_); | 535 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, tab_info_); |
536 | 536 |
537 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 537 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
538 base::TimeTicks::Now() - download_start_time_); | 538 base::TimeTicks::Now() - download_start_time_); |
539 } | 539 } |
540 | 540 |
541 } // namespace content | 541 } // namespace content |
OLD | NEW |