| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 13 matching lines...) Expand all Loading... |
| 24 #include "net/http/http_auth_handler_factory.h" | 24 #include "net/http/http_auth_handler_factory.h" |
| 25 #include "net/http/http_request_info.h" | 25 #include "net/http/http_request_info.h" |
| 26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 27 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
| 28 #include "net/socket/client_socket_factory.h" | 28 #include "net/socket/client_socket_factory.h" |
| 29 #include "net/socket/socks5_client_socket.h" | 29 #include "net/socket/socks5_client_socket.h" |
| 30 #include "net/socket/socks_client_socket.h" | 30 #include "net/socket/socks_client_socket.h" |
| 31 #include "net/socket/ssl_client_socket.h" | 31 #include "net/socket/ssl_client_socket.h" |
| 32 #include "net/socket/tcp_client_socket.h" | 32 #include "net/socket/tcp_client_socket.h" |
| 33 #include "net/socket_stream/socket_stream_metrics.h" | 33 #include "net/socket_stream/socket_stream_metrics.h" |
| 34 #include "net/spdy/spdy_session.h" |
| 35 #include "net/spdy/spdy_stream.h" |
| 34 #include "net/url_request/url_request.h" | 36 #include "net/url_request/url_request.h" |
| 35 | 37 |
| 36 static const int kMaxPendingSendAllowed = 32768; // 32 kilobytes. | 38 static const int kMaxPendingSendAllowed = 32768; // 32 kilobytes. |
| 37 static const int kReadBufferSize = 4096; | 39 static const int kReadBufferSize = 4096; |
| 38 | 40 |
| 39 namespace net { | 41 namespace net { |
| 40 | 42 |
| 41 SocketStream::ResponseHeaders::ResponseHeaders() : IOBuffer() {} | 43 SocketStream::ResponseHeaders::ResponseHeaders() : IOBuffer() {} |
| 42 SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; } | 44 SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; } |
| 43 | 45 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 break; | 433 break; |
| 432 case STATE_AUTH_REQUIRED: | 434 case STATE_AUTH_REQUIRED: |
| 433 // It might be called when DoClose is called while waiting in | 435 // It might be called when DoClose is called while waiting in |
| 434 // STATE_AUTH_REQUIRED. | 436 // STATE_AUTH_REQUIRED. |
| 435 Finish(result); | 437 Finish(result); |
| 436 return; | 438 return; |
| 437 case STATE_CLOSE: | 439 case STATE_CLOSE: |
| 438 DCHECK_LE(result, OK); | 440 DCHECK_LE(result, OK); |
| 439 Finish(result); | 441 Finish(result); |
| 440 return; | 442 return; |
| 443 case STATE_SPDY: |
| 444 DCHECK_EQ(result, OK); |
| 445 result = DoSpdy(); |
| 446 break; |
| 441 default: | 447 default: |
| 442 NOTREACHED() << "bad state " << state; | 448 NOTREACHED() << "bad state " << state; |
| 443 Finish(result); | 449 Finish(result); |
| 444 return; | 450 return; |
| 445 } | 451 } |
| 446 // If the connection is not established yet and had actual errors, | 452 // If the connection is not established yet and had actual errors, |
| 447 // close the connection. | 453 // close the connection. |
| 448 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { | 454 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { |
| 449 DCHECK_EQ(next_state_, STATE_CLOSE); | 455 DCHECK_EQ(next_state_, STATE_CLOSE); |
| 450 net_log_.EndEvent( | 456 net_log_.EndEvent( |
| 451 NetLog::TYPE_SOCKET_STREAM_CONNECT, | 457 NetLog::TYPE_SOCKET_STREAM_CONNECT, |
| 452 make_scoped_refptr(new NetLogIntegerParameter("net_error", result))); | 458 make_scoped_refptr(new NetLogIntegerParameter("net_error", result))); |
| 453 } | 459 } |
| 454 } while (result != ERR_IO_PENDING); | 460 } while (result != ERR_IO_PENDING); |
| 455 } | 461 } |
| 456 | 462 |
| 457 int SocketStream::DoResolveProxy() { | 463 int SocketStream::DoResolveProxy() { |
| 458 DCHECK(!pac_request_); | 464 DCHECK(!pac_request_); |
| 459 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | 465 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
| 460 | 466 |
| 461 if (!proxy_url_.is_valid()) { | 467 if (!proxy_url_.is_valid()) { |
| 462 next_state_ = STATE_CLOSE; | 468 next_state_ = STATE_CLOSE; |
| 463 return ERR_INVALID_ARGUMENT; | 469 return ERR_INVALID_ARGUMENT; |
| 464 } | 470 } |
| 465 | 471 |
| 472 // |endpoint_| indicates the final destination endpoint. |
| 473 endpoint_ = HostPortPair(url_.HostNoBrackets(), url_.EffectiveIntPort()); |
| 474 |
| 475 // TODO(ukai): check alternate protocols? |
| 476 |
| 466 return proxy_service()->ResolveProxy( | 477 return proxy_service()->ResolveProxy( |
| 467 proxy_url_, &proxy_info_, &io_callback_, &pac_request_, net_log_); | 478 proxy_url_, &proxy_info_, &io_callback_, &pac_request_, net_log_); |
| 468 } | 479 } |
| 469 | 480 |
| 470 int SocketStream::DoResolveProxyComplete(int result) { | 481 int SocketStream::DoResolveProxyComplete(int result) { |
| 471 pac_request_ = NULL; | 482 pac_request_ = NULL; |
| 472 if (result != OK) { | 483 if (result != OK) { |
| 473 LOG(ERROR) << "Failed to resolve proxy: " << result; | 484 LOG(ERROR) << "Failed to resolve proxy: " << result; |
| 474 if (delegate_) | 485 if (delegate_) |
| 475 delegate_->OnError(this, result); | 486 delegate_->OnError(this, result); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 result = delegate_->OnStartOpenConnection(this, &io_callback_); | 545 result = delegate_->OnStartOpenConnection(this, &io_callback_); |
| 535 if (result == net::ERR_IO_PENDING) | 546 if (result == net::ERR_IO_PENDING) |
| 536 metrics_->OnWaitConnection(); | 547 metrics_->OnWaitConnection(); |
| 537 } else { | 548 } else { |
| 538 next_state_ = STATE_CLOSE; | 549 next_state_ = STATE_CLOSE; |
| 539 } | 550 } |
| 540 // TODO(ukai): if error occured, reconsider proxy after error. | 551 // TODO(ukai): if error occured, reconsider proxy after error. |
| 541 return result; | 552 return result; |
| 542 } | 553 } |
| 543 | 554 |
| 555 const HostPortPair& SocketStream::GetHostPortPair() const { |
| 556 return endpoint_; |
| 557 } |
| 558 |
| 559 const ProxyServer& SocketStream::proxy_server() const { |
| 560 return proxy_info_.proxy_server(); |
| 561 } |
| 562 |
| 563 void SocketStream::SwitchToSpdy() { |
| 564 DCHECK_EQ(STATE_TCP_CONNECT, next_state_); |
| 565 next_state_ = STATE_SPDY; |
| 566 } |
| 567 |
| 568 int SocketStream::DoSpdy() { |
| 569 metrics_->OnConnected(); |
| 570 net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT, NULL); |
| 571 return ERR_IO_PENDING; // Finish DoLoop. |
| 572 } |
| 573 |
| 544 int SocketStream::DoTcpConnect(int result) { | 574 int SocketStream::DoTcpConnect(int result) { |
| 545 if (result != OK) { | 575 if (result != OK) { |
| 546 next_state_ = STATE_CLOSE; | 576 next_state_ = STATE_CLOSE; |
| 547 return result; | 577 return result; |
| 548 } | 578 } |
| 549 next_state_ = STATE_TCP_CONNECT_COMPLETE; | 579 next_state_ = STATE_TCP_CONNECT_COMPLETE; |
| 550 DCHECK(factory_); | 580 DCHECK(factory_); |
| 551 socket_.reset(factory_->CreateTCPClientSocket(addresses_, | 581 socket_.reset(factory_->CreateTCPClientSocket(addresses_, |
| 552 net_log_.net_log(), | 582 net_log_.net_log(), |
| 553 net_log_.source())); | 583 net_log_.source())); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 // SSL info object. | 866 // SSL info object. |
| 837 ssl_config_.allowed_bad_certs.push_back(bad_cert); | 867 ssl_config_.allowed_bad_certs.push_back(bad_cert); |
| 838 // Restart connection ignoring the bad certificate. | 868 // Restart connection ignoring the bad certificate. |
| 839 socket_->Disconnect(); | 869 socket_->Disconnect(); |
| 840 socket_.reset(); | 870 socket_.reset(); |
| 841 next_state_ = STATE_TCP_CONNECT; | 871 next_state_ = STATE_TCP_CONNECT; |
| 842 return OK; | 872 return OK; |
| 843 } | 873 } |
| 844 } | 874 } |
| 845 | 875 |
| 876 // TODO(ukai): upgrade to spdy session if possible. |
| 877 |
| 846 if (result == OK) | 878 if (result == OK) |
| 847 result = DidEstablishConnection(); | 879 result = DidEstablishConnection(); |
| 848 else | 880 else |
| 849 next_state_ = STATE_CLOSE; | 881 next_state_ = STATE_CLOSE; |
| 850 return result; | 882 return result; |
| 851 } | 883 } |
| 852 | 884 |
| 853 int SocketStream::DoReadWrite(int result) { | 885 int SocketStream::DoReadWrite(int result) { |
| 854 if (result < OK) { | 886 if (result < OK) { |
| 855 next_state_ = STATE_CLOSE; | 887 next_state_ = STATE_CLOSE; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1055 |
| 1024 SSLConfigService* SocketStream::ssl_config_service() const { | 1056 SSLConfigService* SocketStream::ssl_config_service() const { |
| 1025 return context_->ssl_config_service(); | 1057 return context_->ssl_config_service(); |
| 1026 } | 1058 } |
| 1027 | 1059 |
| 1028 ProxyService* SocketStream::proxy_service() const { | 1060 ProxyService* SocketStream::proxy_service() const { |
| 1029 return context_->proxy_service(); | 1061 return context_->proxy_service(); |
| 1030 } | 1062 } |
| 1031 | 1063 |
| 1032 } // namespace net | 1064 } // namespace net |
| OLD | NEW |