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" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/metrics/stats_counters.h" | 13 #include "base/metrics/stats_counters.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "content/browser/byte_stream.h" | 15 #include "content/browser/byte_stream.h" |
16 #include "content/browser/download/download_create_info.h" | 16 #include "content/browser/download/download_create_info.h" |
17 #include "content/browser/download/download_interrupt_reasons_impl.h" | 17 #include "content/browser/download/download_interrupt_reasons_impl.h" |
18 #include "content/browser/download/download_manager_impl.h" | 18 #include "content/browser/download/download_manager_impl.h" |
19 #include "content/browser/download/download_request_handle.h" | 19 #include "content/browser/download/download_request_handle.h" |
20 #include "content/browser/download/download_stats.h" | 20 #include "content/browser/download/download_stats.h" |
21 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 21 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
22 #include "content/browser/loader/resource_request_info_impl.h" | 22 #include "content/browser/loader/resource_request_info_impl.h" |
23 #include "content/common/ssl_status_serialization.h" | |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/download_interrupt_reasons.h" | 25 #include "content/public/browser/download_interrupt_reasons.h" |
25 #include "content/public/browser/download_item.h" | 26 #include "content/public/browser/download_item.h" |
26 #include "content/public/browser/download_manager_delegate.h" | 27 #include "content/public/browser/download_manager_delegate.h" |
27 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
28 #include "content/public/browser/power_save_blocker.h" | 29 #include "content/public/browser/power_save_blocker.h" |
29 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
30 #include "content/public/common/resource_response.h" | 31 #include "content/public/common/resource_response.h" |
31 #include "net/base/io_buffer.h" | 32 #include "net/base/io_buffer.h" |
32 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 WebContents* web_contents = request_handle.GetWebContents(); | 91 WebContents* web_contents = request_handle.GetWebContents(); |
91 if (web_contents) { | 92 if (web_contents) { |
92 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); | 93 NavigationEntry* entry = web_contents->GetController().GetVisibleEntry(); |
93 if (entry) { | 94 if (entry) { |
94 tab_info->tab_url = entry->GetURL(); | 95 tab_info->tab_url = entry->GetURL(); |
95 tab_info->tab_referrer_url = entry->GetReferrer().url; | 96 tab_info->tab_referrer_url = entry->GetReferrer().url; |
96 } | 97 } |
97 } | 98 } |
98 } | 99 } |
99 | 100 |
101 bool IsSSLCertificateError(const std::string& security_info) { | |
102 int ssl_cert_id; | |
103 net::CertStatus ssl_cert_status; | |
104 int ssl_security_bits; | |
105 int ssl_connection_status; | |
106 SignedCertificateTimestampIDStatusList ssl_signed_certificate_timestamp_ids; | |
107 if (!DeserializeSecurityInfo(security_info, | |
108 &ssl_cert_id, | |
109 &ssl_cert_status, | |
110 &ssl_security_bits, | |
111 &ssl_connection_status, | |
112 &ssl_signed_certificate_timestamp_ids)) | |
asanka
2014/07/11 18:13:53
Nit: Formatting seems off. "git cl format" ?
Note
| |
113 return false; | |
114 return net::IsCertStatusError(ssl_cert_status); | |
115 } | |
116 | |
100 } // namespace | 117 } // namespace |
101 | 118 |
102 const int DownloadResourceHandler::kDownloadByteStreamSize = 100 * 1024; | 119 const int DownloadResourceHandler::kDownloadByteStreamSize = 100 * 1024; |
103 | 120 |
104 DownloadResourceHandler::DownloadResourceHandler( | 121 DownloadResourceHandler::DownloadResourceHandler( |
105 uint32 id, | 122 uint32 id, |
106 net::URLRequest* request, | 123 net::URLRequest* request, |
107 const DownloadUrlParameters::OnStartedCallback& started_cb, | 124 const DownloadUrlParameters::OnStartedCallback& started_cb, |
108 scoped_ptr<DownloadSaveInfo> save_info) | 125 scoped_ptr<DownloadSaveInfo> save_info) |
109 : ResourceHandler(request), | 126 : ResourceHandler(request), |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 if (status.status() == net::URLRequestStatus::CANCELED && | 393 if (status.status() == net::URLRequestStatus::CANCELED && |
377 status.error() == net::ERR_ABORTED) { | 394 status.error() == net::ERR_ABORTED) { |
378 // CANCELED + ERR_ABORTED == something outside of the network | 395 // CANCELED + ERR_ABORTED == something outside of the network |
379 // stack cancelled the request. There aren't that many things that | 396 // stack cancelled the request. There aren't that many things that |
380 // could do this to a download request (whose lifetime is separated from | 397 // could do this to a download request (whose lifetime is separated from |
381 // the tab from which it came). We map this to USER_CANCELLED as the | 398 // the tab from which it came). We map this to USER_CANCELLED as the |
382 // case we know about (system suspend because of laptop close) corresponds | 399 // case we know about (system suspend because of laptop close) corresponds |
383 // to a user action. | 400 // to a user action. |
384 // TODO(ahendrickson) -- Find a better set of codes to use here, as | 401 // TODO(ahendrickson) -- Find a better set of codes to use here, as |
385 // CANCELED/ERR_ABORTED can occur for reasons other than user cancel. | 402 // CANCELED/ERR_ABORTED can occur for reasons other than user cancel. |
386 reason = DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; | 403 if (IsSSLCertificateError(security_info)) |
asanka
2014/07/11 18:13:53
if (net::IsCertStatusError(request()->ssl_info().c
| |
404 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM; | |
405 else | |
406 reason = DOWNLOAD_INTERRUPT_REASON_USER_CANCELED; | |
387 } | 407 } |
388 | 408 |
389 if (status.is_success() && | 409 if (status.is_success() && |
390 reason == DOWNLOAD_INTERRUPT_REASON_NONE && | 410 reason == DOWNLOAD_INTERRUPT_REASON_NONE && |
391 request()->response_headers()) { | 411 request()->response_headers()) { |
392 // Handle server's response codes. | 412 // Handle server's response codes. |
393 switch(response_code) { | 413 switch(response_code) { |
394 case -1: // Non-HTTP request. | 414 case -1: // Non-HTTP request. |
395 case net::HTTP_OK: | 415 case net::HTTP_OK: |
396 case net::HTTP_CREATED: | 416 case net::HTTP_CREATED: |
(...skipping 10 matching lines...) Expand all Loading... | |
407 case net::HTTP_PRECONDITION_FAILED: | 427 case net::HTTP_PRECONDITION_FAILED: |
408 // Failed our 'If-Unmodified-Since' or 'If-Match'; see | 428 // Failed our 'If-Unmodified-Since' or 'If-Match'; see |
409 // download_manager_impl.cc BeginDownload() | 429 // download_manager_impl.cc BeginDownload() |
410 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; | 430 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_PRECONDITION; |
411 break; | 431 break; |
412 case net::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE: | 432 case net::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE: |
413 // Retry by downloading from the start automatically: | 433 // Retry by downloading from the start automatically: |
414 // If we haven't received data when we get this error, we won't. | 434 // If we haven't received data when we get this error, we won't. |
415 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE; | 435 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_NO_RANGE; |
416 break; | 436 break; |
437 case net::HTTP_UNAUTHORIZED: | |
438 // Server didn't authorize this request. | |
439 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_UNAUTHORIZED; | |
440 break; | |
417 default: // All other errors. | 441 default: // All other errors. |
418 // Redirection and informational codes should have been handled earlier | 442 // Redirection and informational codes should have been handled earlier |
419 // in the stack. | 443 // in the stack. |
420 DCHECK_NE(3, response_code / 100); | 444 DCHECK_NE(3, response_code / 100); |
421 DCHECK_NE(1, response_code / 100); | 445 DCHECK_NE(1, response_code / 100); |
422 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; | 446 reason = DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED; |
423 break; | 447 break; |
424 } | 448 } |
425 } | 449 } |
426 | 450 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 // tab_info_ must be destroyed on UI thread, since | 552 // tab_info_ must be destroyed on UI thread, since |
529 // InitializeDownloadTabInfoOnUIThread might still be using it. | 553 // InitializeDownloadTabInfoOnUIThread might still be using it. |
530 if (tab_info_) | 554 if (tab_info_) |
531 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, tab_info_); | 555 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, tab_info_); |
532 | 556 |
533 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 557 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
534 base::TimeTicks::Now() - download_start_time_); | 558 base::TimeTicks::Now() - download_start_time_); |
535 } | 559 } |
536 | 560 |
537 } // namespace content | 561 } // namespace content |
OLD | NEW |