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

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

Issue 2334943002: Add a new QuicChromiumClientSession::Handle class (Closed)
Patch Set: fixes 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 namespace test { 59 namespace test {
60 class QuicChromiumClientSessionPeer; 60 class QuicChromiumClientSessionPeer;
61 } // namespace test 61 } // namespace test
62 62
63 class NET_EXPORT_PRIVATE QuicChromiumClientSession 63 class NET_EXPORT_PRIVATE QuicChromiumClientSession
64 : public QuicClientSessionBase, 64 : public QuicClientSessionBase,
65 public MultiplexedSession, 65 public MultiplexedSession,
66 public QuicChromiumPacketReader::Visitor, 66 public QuicChromiumPacketReader::Visitor,
67 public QuicChromiumPacketWriter::Delegate { 67 public QuicChromiumPacketWriter::Delegate {
68 public: 68 public:
69 // An interface for observing events on a session. 69 class StreamRequest;
70 class NET_EXPORT_PRIVATE Observer { 70
71 // Wrapper for interacting with the session in a restricted fashion which
72 // hides the details of the underlying session's lifetime. All methods of
73 // the Handle are safe to use even after the underlying session is destroyed.
74 class NET_EXPORT_PRIVATE Handle : public MultiplexedSessionHandle {
71 public: 75 public:
72 virtual ~Observer() {} 76 explicit Handle(const base::WeakPtr<QuicChromiumClientSession>& session);
73 virtual void OnCryptoHandshakeConfirmed() = 0; 77 Handle(const Handle& other) = delete;
74 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0; 78 ~Handle() override;
75 virtual void OnSessionClosed(int error, bool port_migration_detected) = 0; 79
80 // Returns true if the session is still connected.
81 bool IsConnected() const;
82
83 // Returns true if the handshake has been confirmed.
84 bool IsCryptoHandshakeConfirmed() const;
85
86 // Starts a request to create a stream. If OK is returned, then
87 // |stream_| will be updated with the newly created stream. If
88 // ERR_IO_PENDING is returned, then when the request is eventuallly
89 // complete |callback| will be called.
90 int RequestStream(bool requires_confirmation,
91 const CompletionCallback& callback);
92
93 // Releases |stream_| to the caller.
94 QuicChromiumClientStream* ReleaseStream();
95
96 // Sends Rst for the stream, and makes sure that future calls to
97 // IsClosedStream(id) return true, which ensures that any subsequent
98 // frames related to this stream will be ignored (modulo flow
99 // control accounting).
100 void ResetPromised(QuicStreamId id, QuicRstStreamErrorCode error_code);
101
102 // Returns a new packet bundler while will cause writes to be batched up
103 // until a packet is full, or the last bundler is destroyed.
104 std::unique_ptr<QuicConnection::ScopedPacketBundler> CreatePacketBundler(
105 QuicConnection::AckBundling bundling_mode);
106
107 // Populates network error details for this session.
108 void PopulateNetErrorDetails(NetErrorDetails* details) const;
109
110 // Returns the connection timing for the handshake of this session.
111 const LoadTimingInfo::ConnectTiming& GetConnectTiming();
112
113 // Signs the exported keying material used for Token Binding using key
114 // |*key| and puts the signature in |*out|. Returns a net error code.
115 Error GetTokenBindingSignature(crypto::ECPrivateKey* key,
116 TokenBindingType tb_type,
117 std::vector<uint8_t>* out);
118
119 // Returns true if |other| is a handle to the same session as this handle.
120 bool SharesSameSession(const Handle& other) const;
121
122 // Returns the QUIC version used by the session.
123 QuicVersion GetQuicVersion() const;
124
125 // Copies the remote udp address into |address| and returns a net error
126 // code.
127 int GetPeerAddress(IPEndPoint* address) const;
128
129 // Returns the push promise index associated with the session.
130 QuicClientPushPromiseIndex* GetPushPromiseIndex();
131
132 // Returns the session's server ID.
133 QuicServerId server_id() const { return server_id_; }
134
135 // Returns the session's net log.
136 const NetLogWithSource& net_log() const { return net_log_; }
137
138 private:
139 friend class QuicChromiumClientSession;
140 friend class QuicChromiumClientSession::StreamRequest;
141
142 // Waits for the handshake to be confirmed and invokes |callback| when
143 // that happens. If the handshake has already been confirmed, returns OK.
144 // If the connection has already been closed, returns a net error. If the
145 // connection closes before the handshake is confirmed, |callback| will
146 // be invoked with an error.
147 int WaitForHandshakeConfirmation(const CompletionCallback& callback);
148
149 // Called when the handshake is confirmed.
150 void OnCryptoHandshakeConfirmed();
151
152 // Called when the session is closed with a net error.
153 void OnSessionClosed(QuicVersion quic_version,
154 int error,
155 bool port_migration_detected,
156 LoadTimingInfo::ConnectTiming connect_timing);
157
158 // Called by |request| to create a stream.
159 int TryCreateStream(StreamRequest* request);
160
161 // Called by |request| to cancel stream request.
162 void CancelRequest(StreamRequest* request);
163
164 // Underlying session which may be destroyed before this handle.
165 base::WeakPtr<QuicChromiumClientSession> session_;
166
167 // Stream request created by |RequestStream()|.
168 std::unique_ptr<StreamRequest> stream_request_;
169
170 // Information saved from the session which can be used even after the
171 // session is destroyed.
172 NetLogWithSource net_log_;
173 bool was_handshake_confirmed_;
174 int error_;
175 bool port_migration_detected_;
176 QuicServerId server_id_;
177 QuicVersion quic_version_;
178 LoadTimingInfo::ConnectTiming connect_timing_;
179 QuicClientPushPromiseIndex* push_promise_index_;
76 }; 180 };
77 181
78 // A helper class used to manage a request to create a stream. 182 // A helper class used to manage a request to create a stream.
79 class NET_EXPORT_PRIVATE StreamRequest { 183 class NET_EXPORT_PRIVATE StreamRequest {
80 public: 184 public:
81 // Cancels any pending stream creation request and resets |stream_| if 185 // Cancels any pending stream creation request and resets |stream_| if
82 // it has not yet been released. 186 // it has not yet been released.
83 ~StreamRequest(); 187 ~StreamRequest();
84 188
85 // Starts a request to create a stream. If OK is returned, then 189 // Starts a request to create a stream. If OK is returned, then
86 // |stream_| will be updated with the newly created stream. If 190 // |stream_| will be updated with the newly created stream. If
87 // ERR_IO_PENDING is returned, then when the request is eventuallly 191 // ERR_IO_PENDING is returned, then when the request is eventuallly
88 // complete |callback| will be called. 192 // complete |callback| will be called.
89 int StartRequest(const CompletionCallback& callback); 193 int StartRequest(const CompletionCallback& callback);
90 194
91 // Releases |stream_| to the caller 195 // Releases |stream_| to the caller
92 QuicChromiumClientStream* ReleaseStream(); 196 QuicChromiumClientStream* ReleaseStream();
93 197
94 private: 198 private:
95 friend class QuicChromiumClientSession; 199 friend class QuicChromiumClientSession;
96 200
97 enum State { 201 enum State {
98 STATE_NONE, 202 STATE_NONE,
99 STATE_WAIT_FOR_CONFIRMATION, 203 STATE_WAIT_FOR_CONFIRMATION,
100 STATE_WAIT_FOR_CONFIRMATION_COMPLETE, 204 STATE_WAIT_FOR_CONFIRMATION_COMPLETE,
101 STATE_REQUEST_STREAM, 205 STATE_REQUEST_STREAM,
102 STATE_REQUEST_STREAM_COMPLETE, 206 STATE_REQUEST_STREAM_COMPLETE,
103 }; 207 };
104 208
105 StreamRequest(const base::WeakPtr<QuicChromiumClientSession>& session, 209 StreamRequest(std::unique_ptr<QuicChromiumClientSession::Handle> session,
106 bool requires_confirmation); 210 bool requires_confirmation);
107 211
108 void OnIOComplete(int rv); 212 void OnIOComplete(int rv);
109 void DoCallback(int rv); 213 void DoCallback(int rv);
110 214
111 int DoLoop(int rv); 215 int DoLoop(int rv);
112 int DoWaitForConfirmation(); 216 int DoWaitForConfirmation();
113 int DoWaitForConfirmationComplete(int rv); 217 int DoWaitForConfirmationComplete(int rv);
114 int DoRequestStream(); 218 int DoRequestStream();
115 int DoRequestStreamComplete(int rv); 219 int DoRequestStreamComplete(int rv);
116 220
117 // Called by |session_| for an asynchronous request when the stream 221 // Called by |session_| for an asynchronous request when the stream
118 // request has finished successfully. 222 // request has finished successfully.
119 void OnRequestCompleteSuccess(QuicChromiumClientStream* stream); 223 void OnRequestCompleteSuccess(QuicChromiumClientStream* stream);
120 224
121 // Called by |session_| for an asynchronous request when the stream 225 // Called by |session_| for an asynchronous request when the stream
122 // request has finished with an error. Also called with ERR_ABORTED 226 // request has finished with an error. Also called with ERR_ABORTED
123 // if |session_| is destroyed while the stream request is still pending. 227 // if |session_| is destroyed while the stream request is still pending.
124 void OnRequestCompleteFailure(int rv); 228 void OnRequestCompleteFailure(int rv);
125 229
126 base::WeakPtr<QuicChromiumClientSession> session_; 230 std::unique_ptr<QuicChromiumClientSession::Handle> session_;
127 const bool requires_confirmation_; 231 const bool requires_confirmation_;
128 CompletionCallback callback_; 232 CompletionCallback callback_;
129 QuicChromiumClientStream* stream_; 233 QuicChromiumClientStream* stream_;
130 // For tracking how much time pending stream requests wait. 234 // For tracking how much time pending stream requests wait.
131 base::TimeTicks pending_start_time_; 235 base::TimeTicks pending_start_time_;
132 State next_state_; 236 State next_state_;
133 237
134 base::WeakPtrFactory<StreamRequest> weak_factory_; 238 base::WeakPtrFactory<StreamRequest> weak_factory_;
135 239
136 DISALLOW_COPY_AND_ASSIGN(StreamRequest); 240 DISALLOW_COPY_AND_ASSIGN(StreamRequest);
(...skipping 22 matching lines...) Expand all
159 base::TimeTicks dns_resolution_end_time, 263 base::TimeTicks dns_resolution_end_time,
160 QuicClientPushPromiseIndex* push_promise_index, 264 QuicClientPushPromiseIndex* push_promise_index,
161 ServerPushDelegate* push_delegate, 265 ServerPushDelegate* push_delegate,
162 base::TaskRunner* task_runner, 266 base::TaskRunner* task_runner,
163 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, 267 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher,
164 NetLog* net_log); 268 NetLog* net_log);
165 ~QuicChromiumClientSession() override; 269 ~QuicChromiumClientSession() override;
166 270
167 void Initialize() override; 271 void Initialize() override;
168 272
169 void AddObserver(Observer* observer); 273 void AddHandle(Handle* handle);
170 void RemoveObserver(Observer* observer); 274 void RemoveHandle(Handle* handle);
171 275
172 // Waits for the handshake to be confirmed and invokes |callback| when 276 // Waits for the handshake to be confirmed and invokes |callback| when
173 // that happens. If the handshake has already been confirmed, returns OK. 277 // 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 278 // If the connection has already been closed, returns a net error. If the
175 // connection closes before the handshake is confirmed, |callback| will 279 // connection closes before the handshake is confirmed, |callback| will
176 // be invoked with an error. 280 // be invoked with an error.
177 int WaitForHandshakeConfirmation(const CompletionCallback& callback); 281 int WaitForHandshakeConfirmation(const CompletionCallback& callback);
178 282
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);
184
185 // Attempts to create a new stream. If the stream can be 283 // Attempts to create a new stream. If the stream can be
186 // created immediately, returns OK. If the open stream limit 284 // created immediately, returns OK. If the open stream limit
187 // has been reached, returns ERR_IO_PENDING, and |request| 285 // has been reached, returns ERR_IO_PENDING, and |request|
188 // will be added to the stream requets queue and will 286 // will be added to the stream requets queue and will
189 // be completed asynchronously. 287 // be completed asynchronously.
190 // TODO(rch): remove |stream| from this and use setter on |request| 288 // TODO(rch): remove |stream| from this and use setter on |request|
191 // and fix in spdy too. 289 // and fix in spdy too.
192 int TryCreateStream(StreamRequest* request); 290 int TryCreateStream(StreamRequest* request);
193 291
194 // Cancels the pending stream creation request. 292 // Cancels the pending stream creation request.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 355
258 // Close the session because of |net_error| and notifies the factory 356 // Close the session because of |net_error| and notifies the factory
259 // that this session has been closed, which will delete the session. 357 // that this session has been closed, which will delete the session.
260 void CloseSessionOnError(int net_error, QuicErrorCode quic_error); 358 void CloseSessionOnError(int net_error, QuicErrorCode quic_error);
261 359
262 std::unique_ptr<base::Value> GetInfoAsValue( 360 std::unique_ptr<base::Value> GetInfoAsValue(
263 const std::set<HostPortPair>& aliases); 361 const std::set<HostPortPair>& aliases);
264 362
265 const NetLogWithSource& net_log() const { return net_log_; } 363 const NetLogWithSource& net_log() const { return net_log_; }
266 364
267 base::WeakPtr<QuicChromiumClientSession> GetWeakPtr(); 365 // Returns a Handle to this session.
366 std::unique_ptr<QuicChromiumClientSession::Handle> CreateHandle();
268 367
269 // Returns the number of client hello messages that have been sent on the 368 // Returns the number of client hello messages that have been sent on the
270 // crypto stream. If the handshake has completed then this is one greater 369 // crypto stream. If the handshake has completed then this is one greater
271 // than the number of round-trips needed for the handshake. 370 // than the number of round-trips needed for the handshake.
272 int GetNumSentClientHellos() const; 371 int GetNumSentClientHellos() const;
273 372
274 // Returns the stream id of the push stream if it is not claimed yet, or 0 373 // Returns the stream id of the push stream if it is not claimed yet, or 0
275 // otherwise. 374 // otherwise.
276 QuicStreamId GetStreamIdForPush(const GURL& pushed_url); 375 QuicStreamId GetStreamIdForPush(const GURL& pushed_url);
277 376
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 const NetLogWithSource& net_log); 408 const NetLogWithSource& net_log);
310 409
311 // Schedules a migration alarm to wait for a new network. 410 // Schedules a migration alarm to wait for a new network.
312 void OnNoNewNetwork(); 411 void OnNoNewNetwork();
313 412
314 // Called when migration alarm fires. If migration has not occurred 413 // Called when migration alarm fires. If migration has not occurred
315 // since alarm was set, closes session with error. 414 // since alarm was set, closes session with error.
316 void OnMigrationTimeout(size_t num_sockets); 415 void OnMigrationTimeout(size_t num_sockets);
317 416
318 // Populates network error details for this session. 417 // Populates network error details for this session.
319 void PopulateNetErrorDetails(NetErrorDetails* details); 418 void PopulateNetErrorDetails(NetErrorDetails* details) const;
320 419
321 // Returns current default socket. This is the socket over which all 420 // Returns current default socket. This is the socket over which all
322 // QUIC packets are sent. This default socket can change, so do not store the 421 // QUIC packets are sent. This default socket can change, so do not store the
323 // returned socket. 422 // returned socket.
324 const DatagramClientSocket* GetDefaultSocket() const; 423 const DatagramClientSocket* GetDefaultSocket() const;
325 424
326 bool IsAuthorized(const std::string& hostname) override; 425 bool IsAuthorized(const std::string& hostname) override;
327 426
328 // Returns true if session has one ore more streams marked as non-migratable. 427 // Returns true if session has one ore more streams marked as non-migratable.
329 bool HasNonMigratableStreams() const; 428 bool HasNonMigratableStreams() const;
(...skipping 23 matching lines...) Expand all
353 // QuicSession methods: 452 // QuicSession methods:
354 bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override; 453 bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override;
355 bool ShouldCreateOutgoingDynamicStream() override; 454 bool ShouldCreateOutgoingDynamicStream() override;
356 455
357 QuicChromiumClientStream* CreateIncomingDynamicStream( 456 QuicChromiumClientStream* CreateIncomingDynamicStream(
358 QuicStreamId id) override; 457 QuicStreamId id) override;
359 458
360 private: 459 private:
361 friend class test::QuicChromiumClientSessionPeer; 460 friend class test::QuicChromiumClientSessionPeer;
362 461
363 typedef std::set<Observer*> ObserverSet; 462 typedef std::set<Handle*> HandleSet;
364 typedef std::list<StreamRequest*> StreamRequestQueue; 463 typedef std::list<StreamRequest*> StreamRequestQueue;
365 464
366 QuicChromiumClientStream* CreateOutgoingReliableStreamImpl(); 465 QuicChromiumClientStream* CreateOutgoingReliableStreamImpl();
367 QuicChromiumClientStream* CreateIncomingReliableStreamImpl(QuicStreamId id); 466 QuicChromiumClientStream* CreateIncomingReliableStreamImpl(QuicStreamId id);
368 // A completion callback invoked when a read completes. 467 // A completion callback invoked when a read completes.
369 void OnReadComplete(int result); 468 void OnReadComplete(int result);
370 469
371 void OnClosedStream(); 470 void OnClosedStream();
372 471
373 void CloseAllStreams(int net_error); 472 void CloseAllStreams(int net_error);
374 void CloseAllObservers(int net_error); 473 void CloseAllHandles(int net_error);
375 void CancelAllRequests(int net_error); 474 void CancelAllRequests(int net_error);
376 void NotifyRequestsOfConfirmation(int net_error); 475 void NotifyRequestsOfConfirmation(int net_error);
377 476
378 // Notifies the factory that this session is going away and no more streams 477 // Notifies the factory that this session is going away and no more streams
379 // should be created from it. This needs to be called before closing any 478 // should be created from it. This needs to be called before closing any
380 // streams, because closing a stream may cause a new stream to be created. 479 // streams, because closing a stream may cause a new stream to be created.
381 void NotifyFactoryOfSessionGoingAway(); 480 void NotifyFactoryOfSessionGoingAway();
382 481
383 // Posts a task to notify the factory that this session has been closed. 482 // Posts a task to notify the factory that this session has been closed.
384 void NotifyFactoryOfSessionClosedLater(); 483 void NotifyFactoryOfSessionClosedLater();
385 484
386 // Notifies the factory that this session has been closed which will 485 // Notifies the factory that this session has been closed which will
387 // delete |this|. 486 // delete |this|.
388 void NotifyFactoryOfSessionClosed(); 487 void NotifyFactoryOfSessionClosed();
389 488
390 QuicServerId server_id_; 489 QuicServerId server_id_;
391 bool require_confirmation_; 490 bool require_confirmation_;
392 std::unique_ptr<QuicCryptoClientStream> crypto_stream_; 491 std::unique_ptr<QuicCryptoClientStream> crypto_stream_;
393 QuicStreamFactory* stream_factory_; 492 QuicStreamFactory* stream_factory_;
394 std::vector<std::unique_ptr<DatagramClientSocket>> sockets_; 493 std::vector<std::unique_ptr<DatagramClientSocket>> sockets_;
395 TransportSecurityState* transport_security_state_; 494 TransportSecurityState* transport_security_state_;
396 std::unique_ptr<QuicServerInfo> server_info_; 495 std::unique_ptr<QuicServerInfo> server_info_;
397 std::unique_ptr<CertVerifyResult> cert_verify_result_; 496 std::unique_ptr<CertVerifyResult> cert_verify_result_;
398 std::unique_ptr<ct::CTVerifyResult> ct_verify_result_; 497 std::unique_ptr<ct::CTVerifyResult> ct_verify_result_;
399 std::string pinning_failure_log_; 498 std::string pinning_failure_log_;
400 bool pkp_bypassed_; 499 bool pkp_bypassed_;
401 ObserverSet observers_; 500 HandleSet handles_;
402 StreamRequestQueue stream_requests_; 501 StreamRequestQueue stream_requests_;
403 std::vector<CompletionCallback> waiting_for_confirmation_callbacks_; 502 std::vector<CompletionCallback> waiting_for_confirmation_callbacks_;
404 CompletionCallback callback_; 503 CompletionCallback callback_;
405 size_t num_total_streams_; 504 size_t num_total_streams_;
406 base::TaskRunner* task_runner_; 505 base::TaskRunner* task_runner_;
407 NetLogWithSource net_log_; 506 NetLogWithSource net_log_;
408 std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_; 507 std::vector<std::unique_ptr<QuicChromiumPacketReader>> packet_readers_;
409 LoadTimingInfo::ConnectTiming connect_timing_; 508 LoadTimingInfo::ConnectTiming connect_timing_;
410 std::unique_ptr<QuicConnectionLogger> logger_; 509 std::unique_ptr<QuicConnectionLogger> logger_;
411 // True when the session is going away, and streams may no longer be created 510 // True when the session is going away, and streams may no longer be created
(...skipping 19 matching lines...) Expand all
431 // the current sockets_.size() == the passed in value. 530 // the current sockets_.size() == the passed in value.
432 bool migration_pending_; // True while migration is underway. 531 bool migration_pending_; // True while migration is underway.
433 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_; 532 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_;
434 533
435 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession); 534 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession);
436 }; 535 };
437 536
438 } // namespace net 537 } // namespace net
439 538
440 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ 539 #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