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 #include "net/quic/quic_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/quic/quic_connection_helper.h" | 13 #include "net/quic/quic_connection_helper.h" |
14 #include "net/quic/quic_stream_factory.h" | 14 #include "net/quic/quic_stream_factory.h" |
15 #include "net/udp/datagram_client_socket.h" | 15 #include "net/udp/datagram_client_socket.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 QuicClientSession::QuicClientSession(QuicConnection* connection, | 19 QuicClientSession::QuicClientSession(QuicConnection* connection, |
20 QuicConnectionHelper* helper, | 20 DatagramClientSocket* socket, |
21 QuicStreamFactory* stream_factory, | 21 QuicStreamFactory* stream_factory, |
22 const string& server_hostname, | 22 const string& server_hostname, |
23 NetLog* net_log) | 23 NetLog* net_log) |
24 : QuicSession(connection, false), | 24 : QuicSession(connection, false), |
25 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 25 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
26 ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this, server_hostname)), | 26 ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this, server_hostname)), |
27 helper_(helper), | |
28 stream_factory_(stream_factory), | 27 stream_factory_(stream_factory), |
| 28 socket_(socket), |
29 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), | 29 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), |
30 read_pending_(false), | 30 read_pending_(false), |
31 num_total_streams_(0), | 31 num_total_streams_(0), |
32 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 32 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), |
33 logger_(net_log_) { | 33 logger_(net_log_) { |
34 connection->set_debug_visitor(&logger_); | 34 connection->set_debug_visitor(&logger_); |
35 // TODO(rch): pass in full host port proxy pair | 35 // TODO(rch): pass in full host port proxy pair |
36 net_log_.BeginEvent( | 36 net_log_.BeginEvent( |
37 NetLog::TYPE_QUIC_SESSION, | 37 NetLog::TYPE_QUIC_SESSION, |
38 NetLog::StringCallback("host", &server_hostname)); | 38 NetLog::StringCallback("host", &server_hostname)); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 if (!callback_.is_null()) { | 102 if (!callback_.is_null()) { |
103 callback_.Run(error == QUIC_NO_ERROR ? OK : ERR_UNEXPECTED); | 103 callback_.Run(error == QUIC_NO_ERROR ? OK : ERR_UNEXPECTED); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void QuicClientSession::StartReading() { | 107 void QuicClientSession::StartReading() { |
108 if (read_pending_) { | 108 if (read_pending_) { |
109 return; | 109 return; |
110 } | 110 } |
111 read_pending_ = true; | 111 read_pending_ = true; |
112 int rv = helper_->Read(read_buffer_, read_buffer_->size(), | 112 int rv = socket_->Read(read_buffer_, read_buffer_->size(), |
113 base::Bind(&QuicClientSession::OnReadComplete, | 113 base::Bind(&QuicClientSession::OnReadComplete, |
114 weak_factory_.GetWeakPtr())); | 114 weak_factory_.GetWeakPtr())); |
115 if (rv == ERR_IO_PENDING) { | 115 if (rv == ERR_IO_PENDING) { |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 // Data was read, process it. | 119 // Data was read, process it. |
120 // Schedule the work through the message loop to avoid recursive | 120 // Schedule the work through the message loop to avoid recursive |
121 // callbacks. | 121 // callbacks. |
122 MessageLoop::current()->PostTask( | 122 MessageLoop::current()->PostTask( |
(...skipping 28 matching lines...) Expand all Loading... |
151 | 151 |
152 void QuicClientSession::OnReadComplete(int result) { | 152 void QuicClientSession::OnReadComplete(int result) { |
153 read_pending_ = false; | 153 read_pending_ = false; |
154 // TODO(rch): Inform the connection about the result. | 154 // TODO(rch): Inform the connection about the result. |
155 if (result > 0) { | 155 if (result > 0) { |
156 scoped_refptr<IOBufferWithSize> buffer(read_buffer_); | 156 scoped_refptr<IOBufferWithSize> buffer(read_buffer_); |
157 read_buffer_ = new IOBufferWithSize(kMaxPacketSize); | 157 read_buffer_ = new IOBufferWithSize(kMaxPacketSize); |
158 QuicEncryptedPacket packet(buffer->data(), result); | 158 QuicEncryptedPacket packet(buffer->data(), result); |
159 IPEndPoint local_address; | 159 IPEndPoint local_address; |
160 IPEndPoint peer_address; | 160 IPEndPoint peer_address; |
161 helper_->GetLocalAddress(&local_address); | 161 socket_->GetLocalAddress(&local_address); |
162 helper_->GetPeerAddress(&peer_address); | 162 socket_->GetPeerAddress(&peer_address); |
163 // ProcessUdpPacket might result in |this| being deleted, so we | 163 // ProcessUdpPacket might result in |this| being deleted, so we |
164 // use a weak pointer to be safe. | 164 // use a weak pointer to be safe. |
165 connection()->ProcessUdpPacket(local_address, peer_address, packet); | 165 connection()->ProcessUdpPacket(local_address, peer_address, packet); |
166 if (!connection()->connected()) { | 166 if (!connection()->connected()) { |
167 stream_factory_->OnSessionClose(this); | 167 stream_factory_->OnSessionClose(this); |
168 return; | 168 return; |
169 } | 169 } |
170 StartReading(); | 170 StartReading(); |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 } // namespace net | 174 } // namespace net |
OLD | NEW |