| 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_chromium_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_chromium_client_session.h" | 12 #include "net/quic/quic_chromium_client_session.h" |
| 13 #include "net/quic/quic_http_utils.h" |
| 13 #include "net/quic/quic_spdy_session.h" | 14 #include "net/quic/quic_spdy_session.h" |
| 14 #include "net/quic/quic_write_blocked_list.h" | 15 #include "net/quic/quic_write_blocked_list.h" |
| 15 #include "net/quic/spdy_utils.h" | 16 #include "net/quic/spdy_utils.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 QuicChromiumClientStream::QuicChromiumClientStream( | 20 QuicChromiumClientStream::QuicChromiumClientStream( |
| 20 QuicStreamId id, | 21 QuicStreamId id, |
| 21 QuicClientSessionBase* session, | 22 QuicClientSessionBase* session, |
| 22 const BoundNetLog& net_log) | 23 const BoundNetLog& net_log) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 98 } |
| 98 | 99 |
| 99 void QuicChromiumClientStream::OnCanWrite() { | 100 void QuicChromiumClientStream::OnCanWrite() { |
| 100 ReliableQuicStream::OnCanWrite(); | 101 ReliableQuicStream::OnCanWrite(); |
| 101 | 102 |
| 102 if (!HasBufferedData() && !callback_.is_null()) { | 103 if (!HasBufferedData() && !callback_.is_null()) { |
| 103 base::ResetAndReturn(&callback_).Run(OK); | 104 base::ResetAndReturn(&callback_).Run(OK); |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| 108 size_t QuicChromiumClientStream::WriteHeaders( |
| 109 const SpdyHeaderBlock& header_block, |
| 110 bool fin, |
| 111 QuicAckListenerInterface* ack_notifier_delegate) { |
| 112 net_log_.AddEvent( |
| 113 NetLog::TYPE_QUIC_CHROMIUM_CLIENT_STREAM_SEND_REQUEST_HEADERS, |
| 114 base::Bind(&QuicRequestNetLogCallback, id(), &header_block, |
| 115 QuicSpdyStream::priority())); |
| 116 return QuicSpdyStream::WriteHeaders(header_block, fin, ack_notifier_delegate); |
| 117 } |
| 118 |
| 107 SpdyPriority QuicChromiumClientStream::priority() const { | 119 SpdyPriority QuicChromiumClientStream::priority() const { |
| 108 if (delegate_ && delegate_->HasSendHeadersComplete()) { | 120 if (delegate_ && delegate_->HasSendHeadersComplete()) { |
| 109 return QuicSpdyStream::priority(); | 121 return QuicSpdyStream::priority(); |
| 110 } | 122 } |
| 111 return net::kV3HighestPriority; | 123 return net::kV3HighestPriority; |
| 112 } | 124 } |
| 113 | 125 |
| 114 int QuicChromiumClientStream::WriteStreamData( | 126 int QuicChromiumClientStream::WriteStreamData( |
| 115 base::StringPiece data, | 127 base::StringPiece data, |
| 116 bool fin, | 128 bool fin, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 base::Bind(&QuicChromiumClientStream::NotifyDelegateOfHeadersComplete, | 192 base::Bind(&QuicChromiumClientStream::NotifyDelegateOfHeadersComplete, |
| 181 weak_factory_.GetWeakPtr(), headers, frame_len)); | 193 weak_factory_.GetWeakPtr(), headers, frame_len)); |
| 182 } | 194 } |
| 183 | 195 |
| 184 void QuicChromiumClientStream::NotifyDelegateOfHeadersComplete( | 196 void QuicChromiumClientStream::NotifyDelegateOfHeadersComplete( |
| 185 SpdyHeaderBlock headers, | 197 SpdyHeaderBlock headers, |
| 186 size_t frame_len) { | 198 size_t frame_len) { |
| 187 if (!delegate_) | 199 if (!delegate_) |
| 188 return; | 200 return; |
| 189 // Only mark trailers consumed when we are about to notify delegate. | 201 // Only mark trailers consumed when we are about to notify delegate. |
| 190 if (headers_delivered_) | 202 if (headers_delivered_) { |
| 191 MarkTrailersConsumed(decompressed_trailers().length()); | 203 MarkTrailersConsumed(decompressed_trailers().length()); |
| 204 net_log_.AddEvent( |
| 205 NetLog::TYPE_QUIC_CHROMIUM_CLIENT_STREAM_READ_RESPONSE_TRAILERS, |
| 206 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); |
| 207 } else { |
| 208 headers_delivered_ = true; |
| 209 net_log_.AddEvent( |
| 210 NetLog::TYPE_QUIC_CHROMIUM_CLIENT_STREAM_READ_RESPONSE_HEADERS, |
| 211 base::Bind(&SpdyHeaderBlockNetLogCallback, &headers)); |
| 212 } |
| 192 | 213 |
| 193 headers_delivered_ = true; | |
| 194 delegate_->OnHeadersAvailable(headers, frame_len); | 214 delegate_->OnHeadersAvailable(headers, frame_len); |
| 195 } | 215 } |
| 196 | 216 |
| 197 void QuicChromiumClientStream::NotifyDelegateOfDataAvailableLater() { | 217 void QuicChromiumClientStream::NotifyDelegateOfDataAvailableLater() { |
| 198 RunOrBuffer( | 218 RunOrBuffer( |
| 199 base::Bind(&QuicChromiumClientStream::NotifyDelegateOfDataAvailable, | 219 base::Bind(&QuicChromiumClientStream::NotifyDelegateOfDataAvailable, |
| 200 weak_factory_.GetWeakPtr())); | 220 weak_factory_.GetWeakPtr())); |
| 201 } | 221 } |
| 202 | 222 |
| 203 void QuicChromiumClientStream::NotifyDelegateOfDataAvailable() { | 223 void QuicChromiumClientStream::NotifyDelegateOfDataAvailable() { |
| 204 if (delegate_) | 224 if (delegate_) |
| 205 delegate_->OnDataAvailable(); | 225 delegate_->OnDataAvailable(); |
| 206 } | 226 } |
| 207 | 227 |
| 208 void QuicChromiumClientStream::RunOrBuffer(base::Closure closure) { | 228 void QuicChromiumClientStream::RunOrBuffer(base::Closure closure) { |
| 209 if (delegate_) { | 229 if (delegate_) { |
| 210 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); | 230 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, closure); |
| 211 } else { | 231 } else { |
| 212 delegate_tasks_.push_back(closure); | 232 delegate_tasks_.push_back(closure); |
| 213 } | 233 } |
| 214 } | 234 } |
| 215 | 235 |
| 216 void QuicChromiumClientStream::DisableConnectionMigration() { | 236 void QuicChromiumClientStream::DisableConnectionMigration() { |
| 217 can_migrate_ = false; | 237 can_migrate_ = false; |
| 218 } | 238 } |
| 219 | 239 |
| 220 } // namespace net | 240 } // namespace net |
| OLD | NEW |