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/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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::URLRangeRequestJob(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 error_code_(0), | |
|
tyoshino (SeeGerritForStatus)
2016/09/27 10:24:56
how about net::OK so that it's clear that it's int
jam
2016/09/27 15:41:07
Done.
| |
| 33 weak_factory_(this) { | 34 weak_factory_(this) { |
| 34 DCHECK(stream_.get()); | 35 DCHECK(stream_.get()); |
| 35 stream_->SetReadObserver(this); | 36 stream_->SetReadObserver(this); |
| 36 } | 37 } |
| 37 | 38 |
| 38 StreamURLRequestJob::~StreamURLRequestJob() { | 39 StreamURLRequestJob::~StreamURLRequestJob() { |
| 39 ClearStream(); | 40 ClearStream(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void StreamURLRequestJob::OnDataAvailable(Stream* stream) { | 43 void StreamURLRequestJob::OnDataAvailable(Stream* stream) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 base::Bind(&StreamURLRequestJob::DidStart, weak_factory_.GetWeakPtr())); | 86 base::Bind(&StreamURLRequestJob::DidStart, weak_factory_.GetWeakPtr())); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void StreamURLRequestJob::Kill() { | 89 void StreamURLRequestJob::Kill() { |
| 89 net::URLRequestJob::Kill(); | 90 net::URLRequestJob::Kill(); |
| 90 weak_factory_.InvalidateWeakPtrs(); | 91 weak_factory_.InvalidateWeakPtrs(); |
| 91 ClearStream(); | 92 ClearStream(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 int StreamURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) { | 95 int StreamURLRequestJob::ReadRawData(net::IOBuffer* buf, int buf_size) { |
| 95 // TODO(ellyjones): This is not right. The old code returned true here, but | |
| 96 // ReadRawData's old contract was to return true only for synchronous | |
| 97 // successes, which had the effect of treating all errors as synchronous EOFs. | |
| 98 // See https://crbug.com/508957 | |
| 99 if (request_failed_) | 96 if (request_failed_) |
| 100 return 0; | 97 return error_code_; |
| 101 | 98 |
| 102 DCHECK(buf); | 99 DCHECK(buf); |
| 103 int to_read = buf_size; | 100 int to_read = buf_size; |
| 104 if (max_range_ && to_read) { | 101 if (max_range_ && to_read) { |
| 105 if (to_read + total_bytes_read_ > max_range_) | 102 if (to_read + total_bytes_read_ > max_range_) |
| 106 to_read = max_range_ - total_bytes_read_; | 103 to_read = max_range_ - total_bytes_read_; |
| 107 | 104 |
| 108 if (to_read == 0) | 105 if (to_read == 0) |
| 109 return 0; | 106 return 0; |
| 110 } | 107 } |
| 111 | 108 |
| 112 int bytes_read = 0; | 109 int bytes_read = 0; |
| 113 switch (stream_->ReadRawData(buf, to_read, &bytes_read)) { | 110 switch (stream_->ReadRawData(buf, to_read, &bytes_read)) { |
| 114 case Stream::STREAM_HAS_DATA: | 111 case Stream::STREAM_HAS_DATA: |
| 115 case Stream::STREAM_COMPLETE: | |
| 116 total_bytes_read_ += bytes_read; | 112 total_bytes_read_ += bytes_read; |
| 117 return bytes_read; | 113 return bytes_read; |
| 114 case Stream::STREAM_COMPLETE: | |
| 115 return stream_->GetStatus(); | |
| 118 case Stream::STREAM_EMPTY: | 116 case Stream::STREAM_EMPTY: |
| 119 pending_buffer_ = buf; | 117 pending_buffer_ = buf; |
| 120 pending_buffer_size_ = to_read; | 118 pending_buffer_size_ = to_read; |
| 121 return net::ERR_IO_PENDING; | 119 return net::ERR_IO_PENDING; |
| 122 case Stream::STREAM_ABORTED: | 120 case Stream::STREAM_ABORTED: |
| 123 // Handle this as connection reset. | 121 // Handle this as connection reset. |
| 124 return net::ERR_CONNECTION_RESET; | 122 return net::ERR_CONNECTION_RESET; |
| 125 } | 123 } |
| 126 NOTREACHED(); | 124 NOTREACHED(); |
| 127 return net::ERR_FAILED; | 125 return net::ERR_FAILED; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 if (request()->method() != "GET") { | 160 if (request()->method() != "GET") { |
| 163 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); | 161 NotifyFailure(net::ERR_METHOD_NOT_SUPPORTED); |
| 164 return; | 162 return; |
| 165 } | 163 } |
| 166 | 164 |
| 167 HeadersCompleted(net::HTTP_OK); | 165 HeadersCompleted(net::HTTP_OK); |
| 168 } | 166 } |
| 169 | 167 |
| 170 void StreamURLRequestJob::NotifyFailure(int error_code) { | 168 void StreamURLRequestJob::NotifyFailure(int error_code) { |
| 171 request_failed_ = true; | 169 request_failed_ = true; |
| 170 error_code_ = error_code; | |
| 172 | 171 |
| 173 // This method can only be called before headers are set. | 172 // This method can only be called before headers are set. |
| 174 DCHECK(!headers_set_); | 173 DCHECK(!headers_set_); |
| 175 | 174 |
| 176 // TODO(zork): Share these with BlobURLRequestJob. | 175 // TODO(zork): Share these with BlobURLRequestJob. |
| 177 net::HttpStatusCode status_code = net::HTTP_INTERNAL_SERVER_ERROR; | 176 net::HttpStatusCode status_code = net::HTTP_INTERNAL_SERVER_ERROR; |
| 178 switch (error_code) { | 177 switch (error_code) { |
| 179 case net::ERR_ACCESS_DENIED: | 178 case net::ERR_ACCESS_DENIED: |
| 180 status_code = net::HTTP_FORBIDDEN; | 179 status_code = net::HTTP_FORBIDDEN; |
| 181 break; | 180 break; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 } | 217 } |
| 219 | 218 |
| 220 void StreamURLRequestJob::ClearStream() { | 219 void StreamURLRequestJob::ClearStream() { |
| 221 if (stream_.get()) { | 220 if (stream_.get()) { |
| 222 stream_->RemoveReadObserver(this); | 221 stream_->RemoveReadObserver(this); |
| 223 stream_ = NULL; | 222 stream_ = NULL; |
| 224 } | 223 } |
| 225 } | 224 } |
| 226 | 225 |
| 227 } // namespace content | 226 } // namespace content |
| OLD | NEW |