Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/streams/stream_url_request_job.h" | 5 #include "content/browser/streams/stream_url_request_job.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "content/browser/streams/stream.h" | 11 #include "content/browser/streams/stream.h" |
| 12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/http/http_byte_range.h" | 14 #include "net/http/http_byte_range.h" |
| 15 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
| 16 #include "net/http/http_response_info.h" | 16 #include "net/http/http_response_info.h" |
| 17 #include "net/http/http_util.h" | 17 #include "net/http/http_util.h" |
| 18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 StreamURLRequestJob::StreamURLRequestJob( | 22 StreamURLRequestJob::StreamURLRequestJob( |
| 23 net::URLRequest* request, | 23 net::URLRequest* request, |
| 24 net::NetworkDelegate* network_delegate, | 24 net::NetworkDelegate* network_delegate, |
| 25 scoped_refptr<Stream> stream) | 25 scoped_refptr<Stream> stream) |
| 26 : net::URLRequestJob(request, network_delegate), | 26 : net::URLRangeRequestJob(request, network_delegate), |
| 27 stream_(stream), | 27 stream_(stream), |
| 28 headers_set_(false), | 28 headers_set_(false), |
| 29 pending_buffer_size_(0), | 29 pending_buffer_size_(0), |
| 30 total_bytes_read_(0), | 30 total_bytes_read_(0), |
| 31 max_range_(0), | 31 max_range_(0), |
| 32 request_failed_(false), | 32 request_failed_(false), |
| 33 weak_factory_(this) { | 33 weak_factory_(this) { |
| 34 DCHECK(stream_.get()); | 34 DCHECK(stream_.get()); |
| 35 stream_->SetReadObserver(this); | 35 stream_->SetReadObserver(this); |
| 36 } | 36 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 *info = *response_info_; | 140 *info = *response_info_; |
| 141 } | 141 } |
| 142 | 142 |
| 143 int StreamURLRequestJob::GetResponseCode() const { | 143 int StreamURLRequestJob::GetResponseCode() const { |
| 144 if (!response_info_) | 144 if (!response_info_) |
| 145 return -1; | 145 return -1; |
| 146 | 146 |
| 147 return response_info_->headers->response_code(); | 147 return response_info_->headers->response_code(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void StreamURLRequestJob::SetExtraRequestHeaders( | 150 void StreamURLRequestJob::DidStart() { |
| 151 const net::HttpRequestHeaders& headers) { | 151 if (range_parse_result() == net::OK && ranges().size() > 0) { |
| 152 std::string range_header; | 152 // Only one range is supported, and it must start at the first byte. |
| 153 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { | 153 if (ranges().size() > 1 || ranges()[0].first_byte_position() != 0) { |
| 154 std::vector<net::HttpByteRange> ranges; | 154 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); |
|
mmenke
2016/01/20 16:47:31
Note that the old code called NotifyFailure in Set
| |
| 155 if (net::HttpUtil::ParseRangeHeader(range_header, &ranges)) { | 155 return; |
| 156 if (ranges.size() == 1) { | |
| 157 // Streams don't support seeking, so a non-zero starting position | |
| 158 // doesn't make sense. | |
| 159 if (ranges[0].first_byte_position() == 0) { | |
| 160 max_range_ = ranges[0].last_byte_position() + 1; | |
| 161 } else { | |
| 162 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); | |
| 163 return; | |
| 164 } | |
| 165 } else { | |
| 166 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); | |
| 167 return; | |
| 168 } | |
| 169 } | 156 } |
| 157 | |
| 158 max_range_ = ranges()[0].last_byte_position() + 1; | |
| 170 } | 159 } |
| 171 } | |
| 172 | 160 |
| 173 void StreamURLRequestJob::DidStart() { | 161 // This class only supports GET requests. |
| 174 // We only support GET request. | |
| 175 if (request()->method() != "GET") { | 162 if (request()->method() != "GET") { |
| 176 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); | 163 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); |
| 177 return; | 164 return; |
| 178 } | 165 } |
| 179 | 166 |
| 180 HeadersCompleted(net::HTTP_OK); | 167 HeadersCompleted(net::HTTP_OK); |
| 181 } | 168 } |
| 182 | 169 |
| 183 void StreamURLRequestJob::NotifyFailure(int error_code) { | 170 void StreamURLRequestJob::NotifyFailure(int error_code) { |
| 184 request_failed_ = true; | 171 request_failed_ = true; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 } | 218 } |
| 232 | 219 |
| 233 void StreamURLRequestJob::ClearStream() { | 220 void StreamURLRequestJob::ClearStream() { |
| 234 if (stream_.get()) { | 221 if (stream_.get()) { |
| 235 stream_->RemoveReadObserver(this); | 222 stream_->RemoveReadObserver(this); |
| 236 stream_ = NULL; | 223 stream_ = NULL; |
| 237 } | 224 } |
| 238 } | 225 } |
| 239 | 226 |
| 240 } // namespace content | 227 } // namespace content |
| OLD | NEW |