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 // A client specific QuicSession subclass. This class owns the underlying | 5 // A client specific QuicSession subclass. This class owns the underlying |
| 6 // QuicConnection and QuicConnectionHelper objects. The connection stores | 6 // QuicConnection and QuicConnectionHelper objects. The connection stores |
| 7 // a non-owning pointer to the helper so this session needs to ensure that | 7 // a non-owning pointer to the helper so this session needs to ensure that |
| 8 // the helper outlives the connection. | 8 // the helper outlives the connection. |
| 9 | 9 |
| 10 #ifndef NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ | 10 #ifndef NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 // ERR_IO_PENDING is returned, then when the request is eventuallly | 87 // ERR_IO_PENDING is returned, then when the request is eventuallly |
| 88 // complete |callback| will be called. | 88 // complete |callback| will be called. |
| 89 int StartRequest(const CompletionCallback& callback); | 89 int StartRequest(const CompletionCallback& callback); |
| 90 | 90 |
| 91 // Releases |stream_| to the caller | 91 // Releases |stream_| to the caller |
| 92 QuicChromiumClientStream* ReleaseStream(); | 92 QuicChromiumClientStream* ReleaseStream(); |
| 93 | 93 |
| 94 private: | 94 private: |
| 95 friend class QuicChromiumClientSession; | 95 friend class QuicChromiumClientSession; |
| 96 | 96 |
| 97 StreamRequest(const base::WeakPtr<QuicChromiumClientSession>& session); | 97 enum State { |
| 98 STATE_NONE, | |
| 99 STATE_WAIT_FOR_CONFIRMATION, | |
| 100 STATE_WAIT_FOR_CONFIRMATION_COMPLETE, | |
| 101 STATE_REQUEST_STREAM, | |
| 102 STATE_REQUEST_STREAM_COMPLETE, | |
| 103 }; | |
| 104 | |
| 105 StreamRequest(const base::WeakPtr<QuicChromiumClientSession>& session, | |
| 106 bool requires_confirmation); | |
| 107 | |
| 108 void OnIOComplete(int rv); | |
| 109 void DoCallback(int rv); | |
| 110 | |
| 111 int DoLoop(int rv); | |
| 112 int DoWaitForConfirmation(); | |
| 113 int DoWaitForConfirmationComplete(int rv); | |
| 114 int DoRequestStream(); | |
| 115 int DoRequestStreamComplete(int rv); | |
| 98 | 116 |
| 99 // Called by |session_| for an asynchronous request when the stream | 117 // Called by |session_| for an asynchronous request when the stream |
| 100 // request has finished successfully. | 118 // request has finished successfully. |
| 101 void OnRequestCompleteSuccess(QuicChromiumClientStream* stream); | 119 void OnRequestCompleteSuccess(QuicChromiumClientStream* stream); |
| 102 | 120 |
| 103 // Called by |session_| for an asynchronous request when the stream | 121 // Called by |session_| for an asynchronous request when the stream |
| 104 // request has finished with an error. Also called with ERR_ABORTED | 122 // request has finished with an error. Also called with ERR_ABORTED |
| 105 // if |session_| is destroyed while the stream request is still pending. | 123 // if |session_| is destroyed while the stream request is still pending. |
| 106 void OnRequestCompleteFailure(int rv); | 124 void OnRequestCompleteFailure(int rv); |
| 107 | 125 |
| 108 base::WeakPtr<QuicChromiumClientSession> session_; | 126 base::WeakPtr<QuicChromiumClientSession> session_; |
| 127 bool requires_confirmation_; | |
|
xunjieli
2017/05/01 20:15:06
nit: add a const so we know this variable is not c
Ryan Hamilton
2017/05/01 21:42:35
Done.
| |
| 109 CompletionCallback callback_; | 128 CompletionCallback callback_; |
| 110 QuicChromiumClientStream* stream_; | 129 QuicChromiumClientStream* stream_; |
| 111 // For tracking how much time pending stream requests wait. | 130 // For tracking how much time pending stream requests wait. |
| 112 base::TimeTicks pending_start_time_; | 131 base::TimeTicks pending_start_time_; |
| 132 State next_state_; | |
| 133 | |
| 134 base::WeakPtrFactory<StreamRequest> weak_factory_; | |
| 113 | 135 |
| 114 DISALLOW_COPY_AND_ASSIGN(StreamRequest); | 136 DISALLOW_COPY_AND_ASSIGN(StreamRequest); |
| 115 }; | 137 }; |
| 116 | 138 |
| 117 // Constructs a new session which will own |connection|, but not | 139 // Constructs a new session which will own |connection|, but not |
| 118 // |stream_factory|, which must outlive this session. | 140 // |stream_factory|, which must outlive this session. |
| 119 // TODO(rch): decouple the factory from the session via a Delegate interface. | 141 // TODO(rch): decouple the factory from the session via a Delegate interface. |
| 120 QuicChromiumClientSession( | 142 QuicChromiumClientSession( |
| 121 QuicConnection* connection, | 143 QuicConnection* connection, |
| 122 std::unique_ptr<DatagramClientSocket> socket, | 144 std::unique_ptr<DatagramClientSocket> socket, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 140 base::TaskRunner* task_runner, | 162 base::TaskRunner* task_runner, |
| 141 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 163 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
| 142 NetLog* net_log); | 164 NetLog* net_log); |
| 143 ~QuicChromiumClientSession() override; | 165 ~QuicChromiumClientSession() override; |
| 144 | 166 |
| 145 void Initialize() override; | 167 void Initialize() override; |
| 146 | 168 |
| 147 void AddObserver(Observer* observer); | 169 void AddObserver(Observer* observer); |
| 148 void RemoveObserver(Observer* observer); | 170 void RemoveObserver(Observer* observer); |
| 149 | 171 |
| 150 std::unique_ptr<StreamRequest> CreateStreamRequest(); | 172 // Waits for the handshake to be confirmed and invokes |callback| when |
| 173 // that happens. If the handshake has already been confirmed, returns OK. | |
| 174 // If the connection has already been closed, returns a net error. If the | |
| 175 // connection closes before the handshake is confirmed, |callback| will | |
| 176 // be invoked with an error. | |
| 177 int WaitForHandshakeConfirmation(const CompletionCallback& callback); | |
| 178 | |
| 179 // Returns an new stream request which can be used to create a new | |
|
xunjieli
2017/05/01 20:15:06
nit: s/an/a
Ryan Hamilton
2017/05/01 21:42:35
Done.
| |
| 180 // QUIC stream. If |requires_confirmation| is true, then the requested | |
| 181 // stream will no be created until the handshake as been confirmed. | |
|
xunjieli
2017/05/01 20:15:06
nit:
s/will no/will not
s/as/has
Ryan Hamilton
2017/05/01 21:42:35
Done.
| |
| 182 std::unique_ptr<StreamRequest> CreateStreamRequest( | |
| 183 bool requires_confirmation); | |
| 151 | 184 |
| 152 // Attempts to create a new stream. If the stream can be | 185 // Attempts to create a new stream. If the stream can be |
| 153 // created immediately, returns OK. If the open stream limit | 186 // created immediately, returns OK. If the open stream limit |
| 154 // has been reached, returns ERR_IO_PENDING, and |request| | 187 // has been reached, returns ERR_IO_PENDING, and |request| |
| 155 // will be added to the stream requets queue and will | 188 // will be added to the stream requets queue and will |
| 156 // be completed asynchronously. | 189 // be completed asynchronously. |
| 157 // TODO(rch): remove |stream| from this and use setter on |request| | 190 // TODO(rch): remove |stream| from this and use setter on |request| |
| 158 // and fix in spdy too. | 191 // and fix in spdy too. |
| 159 int TryCreateStream(StreamRequest* request); | 192 int TryCreateStream(StreamRequest* request); |
| 160 | 193 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 // closed, perhaps due to a timeout or a protocol error. | 378 // closed, perhaps due to a timeout or a protocol error. |
| 346 // CloseSessionOnError - called from the owner of the session, | 379 // CloseSessionOnError - called from the owner of the session, |
| 347 // the QuicStreamFactory, when there is an error. | 380 // the QuicStreamFactory, when there is an error. |
| 348 // OnReadComplete - when there is a read error. | 381 // OnReadComplete - when there is a read error. |
| 349 // This method closes all stream and performs any necessary cleanup. | 382 // This method closes all stream and performs any necessary cleanup. |
| 350 void CloseSessionOnErrorInner(int net_error, QuicErrorCode quic_error); | 383 void CloseSessionOnErrorInner(int net_error, QuicErrorCode quic_error); |
| 351 | 384 |
| 352 void CloseAllStreams(int net_error); | 385 void CloseAllStreams(int net_error); |
| 353 void CloseAllObservers(int net_error); | 386 void CloseAllObservers(int net_error); |
| 354 void CancelAllRequests(int net_error); | 387 void CancelAllRequests(int net_error); |
| 388 void NotifyAllWaitingForConfirmation(int net_error); | |
|
xunjieli
2017/05/01 20:15:06
nit: maybe mention "Request" or "StreamRequest" so
Ryan Hamilton
2017/05/01 21:42:35
Done.
| |
| 355 | 389 |
| 356 // Notifies the factory that this session is going away and no more streams | 390 // Notifies the factory that this session is going away and no more streams |
| 357 // should be created from it. This needs to be called before closing any | 391 // should be created from it. This needs to be called before closing any |
| 358 // streams, because closing a stream may cause a new stream to be created. | 392 // streams, because closing a stream may cause a new stream to be created. |
| 359 void NotifyFactoryOfSessionGoingAway(); | 393 void NotifyFactoryOfSessionGoingAway(); |
| 360 | 394 |
| 361 // Posts a task to notify the factory that this session has been closed. | 395 // Posts a task to notify the factory that this session has been closed. |
| 362 void NotifyFactoryOfSessionClosedLater(); | 396 void NotifyFactoryOfSessionClosedLater(); |
| 363 | 397 |
| 364 // Notifies the factory that this session has been closed which will | 398 // Notifies the factory that this session has been closed which will |
| 365 // delete |this|. | 399 // delete |this|. |
| 366 void NotifyFactoryOfSessionClosed(); | 400 void NotifyFactoryOfSessionClosed(); |
| 367 | 401 |
| 368 QuicServerId server_id_; | 402 QuicServerId server_id_; |
| 369 bool require_confirmation_; | 403 bool require_confirmation_; |
| 370 std::unique_ptr<QuicCryptoClientStream> crypto_stream_; | 404 std::unique_ptr<QuicCryptoClientStream> crypto_stream_; |
| 371 QuicStreamFactory* stream_factory_; | 405 QuicStreamFactory* stream_factory_; |
| 372 std::vector<std::unique_ptr<DatagramClientSocket>> sockets_; | 406 std::vector<std::unique_ptr<DatagramClientSocket>> sockets_; |
| 373 TransportSecurityState* transport_security_state_; | 407 TransportSecurityState* transport_security_state_; |
| 374 std::unique_ptr<QuicServerInfo> server_info_; | 408 std::unique_ptr<QuicServerInfo> server_info_; |
| 375 std::unique_ptr<CertVerifyResult> cert_verify_result_; | 409 std::unique_ptr<CertVerifyResult> cert_verify_result_; |
| 376 std::unique_ptr<ct::CTVerifyResult> ct_verify_result_; | 410 std::unique_ptr<ct::CTVerifyResult> ct_verify_result_; |
| 377 std::string pinning_failure_log_; | 411 std::string pinning_failure_log_; |
| 378 bool pkp_bypassed_; | 412 bool pkp_bypassed_; |
| 379 ObserverSet observers_; | 413 ObserverSet observers_; |
| 380 StreamRequestQueue stream_requests_; | 414 StreamRequestQueue stream_requests_; |
| 415 std::vector<CompletionCallback> waiting_for_confirmation_callbacks_; | |
| 381 CompletionCallback callback_; | 416 CompletionCallback callback_; |
| 382 size_t num_total_streams_; | 417 size_t num_total_streams_; |
| 383 base::TaskRunner* task_runner_; | 418 base::TaskRunner* task_runner_; |
| 384 NetLogWithSource net_log_; | 419 NetLogWithSource net_log_; |
| 385 std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_; | 420 std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_; |
| 386 LoadTimingInfo::ConnectTiming connect_timing_; | 421 LoadTimingInfo::ConnectTiming connect_timing_; |
| 387 std::unique_ptr<QuicConnectionLogger> logger_; | 422 std::unique_ptr<QuicConnectionLogger> logger_; |
| 388 // True when the session is going away, and streams may no longer be created | 423 // True when the session is going away, and streams may no longer be created |
| 389 // on this session. Existing stream will continue to be processed. | 424 // on this session. Existing stream will continue to be processed. |
| 390 bool going_away_; | 425 bool going_away_; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 408 // the current sockets_.size() == the passed in value. | 443 // the current sockets_.size() == the passed in value. |
| 409 bool migration_pending_; // True while migration is underway. | 444 bool migration_pending_; // True while migration is underway. |
| 410 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_; | 445 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_; |
| 411 | 446 |
| 412 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession); | 447 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession); |
| 413 }; | 448 }; |
| 414 | 449 |
| 415 } // namespace net | 450 } // namespace net |
| 416 | 451 |
| 417 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ | 452 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ |
| OLD | NEW |