| 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_request_core.h" | 5 #include "content/browser/download/download_request_core.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 DownloadUrlParameters* params) { | 105 DownloadUrlParameters* params) { |
| 106 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 106 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 107 DCHECK(download_id == DownloadItem::kInvalidId || | 107 DCHECK(download_id == DownloadItem::kInvalidId || |
| 108 !params->content_initiated()) | 108 !params->content_initiated()) |
| 109 << "Content initiated downloads shouldn't specify a download ID"; | 109 << "Content initiated downloads shouldn't specify a download ID"; |
| 110 | 110 |
| 111 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and | 111 // ResourceDispatcherHost{Base} is-not-a URLRequest::Delegate, and |
| 112 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so | 112 // DownloadUrlParameters can-not include resource_dispatcher_host_impl.h, so |
| 113 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. | 113 // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. |
| 114 scoped_ptr<net::URLRequest> request( | 114 scoped_ptr<net::URLRequest> request( |
| 115 params->resource_context()->GetRequestContext()->CreateRequest( | 115 params->url_request_context_getter() |
| 116 params->url(), net::DEFAULT_PRIORITY, nullptr)); | 116 ->GetURLRequestContext() |
| 117 ->CreateRequest(params->url(), net::DEFAULT_PRIORITY, nullptr)); |
| 117 request->set_method(params->method()); | 118 request->set_method(params->method()); |
| 118 | 119 |
| 119 if (!params->post_body().empty()) { | 120 if (!params->post_body().empty()) { |
| 120 const std::string& body = params->post_body(); | 121 const std::string& body = params->post_body(); |
| 121 scoped_ptr<net::UploadElementReader> reader( | 122 scoped_ptr<net::UploadElementReader> reader( |
| 122 net::UploadOwnedBytesElementReader::CreateWithString(body)); | 123 net::UploadOwnedBytesElementReader::CreateWithString(body)); |
| 123 request->set_upload( | 124 request->set_upload( |
| 124 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); | 125 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0)); |
| 125 } | 126 } |
| 126 | 127 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // This function assumes that HasStrongValidators() was true and that the | 175 // This function assumes that HasStrongValidators() was true and that the |
| 175 // ETag and Last-Modified header values supplied are valid. | 176 // ETag and Last-Modified header values supplied are valid. |
| 176 request->SetExtraRequestHeaderByName( | 177 request->SetExtraRequestHeaderByName( |
| 177 "If-Range", has_etag ? params->etag() : params->last_modified(), true); | 178 "If-Range", has_etag ? params->etag() : params->last_modified(), true); |
| 178 } | 179 } |
| 179 | 180 |
| 180 for (const auto& header : params->request_headers()) | 181 for (const auto& header : params->request_headers()) |
| 181 request->SetExtraRequestHeaderByName(header.first, header.second, | 182 request->SetExtraRequestHeaderByName(header.first, header.second, |
| 182 false /*overwrite*/); | 183 false /*overwrite*/); |
| 183 | 184 |
| 184 DownloadRequestData::Attach(request.get(), std::move(params), download_id); | 185 DownloadRequestData::Attach(request.get(), params, download_id); |
| 185 return request; | 186 return request; |
| 186 } | 187 } |
| 187 | 188 |
| 188 DownloadRequestCore::DownloadRequestCore(net::URLRequest* request, | 189 DownloadRequestCore::DownloadRequestCore(net::URLRequest* request, |
| 189 Delegate* delegate) | 190 Delegate* delegate) |
| 190 : delegate_(delegate), | 191 : delegate_(delegate), |
| 191 request_(request), | 192 request_(request), |
| 192 download_id_(DownloadItem::kInvalidId), | 193 download_id_(DownloadItem::kInvalidId), |
| 193 last_buffer_size_(0), | 194 last_buffer_size_(0), |
| 194 bytes_read_(0), | 195 bytes_read_(0), |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 return DOWNLOAD_INTERRUPT_REASON_NONE; | 625 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 625 } | 626 } |
| 626 | 627 |
| 627 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) | 628 if (http_headers.response_code() == net::HTTP_PARTIAL_CONTENT) |
| 628 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; | 629 return DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT; |
| 629 | 630 |
| 630 return DOWNLOAD_INTERRUPT_REASON_NONE; | 631 return DOWNLOAD_INTERRUPT_REASON_NONE; |
| 631 } | 632 } |
| 632 | 633 |
| 633 } // namespace content | 634 } // namespace content |
| OLD | NEW |