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
3 // found in the LICENSE file.
5 #include "net/quic/quic_reliable_client_stream.h"
7 #include "base/callback_helpers.h"
8 #include "net/base/net_errors.h"
9 #include "net/quic/quic_session.h"
10 #include "net/quic/quic_write_blocked_list.h"
14 QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id
,
16 const BoundNetLog
& net_log
)
17 : QuicDataStream(id
, session
),
22 QuicReliableClientStream::~QuicReliableClientStream() {
24 delegate_
->OnClose(connection_error());
27 uint32
QuicReliableClientStream::ProcessData(const char* data
,
29 // TODO(rch): buffer data if we don't have a delegate.
33 int rv
= delegate_
->OnDataReceived(data
, data_len
);
35 DLOG(ERROR
) << "Delegate refused data, rv: " << rv
;
36 Reset(QUIC_BAD_APPLICATION_PAYLOAD
);
42 void QuicReliableClientStream::OnFinRead() {
44 delegate_
->OnClose(connection_error());
47 ReliableQuicStream::OnFinRead();
50 void QuicReliableClientStream::OnCanWrite() {
51 ReliableQuicStream::OnCanWrite();
53 if (!HasBufferedData() && !callback_
.is_null()) {
54 base::ResetAndReturn(&callback_
).Run(OK
);
58 QuicPriority
QuicReliableClientStream::EffectivePriority() const {
59 if (delegate_
&& delegate_
->HasSendHeadersComplete()) {
60 return QuicDataStream::EffectivePriority();
62 return QuicWriteBlockedList::kHighestPriority
;
65 int QuicReliableClientStream::WriteStreamData(
66 base::StringPiece data
,
68 const CompletionCallback
& callback
) {
69 // We should not have data buffered.
70 DCHECK(!HasBufferedData());
71 // Writes the data, or buffers it.
72 WriteOrBufferData(data
, fin
);
73 if (!HasBufferedData()) {
78 return ERR_IO_PENDING
;
81 void QuicReliableClientStream::SetDelegate(
82 QuicReliableClientStream::Delegate
* delegate
) {
83 DCHECK((!delegate_
&& delegate
) || (delegate_
&& !delegate
));
87 void QuicReliableClientStream::OnError(int error
) {
89 QuicReliableClientStream::Delegate
* delegate
= delegate_
;
91 delegate
->OnError(error
);
95 bool QuicReliableClientStream::CanWrite(const CompletionCallback
& callback
) {
96 bool can_write
= session()->connection()->CanWrite(
97 NOT_RETRANSMISSION
, HAS_RETRANSMITTABLE_DATA
,
98 id() == kCryptoStreamId
? IS_HANDSHAKE
: NOT_HANDSHAKE
);
100 session()->MarkWriteBlocked(id(), EffectivePriority());
101 DCHECK(callback_
.is_null());
102 callback_
= callback
;