Add explicit |forceOnlineSignin| to user pod status
[chromium-blink-merge.git] / net / quic / quic_reliable_client_stream.cc
blob996a5c5612b3dbad1b8f47d5673a122a3a4a98ce
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"
12 namespace net {
14 QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id,
15 QuicSession* session,
16 const BoundNetLog& net_log)
17 : QuicDataStream(id, session),
18 net_log_(net_log),
19 delegate_(NULL) {
22 QuicReliableClientStream::~QuicReliableClientStream() {
23 if (delegate_)
24 delegate_->OnClose(connection_error());
27 uint32 QuicReliableClientStream::ProcessData(const char* data,
28 uint32 data_len) {
29 // TODO(rch): buffer data if we don't have a delegate.
30 if (!delegate_)
31 return ERR_ABORTED;
33 int rv = delegate_->OnDataReceived(data, data_len);
34 if (rv != OK) {
35 DLOG(ERROR) << "Delegate refused data, rv: " << rv;
36 Reset(QUIC_BAD_APPLICATION_PAYLOAD);
37 return 0;
39 return data_len;
42 void QuicReliableClientStream::OnFinRead() {
43 if (delegate_) {
44 delegate_->OnClose(connection_error());
45 delegate_ = NULL;
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,
67 bool fin,
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()) {
74 return OK;
77 callback_ = callback;
78 return ERR_IO_PENDING;
81 void QuicReliableClientStream::SetDelegate(
82 QuicReliableClientStream::Delegate* delegate) {
83 DCHECK((!delegate_ && delegate) || (delegate_ && !delegate));
84 delegate_ = delegate;
87 void QuicReliableClientStream::OnError(int error) {
88 if (delegate_) {
89 QuicReliableClientStream::Delegate* delegate = delegate_;
90 delegate_ = NULL;
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);
99 if (!can_write) {
100 session()->MarkWriteBlocked(id(), EffectivePriority());
101 DCHECK(callback_.is_null());
102 callback_ = callback;
104 return can_write;
107 } // namespace net