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