Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / quic / quic_reliable_client_stream.cc
blob70259060f8f352fde2f513fa97a5cd428457d20f
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_spdy_session.h"
10 #include "net/quic/quic_write_blocked_list.h"
12 namespace net {
14 QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id,
15 QuicSpdySession* session,
16 const BoundNetLog& net_log)
17 : QuicDataStream(id, session), net_log_(net_log), delegate_(nullptr) {
20 QuicReliableClientStream::~QuicReliableClientStream() {
21 if (delegate_)
22 delegate_->OnClose(connection_error());
25 void QuicReliableClientStream::OnStreamHeadersComplete(bool fin,
26 size_t frame_len) {
27 QuicDataStream::OnStreamHeadersComplete(fin, frame_len);
28 if (delegate_) {
29 delegate_->OnHeadersAvailable(decompressed_headers());
30 MarkHeadersConsumed(decompressed_headers().length());
34 uint32 QuicReliableClientStream::ProcessData(const char* data,
35 uint32 data_len) {
36 // TODO(rch): buffer data if we don't have a delegate.
37 if (!delegate_) {
38 DLOG(ERROR) << "Missing delegate";
39 Reset(QUIC_STREAM_CANCELLED);
40 return 0;
43 if (!FinishedReadingHeaders()) {
44 // Buffer the data in the sequencer until the headers have been read.
45 return 0;
48 int rv = delegate_->OnDataReceived(data, data_len);
49 if (rv != OK) {
50 DLOG(ERROR) << "Delegate refused data, rv: " << rv;
51 Reset(QUIC_BAD_APPLICATION_PAYLOAD);
52 return 0;
54 return data_len;
57 void QuicReliableClientStream::OnClose() {
58 if (delegate_) {
59 delegate_->OnClose(connection_error());
60 delegate_ = nullptr;
62 ReliableQuicStream::OnClose();
65 void QuicReliableClientStream::OnCanWrite() {
66 ReliableQuicStream::OnCanWrite();
68 if (!HasBufferedData() && !callback_.is_null()) {
69 base::ResetAndReturn(&callback_).Run(OK);
73 QuicPriority QuicReliableClientStream::EffectivePriority() const {
74 if (delegate_ && delegate_->HasSendHeadersComplete()) {
75 return QuicDataStream::EffectivePriority();
77 return QuicWriteBlockedList::kHighestPriority;
80 int QuicReliableClientStream::WriteStreamData(
81 base::StringPiece data,
82 bool fin,
83 const CompletionCallback& callback) {
84 // We should not have data buffered.
85 DCHECK(!HasBufferedData());
86 // Writes the data, or buffers it.
87 WriteOrBufferData(data, fin, nullptr);
88 if (!HasBufferedData()) {
89 return OK;
92 callback_ = callback;
93 return ERR_IO_PENDING;
96 void QuicReliableClientStream::SetDelegate(
97 QuicReliableClientStream::Delegate* delegate) {
98 DCHECK(!(delegate_ && delegate));
99 delegate_ = delegate;
102 void QuicReliableClientStream::OnError(int error) {
103 if (delegate_) {
104 QuicReliableClientStream::Delegate* delegate = delegate_;
105 delegate_ = nullptr;
106 delegate->OnError(error);
110 bool QuicReliableClientStream::CanWrite(const CompletionCallback& callback) {
111 bool can_write = session()->connection()->CanWrite(HAS_RETRANSMITTABLE_DATA);
112 if (!can_write) {
113 session()->MarkConnectionLevelWriteBlocked(id(), EffectivePriority());
114 DCHECK(callback_.is_null());
115 callback_ = callback;
117 return can_write;
120 } // namespace net