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/quic_reliable_client_stream.h" | 5 #include "net/quic/quic_reliable_client_stream.h" |
6 | 6 |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/quic/quic_session.h" |
8 | 9 |
9 namespace net { | 10 namespace net { |
10 | 11 |
11 QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id, | 12 QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id, |
12 QuicSession* session) | 13 QuicSession* session) |
13 : ReliableQuicStream(id, session) { | 14 : ReliableQuicStream(id, session), |
| 15 delegate_(NULL) { |
14 } | 16 } |
15 | 17 |
16 QuicReliableClientStream::~QuicReliableClientStream() { | 18 QuicReliableClientStream::~QuicReliableClientStream() { |
| 19 if (delegate_) { |
| 20 delegate_->OnClose(error()); |
| 21 } |
17 } | 22 } |
18 | 23 |
19 uint32 QuicReliableClientStream::ProcessData(const char* data, | 24 uint32 QuicReliableClientStream::ProcessData(const char* data, |
20 uint32 data_len) { | 25 uint32 data_len) { |
| 26 // TODO(rch): buffer data if we don't have a delegate. |
| 27 DCHECK(delegate_); |
21 int rv = delegate_->OnDataReceived(data, data_len); | 28 int rv = delegate_->OnDataReceived(data, data_len); |
22 if (rv != OK) { | 29 if (rv != OK) { |
23 DLOG(ERROR) << "Delegate refused data, rv: " << rv; | 30 DLOG(ERROR) << "Delegate refused data, rv: " << rv; |
24 Close(QUIC_BAD_APPLICATION_PAYLOAD); | 31 Close(QUIC_BAD_APPLICATION_PAYLOAD); |
25 return 0; | 32 return 0; |
26 } | 33 } |
27 return data_len; | 34 return data_len; |
28 } | 35 } |
29 | 36 |
30 void QuicReliableClientStream::TerminateFromPeer(bool half_close) { | 37 void QuicReliableClientStream::TerminateFromPeer(bool half_close) { |
31 delegate_->OnClose(error()); | 38 if (delegate_) { |
| 39 delegate_->OnClose(error()); |
| 40 delegate_ = NULL; |
| 41 } |
32 } | 42 } |
33 | 43 |
34 void QuicReliableClientStream::SetDelegate( | 44 void QuicReliableClientStream::SetDelegate( |
35 QuicReliableClientStream::Delegate* delegate) { | 45 QuicReliableClientStream::Delegate* delegate) { |
| 46 DCHECK((!delegate_ && delegate) || (delegate_ && !delegate)); |
36 delegate_ = delegate; | 47 delegate_ = delegate; |
37 } | 48 } |
38 | 49 |
39 } // namespace net | 50 } // namespace net |
OLD | NEW |