| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/http/http_basic_stream.h" | 5 #include "net/http/http_basic_stream.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 parser_(parser), | 26 parser_(parser), |
| 27 connection_(connection), | 27 connection_(connection), |
| 28 using_proxy_(using_proxy), | 28 using_proxy_(using_proxy), |
| 29 request_info_(NULL), | 29 request_info_(NULL), |
| 30 response_(NULL), | 30 response_(NULL), |
| 31 bytes_read_offset_(0) { | 31 bytes_read_offset_(0) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 HttpBasicStream::~HttpBasicStream() {} | 34 HttpBasicStream::~HttpBasicStream() {} |
| 35 | 35 |
| 36 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, | 36 int HttpBasicStream::InitializeStream( |
| 37 const BoundNetLog& net_log, | 37 const HttpRequestInfo* request_info, const BoundNetLog& net_log, |
| 38 OldCompletionCallback* callback) { | 38 const CompletionCallback& callback) { |
| 39 DCHECK(!parser_.get()); | 39 DCHECK(!parser_.get()); |
| 40 request_info_ = request_info; | 40 request_info_ = request_info; |
| 41 parser_.reset(new HttpStreamParser(connection_.get(), request_info, | 41 parser_.reset(new HttpStreamParser(connection_.get(), request_info, |
| 42 read_buf_, net_log)); | 42 read_buf_, net_log)); |
| 43 bytes_read_offset_ = connection_->socket()->NumBytesRead(); | 43 bytes_read_offset_ = connection_->socket()->NumBytesRead(); |
| 44 return OK; | 44 return OK; |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, | 48 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, |
| 49 UploadDataStream* request_body, | 49 UploadDataStream* request_body, |
| 50 HttpResponseInfo* response, | 50 HttpResponseInfo* response, |
| 51 OldCompletionCallback* callback) { | 51 const CompletionCallback& callback) { |
| 52 DCHECK(parser_.get()); | 52 DCHECK(parser_.get()); |
| 53 DCHECK(request_info_); | 53 DCHECK(request_info_); |
| 54 const std::string path = using_proxy_ ? | 54 const std::string path = using_proxy_ ? |
| 55 HttpUtil::SpecForRequest(request_info_->url) : | 55 HttpUtil::SpecForRequest(request_info_->url) : |
| 56 HttpUtil::PathForRequest(request_info_->url); | 56 HttpUtil::PathForRequest(request_info_->url); |
| 57 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", | 57 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", |
| 58 request_info_->method.c_str(), | 58 request_info_->method.c_str(), |
| 59 path.c_str()); | 59 path.c_str()); |
| 60 response_ = response; | 60 response_ = response; |
| 61 return parser_->SendRequest(request_line_, headers, request_body, response, | 61 return parser_->SendRequest(request_line_, headers, request_body, response, |
| 62 callback); | 62 callback); |
| 63 } | 63 } |
| 64 | 64 |
| 65 uint64 HttpBasicStream::GetUploadProgress() const { | 65 uint64 HttpBasicStream::GetUploadProgress() const { |
| 66 return parser_->GetUploadProgress(); | 66 return parser_->GetUploadProgress(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 int HttpBasicStream::ReadResponseHeaders(OldCompletionCallback* callback) { | 69 int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) { |
| 70 return parser_->ReadResponseHeaders(callback); | 70 return parser_->ReadResponseHeaders(callback); |
| 71 } | 71 } |
| 72 | 72 |
| 73 const HttpResponseInfo* HttpBasicStream::GetResponseInfo() const { | 73 const HttpResponseInfo* HttpBasicStream::GetResponseInfo() const { |
| 74 return parser_->GetResponseInfo(); | 74 return parser_->GetResponseInfo(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 int HttpBasicStream::ReadResponseBody(IOBuffer* buf, int buf_len, | 77 int HttpBasicStream::ReadResponseBody(IOBuffer* buf, int buf_len, |
| 78 OldCompletionCallback* callback) { | 78 const CompletionCallback& callback) { |
| 79 return parser_->ReadResponseBody(buf, buf_len, callback); | 79 return parser_->ReadResponseBody(buf, buf_len, callback); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void HttpBasicStream::Close(bool not_reusable) { | 82 void HttpBasicStream::Close(bool not_reusable) { |
| 83 parser_->Close(not_reusable); | 83 parser_->Close(not_reusable); |
| 84 } | 84 } |
| 85 | 85 |
| 86 HttpStream* HttpBasicStream::RenewStreamForAuth() { | 86 HttpStream* HttpBasicStream::RenewStreamForAuth() { |
| 87 DCHECK(IsResponseBodyComplete()); | 87 DCHECK(IsResponseBodyComplete()); |
| 88 DCHECK(!IsMoreDataBuffered()); | 88 DCHECK(!IsMoreDataBuffered()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Log rtt metrics here. | 131 // Log rtt metrics here. |
| 132 } | 132 } |
| 133 | 133 |
| 134 void HttpBasicStream::Drain(HttpNetworkSession* session) { | 134 void HttpBasicStream::Drain(HttpNetworkSession* session) { |
| 135 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this); | 135 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this); |
| 136 drainer->Start(session); | 136 drainer->Start(session); |
| 137 // |drainer| will delete itself. | 137 // |drainer| will delete itself. |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace net | 140 } // namespace net |
| OLD | NEW |