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/chromium/quic_chromium_client_session.h" | 5 #include "net/quic/chromium/quic_chromium_client_session.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 | 192 |
193 QuicChromiumClientSession::Handle::Handle( | 193 QuicChromiumClientSession::Handle::Handle( |
194 const base::WeakPtr<QuicChromiumClientSession>& session) | 194 const base::WeakPtr<QuicChromiumClientSession>& session) |
195 : MultiplexedSessionHandle(session), | 195 : MultiplexedSessionHandle(session), |
196 session_(session), | 196 session_(session), |
197 net_log_(session_->net_log()), | 197 net_log_(session_->net_log()), |
198 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), | 198 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), |
199 error_(OK), | 199 error_(OK), |
200 port_migration_detected_(false), | 200 port_migration_detected_(false), |
201 server_id_(session_->server_id()), | 201 server_id_(session_->server_id()), |
202 quic_version_(session->connection()->version()) { | 202 quic_version_(session->connection()->version()), |
203 push_handle_(nullptr) { | |
203 DCHECK(session_); | 204 DCHECK(session_); |
204 session_->AddHandle(this); | 205 session_->AddHandle(this); |
205 } | 206 } |
206 | 207 |
207 QuicChromiumClientSession::Handle::~Handle() { | 208 QuicChromiumClientSession::Handle::~Handle() { |
209 if (push_handle_) { | |
210 auto* push_handle = push_handle_; | |
xunjieli
2017/06/22 14:43:30
Is saving |push_handle_| on to the stack still nec
Ryan Hamilton
2017/06/22 20:40:38
So it "should" work, but I'm nervous. As you point
| |
211 push_handle_ = nullptr; | |
212 push_handle->Cancel(); | |
213 } | |
214 | |
208 if (session_) | 215 if (session_) |
209 session_->RemoveHandle(this); | 216 session_->RemoveHandle(this); |
210 } | 217 } |
211 | 218 |
212 void QuicChromiumClientSession::Handle::OnCryptoHandshakeConfirmed() { | 219 void QuicChromiumClientSession::Handle::OnCryptoHandshakeConfirmed() { |
213 was_handshake_confirmed_ = true; | 220 was_handshake_confirmed_ = true; |
214 } | 221 } |
215 | 222 |
216 void QuicChromiumClientSession::Handle::OnSessionClosed( | 223 void QuicChromiumClientSession::Handle::OnSessionClosed( |
217 QuicVersion quic_version, | 224 QuicVersion quic_version, |
218 int error, | 225 int error, |
219 bool port_migration_detected, | 226 bool port_migration_detected, |
220 LoadTimingInfo::ConnectTiming connect_timing) { | 227 LoadTimingInfo::ConnectTiming connect_timing) { |
221 session_ = nullptr; | 228 session_ = nullptr; |
222 port_migration_detected_ = port_migration_detected; | 229 port_migration_detected_ = port_migration_detected; |
223 error_ = error; | 230 error_ = error; |
224 quic_version_ = quic_version; | 231 quic_version_ = quic_version; |
225 connect_timing_ = connect_timing; | 232 connect_timing_ = connect_timing; |
233 push_handle_ = nullptr; | |
226 } | 234 } |
227 | 235 |
228 bool QuicChromiumClientSession::Handle::IsConnected() const { | 236 bool QuicChromiumClientSession::Handle::IsConnected() const { |
229 return session_ != nullptr; | 237 return session_ != nullptr; |
230 } | 238 } |
231 | 239 |
232 bool QuicChromiumClientSession::Handle::IsCryptoHandshakeConfirmed() const { | 240 bool QuicChromiumClientSession::Handle::IsCryptoHandshakeConfirmed() const { |
233 return was_handshake_confirmed_; | 241 return was_handshake_confirmed_; |
234 } | 242 } |
235 | 243 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 | 290 |
283 return base::MakeUnique<QuicConnection::ScopedPacketBundler>( | 291 return base::MakeUnique<QuicConnection::ScopedPacketBundler>( |
284 session_->connection(), bundling_mode); | 292 session_->connection(), bundling_mode); |
285 } | 293 } |
286 | 294 |
287 bool QuicChromiumClientSession::Handle::SharesSameSession( | 295 bool QuicChromiumClientSession::Handle::SharesSameSession( |
288 const Handle& other) const { | 296 const Handle& other) const { |
289 return session_.get() == other.session_.get(); | 297 return session_.get() == other.session_.get(); |
290 } | 298 } |
291 | 299 |
300 int QuicChromiumClientSession::Handle::RendezvousWithPromised( | |
301 const SpdyHeaderBlock& headers, | |
302 const CompletionCallback& callback) { | |
303 if (!session_) | |
304 return ERR_CONNECTION_CLOSED; | |
305 | |
306 QuicAsyncStatus push_status = | |
307 session_->push_promise_index()->Try(headers, this, &push_handle_); | |
308 | |
309 switch (push_status) { | |
310 case QUIC_FAILURE: | |
311 return ERR_FAILED; | |
312 case QUIC_SUCCESS: | |
313 return OK; | |
314 case QUIC_PENDING: | |
315 push_callback_ = callback; | |
316 return ERR_IO_PENDING; | |
317 } | |
318 NOTREACHED(); | |
319 return ERR_UNEXPECTED; | |
320 } | |
321 | |
292 int QuicChromiumClientSession::Handle::RequestStream( | 322 int QuicChromiumClientSession::Handle::RequestStream( |
293 bool requires_confirmation, | 323 bool requires_confirmation, |
294 const CompletionCallback& callback) { | 324 const CompletionCallback& callback) { |
295 DCHECK(!stream_request_); | 325 DCHECK(!stream_request_); |
296 | 326 |
297 if (!session_) | 327 if (!session_) |
298 return ERR_CONNECTION_CLOSED; | 328 return ERR_CONNECTION_CLOSED; |
299 | 329 |
300 // base::MakeUnique does not work because the StreamRequest constructor | 330 // base::MakeUnique does not work because the StreamRequest constructor |
301 // is private. | 331 // is private. |
302 stream_request_ = std::unique_ptr<StreamRequest>( | 332 stream_request_ = std::unique_ptr<StreamRequest>( |
303 new StreamRequest(this, requires_confirmation)); | 333 new StreamRequest(this, requires_confirmation)); |
304 return stream_request_->StartRequest(callback); | 334 return stream_request_->StartRequest(callback); |
305 } | 335 } |
306 | 336 |
307 std::unique_ptr<QuicChromiumClientStream::Handle> | 337 std::unique_ptr<QuicChromiumClientStream::Handle> |
308 QuicChromiumClientSession::Handle::ReleaseStream() { | 338 QuicChromiumClientSession::Handle::ReleaseStream() { |
309 DCHECK(stream_request_); | 339 DCHECK(stream_request_); |
310 | 340 |
311 auto handle = stream_request_->ReleaseStream(); | 341 auto handle = stream_request_->ReleaseStream(); |
312 stream_request_.reset(); | 342 stream_request_.reset(); |
313 return handle; | 343 return handle; |
314 } | 344 } |
315 | 345 |
346 std::unique_ptr<QuicChromiumClientStream::Handle> | |
347 QuicChromiumClientSession::Handle::ReleasePromisedStream() { | |
348 DCHECK(push_stream_); | |
349 return std::move(push_stream_); | |
350 } | |
351 | |
316 int QuicChromiumClientSession::Handle::WaitForHandshakeConfirmation( | 352 int QuicChromiumClientSession::Handle::WaitForHandshakeConfirmation( |
317 const CompletionCallback& callback) { | 353 const CompletionCallback& callback) { |
318 if (!session_) | 354 if (!session_) |
319 return ERR_CONNECTION_CLOSED; | 355 return ERR_CONNECTION_CLOSED; |
320 | 356 |
321 return session_->WaitForHandshakeConfirmation(callback); | 357 return session_->WaitForHandshakeConfirmation(callback); |
322 } | 358 } |
323 | 359 |
324 void QuicChromiumClientSession::Handle::CancelRequest(StreamRequest* request) { | 360 void QuicChromiumClientSession::Handle::CancelRequest(StreamRequest* request) { |
325 if (session_) | 361 if (session_) |
(...skipping 17 matching lines...) Expand all Loading... | |
343 | 379 |
344 int QuicChromiumClientSession::Handle::GetPeerAddress( | 380 int QuicChromiumClientSession::Handle::GetPeerAddress( |
345 IPEndPoint* address) const { | 381 IPEndPoint* address) const { |
346 if (!session_) | 382 if (!session_) |
347 return ERR_CONNECTION_CLOSED; | 383 return ERR_CONNECTION_CLOSED; |
348 | 384 |
349 *address = session_->peer_address().impl().socket_address(); | 385 *address = session_->peer_address().impl().socket_address(); |
350 return OK; | 386 return OK; |
351 } | 387 } |
352 | 388 |
389 bool QuicChromiumClientSession::Handle::CheckVary( | |
390 const SpdyHeaderBlock& client_request, | |
391 const SpdyHeaderBlock& promise_request, | |
392 const SpdyHeaderBlock& promise_response) { | |
393 HttpRequestInfo promise_request_info; | |
394 ConvertHeaderBlockToHttpRequestHeaders(promise_request, | |
395 &promise_request_info.extra_headers); | |
396 HttpRequestInfo client_request_info; | |
397 ConvertHeaderBlockToHttpRequestHeaders(client_request, | |
398 &client_request_info.extra_headers); | |
399 | |
400 HttpResponseInfo promise_response_info; | |
401 if (!SpdyHeadersToHttpResponse(promise_response, &promise_response_info)) { | |
402 DLOG(WARNING) << "Invalid headers"; | |
403 return false; | |
404 } | |
405 | |
406 HttpVaryData vary_data; | |
407 if (!vary_data.Init(promise_request_info, | |
408 *promise_response_info.headers.get())) { | |
409 // Promise didn't contain valid vary info, so URL match was sufficient. | |
410 return true; | |
411 } | |
412 // Now compare the client request for matching. | |
413 return vary_data.MatchesRequest(client_request_info, | |
414 *promise_response_info.headers.get()); | |
415 } | |
416 | |
417 void QuicChromiumClientSession::Handle::OnRendezvousResult( | |
418 QuicSpdyStream* stream) { | |
419 DCHECK(!push_stream_); | |
420 int rv = ERR_FAILED; | |
421 if (stream) { | |
422 rv = OK; | |
423 push_stream_ = | |
424 static_cast<QuicChromiumClientStream*>(stream)->CreateHandle(); | |
425 } | |
426 | |
427 if (push_callback_) { | |
428 DCHECK(push_handle_); | |
429 push_handle_ = nullptr; | |
430 base::ResetAndReturn(&push_callback_).Run(rv); | |
431 } | |
432 } | |
433 | |
353 QuicChromiumClientSession::StreamRequest::StreamRequest( | 434 QuicChromiumClientSession::StreamRequest::StreamRequest( |
354 QuicChromiumClientSession::Handle* session, | 435 QuicChromiumClientSession::Handle* session, |
355 bool requires_confirmation) | 436 bool requires_confirmation) |
356 : session_(session), | 437 : session_(session), |
357 requires_confirmation_(requires_confirmation), | 438 requires_confirmation_(requires_confirmation), |
358 stream_(nullptr), | 439 stream_(nullptr), |
359 weak_factory_(this) {} | 440 weak_factory_(this) {} |
360 | 441 |
361 QuicChromiumClientSession::StreamRequest::~StreamRequest() { | 442 QuicChromiumClientSession::StreamRequest::~StreamRequest() { |
362 if (stream_) | 443 if (stream_) |
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1763 } | 1844 } |
1764 | 1845 |
1765 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { | 1846 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { |
1766 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's | 1847 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's |
1767 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and | 1848 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and |
1768 // unacked packet map. | 1849 // unacked packet map. |
1769 return base::trace_event::EstimateMemoryUsage(packet_readers_); | 1850 return base::trace_event::EstimateMemoryUsage(packet_readers_); |
1770 } | 1851 } |
1771 | 1852 |
1772 } // namespace net | 1853 } // namespace net |
OLD | NEW |