Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / http / http_basic_stream.cc
blob42a25929fe53e05a173178970a23d33316b79cf7
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
3 // found in the LICENSE file.
5 #include "net/http/http_basic_stream.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "net/http/http_request_info.h"
9 #include "net/http/http_response_body_drainer.h"
10 #include "net/http/http_stream_parser.h"
11 #include "net/socket/client_socket_handle.h"
13 namespace net {
15 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection,
16 bool using_proxy)
17 : state_(connection, using_proxy) {}
19 HttpBasicStream::~HttpBasicStream() {}
21 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info,
22 RequestPriority priority,
23 const BoundNetLog& net_log,
24 const CompletionCallback& callback) {
25 state_.Initialize(request_info, priority, net_log, callback);
26 return OK;
29 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
30 HttpResponseInfo* response,
31 const CompletionCallback& callback) {
32 DCHECK(parser());
33 return parser()->SendRequest(
34 state_.GenerateRequestLine(), headers, response, callback);
37 UploadProgress HttpBasicStream::GetUploadProgress() const {
38 return parser()->GetUploadProgress();
41 int HttpBasicStream::ReadResponseHeaders(const CompletionCallback& callback) {
42 return parser()->ReadResponseHeaders(callback);
45 int HttpBasicStream::ReadResponseBody(IOBuffer* buf,
46 int buf_len,
47 const CompletionCallback& callback) {
48 return parser()->ReadResponseBody(buf, buf_len, callback);
51 void HttpBasicStream::Close(bool not_reusable) {
52 parser()->Close(not_reusable);
55 HttpStream* HttpBasicStream::RenewStreamForAuth() {
56 DCHECK(IsResponseBodyComplete());
57 DCHECK(!parser()->IsMoreDataBuffered());
58 // The HttpStreamParser object still has a pointer to the connection. Just to
59 // be extra-sure it doesn't touch the connection again, delete it here rather
60 // than leaving it until the destructor is called.
61 state_.DeleteParser();
62 return new HttpBasicStream(state_.ReleaseConnection().release(),
63 state_.using_proxy());
66 bool HttpBasicStream::IsResponseBodyComplete() const {
67 return parser()->IsResponseBodyComplete();
70 bool HttpBasicStream::IsConnectionReused() const {
71 return parser()->IsConnectionReused();
74 void HttpBasicStream::SetConnectionReused() { parser()->SetConnectionReused(); }
76 bool HttpBasicStream::CanReuseConnection() const {
77 return parser()->CanReuseConnection();
80 int64 HttpBasicStream::GetTotalReceivedBytes() const {
81 if (parser())
82 return parser()->received_bytes();
83 return 0;
86 int64_t HttpBasicStream::GetTotalSentBytes() const {
87 if (parser())
88 return parser()->sent_bytes();
89 return 0;
92 bool HttpBasicStream::GetLoadTimingInfo(
93 LoadTimingInfo* load_timing_info) const {
94 return state_.connection()->GetLoadTimingInfo(IsConnectionReused(),
95 load_timing_info);
98 void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) {
99 parser()->GetSSLInfo(ssl_info);
102 void HttpBasicStream::GetSSLCertRequestInfo(
103 SSLCertRequestInfo* cert_request_info) {
104 parser()->GetSSLCertRequestInfo(cert_request_info);
107 void HttpBasicStream::Drain(HttpNetworkSession* session) {
108 HttpResponseBodyDrainer* drainer = new HttpResponseBodyDrainer(this);
109 drainer->Start(session);
110 // |drainer| will delete itself.
113 void HttpBasicStream::SetPriority(RequestPriority priority) {
114 // TODO(akalin): Plumb this through to |connection_|.
117 } // namespace net