Patch 1/3 to get WebScheduler via WebThread
[chromium-blink-merge.git] / net / http / http_basic_stream.cc
blob0d14e0f9a0eac6683aa6ff8a411cffe4fb796ca1
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::CanFindEndOfResponse() const {
71 return parser()->CanFindEndOfResponse();
74 bool HttpBasicStream::IsConnectionReused() const {
75 return parser()->IsConnectionReused();
78 void HttpBasicStream::SetConnectionReused() { parser()->SetConnectionReused(); }
80 bool HttpBasicStream::IsConnectionReusable() const {
81 return parser()->IsConnectionReusable();
84 int64 HttpBasicStream::GetTotalReceivedBytes() const {
85 if (parser())
86 return parser()->received_bytes();
87 return 0;
90 bool HttpBasicStream::GetLoadTimingInfo(
91 LoadTimingInfo* load_timing_info) const {
92 return state_.connection()->GetLoadTimingInfo(IsConnectionReused(),
93 load_timing_info);
96 void HttpBasicStream::GetSSLInfo(SSLInfo* ssl_info) {
97 parser()->GetSSLInfo(ssl_info);
100 void HttpBasicStream::GetSSLCertRequestInfo(
101 SSLCertRequestInfo* cert_request_info) {
102 parser()->GetSSLCertRequestInfo(cert_request_info);
105 bool HttpBasicStream::IsSpdyHttpStream() const { return false; }
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