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 <string> | 10 #include <string> |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 if (prev_context != context) { | 91 if (prev_context != context) { |
92 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); | 92 net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); |
93 net_log_ = BoundNetLog(); | 93 net_log_ = BoundNetLog(); |
94 | 94 |
95 if (context) { | 95 if (context) { |
96 net_log_ = BoundNetLog::Make( | 96 net_log_ = BoundNetLog::Make( |
97 context->net_log(), | 97 context->net_log(), |
98 NetLog::SOURCE_SOCKET_STREAM); | 98 NetLog::SOURCE_SOCKET_STREAM); |
99 | 99 |
100 net_log_.BeginEventWithString(NetLog::TYPE_REQUEST_ALIVE, | 100 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
101 url_.possibly_invalid_spec()); | |
102 } | 101 } |
103 } | 102 } |
104 | 103 |
105 if (context_) { | 104 if (context_) { |
106 host_resolver_ = context_->host_resolver(); | 105 host_resolver_ = context_->host_resolver(); |
107 http_auth_handler_factory_ = context_->http_auth_handler_factory(); | 106 http_auth_handler_factory_ = context_->http_auth_handler_factory(); |
108 } | 107 } |
109 } | 108 } |
110 | 109 |
111 void SocketStream::Connect() { | 110 void SocketStream::Connect() { |
112 DCHECK(MessageLoop::current()) << | 111 DCHECK(MessageLoop::current()) << |
113 "The current MessageLoop must exist"; | 112 "The current MessageLoop must exist"; |
114 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 113 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
115 "The current MessageLoop must be TYPE_IO"; | 114 "The current MessageLoop must be TYPE_IO"; |
116 if (context_) | 115 if (context_) |
117 ssl_config_service()->GetSSLConfig(&ssl_config_); | 116 ssl_config_service()->GetSSLConfig(&ssl_config_); |
118 DCHECK_EQ(next_state_, STATE_NONE); | 117 DCHECK_EQ(next_state_, STATE_NONE); |
119 | 118 |
120 AddRef(); // Released in Finish() | 119 AddRef(); // Released in Finish() |
121 // Open a connection asynchronously, so that delegate won't be called | 120 // Open a connection asynchronously, so that delegate won't be called |
122 // back before returning Connect(). | 121 // back before returning Connect(). |
123 next_state_ = STATE_RESOLVE_PROXY; | 122 next_state_ = STATE_RESOLVE_PROXY; |
124 net_log_.BeginEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT); | 123 net_log_.BeginEventWithString(NetLog::TYPE_SOCKET_STREAM_CONNECT, |
| 124 url_.possibly_invalid_spec()); |
125 MessageLoop::current()->PostTask( | 125 MessageLoop::current()->PostTask( |
126 FROM_HERE, | 126 FROM_HERE, |
127 NewRunnableMethod(this, &SocketStream::DoLoop, OK)); | 127 NewRunnableMethod(this, &SocketStream::DoLoop, OK)); |
128 } | 128 } |
129 | 129 |
130 bool SocketStream::SendData(const char* data, int len) { | 130 bool SocketStream::SendData(const char* data, int len) { |
131 DCHECK(MessageLoop::current()) << | 131 DCHECK(MessageLoop::current()) << |
132 "The current MessageLoop must exist"; | 132 "The current MessageLoop must exist"; |
133 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 133 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
134 "The current MessageLoop must be TYPE_IO"; | 134 "The current MessageLoop must be TYPE_IO"; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return; | 399 return; |
400 default: | 400 default: |
401 NOTREACHED() << "bad state"; | 401 NOTREACHED() << "bad state"; |
402 Finish(result); | 402 Finish(result); |
403 return; | 403 return; |
404 } | 404 } |
405 // If the connection is not established yet and had actual errors, | 405 // If the connection is not established yet and had actual errors, |
406 // close the connection. | 406 // close the connection. |
407 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { | 407 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { |
408 DCHECK_EQ(next_state_, STATE_CLOSE); | 408 DCHECK_EQ(next_state_, STATE_CLOSE); |
409 net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT); | 409 net_log_.EndEventWithInteger(NetLog::TYPE_SOCKET_STREAM_CONNECT, result); |
410 } | 410 } |
411 } while (result != ERR_IO_PENDING); | 411 } while (result != ERR_IO_PENDING); |
412 } | 412 } |
413 | 413 |
414 int SocketStream::DoResolveProxy() { | 414 int SocketStream::DoResolveProxy() { |
415 DCHECK(!pac_request_); | 415 DCHECK(!pac_request_); |
416 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | 416 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
417 | 417 |
418 if (!proxy_url_.is_valid()) { | 418 if (!proxy_url_.is_valid()) { |
419 next_state_ = STATE_CLOSE; | 419 next_state_ = STATE_CLOSE; |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 | 938 |
939 SSLConfigService* SocketStream::ssl_config_service() const { | 939 SSLConfigService* SocketStream::ssl_config_service() const { |
940 return context_->ssl_config_service(); | 940 return context_->ssl_config_service(); |
941 } | 941 } |
942 | 942 |
943 ProxyService* SocketStream::proxy_service() const { | 943 ProxyService* SocketStream::proxy_service() const { |
944 return context_->proxy_service(); | 944 return context_->proxy_service(); |
945 } | 945 } |
946 | 946 |
947 } // namespace net | 947 } // namespace net |
OLD | NEW |