Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: net/quic/quic_client_session.cc

Issue 14718011: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_client_session_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/callback_helpers.h"
7 #include "base/message_loop.h" 8 #include "base/message_loop.h"
8 #include "base/stl_util.h" 9 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
12 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
13 #include "net/quic/quic_connection_helper.h" 14 #include "net/quic/quic_connection_helper.h"
14 #include "net/quic/quic_crypto_client_stream_factory.h" 15 #include "net/quic/quic_crypto_client_stream_factory.h"
15 #include "net/quic/quic_stream_factory.h" 16 #include "net/quic/quic_stream_factory.h"
16 #include "net/udp/datagram_client_socket.h" 17 #include "net/udp/datagram_client_socket.h"
(...skipping 26 matching lines...) Expand all
43 server_hostname, config_, this, crypto_config)); 44 server_hostname, config_, this, crypto_config));
44 45
45 connection->set_debug_visitor(&logger_); 46 connection->set_debug_visitor(&logger_);
46 // TODO(rch): pass in full host port proxy pair 47 // TODO(rch): pass in full host port proxy pair
47 net_log_.BeginEvent( 48 net_log_.BeginEvent(
48 NetLog::TYPE_QUIC_SESSION, 49 NetLog::TYPE_QUIC_SESSION,
49 NetLog::StringCallback("host", &server_hostname)); 50 NetLog::StringCallback("host", &server_hostname));
50 } 51 }
51 52
52 QuicClientSession::~QuicClientSession() { 53 QuicClientSession::~QuicClientSession() {
54 DCHECK(callback_.is_null());
53 connection()->set_debug_visitor(NULL); 55 connection()->set_debug_visitor(NULL);
54 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION); 56 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION);
55 } 57 }
56 58
57 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { 59 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() {
58 if (!crypto_stream_->handshake_complete()) { 60 if (!crypto_stream_->encryption_established()) {
59 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created."; 61 DLOG(INFO) << "Encryption not active so no outgoing stream created.";
60 return NULL; 62 return NULL;
61 } 63 }
62 if (GetNumOpenStreams() >= get_max_open_streams()) { 64 if (GetNumOpenStreams() >= get_max_open_streams()) {
63 DLOG(INFO) << "Failed to create a new outgoing stream. " 65 DLOG(INFO) << "Failed to create a new outgoing stream. "
64 << "Already " << GetNumOpenStreams() << " open."; 66 << "Already " << GetNumOpenStreams() << " open.";
65 return NULL; 67 return NULL;
66 } 68 }
67 if (goaway_received()) { 69 if (goaway_received()) {
68 DLOG(INFO) << "Failed to create a new outgoing stream. " 70 DLOG(INFO) << "Failed to create a new outgoing stream. "
69 << "Already received goaway."; 71 << "Already received goaway.";
(...skipping 10 matching lines...) Expand all
80 return crypto_stream_.get(); 82 return crypto_stream_.get();
81 }; 83 };
82 84
83 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { 85 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) {
84 if (!crypto_stream_->CryptoConnect()) { 86 if (!crypto_stream_->CryptoConnect()) {
85 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a 87 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a
86 // QuicErrorCode and map it to a net error code. 88 // QuicErrorCode and map it to a net error code.
87 return ERR_CONNECTION_FAILED; 89 return ERR_CONNECTION_FAILED;
88 } 90 }
89 91
90 if (IsCryptoHandshakeComplete()) { 92 if (IsEncryptionEstablished()) {
91 return OK; 93 return OK;
92 } 94 }
93 95
94 callback_ = callback; 96 callback_ = callback;
95 return ERR_IO_PENDING; 97 return ERR_IO_PENDING;
96 } 98 }
97 99
98 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream( 100 ReliableQuicStream* QuicClientSession::CreateIncomingReliableStream(
99 QuicStreamId id) { 101 QuicStreamId id) {
100 DLOG(ERROR) << "Server push not supported"; 102 DLOG(ERROR) << "Server push not supported";
101 return NULL; 103 return NULL;
102 } 104 }
103 105
104 void QuicClientSession::CloseStream(QuicStreamId stream_id) { 106 void QuicClientSession::CloseStream(QuicStreamId stream_id) {
105 QuicSession::CloseStream(stream_id); 107 QuicSession::CloseStream(stream_id);
106 108
107 if (GetNumOpenStreams() == 0) { 109 if (GetNumOpenStreams() == 0) {
108 stream_factory_->OnIdleSession(this); 110 stream_factory_->OnIdleSession(this);
109 } 111 }
110 } 112 }
111 113
112 void QuicClientSession::OnCryptoHandshakeComplete(QuicErrorCode error) { 114 void QuicClientSession::OnCryptoHandshakeEvent(CryptoHandshakeEvent event) {
113 if (!callback_.is_null()) { 115 if (!callback_.is_null()) {
114 callback_.Run(error == QUIC_NO_ERROR ? OK : ERR_UNEXPECTED); 116 // TODO(rtenneti): Currently for all CryptoHandshakeEvent events, callback_
117 // could be called because there are no error events in CryptoHandshakeEvent
118 // enum. If error events are added to CryptoHandshakeEvent, then the
119 // following code needs to changed.
120 base::ResetAndReturn(&callback_).Run(OK);
115 } 121 }
116 } 122 }
117 123
124 void QuicClientSession::ConnectionClose(QuicErrorCode error, bool from_peer) {
125 if (!callback_.is_null()) {
126 base::ResetAndReturn(&callback_).Run(error);
127 }
128 QuicSession::ConnectionClose(error, from_peer);
129 }
130
118 void QuicClientSession::StartReading() { 131 void QuicClientSession::StartReading() {
119 if (read_pending_) { 132 if (read_pending_) {
120 return; 133 return;
121 } 134 }
122 read_pending_ = true; 135 read_pending_ = true;
123 int rv = socket_->Read(read_buffer_, read_buffer_->size(), 136 int rv = socket_->Read(read_buffer_, read_buffer_->size(),
124 base::Bind(&QuicClientSession::OnReadComplete, 137 base::Bind(&QuicClientSession::OnReadComplete,
125 weak_factory_.GetWeakPtr())); 138 weak_factory_.GetWeakPtr()));
126 if (rv == ERR_IO_PENDING) { 139 if (rv == ERR_IO_PENDING) {
127 return; 140 return;
128 } 141 }
129 142
130 // Data was read, process it. 143 // Data was read, process it.
131 // Schedule the work through the message loop to avoid recursive 144 // Schedule the work through the message loop to avoid recursive
132 // callbacks. 145 // callbacks.
133 MessageLoop::current()->PostTask( 146 MessageLoop::current()->PostTask(
134 FROM_HERE, 147 FROM_HERE,
135 base::Bind(&QuicClientSession::OnReadComplete, 148 base::Bind(&QuicClientSession::OnReadComplete,
136 weak_factory_.GetWeakPtr(), rv)); 149 weak_factory_.GetWeakPtr(), rv));
137 } 150 }
138 151
139 void QuicClientSession::CloseSessionOnError(int error) { 152 void QuicClientSession::CloseSessionOnError(int error) {
153 if (!callback_.is_null()) {
154 base::ResetAndReturn(&callback_).Run(error);
155 }
140 while (!streams()->empty()) { 156 while (!streams()->empty()) {
141 ReliableQuicStream* stream = streams()->begin()->second; 157 ReliableQuicStream* stream = streams()->begin()->second;
142 QuicStreamId id = stream->id(); 158 QuicStreamId id = stream->id();
143 static_cast<QuicReliableClientStream*>(stream)->OnError(error); 159 static_cast<QuicReliableClientStream*>(stream)->OnError(error);
144 CloseStream(id); 160 CloseStream(id);
145 } 161 }
146 net_log_.BeginEvent( 162 net_log_.BeginEvent(
147 NetLog::TYPE_QUIC_SESSION, 163 NetLog::TYPE_QUIC_SESSION,
148 NetLog::IntegerCallback("net_error", error)); 164 NetLog::IntegerCallback("net_error", error));
149 // Will delete |this|. 165 // Will delete |this|.
(...skipping 26 matching lines...) Expand all
176 connection()->ProcessUdpPacket(local_address, peer_address, packet); 192 connection()->ProcessUdpPacket(local_address, peer_address, packet);
177 if (!connection()->connected()) { 193 if (!connection()->connected()) {
178 stream_factory_->OnSessionClose(this); 194 stream_factory_->OnSessionClose(this);
179 return; 195 return;
180 } 196 }
181 StartReading(); 197 StartReading();
182 } 198 }
183 } 199 }
184 200
185 } // namespace net 201 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_client_session_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698