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/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
6 | 6 |
7 #include <algorithm> // min | 7 #include <algorithm> // min |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 write_callback_(NULL), | 37 write_callback_(NULL), |
38 endpoint_(endpoint), | 38 endpoint_(endpoint), |
39 auth_( | 39 auth_( |
40 new HttpAuthController(HttpAuth::AUTH_PROXY, | 40 new HttpAuthController(HttpAuth::AUTH_PROXY, |
41 GURL("https://" + proxy_server.ToString()), | 41 GURL("https://" + proxy_server.ToString()), |
42 auth_cache, | 42 auth_cache, |
43 auth_handler_factory)), | 43 auth_handler_factory)), |
44 user_buffer_(NULL), | 44 user_buffer_(NULL), |
45 write_buffer_len_(0), | 45 write_buffer_len_(0), |
46 write_bytes_outstanding_(0), | 46 write_bytes_outstanding_(0), |
47 eof_has_been_read_(false), | |
48 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 47 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
49 net_log_(spdy_stream->net_log()) { | 48 net_log_(spdy_stream->net_log()) { |
50 request_.method = "CONNECT"; | 49 request_.method = "CONNECT"; |
51 request_.url = url; | 50 request_.url = url; |
52 if (!user_agent.empty()) | 51 if (!user_agent.empty()) |
53 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 52 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
54 user_agent); | 53 user_agent); |
55 spdy_stream_->SetDelegate(this); | 54 spdy_stream_->SetDelegate(this); |
56 was_ever_used_ = spdy_stream_->WasEverUsed(); | 55 was_ever_used_ = spdy_stream_->WasEverUsed(); |
57 } | 56 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 | 116 |
118 next_state_ = STATE_DISCONNECTED; | 117 next_state_ = STATE_DISCONNECTED; |
119 | 118 |
120 if (spdy_stream_) | 119 if (spdy_stream_) |
121 // This will cause OnClose to be invoked, which takes care of | 120 // This will cause OnClose to be invoked, which takes care of |
122 // cleaning up all the internal state. | 121 // cleaning up all the internal state. |
123 spdy_stream_->Cancel(); | 122 spdy_stream_->Cancel(); |
124 } | 123 } |
125 | 124 |
126 bool SpdyProxyClientSocket::IsConnected() const { | 125 bool SpdyProxyClientSocket::IsConnected() const { |
127 return next_state_ == STATE_OPEN || next_state_ == STATE_CLOSED; | 126 return next_state_ == STATE_OPEN; |
128 } | 127 } |
129 | 128 |
130 bool SpdyProxyClientSocket::IsConnectedAndIdle() const { | 129 bool SpdyProxyClientSocket::IsConnectedAndIdle() const { |
131 return IsConnected() && spdy_stream_.get() != NULL && | 130 return IsConnected() && read_buffer_.empty() && spdy_stream_->is_idle(); |
132 !spdy_stream_->is_idle(); | |
133 } | 131 } |
134 | 132 |
135 const BoundNetLog& SpdyProxyClientSocket::NetLog() const { | 133 const BoundNetLog& SpdyProxyClientSocket::NetLog() const { |
136 return net_log_; | 134 return net_log_; |
137 } | 135 } |
138 | 136 |
139 void SpdyProxyClientSocket::SetSubresourceSpeculation() { | 137 void SpdyProxyClientSocket::SetSubresourceSpeculation() { |
140 // TODO(rch): what should this implementation be? | 138 // TODO(rch): what should this implementation be? |
141 } | 139 } |
142 | 140 |
(...skipping 18 matching lines...) Expand all Loading... | |
161 } | 159 } |
162 | 160 |
163 int SpdyProxyClientSocket::Read(IOBuffer* buf, int buf_len, | 161 int SpdyProxyClientSocket::Read(IOBuffer* buf, int buf_len, |
164 OldCompletionCallback* callback) { | 162 OldCompletionCallback* callback) { |
165 DCHECK(!read_callback_); | 163 DCHECK(!read_callback_); |
166 DCHECK(!user_buffer_); | 164 DCHECK(!user_buffer_); |
167 | 165 |
168 if (next_state_ == STATE_DISCONNECTED) | 166 if (next_state_ == STATE_DISCONNECTED) |
169 return ERR_SOCKET_NOT_CONNECTED; | 167 return ERR_SOCKET_NOT_CONNECTED; |
170 | 168 |
171 if (!spdy_stream_ && read_buffer_.empty()) { | 169 if (next_state_ == STATE_CLOSED && read_buffer_.empty()) { |
172 if (eof_has_been_read_) | 170 Disconnect(); |
wtc
2011/12/02 23:16:40
This Disconnect() call may not be necessary.
I un
Ryan Hamilton
2011/12/02 23:59:17
You're right. recv will return 0 each time you ca
| |
173 return ERR_CONNECTION_CLOSED; | |
174 eof_has_been_read_ = true; | |
175 return 0; | 171 return 0; |
176 } | 172 } |
177 | 173 |
178 DCHECK(next_state_ == STATE_OPEN || next_state_ == STATE_CLOSED); | 174 DCHECK(next_state_ == STATE_OPEN || next_state_ == STATE_CLOSED); |
179 DCHECK(buf); | 175 DCHECK(buf); |
180 user_buffer_ = new DrainableIOBuffer(buf, buf_len); | 176 user_buffer_ = new DrainableIOBuffer(buf, buf_len); |
181 int result = PopulateUserReadBuffer(); | 177 int result = PopulateUserReadBuffer(); |
182 if (result == 0) { | 178 if (result == 0) { |
183 DCHECK(callback); | 179 DCHECK(callback); |
184 read_callback_ = callback; | 180 read_callback_ = callback; |
(...skipping 20 matching lines...) Expand all Loading... | |
205 data->DidConsume(bytes_to_copy); | 201 data->DidConsume(bytes_to_copy); |
206 } | 202 } |
207 } | 203 } |
208 | 204 |
209 return user_buffer_->BytesConsumed(); | 205 return user_buffer_->BytesConsumed(); |
210 } | 206 } |
211 | 207 |
212 int SpdyProxyClientSocket::Write(IOBuffer* buf, int buf_len, | 208 int SpdyProxyClientSocket::Write(IOBuffer* buf, int buf_len, |
213 OldCompletionCallback* callback) { | 209 OldCompletionCallback* callback) { |
214 DCHECK(!write_callback_); | 210 DCHECK(!write_callback_); |
215 if (next_state_ == STATE_DISCONNECTED) | 211 if (next_state_ != STATE_OPEN) |
216 return ERR_SOCKET_NOT_CONNECTED; | 212 return ERR_SOCKET_NOT_CONNECTED; |
217 | 213 |
218 if (!spdy_stream_) | 214 DCHECK(spdy_stream_); |
219 return ERR_CONNECTION_CLOSED; | |
220 | |
221 write_bytes_outstanding_= buf_len; | 215 write_bytes_outstanding_= buf_len; |
222 if (buf_len <= kMaxSpdyFrameChunkSize) { | 216 if (buf_len <= kMaxSpdyFrameChunkSize) { |
223 int rv = spdy_stream_->WriteStreamData(buf, buf_len, spdy::DATA_FLAG_NONE); | 217 int rv = spdy_stream_->WriteStreamData(buf, buf_len, spdy::DATA_FLAG_NONE); |
224 if (rv == ERR_IO_PENDING) { | 218 if (rv == ERR_IO_PENDING) { |
225 write_callback_ = callback; | 219 write_callback_ = callback; |
226 write_buffer_len_ = buf_len; | 220 write_buffer_len_ = buf_len; |
227 } | 221 } |
228 return rv; | 222 return rv; |
229 } | 223 } |
230 | 224 |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 } | 530 } |
537 // This may have been deleted by read_callback_, so check first. | 531 // This may have been deleted by read_callback_, so check first. |
538 if (weak_ptr && write_callback) | 532 if (weak_ptr && write_callback) |
539 write_callback->Run(ERR_CONNECTION_CLOSED); | 533 write_callback->Run(ERR_CONNECTION_CLOSED); |
540 } | 534 } |
541 | 535 |
542 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { | 536 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { |
543 } | 537 } |
544 | 538 |
545 } // namespace net | 539 } // namespace net |
OLD | NEW |