Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: net/quic/quic_chromium_client_stream.cc

Issue 1581283002: Rename chromium-specific QUIC classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_chromium_client_stream.h ('k') | net/quic/quic_chromium_client_stream_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_chromium_client_stream.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/quic/quic_spdy_session.h" 12 #include "net/quic/quic_spdy_session.h"
13 #include "net/quic/quic_write_blocked_list.h" 13 #include "net/quic/quic_write_blocked_list.h"
14 #include "net/quic/spdy_utils.h" 14 #include "net/quic/spdy_utils.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 QuicReliableClientStream::QuicReliableClientStream(QuicStreamId id, 18 QuicChromiumClientStream::QuicChromiumClientStream(QuicStreamId id,
19 QuicSpdySession* session, 19 QuicSpdySession* session,
20 const BoundNetLog& net_log) 20 const BoundNetLog& net_log)
21 : QuicSpdyStream(id, session), 21 : QuicSpdyStream(id, session),
22 net_log_(net_log), 22 net_log_(net_log),
23 delegate_(nullptr), 23 delegate_(nullptr),
24 headers_delivered_(false), 24 headers_delivered_(false),
25 weak_factory_(this) {} 25 weak_factory_(this) {}
26 26
27 QuicReliableClientStream::~QuicReliableClientStream() { 27 QuicChromiumClientStream::~QuicChromiumClientStream() {
28 if (delegate_) 28 if (delegate_)
29 delegate_->OnClose(connection_error()); 29 delegate_->OnClose(connection_error());
30 } 30 }
31 31
32 void QuicReliableClientStream::OnStreamHeadersComplete(bool fin, 32 void QuicChromiumClientStream::OnStreamHeadersComplete(bool fin,
33 size_t frame_len) { 33 size_t frame_len) {
34 QuicSpdyStream::OnStreamHeadersComplete(fin, frame_len); 34 QuicSpdyStream::OnStreamHeadersComplete(fin, frame_len);
35 // The delegate will read the headers via a posted task. 35 // The delegate will read the headers via a posted task.
36 NotifyDelegateOfHeadersCompleteLater(frame_len); 36 NotifyDelegateOfHeadersCompleteLater(frame_len);
37 } 37 }
38 38
39 void QuicReliableClientStream::OnDataAvailable() { 39 void QuicChromiumClientStream::OnDataAvailable() {
40 // TODO(rch): buffer data if we don't have a delegate. 40 // TODO(rch): buffer data if we don't have a delegate.
41 if (!delegate_) { 41 if (!delegate_) {
42 DLOG(ERROR) << "Missing delegate"; 42 DLOG(ERROR) << "Missing delegate";
43 Reset(QUIC_STREAM_CANCELLED); 43 Reset(QUIC_STREAM_CANCELLED);
44 return; 44 return;
45 } 45 }
46 46
47 if (!FinishedReadingHeaders() || !headers_delivered_) { 47 if (!FinishedReadingHeaders() || !headers_delivered_) {
48 // Buffer the data in the sequencer until the headers have been read. 48 // Buffer the data in the sequencer until the headers have been read.
49 return; 49 return;
50 } 50 }
51 51
52 // The delegate will read the data via a posted task, and 52 // The delegate will read the data via a posted task, and
53 // will be able to, potentially, read all data which has queued up. 53 // will be able to, potentially, read all data which has queued up.
54 NotifyDelegateOfDataAvailableLater(); 54 NotifyDelegateOfDataAvailableLater();
55 } 55 }
56 56
57 void QuicReliableClientStream::OnClose() { 57 void QuicChromiumClientStream::OnClose() {
58 if (delegate_) { 58 if (delegate_) {
59 delegate_->OnClose(connection_error()); 59 delegate_->OnClose(connection_error());
60 delegate_ = nullptr; 60 delegate_ = nullptr;
61 } 61 }
62 ReliableQuicStream::OnClose(); 62 ReliableQuicStream::OnClose();
63 } 63 }
64 64
65 void QuicReliableClientStream::OnCanWrite() { 65 void QuicChromiumClientStream::OnCanWrite() {
66 ReliableQuicStream::OnCanWrite(); 66 ReliableQuicStream::OnCanWrite();
67 67
68 if (!HasBufferedData() && !callback_.is_null()) { 68 if (!HasBufferedData() && !callback_.is_null()) {
69 base::ResetAndReturn(&callback_).Run(OK); 69 base::ResetAndReturn(&callback_).Run(OK);
70 } 70 }
71 } 71 }
72 72
73 SpdyPriority QuicReliableClientStream::Priority() const { 73 SpdyPriority QuicChromiumClientStream::Priority() const {
74 if (delegate_ && delegate_->HasSendHeadersComplete()) { 74 if (delegate_ && delegate_->HasSendHeadersComplete()) {
75 return QuicSpdyStream::Priority(); 75 return QuicSpdyStream::Priority();
76 } 76 }
77 return net::kV3HighestPriority; 77 return net::kV3HighestPriority;
78 } 78 }
79 79
80 int QuicReliableClientStream::WriteStreamData( 80 int QuicChromiumClientStream::WriteStreamData(
81 base::StringPiece data, 81 base::StringPiece data,
82 bool fin, 82 bool fin,
83 const CompletionCallback& callback) { 83 const CompletionCallback& callback) {
84 // We should not have data buffered. 84 // We should not have data buffered.
85 DCHECK(!HasBufferedData()); 85 DCHECK(!HasBufferedData());
86 // Writes the data, or buffers it. 86 // Writes the data, or buffers it.
87 WriteOrBufferData(data, fin, nullptr); 87 WriteOrBufferData(data, fin, nullptr);
88 if (!HasBufferedData()) { 88 if (!HasBufferedData()) {
89 return OK; 89 return OK;
90 } 90 }
91 91
92 callback_ = callback; 92 callback_ = callback;
93 return ERR_IO_PENDING; 93 return ERR_IO_PENDING;
94 } 94 }
95 95
96 void QuicReliableClientStream::SetDelegate( 96 void QuicChromiumClientStream::SetDelegate(
97 QuicReliableClientStream::Delegate* delegate) { 97 QuicChromiumClientStream::Delegate* delegate) {
98 DCHECK(!(delegate_ && delegate)); 98 DCHECK(!(delegate_ && delegate));
99 delegate_ = delegate; 99 delegate_ = delegate;
100 if (delegate == nullptr && sequencer()->IsClosed()) { 100 if (delegate == nullptr && sequencer()->IsClosed()) {
101 OnFinRead(); 101 OnFinRead();
102 } 102 }
103 } 103 }
104 104
105 void QuicReliableClientStream::OnError(int error) { 105 void QuicChromiumClientStream::OnError(int error) {
106 if (delegate_) { 106 if (delegate_) {
107 QuicReliableClientStream::Delegate* delegate = delegate_; 107 QuicChromiumClientStream::Delegate* delegate = delegate_;
108 delegate_ = nullptr; 108 delegate_ = nullptr;
109 delegate->OnError(error); 109 delegate->OnError(error);
110 } 110 }
111 } 111 }
112 112
113 int QuicReliableClientStream::Read(IOBuffer* buf, int buf_len) { 113 int QuicChromiumClientStream::Read(IOBuffer* buf, int buf_len) {
114 if (sequencer()->IsClosed()) 114 if (sequencer()->IsClosed())
115 return 0; // EOF 115 return 0; // EOF
116 116
117 if (!HasBytesToRead()) 117 if (!HasBytesToRead())
118 return ERR_IO_PENDING; 118 return ERR_IO_PENDING;
119 119
120 iovec iov; 120 iovec iov;
121 iov.iov_base = buf->data(); 121 iov.iov_base = buf->data();
122 iov.iov_len = buf_len; 122 iov.iov_len = buf_len;
123 return Readv(&iov, 1); 123 return Readv(&iov, 1);
124 } 124 }
125 125
126 bool QuicReliableClientStream::CanWrite(const CompletionCallback& callback) { 126 bool QuicChromiumClientStream::CanWrite(const CompletionCallback& callback) {
127 bool can_write = session()->connection()->CanWrite(HAS_RETRANSMITTABLE_DATA); 127 bool can_write = session()->connection()->CanWrite(HAS_RETRANSMITTABLE_DATA);
128 if (!can_write) { 128 if (!can_write) {
129 session()->MarkConnectionLevelWriteBlocked(id(), Priority()); 129 session()->MarkConnectionLevelWriteBlocked(id(), Priority());
130 DCHECK(callback_.is_null()); 130 DCHECK(callback_.is_null());
131 callback_ = callback; 131 callback_ = callback;
132 } 132 }
133 return can_write; 133 return can_write;
134 } 134 }
135 135
136 void QuicReliableClientStream::NotifyDelegateOfHeadersCompleteLater( 136 void QuicChromiumClientStream::NotifyDelegateOfHeadersCompleteLater(
137 size_t frame_len) { 137 size_t frame_len) {
138 DCHECK(delegate_); 138 DCHECK(delegate_);
139 base::ThreadTaskRunnerHandle::Get()->PostTask( 139 base::ThreadTaskRunnerHandle::Get()->PostTask(
140 FROM_HERE, 140 FROM_HERE,
141 base::Bind(&QuicReliableClientStream::NotifyDelegateOfHeadersComplete, 141 base::Bind(&QuicChromiumClientStream::NotifyDelegateOfHeadersComplete,
142 weak_factory_.GetWeakPtr(), frame_len)); 142 weak_factory_.GetWeakPtr(), frame_len));
143 } 143 }
144 144
145 void QuicReliableClientStream::NotifyDelegateOfHeadersComplete( 145 void QuicChromiumClientStream::NotifyDelegateOfHeadersComplete(
146 size_t frame_len) { 146 size_t frame_len) {
147 if (!delegate_) 147 if (!delegate_)
148 return; 148 return;
149 149
150 size_t headers_len = decompressed_headers().length(); 150 size_t headers_len = decompressed_headers().length();
151 SpdyHeaderBlock headers; 151 SpdyHeaderBlock headers;
152 SpdyFramer framer(HTTP2); 152 SpdyFramer framer(HTTP2);
153 if (!framer.ParseHeaderBlockInBuffer(decompressed_headers().data(), 153 if (!framer.ParseHeaderBlockInBuffer(decompressed_headers().data(),
154 headers_len, &headers)) { 154 headers_len, &headers)) {
155 DLOG(WARNING) << "Invalid headers"; 155 DLOG(WARNING) << "Invalid headers";
156 Reset(QUIC_BAD_APPLICATION_PAYLOAD); 156 Reset(QUIC_BAD_APPLICATION_PAYLOAD);
157 return; 157 return;
158 } 158 }
159 MarkHeadersConsumed(headers_len); 159 MarkHeadersConsumed(headers_len);
160 headers_delivered_ = true; 160 headers_delivered_ = true;
161 161
162 delegate_->OnHeadersAvailable(headers, frame_len); 162 delegate_->OnHeadersAvailable(headers, frame_len);
163 } 163 }
164 164
165 void QuicReliableClientStream::NotifyDelegateOfDataAvailableLater() { 165 void QuicChromiumClientStream::NotifyDelegateOfDataAvailableLater() {
166 DCHECK(delegate_); 166 DCHECK(delegate_);
167 base::ThreadTaskRunnerHandle::Get()->PostTask( 167 base::ThreadTaskRunnerHandle::Get()->PostTask(
168 FROM_HERE, 168 FROM_HERE,
169 base::Bind(&QuicReliableClientStream::NotifyDelegateOfDataAvailable, 169 base::Bind(&QuicChromiumClientStream::NotifyDelegateOfDataAvailable,
170 weak_factory_.GetWeakPtr())); 170 weak_factory_.GetWeakPtr()));
171 } 171 }
172 172
173 void QuicReliableClientStream::NotifyDelegateOfDataAvailable() { 173 void QuicChromiumClientStream::NotifyDelegateOfDataAvailable() {
174 if (delegate_) 174 if (delegate_)
175 delegate_->OnDataAvailable(); 175 delegate_->OnDataAvailable();
176 } 176 }
177 177
178 } // namespace net 178 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_chromium_client_stream.h ('k') | net/quic/quic_chromium_client_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698