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

Side by Side Diff: net/quic/chromium/quic_chromium_client_session.h

Issue 2848923004: Move the "wait for QUIC handshake confirmation" logic to QuicChromiumClientSession::StreamRequest (Closed)
Patch Set: fix Created 3 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
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 // 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
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 const bool requires_confirmation_;
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
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 a new stream request which can be used to create a new
180 // QUIC stream. If |requires_confirmation| is true, then the requested
181 // stream will not be created until the handshake as been confirmed.
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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 QuicChromiumClientStream* CreateOutgoingReliableStreamImpl(); 366 QuicChromiumClientStream* CreateOutgoingReliableStreamImpl();
334 QuicChromiumClientStream* CreateIncomingReliableStreamImpl(QuicStreamId id); 367 QuicChromiumClientStream* CreateIncomingReliableStreamImpl(QuicStreamId id);
335 // A completion callback invoked when a read completes. 368 // A completion callback invoked when a read completes.
336 void OnReadComplete(int result); 369 void OnReadComplete(int result);
337 370
338 void OnClosedStream(); 371 void OnClosedStream();
339 372
340 void CloseAllStreams(int net_error); 373 void CloseAllStreams(int net_error);
341 void CloseAllObservers(int net_error); 374 void CloseAllObservers(int net_error);
342 void CancelAllRequests(int net_error); 375 void CancelAllRequests(int net_error);
376 void NotifyRequestsOfConfirmation(int net_error);
343 377
344 // Notifies the factory that this session is going away and no more streams 378 // Notifies the factory that this session is going away and no more streams
345 // should be created from it. This needs to be called before closing any 379 // should be created from it. This needs to be called before closing any
346 // streams, because closing a stream may cause a new stream to be created. 380 // streams, because closing a stream may cause a new stream to be created.
347 void NotifyFactoryOfSessionGoingAway(); 381 void NotifyFactoryOfSessionGoingAway();
348 382
349 // Posts a task to notify the factory that this session has been closed. 383 // Posts a task to notify the factory that this session has been closed.
350 void NotifyFactoryOfSessionClosedLater(); 384 void NotifyFactoryOfSessionClosedLater();
351 385
352 // Notifies the factory that this session has been closed which will 386 // Notifies the factory that this session has been closed which will
353 // delete |this|. 387 // delete |this|.
354 void NotifyFactoryOfSessionClosed(); 388 void NotifyFactoryOfSessionClosed();
355 389
356 QuicServerId server_id_; 390 QuicServerId server_id_;
357 bool require_confirmation_; 391 bool require_confirmation_;
358 std::unique_ptr<QuicCryptoClientStream> crypto_stream_; 392 std::unique_ptr<QuicCryptoClientStream> crypto_stream_;
359 QuicStreamFactory* stream_factory_; 393 QuicStreamFactory* stream_factory_;
360 std::vector<std::unique_ptr<DatagramClientSocket>> sockets_; 394 std::vector<std::unique_ptr<DatagramClientSocket>> sockets_;
361 TransportSecurityState* transport_security_state_; 395 TransportSecurityState* transport_security_state_;
362 std::unique_ptr<QuicServerInfo> server_info_; 396 std::unique_ptr<QuicServerInfo> server_info_;
363 std::unique_ptr<CertVerifyResult> cert_verify_result_; 397 std::unique_ptr<CertVerifyResult> cert_verify_result_;
364 std::unique_ptr<ct::CTVerifyResult> ct_verify_result_; 398 std::unique_ptr<ct::CTVerifyResult> ct_verify_result_;
365 std::string pinning_failure_log_; 399 std::string pinning_failure_log_;
366 bool pkp_bypassed_; 400 bool pkp_bypassed_;
367 ObserverSet observers_; 401 ObserverSet observers_;
368 StreamRequestQueue stream_requests_; 402 StreamRequestQueue stream_requests_;
403 std::vector<CompletionCallback> waiting_for_confirmation_callbacks_;
369 CompletionCallback callback_; 404 CompletionCallback callback_;
370 size_t num_total_streams_; 405 size_t num_total_streams_;
371 base::TaskRunner* task_runner_; 406 base::TaskRunner* task_runner_;
372 NetLogWithSource net_log_; 407 NetLogWithSource net_log_;
373 std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_; 408 std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_;
374 LoadTimingInfo::ConnectTiming connect_timing_; 409 LoadTimingInfo::ConnectTiming connect_timing_;
375 std::unique_ptr<QuicConnectionLogger> logger_; 410 std::unique_ptr<QuicConnectionLogger> logger_;
376 // True when the session is going away, and streams may no longer be created 411 // True when the session is going away, and streams may no longer be created
377 // on this session. Existing stream will continue to be processed. 412 // on this session. Existing stream will continue to be processed.
378 bool going_away_; 413 bool going_away_;
(...skipping 17 matching lines...) Expand all
396 // the current sockets_.size() == the passed in value. 431 // the current sockets_.size() == the passed in value.
397 bool migration_pending_; // True while migration is underway. 432 bool migration_pending_; // True while migration is underway.
398 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_; 433 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_;
399 434
400 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession); 435 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession);
401 }; 436 };
402 437
403 } // namespace net 438 } // namespace net
404 439
405 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ 440 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_
OLDNEW
« no previous file with comments | « net/quic/chromium/bidirectional_stream_quic_impl_unittest.cc ('k') | net/quic/chromium/quic_chromium_client_session.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698