OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // TODO(ukai): code is similar with http_network_transaction.cc. We should | 5 // TODO(ukai): code is similar with http_network_transaction.cc. We should |
6 // think about ways to share code, if possible. | 6 // think about ways to share code, if possible. |
7 | 7 |
8 #include "net/socket_stream/socket_stream.h" | 8 #include "net/socket_stream/socket_stream.h" |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "net/ssl/ssl_info.h" | 43 #include "net/ssl/ssl_info.h" |
44 #include "net/url_request/url_request.h" | 44 #include "net/url_request/url_request.h" |
45 #include "net/url_request/url_request_context.h" | 45 #include "net/url_request/url_request_context.h" |
46 | 46 |
47 static const int kMaxPendingSendAllowed = 32768; // 32 kilobytes. | 47 static const int kMaxPendingSendAllowed = 32768; // 32 kilobytes. |
48 static const int kReadBufferSize = 4096; | 48 static const int kReadBufferSize = 4096; |
49 | 49 |
50 namespace net { | 50 namespace net { |
51 | 51 |
52 int SocketStream::Delegate::OnStartOpenConnection( | 52 int SocketStream::Delegate::OnStartOpenConnection( |
53 SocketStream* socket, const CompletionCallback& callback) { | 53 SocketStream* socket, |
| 54 const CompletionCallback& callback) { |
54 return OK; | 55 return OK; |
55 } | 56 } |
56 | 57 |
57 void SocketStream::Delegate::OnAuthRequired(SocketStream* socket, | 58 void SocketStream::Delegate::OnAuthRequired(SocketStream* socket, |
58 AuthChallengeInfo* auth_info) { | 59 AuthChallengeInfo* auth_info) { |
59 // By default, no credential is available and close the connection. | 60 // By default, no credential is available and close the connection. |
60 socket->Close(); | 61 socket->Close(); |
61 } | 62 } |
62 | 63 |
63 void SocketStream::Delegate::OnSSLCertificateError( | 64 void SocketStream::Delegate::OnSSLCertificateError(SocketStream* socket, |
64 SocketStream* socket, | 65 const SSLInfo& ssl_info, |
65 const SSLInfo& ssl_info, | 66 bool fatal) { |
66 bool fatal) { | |
67 socket->CancelWithSSLError(ssl_info); | 67 socket->CancelWithSSLError(ssl_info); |
68 } | 68 } |
69 | 69 |
70 bool SocketStream::Delegate::CanGetCookies(SocketStream* socket, | 70 bool SocketStream::Delegate::CanGetCookies(SocketStream* socket, |
71 const GURL& url) { | 71 const GURL& url) { |
72 return true; | 72 return true; |
73 } | 73 } |
74 | 74 |
75 bool SocketStream::Delegate::CanSetCookie(SocketStream* request, | 75 bool SocketStream::Delegate::CanSetCookie(SocketStream* request, |
76 const GURL& url, | 76 const GURL& url, |
77 const std::string& cookie_line, | 77 const std::string& cookie_line, |
78 CookieOptions* options) { | 78 CookieOptions* options) { |
79 return true; | 79 return true; |
80 } | 80 } |
81 | 81 |
82 SocketStream::ResponseHeaders::ResponseHeaders() : IOBuffer() {} | 82 SocketStream::ResponseHeaders::ResponseHeaders() : IOBuffer() { |
| 83 } |
83 | 84 |
84 void SocketStream::ResponseHeaders::Realloc(size_t new_size) { | 85 void SocketStream::ResponseHeaders::Realloc(size_t new_size) { |
85 headers_.reset(static_cast<char*>(realloc(headers_.release(), new_size))); | 86 headers_.reset(static_cast<char*>(realloc(headers_.release(), new_size))); |
86 } | 87 } |
87 | 88 |
88 SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; } | 89 SocketStream::ResponseHeaders::~ResponseHeaders() { |
| 90 data_ = NULL; |
| 91 } |
89 | 92 |
90 SocketStream::SocketStream(const GURL& url, Delegate* delegate, | 93 SocketStream::SocketStream(const GURL& url, |
| 94 Delegate* delegate, |
91 URLRequestContext* context, | 95 URLRequestContext* context, |
92 CookieStore* cookie_store) | 96 CookieStore* cookie_store) |
93 : delegate_(delegate), | 97 : delegate_(delegate), |
94 url_(url), | 98 url_(url), |
95 max_pending_send_allowed_(kMaxPendingSendAllowed), | 99 max_pending_send_allowed_(kMaxPendingSendAllowed), |
96 context_(context), | 100 context_(context), |
97 next_state_(STATE_NONE), | 101 next_state_(STATE_NONE), |
98 factory_(ClientSocketFactory::GetDefaultFactory()), | 102 factory_(ClientSocketFactory::GetDefaultFactory()), |
99 proxy_mode_(kDirectConnection), | 103 proxy_mode_(kDirectConnection), |
100 proxy_url_(url), | 104 proxy_url_(url), |
101 pac_request_(NULL), | 105 pac_request_(NULL), |
102 connection_(new ClientSocketHandle), | 106 connection_(new ClientSocketHandle), |
103 privacy_mode_(PRIVACY_MODE_DISABLED), | 107 privacy_mode_(PRIVACY_MODE_DISABLED), |
104 // Unretained() is required; without it, Bind() creates a circular | 108 // Unretained() is required; without it, Bind() creates a circular |
105 // dependency and the SocketStream object will not be freed. | 109 // dependency and the SocketStream object will not be freed. |
106 io_callback_(base::Bind(&SocketStream::OnIOCompleted, | 110 io_callback_( |
107 base::Unretained(this))), | 111 base::Bind(&SocketStream::OnIOCompleted, base::Unretained(this))), |
108 read_buf_(NULL), | 112 read_buf_(NULL), |
109 current_write_buf_(NULL), | 113 current_write_buf_(NULL), |
110 waiting_for_write_completion_(false), | 114 waiting_for_write_completion_(false), |
111 closing_(false), | 115 closing_(false), |
112 server_closed_(false), | 116 server_closed_(false), |
113 metrics_(new SocketStreamMetrics(url)), | 117 metrics_(new SocketStreamMetrics(url)), |
114 cookie_store_(cookie_store) { | 118 cookie_store_(cookie_store) { |
115 DCHECK(base::MessageLoop::current()) | 119 DCHECK(base::MessageLoop::current()) |
116 << "The current base::MessageLoop must exist"; | 120 << "The current base::MessageLoop must exist"; |
117 DCHECK(base::MessageLoopForIO::IsCurrent()) | 121 DCHECK(base::MessageLoopForIO::IsCurrent()) |
118 << "The current base::MessageLoop must be TYPE_IO"; | 122 << "The current base::MessageLoop must be TYPE_IO"; |
119 DCHECK(delegate_); | 123 DCHECK(delegate_); |
120 | 124 |
121 if (context_) { | 125 if (context_) { |
122 if (!cookie_store_) | 126 if (!cookie_store_) |
123 cookie_store_ = context_->cookie_store(); | 127 cookie_store_ = context_->cookie_store(); |
124 | 128 |
125 net_log_ = BoundNetLog::Make( | 129 net_log_ = |
126 context->net_log(), | 130 BoundNetLog::Make(context->net_log(), NetLog::SOURCE_SOCKET_STREAM); |
127 NetLog::SOURCE_SOCKET_STREAM); | |
128 | 131 |
129 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | 132 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
130 } | 133 } |
131 } | 134 } |
132 | 135 |
133 SocketStream::UserData* SocketStream::GetUserData( | 136 SocketStream::UserData* SocketStream::GetUserData(const void* key) const { |
134 const void* key) const { | |
135 UserDataMap::const_iterator found = user_data_.find(key); | 137 UserDataMap::const_iterator found = user_data_.find(key); |
136 if (found != user_data_.end()) | 138 if (found != user_data_.end()) |
137 return found->second.get(); | 139 return found->second.get(); |
138 return NULL; | 140 return NULL; |
139 } | 141 } |
140 | 142 |
141 void SocketStream::SetUserData(const void* key, UserData* data) { | 143 void SocketStream::SetUserData(const void* key, UserData* data) { |
142 user_data_[key] = linked_ptr<UserData>(data); | 144 user_data_[key] = linked_ptr<UserData>(data); |
143 } | 145 } |
144 | 146 |
(...skipping 12 matching lines...) Expand all Loading... |
157 | 159 |
158 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); | 160 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); |
159 net_log_ = BoundNetLog(); | 161 net_log_ = BoundNetLog(); |
160 | 162 |
161 context_ = NULL; | 163 context_ = NULL; |
162 cookie_store_ = NULL; | 164 cookie_store_ = NULL; |
163 } | 165 } |
164 | 166 |
165 void SocketStream::CheckPrivacyMode() { | 167 void SocketStream::CheckPrivacyMode() { |
166 if (context_ && context_->network_delegate()) { | 168 if (context_ && context_->network_delegate()) { |
167 bool enable = context_->network_delegate()->CanEnablePrivacyMode(url_, | 169 bool enable = |
168 url_); | 170 context_->network_delegate()->CanEnablePrivacyMode(url_, url_); |
169 privacy_mode_ = enable ? PRIVACY_MODE_ENABLED : PRIVACY_MODE_DISABLED; | 171 privacy_mode_ = enable ? PRIVACY_MODE_ENABLED : PRIVACY_MODE_DISABLED; |
170 // Disable Channel ID if privacy mode is enabled. | 172 // Disable Channel ID if privacy mode is enabled. |
171 if (enable) | 173 if (enable) |
172 server_ssl_config_.channel_id_enabled = false; | 174 server_ssl_config_.channel_id_enabled = false; |
173 } | 175 } |
174 } | 176 } |
175 | 177 |
176 void SocketStream::Connect() { | 178 void SocketStream::Connect() { |
177 DCHECK(base::MessageLoop::current()) | 179 DCHECK(base::MessageLoop::current()) |
178 << "The current base::MessageLoop must exist"; | 180 << "The current base::MessageLoop must exist"; |
(...skipping 27 matching lines...) Expand all Loading... |
206 return total_size; | 208 return total_size; |
207 } | 209 } |
208 | 210 |
209 bool SocketStream::SendData(const char* data, int len) { | 211 bool SocketStream::SendData(const char* data, int len) { |
210 DCHECK(base::MessageLoop::current()) | 212 DCHECK(base::MessageLoop::current()) |
211 << "The current base::MessageLoop must exist"; | 213 << "The current base::MessageLoop must exist"; |
212 DCHECK(base::MessageLoopForIO::IsCurrent()) | 214 DCHECK(base::MessageLoopForIO::IsCurrent()) |
213 << "The current base::MessageLoop must be TYPE_IO"; | 215 << "The current base::MessageLoop must be TYPE_IO"; |
214 DCHECK_GT(len, 0); | 216 DCHECK_GT(len, 0); |
215 | 217 |
216 if (!connection_->socket() || | 218 if (!connection_->socket() || !connection_->socket()->IsConnected() || |
217 !connection_->socket()->IsConnected() || next_state_ == STATE_NONE) { | 219 next_state_ == STATE_NONE) { |
218 return false; | 220 return false; |
219 } | 221 } |
220 | 222 |
221 int total_buffered_bytes = len; | 223 int total_buffered_bytes = len; |
222 if (current_write_buf_.get()) { | 224 if (current_write_buf_.get()) { |
223 // Since | 225 // Since |
224 // - the purpose of this check is to limit the amount of buffer used by | 226 // - the purpose of this check is to limit the amount of buffer used by |
225 // this instance. | 227 // this instance. |
226 // - the DrainableIOBuffer doesn't release consumed memory. | 228 // - the DrainableIOBuffer doesn't release consumed memory. |
227 // we need to use not BytesRemaining() but size() here. | 229 // we need to use not BytesRemaining() but size() here. |
228 total_buffered_bytes += current_write_buf_->size(); | 230 total_buffered_bytes += current_write_buf_->size(); |
229 } | 231 } |
230 total_buffered_bytes += GetTotalSizeOfPendingWriteBufs(); | 232 total_buffered_bytes += GetTotalSizeOfPendingWriteBufs(); |
231 if (total_buffered_bytes > max_pending_send_allowed_) | 233 if (total_buffered_bytes > max_pending_send_allowed_) |
232 return false; | 234 return false; |
233 | 235 |
234 // TODO(tyoshino): Split data into smaller chunks e.g. 8KiB to free consumed | 236 // TODO(tyoshino): Split data into smaller chunks e.g. 8KiB to free consumed |
235 // buffer progressively | 237 // buffer progressively |
236 pending_write_bufs_.push_back(make_scoped_refptr( | 238 pending_write_bufs_.push_back(make_scoped_refptr(new IOBufferWithSize(len))); |
237 new IOBufferWithSize(len))); | |
238 memcpy(pending_write_bufs_.back()->data(), data, len); | 239 memcpy(pending_write_bufs_.back()->data(), data, len); |
239 | 240 |
240 // If current_write_buf_ is not NULL, it means that a) there's ongoing write | 241 // If current_write_buf_ is not NULL, it means that a) there's ongoing write |
241 // operation or b) the connection is being closed. If a), the buffer we just | 242 // operation or b) the connection is being closed. If a), the buffer we just |
242 // pushed will be automatically handled when the completion callback runs | 243 // pushed will be automatically handled when the completion callback runs |
243 // the loop, and therefore we don't need to enqueue DoLoop(). If b), it's ok | 244 // the loop, and therefore we don't need to enqueue DoLoop(). If b), it's ok |
244 // to do nothing. If current_write_buf_ is NULL, to make sure DoLoop() is | 245 // to do nothing. If current_write_buf_ is NULL, to make sure DoLoop() is |
245 // ran soon, enequeue it. | 246 // ran soon, enequeue it. |
246 if (!current_write_buf_.get()) { | 247 if (!current_write_buf_.get()) { |
247 // Send pending data asynchronously, so that delegate won't be called | 248 // Send pending data asynchronously, so that delegate won't be called |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 297 net_log_.AddEvent(NetLog::TYPE_CANCELLED); |
297 // We don't need to send pending data when client detach the delegate. | 298 // We don't need to send pending data when client detach the delegate. |
298 pending_write_bufs_.clear(); | 299 pending_write_bufs_.clear(); |
299 Close(); | 300 Close(); |
300 } | 301 } |
301 | 302 |
302 const ProxyServer& SocketStream::proxy_server() const { | 303 const ProxyServer& SocketStream::proxy_server() const { |
303 return proxy_info_.proxy_server(); | 304 return proxy_info_.proxy_server(); |
304 } | 305 } |
305 | 306 |
306 void SocketStream::SetClientSocketFactory( | 307 void SocketStream::SetClientSocketFactory(ClientSocketFactory* factory) { |
307 ClientSocketFactory* factory) { | |
308 DCHECK(factory); | 308 DCHECK(factory); |
309 factory_ = factory; | 309 factory_ = factory; |
310 } | 310 } |
311 | 311 |
312 void SocketStream::CancelWithError(int error) { | 312 void SocketStream::CancelWithError(int error) { |
313 base::MessageLoop::current()->PostTask( | 313 base::MessageLoop::current()->PostTask( |
314 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, error)); | 314 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, error)); |
315 } | 315 } |
316 | 316 |
317 void SocketStream::CancelWithSSLError(const SSLInfo& ssl_info) { | 317 void SocketStream::CancelWithSSLError(const SSLInfo& ssl_info) { |
318 CancelWithError(MapCertStatusToNetError(ssl_info.cert_status)); | 318 CancelWithError(MapCertStatusToNetError(ssl_info.cert_status)); |
319 } | 319 } |
320 | 320 |
321 void SocketStream::ContinueDespiteError() { | 321 void SocketStream::ContinueDespiteError() { |
322 base::MessageLoop::current()->PostTask( | 322 base::MessageLoop::current()->PostTask( |
323 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK)); | 323 FROM_HERE, base::Bind(&SocketStream::DoLoop, this, OK)); |
324 } | 324 } |
325 | 325 |
326 SocketStream::~SocketStream() { | 326 SocketStream::~SocketStream() { |
327 DetachContext(); | 327 DetachContext(); |
328 DCHECK(!delegate_); | 328 DCHECK(!delegate_); |
329 DCHECK(!pac_request_); | 329 DCHECK(!pac_request_); |
330 } | 330 } |
331 | 331 |
332 SocketStream::RequestHeaders::~RequestHeaders() { data_ = NULL; } | 332 SocketStream::RequestHeaders::~RequestHeaders() { |
| 333 data_ = NULL; |
| 334 } |
333 | 335 |
334 void SocketStream::set_addresses(const AddressList& addresses) { | 336 void SocketStream::set_addresses(const AddressList& addresses) { |
335 addresses_ = addresses; | 337 addresses_ = addresses; |
336 } | 338 } |
337 | 339 |
338 void SocketStream::DoClose() { | 340 void SocketStream::DoClose() { |
339 closing_ = true; | 341 closing_ = true; |
340 // If next_state_ is: | 342 // If next_state_ is: |
341 // - STATE_TCP_CONNECT_COMPLETE, it's waiting other socket establishing | 343 // - STATE_TCP_CONNECT_COMPLETE, it's waiting other socket establishing |
342 // connection. | 344 // connection. |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 default: | 576 default: |
575 NOTREACHED() << "bad state " << state; | 577 NOTREACHED() << "bad state " << state; |
576 Finish(result); | 578 Finish(result); |
577 return; | 579 return; |
578 } | 580 } |
579 if (state == STATE_RESOLVE_PROTOCOL && result == ERR_PROTOCOL_SWITCHED) | 581 if (state == STATE_RESOLVE_PROTOCOL && result == ERR_PROTOCOL_SWITCHED) |
580 continue; | 582 continue; |
581 // If the connection is not established yet and had actual errors, | 583 // If the connection is not established yet and had actual errors, |
582 // record the error. In next iteration, it will close the connection. | 584 // record the error. In next iteration, it will close the connection. |
583 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { | 585 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { |
584 net_log_.EndEventWithNetErrorCode( | 586 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_SOCKET_STREAM_CONNECT, |
585 NetLog::TYPE_SOCKET_STREAM_CONNECT, result); | 587 result); |
586 } | 588 } |
587 } while (result != ERR_IO_PENDING); | 589 } while (result != ERR_IO_PENDING); |
588 } | 590 } |
589 | 591 |
590 int SocketStream::DoBeforeConnect() { | 592 int SocketStream::DoBeforeConnect() { |
591 next_state_ = STATE_BEFORE_CONNECT_COMPLETE; | 593 next_state_ = STATE_BEFORE_CONNECT_COMPLETE; |
592 if (!context_ || !context_->network_delegate()) | 594 if (!context_ || !context_->network_delegate()) |
593 return OK; | 595 return OK; |
594 | 596 |
595 int result = context_->network_delegate()->NotifyBeforeSocketStreamConnect( | 597 int result = context_->network_delegate()->NotifyBeforeSocketStreamConnect( |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 else if (result != OK && result != ERR_PROTOCOL_SWITCHED) | 723 else if (result != OK && result != ERR_PROTOCOL_SWITCHED) |
722 next_state_ = STATE_CLOSE; | 724 next_state_ = STATE_CLOSE; |
723 return result; | 725 return result; |
724 } | 726 } |
725 | 727 |
726 int SocketStream::DoResolveProtocolComplete(int result) { | 728 int SocketStream::DoResolveProtocolComplete(int result) { |
727 DCHECK_NE(ERR_IO_PENDING, result); | 729 DCHECK_NE(ERR_IO_PENDING, result); |
728 | 730 |
729 if (result == ERR_PROTOCOL_SWITCHED) { | 731 if (result == ERR_PROTOCOL_SWITCHED) { |
730 next_state_ = STATE_CLOSE; | 732 next_state_ = STATE_CLOSE; |
731 metrics_->OnCountWireProtocolType( | 733 metrics_->OnCountWireProtocolType(SocketStreamMetrics::WIRE_PROTOCOL_SPDY); |
732 SocketStreamMetrics::WIRE_PROTOCOL_SPDY); | |
733 } else if (result == OK) { | 734 } else if (result == OK) { |
734 next_state_ = STATE_TCP_CONNECT; | 735 next_state_ = STATE_TCP_CONNECT; |
735 metrics_->OnCountWireProtocolType( | 736 metrics_->OnCountWireProtocolType( |
736 SocketStreamMetrics::WIRE_PROTOCOL_WEBSOCKET); | 737 SocketStreamMetrics::WIRE_PROTOCOL_WEBSOCKET); |
737 } else { | 738 } else { |
738 next_state_ = STATE_CLOSE; | 739 next_state_ = STATE_CLOSE; |
739 } | 740 } |
740 return result; | 741 return result; |
741 } | 742 } |
742 | 743 |
743 int SocketStream::DoTcpConnect(int result) { | 744 int SocketStream::DoTcpConnect(int result) { |
744 if (result != OK) { | 745 if (result != OK) { |
745 next_state_ = STATE_CLOSE; | 746 next_state_ = STATE_CLOSE; |
746 return result; | 747 return result; |
747 } | 748 } |
748 next_state_ = STATE_TCP_CONNECT_COMPLETE; | 749 next_state_ = STATE_TCP_CONNECT_COMPLETE; |
749 DCHECK(factory_); | 750 DCHECK(factory_); |
750 connection_->SetSocket( | 751 connection_->SetSocket(factory_->CreateTransportClientSocket( |
751 factory_->CreateTransportClientSocket(addresses_, | 752 addresses_, net_log_.net_log(), net_log_.source())); |
752 net_log_.net_log(), | |
753 net_log_.source())); | |
754 metrics_->OnStartConnection(); | 753 metrics_->OnStartConnection(); |
755 return connection_->socket()->Connect(io_callback_); | 754 return connection_->socket()->Connect(io_callback_); |
756 } | 755 } |
757 | 756 |
758 int SocketStream::DoTcpConnectComplete(int result) { | 757 int SocketStream::DoTcpConnectComplete(int result) { |
759 // TODO(ukai): if error occured, reconsider proxy after error. | 758 // TODO(ukai): if error occured, reconsider proxy after error. |
760 if (result != OK) { | 759 if (result != OK) { |
761 next_state_ = STATE_CLOSE; | 760 next_state_ = STATE_CLOSE; |
762 return result; | 761 return result; |
763 } | 762 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 868 |
870 next_state_ = STATE_READ_TUNNEL_HEADERS_COMPLETE; | 869 next_state_ = STATE_READ_TUNNEL_HEADERS_COMPLETE; |
871 | 870 |
872 if (!tunnel_response_headers_.get()) { | 871 if (!tunnel_response_headers_.get()) { |
873 tunnel_response_headers_ = new ResponseHeaders(); | 872 tunnel_response_headers_ = new ResponseHeaders(); |
874 tunnel_response_headers_capacity_ = kMaxTunnelResponseHeadersSize; | 873 tunnel_response_headers_capacity_ = kMaxTunnelResponseHeadersSize; |
875 tunnel_response_headers_->Realloc(tunnel_response_headers_capacity_); | 874 tunnel_response_headers_->Realloc(tunnel_response_headers_capacity_); |
876 tunnel_response_headers_len_ = 0; | 875 tunnel_response_headers_len_ = 0; |
877 } | 876 } |
878 | 877 |
879 int buf_len = tunnel_response_headers_capacity_ - | 878 int buf_len = |
880 tunnel_response_headers_len_; | 879 tunnel_response_headers_capacity_ - tunnel_response_headers_len_; |
881 tunnel_response_headers_->SetDataOffset(tunnel_response_headers_len_); | 880 tunnel_response_headers_->SetDataOffset(tunnel_response_headers_len_); |
882 CHECK(tunnel_response_headers_->data()); | 881 CHECK(tunnel_response_headers_->data()); |
883 | 882 |
884 return connection_->socket()->Read( | 883 return connection_->socket()->Read( |
885 tunnel_response_headers_.get(), buf_len, io_callback_); | 884 tunnel_response_headers_.get(), buf_len, io_callback_); |
886 } | 885 } |
887 | 886 |
888 int SocketStream::DoReadTunnelHeadersComplete(int result) { | 887 int SocketStream::DoReadTunnelHeadersComplete(int result) { |
889 DCHECK_EQ(kTunnelProxy, proxy_mode_); | 888 DCHECK_EQ(kTunnelProxy, proxy_mode_); |
890 | 889 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 if (is_secure()) { | 926 if (is_secure()) { |
928 DCHECK_EQ(eoh, tunnel_response_headers_len_); | 927 DCHECK_EQ(eoh, tunnel_response_headers_len_); |
929 next_state_ = STATE_SSL_CONNECT; | 928 next_state_ = STATE_SSL_CONNECT; |
930 } else { | 929 } else { |
931 result = DidEstablishConnection(); | 930 result = DidEstablishConnection(); |
932 if (result < 0) { | 931 if (result < 0) { |
933 next_state_ = STATE_CLOSE; | 932 next_state_ = STATE_CLOSE; |
934 return result; | 933 return result; |
935 } | 934 } |
936 if ((eoh < tunnel_response_headers_len_) && delegate_) | 935 if ((eoh < tunnel_response_headers_len_) && delegate_) |
937 delegate_->OnReceivedData( | 936 delegate_->OnReceivedData(this, |
938 this, tunnel_response_headers_->headers() + eoh, | 937 tunnel_response_headers_->headers() + eoh, |
939 tunnel_response_headers_len_ - eoh); | 938 tunnel_response_headers_len_ - eoh); |
940 } | 939 } |
941 return OK; | 940 return OK; |
942 case 407: // Proxy Authentication Required. | 941 case 407: // Proxy Authentication Required. |
943 if (proxy_mode_ != kTunnelProxy) | 942 if (proxy_mode_ != kTunnelProxy) |
944 return ERR_UNEXPECTED_PROXY_AUTH; | 943 return ERR_UNEXPECTED_PROXY_AUTH; |
945 | 944 |
946 result = proxy_auth_controller_->HandleAuthChallenge( | 945 result = proxy_auth_controller_->HandleAuthChallenge( |
947 headers, false, true, net_log_); | 946 headers, false, true, net_log_); |
948 if (result != OK) | 947 if (result != OK) |
949 return result; | 948 return result; |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 return OK; | 1330 return OK; |
1332 } | 1331 } |
1333 | 1332 |
1334 if (!delegate_) | 1333 if (!delegate_) |
1335 return result; | 1334 return result; |
1336 | 1335 |
1337 SSLInfo ssl_info; | 1336 SSLInfo ssl_info; |
1338 ssl_socket->GetSSLInfo(&ssl_info); | 1337 ssl_socket->GetSSLInfo(&ssl_info); |
1339 | 1338 |
1340 TransportSecurityState::DomainState domain_state; | 1339 TransportSecurityState::DomainState domain_state; |
1341 const bool fatal = context_->transport_security_state() && | 1340 const bool fatal = |
1342 context_->transport_security_state()->GetDomainState(url_.host(), | 1341 context_->transport_security_state() && |
| 1342 context_->transport_security_state()->GetDomainState( |
| 1343 url_.host(), |
1343 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), | 1344 SSLConfigService::IsSNIAvailable(context_->ssl_config_service()), |
1344 &domain_state) && | 1345 &domain_state) && |
1345 domain_state.ShouldSSLErrorsBeFatal(); | 1346 domain_state.ShouldSSLErrorsBeFatal(); |
1346 | 1347 |
1347 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 1348 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
1348 return ERR_IO_PENDING; | 1349 return ERR_IO_PENDING; |
1349 } | 1350 } |
1350 | 1351 |
1351 CookieStore* SocketStream::cookie_store() const { | 1352 CookieStore* SocketStream::cookie_store() const { |
1352 return cookie_store_; | 1353 return cookie_store_; |
1353 } | 1354 } |
1354 | 1355 |
1355 } // namespace net | 1356 } // namespace net |
OLD | NEW |