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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 : delegate_(delegate), | 56 : delegate_(delegate), |
57 url_(url), | 57 url_(url), |
58 max_pending_send_allowed_(kMaxPendingSendAllowed), | 58 max_pending_send_allowed_(kMaxPendingSendAllowed), |
59 context_(NULL), | 59 context_(NULL), |
60 next_state_(STATE_NONE), | 60 next_state_(STATE_NONE), |
61 host_resolver_(NULL), | 61 host_resolver_(NULL), |
62 cert_verifier_(NULL), | 62 cert_verifier_(NULL), |
63 server_bound_cert_service_(NULL), | 63 server_bound_cert_service_(NULL), |
64 http_auth_handler_factory_(NULL), | 64 http_auth_handler_factory_(NULL), |
65 factory_(ClientSocketFactory::GetDefaultFactory()), | 65 factory_(ClientSocketFactory::GetDefaultFactory()), |
| 66 ALLOW_THIS_IN_INITIALIZER_LIST(before_connect_callback_( |
| 67 base::Bind(&SocketStream::BeforeConnectComplete, |
| 68 base::Unretained(this)))), |
66 proxy_mode_(kDirectConnection), | 69 proxy_mode_(kDirectConnection), |
67 proxy_url_(url), | 70 proxy_url_(url), |
68 pac_request_(NULL), | 71 pac_request_(NULL), |
69 // Unretained() is required; without it, Bind() creates a circular | 72 // Unretained() is required; without it, Bind() creates a circular |
70 // dependency and the SocketStream object will not be freed. | 73 // dependency and the SocketStream object will not be freed. |
71 ALLOW_THIS_IN_INITIALIZER_LIST( | 74 ALLOW_THIS_IN_INITIALIZER_LIST( |
72 io_callback_(base::Bind(&SocketStream::OnIOCompleted, | 75 io_callback_(base::Bind(&SocketStream::OnIOCompleted, |
73 base::Unretained(this)))), | 76 base::Unretained(this)))), |
74 read_buf_(NULL), | 77 read_buf_(NULL), |
75 write_buf_(NULL), | 78 write_buf_(NULL), |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 "The current MessageLoop must be TYPE_IO"; | 143 "The current MessageLoop must be TYPE_IO"; |
141 if (context_) { | 144 if (context_) { |
142 ssl_config_service()->GetSSLConfig(&server_ssl_config_); | 145 ssl_config_service()->GetSSLConfig(&server_ssl_config_); |
143 proxy_ssl_config_ = server_ssl_config_; | 146 proxy_ssl_config_ = server_ssl_config_; |
144 } | 147 } |
145 DCHECK_EQ(next_state_, STATE_NONE); | 148 DCHECK_EQ(next_state_, STATE_NONE); |
146 | 149 |
147 AddRef(); // Released in Finish() | 150 AddRef(); // Released in Finish() |
148 // Open a connection asynchronously, so that delegate won't be called | 151 // Open a connection asynchronously, so that delegate won't be called |
149 // back before returning Connect(). | 152 // back before returning Connect(). |
150 next_state_ = STATE_RESOLVE_PROXY; | 153 next_state_ = STATE_BEFORE_CONNECT; |
151 net_log_.BeginEvent( | 154 net_log_.BeginEvent( |
152 NetLog::TYPE_SOCKET_STREAM_CONNECT, | 155 NetLog::TYPE_SOCKET_STREAM_CONNECT, |
153 make_scoped_refptr( | 156 make_scoped_refptr( |
154 new NetLogStringParameter("url", url_.possibly_invalid_spec()))); | 157 new NetLogStringParameter("url", url_.possibly_invalid_spec()))); |
155 MessageLoop::current()->PostTask( | 158 MessageLoop::current()->PostTask( |
156 FROM_HERE, | 159 FROM_HERE, |
157 base::Bind(&SocketStream::DoLoop, this, OK)); | 160 base::Bind(&SocketStream::DoLoop, this, OK)); |
158 } | 161 } |
159 | 162 |
160 bool SocketStream::SendData(const char* data, int len) { | 163 bool SocketStream::SendData(const char* data, int len) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (!context_) | 406 if (!context_) |
404 next_state_ = STATE_CLOSE; | 407 next_state_ = STATE_CLOSE; |
405 | 408 |
406 if (next_state_ == STATE_NONE) | 409 if (next_state_ == STATE_NONE) |
407 return; | 410 return; |
408 | 411 |
409 do { | 412 do { |
410 State state = next_state_; | 413 State state = next_state_; |
411 next_state_ = STATE_NONE; | 414 next_state_ = STATE_NONE; |
412 switch (state) { | 415 switch (state) { |
| 416 case STATE_BEFORE_CONNECT: |
| 417 DCHECK_EQ(OK, result); |
| 418 result = DoBeforeConnect(); |
| 419 break; |
413 case STATE_RESOLVE_PROXY: | 420 case STATE_RESOLVE_PROXY: |
414 DCHECK_EQ(OK, result); | 421 DCHECK_EQ(OK, result); |
415 result = DoResolveProxy(); | 422 result = DoResolveProxy(); |
416 break; | 423 break; |
417 case STATE_RESOLVE_PROXY_COMPLETE: | 424 case STATE_RESOLVE_PROXY_COMPLETE: |
418 result = DoResolveProxyComplete(result); | 425 result = DoResolveProxyComplete(result); |
419 break; | 426 break; |
420 case STATE_RESOLVE_HOST: | 427 case STATE_RESOLVE_HOST: |
421 DCHECK_EQ(OK, result); | 428 DCHECK_EQ(OK, result); |
422 result = DoResolveHost(); | 429 result = DoResolveHost(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 continue; | 511 continue; |
505 // If the connection is not established yet and had actual errors, | 512 // If the connection is not established yet and had actual errors, |
506 // record the error. In next iteration, it will close the connection. | 513 // record the error. In next iteration, it will close the connection. |
507 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { | 514 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { |
508 net_log_.EndEventWithNetErrorCode( | 515 net_log_.EndEventWithNetErrorCode( |
509 NetLog::TYPE_SOCKET_STREAM_CONNECT, result); | 516 NetLog::TYPE_SOCKET_STREAM_CONNECT, result); |
510 } | 517 } |
511 } while (result != ERR_IO_PENDING); | 518 } while (result != ERR_IO_PENDING); |
512 } | 519 } |
513 | 520 |
| 521 int SocketStream::DoBeforeConnect() { |
| 522 next_state_ = STATE_RESOLVE_PROXY; |
| 523 if (!context_ || !context_->network_delegate()) |
| 524 return OK; |
| 525 |
| 526 int result = context_->network_delegate()->NotifyBeforeSocketStreamConnect( |
| 527 this, before_connect_callback_); |
| 528 if (result != OK && result != ERR_IO_PENDING) |
| 529 next_state_ = STATE_CLOSE; |
| 530 |
| 531 return result; |
| 532 } |
| 533 |
514 int SocketStream::DoResolveProxy() { | 534 int SocketStream::DoResolveProxy() { |
515 DCHECK(!pac_request_); | 535 DCHECK(!pac_request_); |
516 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | 536 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
517 | 537 |
518 if (!proxy_url_.is_valid()) { | 538 if (!proxy_url_.is_valid()) { |
519 next_state_ = STATE_CLOSE; | 539 next_state_ = STATE_CLOSE; |
520 return ERR_INVALID_ARGUMENT; | 540 return ERR_INVALID_ARGUMENT; |
521 } | 541 } |
522 | 542 |
523 // TODO(toyoshim): Check server advertisement of SPDY through the HTTP | 543 // TODO(toyoshim): Check server advertisement of SPDY through the HTTP |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 next_state_ = STATE_CLOSE; | 1085 next_state_ = STATE_CLOSE; |
1066 return result; | 1086 return result; |
1067 } | 1087 } |
1068 return result; | 1088 return result; |
1069 } | 1089 } |
1070 | 1090 |
1071 // We arrived here when both operation is pending. | 1091 // We arrived here when both operation is pending. |
1072 return ERR_IO_PENDING; | 1092 return ERR_IO_PENDING; |
1073 } | 1093 } |
1074 | 1094 |
| 1095 void SocketStream::BeforeConnectComplete(int result) { |
| 1096 DCHECK_NE(ERR_IO_PENDING, result); |
| 1097 |
| 1098 if (result == OK) |
| 1099 next_state_ = STATE_RESOLVE_PROXY; |
| 1100 else |
| 1101 next_state_ = STATE_CLOSE; |
| 1102 DoLoop(result); |
| 1103 } |
| 1104 |
1075 GURL SocketStream::ProxyAuthOrigin() const { | 1105 GURL SocketStream::ProxyAuthOrigin() const { |
1076 DCHECK(!proxy_info_.is_empty()); | 1106 DCHECK(!proxy_info_.is_empty()); |
1077 return GURL("http://" + | 1107 return GURL("http://" + |
1078 proxy_info_.proxy_server().host_port_pair().ToString()); | 1108 proxy_info_.proxy_server().host_port_pair().ToString()); |
1079 } | 1109 } |
1080 | 1110 |
1081 int SocketStream::HandleAuthChallenge(const HttpResponseHeaders* headers) { | 1111 int SocketStream::HandleAuthChallenge(const HttpResponseHeaders* headers) { |
1082 GURL auth_origin(ProxyAuthOrigin()); | 1112 GURL auth_origin(ProxyAuthOrigin()); |
1083 | 1113 |
1084 VLOG(1) << "The proxy " << auth_origin << " requested auth"; | 1114 VLOG(1) << "The proxy " << auth_origin << " requested auth"; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 | 1290 |
1261 SSLConfigService* SocketStream::ssl_config_service() const { | 1291 SSLConfigService* SocketStream::ssl_config_service() const { |
1262 return context_->ssl_config_service(); | 1292 return context_->ssl_config_service(); |
1263 } | 1293 } |
1264 | 1294 |
1265 ProxyService* SocketStream::proxy_service() const { | 1295 ProxyService* SocketStream::proxy_service() const { |
1266 return context_->proxy_service(); | 1296 return context_->proxy_service(); |
1267 } | 1297 } |
1268 | 1298 |
1269 } // namespace net | 1299 } // namespace net |
OLD | NEW |