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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 public: | 71 public: |
72 virtual ~Observer() {} | 72 virtual ~Observer() {} |
73 virtual void OnCryptoHandshakeConfirmed() = 0; | 73 virtual void OnCryptoHandshakeConfirmed() = 0; |
74 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0; | 74 virtual void OnSuccessfulVersionNegotiation(const QuicVersion& version) = 0; |
75 virtual void OnSessionClosed(int error, bool port_migration_detected) = 0; | 75 virtual void OnSessionClosed(int error, bool port_migration_detected) = 0; |
76 }; | 76 }; |
77 | 77 |
78 // A helper class used to manage a request to create a stream. | 78 // A helper class used to manage a request to create a stream. |
79 class NET_EXPORT_PRIVATE StreamRequest { | 79 class NET_EXPORT_PRIVATE StreamRequest { |
80 public: | 80 public: |
81 StreamRequest(); | 81 // Cancels any pending stream creation request and resets |stream_| if |
| 82 // it has not yet been released. |
82 ~StreamRequest(); | 83 ~StreamRequest(); |
83 | 84 |
84 // Starts a request to create a stream. If OK is returned, then | 85 // Starts a request to create a stream. If OK is returned, then |
85 // |stream| will be updated with the newly created stream. If | 86 // |stream_| will be updated with the newly created stream. If |
86 // ERR_IO_PENDING is returned, then when the request is eventuallly | 87 // ERR_IO_PENDING is returned, then when the request is eventuallly |
87 // complete |callback| will be called. | 88 // complete |callback| will be called. |
88 int StartRequest(const base::WeakPtr<QuicChromiumClientSession>& session, | 89 int StartRequest(const CompletionCallback& callback); |
89 QuicChromiumClientStream** stream, | |
90 const CompletionCallback& callback); | |
91 | 90 |
92 // Cancels any pending stream creation request. May be called | 91 // Releases |stream_| to the caller |
93 // repeatedly. | 92 QuicChromiumClientStream* ReleaseStream(); |
94 void CancelRequest(); | |
95 | 93 |
96 private: | 94 private: |
97 friend class QuicChromiumClientSession; | 95 friend class QuicChromiumClientSession; |
98 | 96 |
| 97 StreamRequest(const base::WeakPtr<QuicChromiumClientSession>& session); |
| 98 |
99 // Called by |session_| for an asynchronous request when the stream | 99 // Called by |session_| for an asynchronous request when the stream |
100 // request has finished successfully. | 100 // request has finished successfully. |
101 void OnRequestCompleteSuccess(QuicChromiumClientStream* stream); | 101 void OnRequestCompleteSuccess(QuicChromiumClientStream* stream); |
102 | 102 |
103 // Called by |session_| for an asynchronous request when the stream | 103 // Called by |session_| for an asynchronous request when the stream |
104 // request has finished with an error. Also called with ERR_ABORTED | 104 // request has finished with an error. Also called with ERR_ABORTED |
105 // if |session_| is destroyed while the stream request is still pending. | 105 // if |session_| is destroyed while the stream request is still pending. |
106 void OnRequestCompleteFailure(int rv); | 106 void OnRequestCompleteFailure(int rv); |
107 | 107 |
108 base::WeakPtr<QuicChromiumClientSession> session_; | 108 base::WeakPtr<QuicChromiumClientSession> session_; |
109 CompletionCallback callback_; | 109 CompletionCallback callback_; |
110 QuicChromiumClientStream** stream_; | 110 QuicChromiumClientStream* stream_; |
111 // For tracking how much time pending stream requests wait. | 111 // For tracking how much time pending stream requests wait. |
112 base::TimeTicks pending_start_time_; | 112 base::TimeTicks pending_start_time_; |
113 | 113 |
114 DISALLOW_COPY_AND_ASSIGN(StreamRequest); | 114 DISALLOW_COPY_AND_ASSIGN(StreamRequest); |
115 }; | 115 }; |
116 | 116 |
117 // Constructs a new session which will own |connection|, but not | 117 // Constructs a new session which will own |connection|, but not |
118 // |stream_factory|, which must outlive this session. | 118 // |stream_factory|, which must outlive this session. |
119 // TODO(rch): decouple the factory from the session via a Delegate interface. | 119 // TODO(rch): decouple the factory from the session via a Delegate interface. |
120 QuicChromiumClientSession( | 120 QuicChromiumClientSession( |
(...skipping 19 matching lines...) Expand all Loading... |
140 base::TaskRunner* task_runner, | 140 base::TaskRunner* task_runner, |
141 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 141 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
142 NetLog* net_log); | 142 NetLog* net_log); |
143 ~QuicChromiumClientSession() override; | 143 ~QuicChromiumClientSession() override; |
144 | 144 |
145 void Initialize() override; | 145 void Initialize() override; |
146 | 146 |
147 void AddObserver(Observer* observer); | 147 void AddObserver(Observer* observer); |
148 void RemoveObserver(Observer* observer); | 148 void RemoveObserver(Observer* observer); |
149 | 149 |
| 150 std::unique_ptr<StreamRequest> CreateStreamRequest(); |
| 151 |
150 // Attempts to create a new stream. If the stream can be | 152 // Attempts to create a new stream. If the stream can be |
151 // created immediately, returns OK. If the open stream limit | 153 // created immediately, returns OK. If the open stream limit |
152 // has been reached, returns ERR_IO_PENDING, and |request| | 154 // has been reached, returns ERR_IO_PENDING, and |request| |
153 // will be added to the stream requets queue and will | 155 // will be added to the stream requets queue and will |
154 // be completed asynchronously. | 156 // be completed asynchronously. |
155 // TODO(rch): remove |stream| from this and use setter on |request| | 157 // TODO(rch): remove |stream| from this and use setter on |request| |
156 // and fix in spdy too. | 158 // and fix in spdy too. |
157 int TryCreateStream(StreamRequest* request, | 159 int TryCreateStream(StreamRequest* request); |
158 QuicChromiumClientStream** stream); | |
159 | 160 |
160 // Cancels the pending stream creation request. | 161 // Cancels the pending stream creation request. |
161 void CancelRequest(StreamRequest* request); | 162 void CancelRequest(StreamRequest* request); |
162 | 163 |
163 // QuicChromiumPacketWriter::Delegate override. | 164 // QuicChromiumPacketWriter::Delegate override. |
164 int HandleWriteError(int error_code, | 165 int HandleWriteError(int error_code, |
165 scoped_refptr<StringIOBuffer> last_packet) override; | 166 scoped_refptr<StringIOBuffer> last_packet) override; |
166 void OnWriteError(int error_code) override; | 167 void OnWriteError(int error_code) override; |
167 void OnWriteUnblocked() override; | 168 void OnWriteUnblocked() override; |
168 | 169 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // the current sockets_.size() == the passed in value. | 407 // the current sockets_.size() == the passed in value. |
407 bool migration_pending_; // True while migration is underway. | 408 bool migration_pending_; // True while migration is underway. |
408 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_; | 409 base::WeakPtrFactory<QuicChromiumClientSession> weak_factory_; |
409 | 410 |
410 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession); | 411 DISALLOW_COPY_AND_ASSIGN(QuicChromiumClientSession); |
411 }; | 412 }; |
412 | 413 |
413 } // namespace net | 414 } // namespace net |
414 | 415 |
415 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ | 416 #endif // NET_QUIC_CHROMIUM_QUIC_CHROMIUM_CLIENT_SESSION_H_ |
OLD | NEW |