Chromium Code Reviews| 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_; | |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 if (!session_) | 305 if (!session_) |
| 298 return ERR_CONNECTION_CLOSED; | 306 return ERR_CONNECTION_CLOSED; |
| 299 | 307 |
| 300 // base::MakeUnique does not work because the StreamRequest constructor | 308 // base::MakeUnique does not work because the StreamRequest constructor |
| 301 // is private. | 309 // is private. |
| 302 stream_request_ = std::unique_ptr<StreamRequest>( | 310 stream_request_ = std::unique_ptr<StreamRequest>( |
| 303 new StreamRequest(this, requires_confirmation)); | 311 new StreamRequest(this, requires_confirmation)); |
| 304 return stream_request_->StartRequest(callback); | 312 return stream_request_->StartRequest(callback); |
| 305 } | 313 } |
| 306 | 314 |
| 315 int QuicChromiumClientSession::Handle::RendezvousWithPromised( | |
| 316 const SpdyHeaderBlock& headers, | |
| 317 const CompletionCallback& callback) { | |
| 318 if (!session_) | |
| 319 return ERR_CONNECTION_CLOSED; | |
| 320 | |
| 321 QuicAsyncStatus push_status = | |
| 322 session_->push_promise_index()->Try(headers, this, &push_handle_); | |
| 323 | |
| 324 switch (push_status) { | |
| 325 case QUIC_FAILURE: | |
| 326 return ERR_FAILED; | |
| 327 case QUIC_SUCCESS: | |
| 328 return OK; | |
| 329 case QUIC_PENDING: | |
| 330 push_callback_ = callback; | |
| 331 return ERR_IO_PENDING; | |
| 332 } | |
| 333 NOTREACHED(); | |
| 334 return ERR_UNEXPECTED; | |
| 335 } | |
| 336 | |
| 337 bool QuicChromiumClientSession::Handle::CheckVary( | |
| 338 const SpdyHeaderBlock& client_request, | |
| 339 const SpdyHeaderBlock& promise_request, | |
| 340 const SpdyHeaderBlock& promise_response) { | |
| 341 HttpResponseInfo promise_response_info; | |
|
xunjieli
2017/06/21 20:55:28
optional nit: Move this closer to where it's neede
Ryan Hamilton
2017/06/21 22:24:50
Done.
| |
| 342 | |
| 343 HttpRequestInfo promise_request_info; | |
| 344 ConvertHeaderBlockToHttpRequestHeaders(promise_request, | |
| 345 &promise_request_info.extra_headers); | |
| 346 HttpRequestInfo client_request_info; | |
| 347 ConvertHeaderBlockToHttpRequestHeaders(client_request, | |
| 348 &client_request_info.extra_headers); | |
| 349 | |
| 350 if (!SpdyHeadersToHttpResponse(promise_response, &promise_response_info)) { | |
| 351 DLOG(WARNING) << "Invalid headers"; | |
| 352 return false; | |
| 353 } | |
| 354 | |
| 355 HttpVaryData vary_data; | |
| 356 if (!vary_data.Init(promise_request_info, | |
| 357 *promise_response_info.headers.get())) { | |
| 358 // Promise didn't contain valid vary info, so URL match was sufficient. | |
| 359 return true; | |
| 360 } | |
| 361 // Now compare the client request for matching. | |
| 362 return vary_data.MatchesRequest(client_request_info, | |
| 363 *promise_response_info.headers.get()); | |
| 364 } | |
| 365 | |
| 366 void QuicChromiumClientSession::Handle::OnRendezvousResult( | |
|
xunjieli
2017/06/21 20:55:28
nit: these four new methods should in the same ord
Ryan Hamilton
2017/06/21 22:24:51
Done.
| |
| 367 QuicSpdyStream* stream) { | |
| 368 DCHECK(!push_stream_); | |
| 369 int rv = ERR_FAILED; | |
| 370 if (stream) { | |
| 371 rv = OK; | |
| 372 push_stream_ = | |
| 373 static_cast<QuicChromiumClientStream*>(stream)->CreateHandle(); | |
| 374 } | |
| 375 | |
| 376 if (push_callback_) { | |
| 377 DCHECK(push_handle_); | |
| 378 push_handle_ = nullptr; | |
| 379 base::ResetAndReturn(&push_callback_).Run(rv); | |
| 380 } | |
| 381 } | |
| 382 | |
| 383 std::unique_ptr<QuicChromiumClientStream::Handle> | |
| 384 QuicChromiumClientSession::Handle::ReleasePromisedStream() { | |
|
xunjieli
2017/06/21 20:55:28
nit: Add a DCHECK(push_stream_) to make sure that
Ryan Hamilton
2017/06/21 22:24:50
Done.
| |
| 385 return std::move(push_stream_); | |
| 386 } | |
| 387 | |
| 307 std::unique_ptr<QuicChromiumClientStream::Handle> | 388 std::unique_ptr<QuicChromiumClientStream::Handle> |
| 308 QuicChromiumClientSession::Handle::ReleaseStream() { | 389 QuicChromiumClientSession::Handle::ReleaseStream() { |
| 309 DCHECK(stream_request_); | 390 DCHECK(stream_request_); |
| 310 | 391 |
| 311 auto handle = stream_request_->ReleaseStream(); | 392 auto handle = stream_request_->ReleaseStream(); |
| 312 stream_request_.reset(); | 393 stream_request_.reset(); |
| 313 return handle; | 394 return handle; |
| 314 } | 395 } |
| 315 | 396 |
| 316 int QuicChromiumClientSession::Handle::WaitForHandshakeConfirmation( | 397 int QuicChromiumClientSession::Handle::WaitForHandshakeConfirmation( |
| (...skipping 1446 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 |