| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 if (context_) | 131 if (context_) |
| 132 ssl_config_service()->GetSSLConfig(&ssl_config_); | 132 ssl_config_service()->GetSSLConfig(&ssl_config_); |
| 133 DCHECK_EQ(next_state_, STATE_NONE); | 133 DCHECK_EQ(next_state_, STATE_NONE); |
| 134 | 134 |
| 135 AddRef(); // Released in Finish() | 135 AddRef(); // Released in Finish() |
| 136 // Open a connection asynchronously, so that delegate won't be called | 136 // Open a connection asynchronously, so that delegate won't be called |
| 137 // back before returning Connect(). | 137 // back before returning Connect(). |
| 138 next_state_ = STATE_RESOLVE_PROXY; | 138 next_state_ = STATE_RESOLVE_PROXY; |
| 139 net_log_.BeginEvent( | 139 net_log_.BeginEvent( |
| 140 NetLog::TYPE_SOCKET_STREAM_CONNECT, | 140 NetLog::TYPE_SOCKET_STREAM_CONNECT, |
| 141 new NetLogStringParameter("url", url_.possibly_invalid_spec())); | 141 make_scoped_refptr( |
| 142 new NetLogStringParameter("url", url_.possibly_invalid_spec()))); |
| 142 MessageLoop::current()->PostTask( | 143 MessageLoop::current()->PostTask( |
| 143 FROM_HERE, | 144 FROM_HERE, |
| 144 NewRunnableMethod(this, &SocketStream::DoLoop, OK)); | 145 NewRunnableMethod(this, &SocketStream::DoLoop, OK)); |
| 145 } | 146 } |
| 146 | 147 |
| 147 bool SocketStream::SendData(const char* data, int len) { | 148 bool SocketStream::SendData(const char* data, int len) { |
| 148 DCHECK(MessageLoop::current()) << | 149 DCHECK(MessageLoop::current()) << |
| 149 "The current MessageLoop must exist"; | 150 "The current MessageLoop must exist"; |
| 150 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 151 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
| 151 "The current MessageLoop must be TYPE_IO"; | 152 "The current MessageLoop must be TYPE_IO"; |
| 152 if (!socket_.get() || !socket_->IsConnected() || next_state_ == STATE_NONE) | 153 if (!socket_.get() || !socket_->IsConnected() || next_state_ == STATE_NONE) |
| 153 return false; | 154 return false; |
| 154 if (write_buf_) { | 155 if (write_buf_) { |
| 155 int current_amount_send = write_buf_size_ - write_buf_offset_; | 156 int current_amount_send = write_buf_size_ - write_buf_offset_; |
| 156 for (PendingDataQueue::const_iterator iter = pending_write_bufs_.begin(); | 157 for (PendingDataQueue::const_iterator iter = pending_write_bufs_.begin(); |
| 157 iter != pending_write_bufs_.end(); | 158 iter != pending_write_bufs_.end(); |
| 158 ++iter) | 159 ++iter) |
| 159 current_amount_send += (*iter)->size(); | 160 current_amount_send += (*iter)->size(); |
| 160 | 161 |
| 161 current_amount_send += len; | 162 current_amount_send += len; |
| 162 if (current_amount_send > max_pending_send_allowed_) | 163 if (current_amount_send > max_pending_send_allowed_) |
| 163 return false; | 164 return false; |
| 164 | 165 |
| 165 pending_write_bufs_.push_back(new IOBufferWithSize(len)); | 166 pending_write_bufs_.push_back(make_scoped_refptr( |
| 167 new IOBufferWithSize(len))); |
| 166 memcpy(pending_write_bufs_.back()->data(), data, len); | 168 memcpy(pending_write_bufs_.back()->data(), data, len); |
| 167 return true; | 169 return true; |
| 168 } | 170 } |
| 169 DCHECK(!current_write_buf_); | 171 DCHECK(!current_write_buf_); |
| 170 write_buf_ = new IOBuffer(len); | 172 write_buf_ = new IOBuffer(len); |
| 171 memcpy(write_buf_->data(), data, len); | 173 memcpy(write_buf_->data(), data, len); |
| 172 write_buf_size_ = len; | 174 write_buf_size_ = len; |
| 173 write_buf_offset_ = 0; | 175 write_buf_offset_ = 0; |
| 174 // Send pending data asynchronously, so that delegate won't be called | 176 // Send pending data asynchronously, so that delegate won't be called |
| 175 // back before returning SendData(). | 177 // back before returning SendData(). |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 return; | 440 return; |
| 439 default: | 441 default: |
| 440 NOTREACHED() << "bad state " << state; | 442 NOTREACHED() << "bad state " << state; |
| 441 Finish(result); | 443 Finish(result); |
| 442 return; | 444 return; |
| 443 } | 445 } |
| 444 // If the connection is not established yet and had actual errors, | 446 // If the connection is not established yet and had actual errors, |
| 445 // close the connection. | 447 // close the connection. |
| 446 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { | 448 if (state != STATE_READ_WRITE && result < ERR_IO_PENDING) { |
| 447 DCHECK_EQ(next_state_, STATE_CLOSE); | 449 DCHECK_EQ(next_state_, STATE_CLOSE); |
| 448 net_log_.EndEvent(NetLog::TYPE_SOCKET_STREAM_CONNECT, | 450 net_log_.EndEvent( |
| 449 new NetLogIntegerParameter("net_error", result)); | 451 NetLog::TYPE_SOCKET_STREAM_CONNECT, |
| 452 make_scoped_refptr(new NetLogIntegerParameter("net_error", result))); |
| 450 } | 453 } |
| 451 } while (result != ERR_IO_PENDING); | 454 } while (result != ERR_IO_PENDING); |
| 452 } | 455 } |
| 453 | 456 |
| 454 int SocketStream::DoResolveProxy() { | 457 int SocketStream::DoResolveProxy() { |
| 455 DCHECK(!pac_request_); | 458 DCHECK(!pac_request_); |
| 456 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; | 459 next_state_ = STATE_RESOLVE_PROXY_COMPLETE; |
| 457 | 460 |
| 458 if (!proxy_url_.is_valid()) { | 461 if (!proxy_url_.is_valid()) { |
| 459 next_state_ = STATE_CLOSE; | 462 next_state_ = STATE_CLOSE; |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 | 1022 |
| 1020 SSLConfigService* SocketStream::ssl_config_service() const { | 1023 SSLConfigService* SocketStream::ssl_config_service() const { |
| 1021 return context_->ssl_config_service(); | 1024 return context_->ssl_config_service(); |
| 1022 } | 1025 } |
| 1023 | 1026 |
| 1024 ProxyService* SocketStream::proxy_service() const { | 1027 ProxyService* SocketStream::proxy_service() const { |
| 1025 return context_->proxy_service(); | 1028 return context_->proxy_service(); |
| 1026 } | 1029 } |
| 1027 | 1030 |
| 1028 } // namespace net | 1031 } // namespace net |
| OLD | NEW |