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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 const GURL& GetURL() const override { return request_url_; } | 180 const GURL& GetURL() const override { return request_url_; } |
181 | 181 |
182 private: | 182 private: |
183 base::WeakPtr<QuicChromiumClientSession> session_; | 183 base::WeakPtr<QuicChromiumClientSession> session_; |
184 const GURL request_url_; | 184 const GURL request_url_; |
185 }; | 185 }; |
186 | 186 |
187 } // namespace | 187 } // namespace |
188 | 188 |
189 QuicChromiumClientSession::StreamRequest::StreamRequest() : stream_(nullptr) {} | 189 QuicChromiumClientSession::StreamRequest::StreamRequest( |
| 190 const base::WeakPtr<QuicChromiumClientSession>& session) |
| 191 : session_(session), stream_(nullptr) {} |
190 | 192 |
191 QuicChromiumClientSession::StreamRequest::~StreamRequest() { | 193 QuicChromiumClientSession::StreamRequest::~StreamRequest() { |
192 CancelRequest(); | 194 if (stream_) |
| 195 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 196 |
| 197 if (session_) |
| 198 session_->CancelRequest(this); |
193 } | 199 } |
194 | 200 |
195 int QuicChromiumClientSession::StreamRequest::StartRequest( | 201 int QuicChromiumClientSession::StreamRequest::StartRequest( |
196 const base::WeakPtr<QuicChromiumClientSession>& session, | |
197 QuicChromiumClientStream** stream, | |
198 const CompletionCallback& callback) { | 202 const CompletionCallback& callback) { |
199 session_ = session; | 203 DCHECK(session_); |
200 stream_ = stream; | 204 int rv = session_->TryCreateStream(this); |
201 int rv = session_->TryCreateStream(this, stream_); | |
202 if (rv == ERR_IO_PENDING) { | 205 if (rv == ERR_IO_PENDING) { |
203 callback_ = callback; | 206 callback_ = callback; |
| 207 } else { |
| 208 session_.reset(); |
204 } | 209 } |
205 | 210 |
206 return rv; | 211 return rv; |
207 } | 212 } |
208 | 213 |
209 void QuicChromiumClientSession::StreamRequest::CancelRequest() { | 214 QuicChromiumClientStream* |
210 if (session_) | 215 QuicChromiumClientSession::StreamRequest::ReleaseStream() { |
211 session_->CancelRequest(this); | 216 DCHECK(stream_); |
212 session_.reset(); | 217 QuicChromiumClientStream* stream = stream_; |
213 callback_.Reset(); | 218 stream_ = nullptr; |
| 219 return stream; |
214 } | 220 } |
215 | 221 |
216 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteSuccess( | 222 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteSuccess( |
217 QuicChromiumClientStream* stream) { | 223 QuicChromiumClientStream* stream) { |
218 session_.reset(); | 224 session_.reset(); |
219 *stream_ = stream; | 225 stream_ = stream; |
220 base::ResetAndReturn(&callback_).Run(OK); | 226 base::ResetAndReturn(&callback_).Run(OK); |
221 } | 227 } |
222 | 228 |
223 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure( | 229 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure( |
224 int rv) { | 230 int rv) { |
225 session_.reset(); | 231 session_.reset(); |
226 base::ResetAndReturn(&callback_).Run(rv); | 232 base::ResetAndReturn(&callback_).Run(rv); |
227 } | 233 } |
228 | 234 |
229 QuicChromiumClientSession::QuicChromiumClientSession( | 235 QuicChromiumClientSession::QuicChromiumClientSession( |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 455 |
450 DCHECK(!base::ContainsKey(observers_, observer)); | 456 DCHECK(!base::ContainsKey(observers_, observer)); |
451 observers_.insert(observer); | 457 observers_.insert(observer); |
452 } | 458 } |
453 | 459 |
454 void QuicChromiumClientSession::RemoveObserver(Observer* observer) { | 460 void QuicChromiumClientSession::RemoveObserver(Observer* observer) { |
455 DCHECK(base::ContainsKey(observers_, observer)); | 461 DCHECK(base::ContainsKey(observers_, observer)); |
456 observers_.erase(observer); | 462 observers_.erase(observer); |
457 } | 463 } |
458 | 464 |
459 int QuicChromiumClientSession::TryCreateStream( | 465 std::unique_ptr<QuicChromiumClientSession::StreamRequest> |
460 StreamRequest* request, | 466 QuicChromiumClientSession::CreateStreamRequest() { |
461 QuicChromiumClientStream** stream) { | 467 // base::MakeUnique does not work because the StreamRequest constructor |
| 468 // is private. |
| 469 return std::unique_ptr<StreamRequest>( |
| 470 new StreamRequest(weak_factory_.GetWeakPtr())); |
| 471 } |
| 472 |
| 473 int QuicChromiumClientSession::TryCreateStream(StreamRequest* request) { |
462 if (goaway_received()) { | 474 if (goaway_received()) { |
463 DVLOG(1) << "Going away."; | 475 DVLOG(1) << "Going away."; |
464 return ERR_CONNECTION_CLOSED; | 476 return ERR_CONNECTION_CLOSED; |
465 } | 477 } |
466 | 478 |
467 if (!connection()->connected()) { | 479 if (!connection()->connected()) { |
468 DVLOG(1) << "Already closed."; | 480 DVLOG(1) << "Already closed."; |
469 return ERR_CONNECTION_CLOSED; | 481 return ERR_CONNECTION_CLOSED; |
470 } | 482 } |
471 | 483 |
472 if (going_away_) { | 484 if (going_away_) { |
473 RecordUnexpectedOpenStreams(TRY_CREATE_STREAM); | 485 RecordUnexpectedOpenStreams(TRY_CREATE_STREAM); |
474 return ERR_CONNECTION_CLOSED; | 486 return ERR_CONNECTION_CLOSED; |
475 } | 487 } |
476 | 488 |
477 if (GetNumOpenOutgoingStreams() < max_open_outgoing_streams()) { | 489 if (GetNumOpenOutgoingStreams() < max_open_outgoing_streams()) { |
478 *stream = CreateOutgoingReliableStreamImpl(); | 490 request->stream_ = CreateOutgoingReliableStreamImpl(); |
479 return OK; | 491 return OK; |
480 } | 492 } |
481 | 493 |
482 request->pending_start_time_ = base::TimeTicks::Now(); | 494 request->pending_start_time_ = base::TimeTicks::Now(); |
483 stream_requests_.push_back(request); | 495 stream_requests_.push_back(request); |
484 UMA_HISTOGRAM_COUNTS_1000("Net.QuicSession.NumPendingStreamRequests", | 496 UMA_HISTOGRAM_COUNTS_1000("Net.QuicSession.NumPendingStreamRequests", |
485 stream_requests_.size()); | 497 stream_requests_.size()); |
486 return ERR_IO_PENDING; | 498 return ERR_IO_PENDING; |
487 } | 499 } |
488 | 500 |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 } | 1493 } |
1482 | 1494 |
1483 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { | 1495 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { |
1484 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's | 1496 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's |
1485 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and | 1497 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and |
1486 // unacked packet map. | 1498 // unacked packet map. |
1487 return base::trace_event::EstimateMemoryUsage(packet_readers_); | 1499 return base::trace_event::EstimateMemoryUsage(packet_readers_); |
1488 } | 1500 } |
1489 | 1501 |
1490 } // namespace net | 1502 } // namespace net |
OLD | NEW |