| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 pause_count_(0), | 114 pause_count_(0), |
| 115 was_deferred_(false), | 115 was_deferred_(false), |
| 116 on_response_started_called_(false) { | 116 on_response_started_called_(false) { |
| 117 RecordDownloadCount(UNTHROTTLED_COUNT); | 117 RecordDownloadCount(UNTHROTTLED_COUNT); |
| 118 | 118 |
| 119 // Do UI thread initialization asap after DownloadResourceHandler creation | 119 // Do UI thread initialization asap after DownloadResourceHandler creation |
| 120 // since the tab could be navigated before StartOnUIThread gets called. | 120 // since the tab could be navigated before StartOnUIThread gets called. |
| 121 const ResourceRequestInfoImpl* request_info = GetRequestInfo(); | 121 const ResourceRequestInfoImpl* request_info = GetRequestInfo(); |
| 122 tab_info_ = new DownloadTabInfo(); | 122 tab_info_ = new DownloadTabInfo(); |
| 123 BrowserThread::PostTask( | 123 BrowserThread::PostTask( |
| 124 BrowserThread::UI, | 124 BrowserThread::UI, FROM_HERE, |
| 125 FROM_HERE, | |
| 126 base::Bind(&InitializeDownloadTabInfoOnUIThread, | 125 base::Bind(&InitializeDownloadTabInfoOnUIThread, |
| 127 DownloadRequestHandle(AsWeakPtr(), | 126 DownloadRequestHandle(AsWeakPtr(), request_info->GetChildID(), |
| 128 request_info->GetChildID(), | |
| 129 request_info->GetRouteID(), | 127 request_info->GetRouteID(), |
| 130 request_info->GetRequestID()), | 128 request_info->GetRequestID(), |
| 129 request_info->frame_tree_node_id()), |
| 131 tab_info_)); | 130 tab_info_)); |
| 132 power_save_blocker_ = PowerSaveBlocker::Create( | 131 power_save_blocker_ = PowerSaveBlocker::Create( |
| 133 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 132 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 134 PowerSaveBlocker::kReasonOther, "Download in progress"); | 133 PowerSaveBlocker::kReasonOther, "Download in progress"); |
| 135 } | 134 } |
| 136 | 135 |
| 137 bool DownloadResourceHandler::OnUploadProgress(uint64 position, | 136 bool DownloadResourceHandler::OnUploadProgress(uint64 position, |
| 138 uint64 size) { | 137 uint64 size) { |
| 139 return true; | 138 return true; |
| 140 } | 139 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 info->download_id = download_id_; | 193 info->download_id = download_id_; |
| 195 info->url_chain = request()->url_chain(); | 194 info->url_chain = request()->url_chain(); |
| 196 info->referrer_url = GURL(request()->referrer()); | 195 info->referrer_url = GURL(request()->referrer()); |
| 197 info->mime_type = response->head.mime_type; | 196 info->mime_type = response->head.mime_type; |
| 198 info->remote_address = request()->GetSocketAddress().host(); | 197 info->remote_address = request()->GetSocketAddress().host(); |
| 199 request()->GetResponseHeaderByName("content-disposition", | 198 request()->GetResponseHeaderByName("content-disposition", |
| 200 &info->content_disposition); | 199 &info->content_disposition); |
| 201 RecordDownloadMimeType(info->mime_type); | 200 RecordDownloadMimeType(info->mime_type); |
| 202 RecordDownloadContentDisposition(info->content_disposition); | 201 RecordDownloadContentDisposition(info->content_disposition); |
| 203 | 202 |
| 204 info->request_handle = | 203 info->request_handle = DownloadRequestHandle( |
| 205 DownloadRequestHandle(AsWeakPtr(), request_info->GetChildID(), | 204 AsWeakPtr(), request_info->GetChildID(), request_info->GetRouteID(), |
| 206 request_info->GetRouteID(), | 205 request_info->GetRequestID(), request_info->frame_tree_node_id()); |
| 207 request_info->GetRequestID()); | |
| 208 | 206 |
| 209 // Get the last modified time and etag. | 207 // Get the last modified time and etag. |
| 210 const net::HttpResponseHeaders* headers = request()->response_headers(); | 208 const net::HttpResponseHeaders* headers = request()->response_headers(); |
| 211 if (headers) { | 209 if (headers) { |
| 212 if (headers->HasStrongValidators()) { | 210 if (headers->HasStrongValidators()) { |
| 213 // If we don't have strong validators as per RFC 2616 section 13.3.3, then | 211 // If we don't have strong validators as per RFC 2616 section 13.3.3, then |
| 214 // we neither store nor use them for range requests. | 212 // we neither store nor use them for range requests. |
| 215 if (!headers->EnumerateHeader(NULL, "Last-Modified", | 213 if (!headers->EnumerateHeader(NULL, "Last-Modified", |
| 216 &info->last_modified)) | 214 &info->last_modified)) |
| 217 info->last_modified.clear(); | 215 info->last_modified.clear(); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // tab_info_ must be destroyed on UI thread, since | 529 // tab_info_ must be destroyed on UI thread, since |
| 532 // InitializeDownloadTabInfoOnUIThread might still be using it. | 530 // InitializeDownloadTabInfoOnUIThread might still be using it. |
| 533 if (tab_info_) | 531 if (tab_info_) |
| 534 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, tab_info_); | 532 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, tab_info_); |
| 535 | 533 |
| 536 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", | 534 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", |
| 537 base::TimeTicks::Now() - download_start_time_); | 535 base::TimeTicks::Now() - download_start_time_); |
| 538 } | 536 } |
| 539 | 537 |
| 540 } // namespace content | 538 } // namespace content |
| OLD | NEW |