Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #include "net/http/http_pipelined_connection_impl.h" | |
| 6 | |
| 7 #include "base/message_loop.h" | |
| 8 #include "base/stl_util.h" | |
| 9 #include "net/base/io_buffer.h" | |
| 10 #include "net/http/http_pipelined_stream.h" | |
| 11 #include "net/http/http_request_info.h" | |
| 12 #include "net/http/http_stream_parser.h" | |
| 13 #include "net/socket/client_socket_handle.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 HttpPipelinedConnectionImpl::HttpPipelinedConnectionImpl( | |
| 18 ClientSocketHandle* connection, | |
| 19 HttpPipelinedConnection::Delegate* delegate, | |
| 20 const SSLConfig& used_ssl_config, | |
| 21 const ProxyInfo& used_proxy_info, | |
| 22 const BoundNetLog& net_log, | |
| 23 bool was_npn_negotiated) | |
| 24 : delegate_(delegate), | |
| 25 connection_(connection), | |
| 26 used_ssl_config_(used_ssl_config), | |
| 27 used_proxy_info_(used_proxy_info), | |
| 28 net_log_(net_log), | |
| 29 was_npn_negotiated_(was_npn_negotiated), | |
| 30 read_buf_(new GrowableIOBuffer()), | |
| 31 next_pipeline_id_(1), | |
| 32 active_(false), | |
| 33 usable_(true), | |
| 34 completed_one_request_(false), | |
| 35 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | |
| 36 send_next_state_(SEND_STATE_NONE), | |
| 37 ALLOW_THIS_IN_INITIALIZER_LIST(send_io_callback_( | |
| 38 this, &HttpPipelinedConnectionImpl::OnSendIOCallback)), | |
| 39 send_user_callback_(NULL), | |
| 40 read_next_state_(READ_STATE_NONE), | |
| 41 ALLOW_THIS_IN_INITIALIZER_LIST(read_io_callback_( | |
| 42 this, &HttpPipelinedConnectionImpl::OnReadIOCallback)), | |
| 43 read_user_callback_(NULL) { | |
| 44 DCHECK(connection_.get()); | |
| 45 } | |
| 46 | |
| 47 HttpPipelinedConnectionImpl::~HttpPipelinedConnectionImpl() { | |
| 48 DCHECK(depth() == 0); | |
|
willchan no longer on Chromium
2011/09/29 19:32:48
DCHECK_EQ?
| |
| 49 DCHECK(parser_map_.empty()); | |
| 50 DCHECK(callback_map_.empty()); | |
| 51 DCHECK(deferred_request_queue_.empty()); | |
| 52 DCHECK(request_order_.empty()); | |
| 53 DCHECK_EQ(send_next_state_, SEND_STATE_NONE); | |
| 54 DCHECK_EQ(read_next_state_, READ_STATE_NONE); | |
| 55 DCHECK(!send_user_callback_); | |
| 56 DCHECK(!read_user_callback_); | |
| 57 if (!usable_) { | |
| 58 connection_->socket()->Disconnect(); | |
| 59 } | |
| 60 connection_->Reset(); | |
| 61 } | |
| 62 | |
| 63 HttpStream* HttpPipelinedConnectionImpl::CreateNewStream() { | |
| 64 int pipeline_id = next_pipeline_id_++; | |
| 65 DCHECK(pipeline_id); | |
| 66 HttpPipelinedStream* stream = new HttpPipelinedStream(this, pipeline_id); | |
| 67 stream_state_map_.insert(std::make_pair(pipeline_id, STREAM_CREATED)); | |
| 68 return stream; | |
| 69 } | |
| 70 | |
| 71 void HttpPipelinedConnectionImpl::InitializeParser( | |
| 72 int pipeline_id, | |
| 73 const HttpRequestInfo* request, | |
| 74 const BoundNetLog& net_log) { | |
| 75 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 76 DCHECK(!ContainsKey(parser_map_, pipeline_id)); | |
| 77 stream_state_map_[pipeline_id] = STREAM_BOUND; | |
| 78 HttpStreamParser* parser = new HttpStreamParser(connection_.get(), | |
| 79 request, | |
| 80 read_buf_.get(), | |
| 81 net_log); | |
| 82 parser_map_.insert(std::make_pair(pipeline_id, parser)); | |
| 83 if (!active_) { | |
| 84 active_ = true; | |
| 85 MessageLoop::current()->PostTask( | |
| 86 FROM_HERE, | |
| 87 method_factory_.NewRunnableMethod( | |
| 88 &HttpPipelinedConnectionImpl::FillPipeline)); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 void HttpPipelinedConnectionImpl::FillPipeline() { | |
| 93 delegate_->OnPipelineHasCapacity(this); | |
| 94 } | |
| 95 | |
| 96 void HttpPipelinedConnectionImpl::OnStreamDeleted(int pipeline_id) { | |
| 97 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 98 Close(pipeline_id, false); | |
| 99 DCHECK(!ContainsKey(callback_map_, pipeline_id)); | |
| 100 | |
| 101 if (stream_state_map_[pipeline_id] != STREAM_CREATED && | |
| 102 stream_state_map_[pipeline_id] != STREAM_UNUSED) { | |
| 103 DCHECK_EQ(stream_state_map_[pipeline_id], STREAM_CLOSED); | |
| 104 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 105 | |
| 106 ParserMap::iterator it = parser_map_.find(pipeline_id); | |
| 107 delete it->second; | |
| 108 parser_map_.erase(it); | |
| 109 } | |
| 110 DCHECK(!ContainsKey(parser_map_, pipeline_id)); | |
| 111 stream_state_map_.erase(pipeline_id); | |
| 112 | |
| 113 MessageLoop::current()->PostTask( | |
| 114 FROM_HERE, | |
| 115 method_factory_.NewRunnableMethod( | |
| 116 &HttpPipelinedConnectionImpl::FillPipeline)); | |
| 117 } | |
| 118 | |
| 119 int HttpPipelinedConnectionImpl::SendRequest(int pipeline_id, | |
| 120 const std::string& request_line, | |
| 121 const HttpRequestHeaders& headers, | |
| 122 UploadDataStream* request_body, | |
| 123 HttpResponseInfo* response, | |
| 124 CompletionCallback* callback) { | |
| 125 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 126 DCHECK_EQ(stream_state_map_[pipeline_id], STREAM_BOUND); | |
| 127 if (!usable_) { | |
| 128 return ERR_PIPELINE_EVICTION; | |
| 129 } | |
| 130 | |
| 131 DeferredSendRequest deferred_request; | |
| 132 deferred_request.pipeline_id = pipeline_id; | |
| 133 deferred_request.request_line = request_line; | |
| 134 deferred_request.headers = headers; | |
| 135 deferred_request.request_body = request_body; | |
| 136 deferred_request.response = response; | |
| 137 deferred_request.callback = callback; | |
| 138 deferred_request_queue_.push(deferred_request); | |
| 139 | |
| 140 if (send_next_state_ == SEND_STATE_NONE) { | |
| 141 send_next_state_ = SEND_STATE_NEXT_REQUEST; | |
| 142 return DoSendRequestLoop(OK); | |
| 143 } else { | |
| 144 return ERR_IO_PENDING; | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 int HttpPipelinedConnectionImpl::DoSendRequestLoop(int result) { | |
| 149 int rv = result; | |
| 150 do { | |
| 151 SendRequestState state = send_next_state_; | |
| 152 send_next_state_ = SEND_STATE_NONE; | |
| 153 switch (state) { | |
| 154 case SEND_STATE_NEXT_REQUEST: | |
| 155 rv = DoSendNextRequest(rv); | |
| 156 break; | |
| 157 case SEND_STATE_COMPLETE: | |
| 158 rv = DoSendComplete(rv); | |
| 159 break; | |
| 160 case SEND_STATE_UNUSABLE: | |
| 161 rv = DoEvictPendingSendRequests(rv); | |
| 162 break; | |
| 163 default: | |
| 164 NOTREACHED() << "bad send state: " << state; | |
| 165 rv = ERR_FAILED; | |
| 166 break; | |
| 167 } | |
| 168 } while (rv != ERR_IO_PENDING && send_next_state_ != SEND_STATE_NONE); | |
| 169 return rv; | |
| 170 } | |
| 171 | |
| 172 void HttpPipelinedConnectionImpl::OnSendIOCallback(int result) { | |
| 173 DCHECK(send_user_callback_); | |
| 174 DoSendRequestLoop(result); | |
| 175 } | |
| 176 | |
| 177 int HttpPipelinedConnectionImpl::DoSendNextRequest(int result) { | |
| 178 DCHECK(!deferred_request_queue_.empty()); | |
| 179 const DeferredSendRequest& deferred_request = deferred_request_queue_.front(); | |
| 180 DCHECK(ContainsKey(stream_state_map_, deferred_request.pipeline_id)); | |
| 181 if (stream_state_map_[deferred_request.pipeline_id] == STREAM_CLOSED) { | |
| 182 deferred_request_queue_.pop(); | |
| 183 if (deferred_request_queue_.empty()) { | |
| 184 send_next_state_ = SEND_STATE_NONE; | |
| 185 } else { | |
| 186 send_next_state_ = SEND_STATE_NEXT_REQUEST; | |
| 187 } | |
| 188 return OK; | |
| 189 } | |
| 190 DCHECK(ContainsKey(parser_map_, deferred_request.pipeline_id)); | |
| 191 int rv = parser_map_[deferred_request.pipeline_id]->SendRequest( | |
| 192 deferred_request.request_line, | |
| 193 deferred_request.headers, | |
| 194 deferred_request.request_body, | |
| 195 deferred_request.response, | |
| 196 &send_io_callback_); | |
| 197 // |result| == ERR_IO_PENDING means this function was *not* called on the same | |
| 198 // stack as SendRequest(). That means we returned ERR_IO_PENDING to | |
| 199 // SendRequest() earlier and will need to invoke its callback. | |
| 200 if (result == ERR_IO_PENDING || rv == ERR_IO_PENDING) { | |
| 201 send_user_callback_ = deferred_request.callback; | |
| 202 } | |
| 203 stream_state_map_[deferred_request.pipeline_id] = STREAM_SENDING; | |
| 204 send_next_state_ = SEND_STATE_COMPLETE; | |
| 205 return rv; | |
| 206 } | |
| 207 | |
| 208 int HttpPipelinedConnectionImpl::DoSendComplete(int result) { | |
| 209 DCHECK(!deferred_request_queue_.empty()); | |
| 210 const DeferredSendRequest& deferred_request = deferred_request_queue_.front(); | |
| 211 DCHECK_EQ(stream_state_map_[deferred_request.pipeline_id], STREAM_SENDING); | |
| 212 request_order_.push(deferred_request.pipeline_id); | |
| 213 stream_state_map_[deferred_request.pipeline_id] = STREAM_SENT; | |
| 214 deferred_request_queue_.pop(); | |
| 215 if (result == ERR_SOCKET_NOT_CONNECTED && completed_one_request_) { | |
| 216 result = ERR_PIPELINE_EVICTION; | |
| 217 } | |
| 218 if (result < OK) { | |
| 219 send_next_state_ = SEND_STATE_UNUSABLE; | |
| 220 usable_ = false; | |
| 221 } | |
| 222 if (send_user_callback_) { | |
| 223 CompletionCallback* callback = send_user_callback_; | |
| 224 send_user_callback_ = NULL; | |
| 225 callback->Run(result); | |
| 226 } | |
| 227 if (result < OK) { | |
| 228 return result; | |
| 229 } | |
| 230 if (deferred_request_queue_.empty()) { | |
| 231 send_next_state_ = SEND_STATE_NONE; | |
| 232 return OK; | |
| 233 } | |
| 234 send_next_state_ = SEND_STATE_NEXT_REQUEST; | |
| 235 MessageLoop::current()->PostTask( | |
| 236 FROM_HERE, | |
| 237 method_factory_.NewRunnableMethod( | |
| 238 &HttpPipelinedConnectionImpl::DoSendRequestLoop, | |
| 239 ERR_IO_PENDING)); | |
| 240 return ERR_IO_PENDING; // Wait for the task to fire. | |
| 241 } | |
| 242 | |
| 243 int HttpPipelinedConnectionImpl::DoEvictPendingSendRequests(int result) { | |
| 244 send_next_state_ = SEND_STATE_NONE; | |
| 245 while (!deferred_request_queue_.empty()) { | |
| 246 const DeferredSendRequest& evicted_send = deferred_request_queue_.front(); | |
| 247 if (stream_state_map_[evicted_send.pipeline_id] != STREAM_CLOSED) { | |
| 248 evicted_send.callback->Run(ERR_PIPELINE_EVICTION); | |
| 249 } | |
| 250 deferred_request_queue_.pop(); | |
| 251 } | |
| 252 return result; | |
| 253 } | |
| 254 | |
| 255 int HttpPipelinedConnectionImpl::ReadResponseHeaders( | |
| 256 int pipeline_id, | |
| 257 CompletionCallback* callback) { | |
| 258 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 259 DCHECK_EQ(stream_state_map_[pipeline_id], STREAM_SENT); | |
| 260 DCHECK(!ContainsKey(callback_map_, pipeline_id)); | |
| 261 if (!usable_) { | |
| 262 return ERR_PIPELINE_EVICTION; | |
| 263 } | |
| 264 stream_state_map_[pipeline_id] = STREAM_READ_PENDING; | |
| 265 callback_map_[pipeline_id] = callback; | |
| 266 if (read_next_state_ == READ_STATE_NONE) { | |
| 267 read_next_state_ = READ_STATE_NEXT_HEADERS; | |
| 268 return DoReadHeadersLoop(OK); | |
| 269 } else { | |
| 270 return ERR_IO_PENDING; | |
| 271 } | |
| 272 } | |
| 273 | |
| 274 int HttpPipelinedConnectionImpl::DoReadHeadersLoop(int result) { | |
| 275 int rv = result; | |
| 276 do { | |
| 277 ReadHeadersState state = read_next_state_; | |
| 278 read_next_state_ = READ_STATE_NONE; | |
| 279 switch (state) { | |
| 280 case READ_STATE_NEXT_HEADERS: | |
| 281 rv = DoReadNextHeaders(rv); | |
| 282 break; | |
| 283 case READ_STATE_COMPLETE: | |
| 284 rv = DoReadHeadersComplete(rv); | |
| 285 break; | |
| 286 case READ_STATE_WAITING_FOR_CLOSE: | |
| 287 rv = DoReadWaitingForClose(rv); | |
| 288 return rv; | |
| 289 case READ_STATE_STREAM_CLOSED: | |
| 290 rv = DoReadStreamClosed(); | |
| 291 break; | |
| 292 case READ_STATE_UNUSABLE: | |
| 293 rv = DoEvictPendingReadHeaders(rv); | |
| 294 break; | |
| 295 case READ_STATE_NONE: | |
| 296 break; | |
| 297 default: | |
| 298 NOTREACHED() << "bad read state"; | |
| 299 rv = ERR_FAILED; | |
| 300 break; | |
| 301 } | |
| 302 } while (rv != ERR_IO_PENDING && read_next_state_ != READ_STATE_NONE); | |
| 303 return rv; | |
| 304 } | |
| 305 | |
| 306 void HttpPipelinedConnectionImpl::OnReadIOCallback(int result) { | |
| 307 DCHECK(read_user_callback_ != NULL); | |
| 308 DoReadHeadersLoop(result); | |
| 309 } | |
| 310 | |
| 311 int HttpPipelinedConnectionImpl::DoReadNextHeaders(int result) { | |
| 312 DCHECK(!request_order_.empty()); | |
| 313 int pipeline_id = request_order_.front(); | |
| 314 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 315 if (stream_state_map_[pipeline_id] == STREAM_CLOSED) { | |
| 316 // Since nobody will read whatever data is on the pipeline associated with | |
| 317 // this closed request, we must shut down the rest of the pipeline. | |
| 318 read_next_state_ = READ_STATE_UNUSABLE; | |
| 319 return OK; | |
| 320 } | |
| 321 CallbackMap::iterator it = callback_map_.find(pipeline_id); | |
| 322 if (it == callback_map_.end()) { | |
| 323 return ERR_IO_PENDING; | |
| 324 } | |
| 325 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 326 | |
| 327 if (result == ERR_IO_PENDING) { | |
| 328 DCHECK_EQ(stream_state_map_[pipeline_id], STREAM_ACTIVE); | |
| 329 } else { | |
| 330 DCHECK_EQ(stream_state_map_[pipeline_id], STREAM_READ_PENDING); | |
| 331 stream_state_map_[pipeline_id] = STREAM_ACTIVE; | |
| 332 } | |
| 333 | |
| 334 int rv = parser_map_[pipeline_id]->ReadResponseHeaders(&read_io_callback_); | |
| 335 if (rv == ERR_IO_PENDING) { | |
| 336 read_next_state_ = READ_STATE_COMPLETE; | |
| 337 read_user_callback_ = it->second; | |
| 338 } else if (rv < OK) { | |
| 339 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | |
| 340 if (rv == ERR_SOCKET_NOT_CONNECTED && completed_one_request_) | |
| 341 rv = ERR_PIPELINE_EVICTION; | |
| 342 } else { | |
| 343 DCHECK_LE(OK, rv); | |
| 344 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | |
| 345 } | |
| 346 | |
| 347 // |result| == ERR_IO_PENDING means this function was *not* called on the same | |
| 348 // stack as ReadResponseHeaders(). That means we returned ERR_IO_PENDING to | |
| 349 // ReadResponseHeaders() earlier and now need to invoke its callback. | |
| 350 if (rv != ERR_IO_PENDING && result == ERR_IO_PENDING) { | |
| 351 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | |
| 352 read_user_callback_ = it->second; | |
| 353 MessageLoop::current()->PostTask( | |
| 354 FROM_HERE, | |
| 355 method_factory_.NewRunnableMethod( | |
| 356 &HttpPipelinedConnectionImpl::FireReadUserCallback, | |
| 357 rv)); | |
| 358 } | |
| 359 return rv; | |
| 360 } | |
| 361 | |
| 362 int HttpPipelinedConnectionImpl::DoReadHeadersComplete(int result) { | |
| 363 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | |
| 364 if (read_user_callback_) { | |
| 365 MessageLoop::current()->PostTask( | |
| 366 FROM_HERE, | |
| 367 method_factory_.NewRunnableMethod( | |
| 368 &HttpPipelinedConnectionImpl::FireReadUserCallback, | |
| 369 result)); | |
| 370 } | |
| 371 return result; | |
| 372 } | |
| 373 | |
| 374 int HttpPipelinedConnectionImpl::DoReadWaitingForClose(int result) { | |
| 375 read_next_state_ = READ_STATE_WAITING_FOR_CLOSE; | |
| 376 return result; | |
| 377 } | |
| 378 | |
| 379 int HttpPipelinedConnectionImpl::DoReadStreamClosed() { | |
| 380 DCHECK(!request_order_.empty()); | |
| 381 int pipeline_id = request_order_.front(); | |
| 382 DCHECK(ContainsKey(callback_map_, pipeline_id)); | |
| 383 DCHECK_EQ(stream_state_map_[pipeline_id], STREAM_CLOSED); | |
| 384 callback_map_.erase(pipeline_id); | |
| 385 request_order_.pop(); | |
| 386 if (!usable_) { | |
| 387 read_next_state_ = READ_STATE_UNUSABLE; | |
| 388 return OK; | |
| 389 } else { | |
| 390 completed_one_request_ = true; | |
| 391 if (request_order_.empty() || | |
| 392 !ContainsKey(callback_map_, request_order_.front())) { | |
| 393 read_next_state_ = READ_STATE_NONE; | |
| 394 return OK; | |
| 395 } else { | |
| 396 stream_state_map_[request_order_.front()] = STREAM_ACTIVE; | |
| 397 read_next_state_ = READ_STATE_NEXT_HEADERS; | |
| 398 MessageLoop::current()->PostTask( | |
| 399 FROM_HERE, | |
| 400 method_factory_.NewRunnableMethod( | |
| 401 &HttpPipelinedConnectionImpl::DoReadHeadersLoop, | |
| 402 ERR_IO_PENDING)); | |
| 403 return ERR_IO_PENDING; // Wait for the task to fire. | |
| 404 } | |
| 405 } | |
| 406 } | |
| 407 | |
| 408 int HttpPipelinedConnectionImpl::DoEvictPendingReadHeaders(int result) { | |
| 409 while (!request_order_.empty()) { | |
| 410 int evicted_id = request_order_.front(); | |
| 411 request_order_.pop(); | |
| 412 CallbackMap::iterator cb_it = callback_map_.find(evicted_id); | |
| 413 if (cb_it == callback_map_.end()) { | |
| 414 continue; | |
| 415 } | |
| 416 if (stream_state_map_[evicted_id] != STREAM_CLOSED) { | |
| 417 cb_it->second->Run(ERR_PIPELINE_EVICTION); | |
| 418 } | |
| 419 callback_map_.erase(cb_it); | |
| 420 } | |
| 421 DCHECK(callback_map_.empty()); | |
| 422 read_next_state_ = READ_STATE_NONE; | |
| 423 return result; | |
| 424 } | |
| 425 | |
| 426 void HttpPipelinedConnectionImpl::Close(int pipeline_id, | |
| 427 bool not_reusable) { | |
| 428 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 429 switch (stream_state_map_[pipeline_id]) { | |
| 430 case STREAM_CREATED: | |
| 431 stream_state_map_[pipeline_id] = STREAM_UNUSED; | |
| 432 break; | |
| 433 | |
| 434 case STREAM_BOUND: | |
| 435 stream_state_map_[pipeline_id] = STREAM_CLOSED; | |
| 436 break; | |
| 437 | |
| 438 case STREAM_SENDING: | |
| 439 usable_ = false; | |
| 440 stream_state_map_[pipeline_id] = STREAM_CLOSED; | |
| 441 send_user_callback_ = NULL; | |
| 442 send_next_state_ = SEND_STATE_UNUSABLE; | |
| 443 DoSendRequestLoop(OK); | |
| 444 break; | |
| 445 | |
| 446 case STREAM_SENT: | |
| 447 case STREAM_READ_PENDING: | |
| 448 usable_ = false; | |
| 449 stream_state_map_[pipeline_id] = STREAM_CLOSED; | |
| 450 if (read_next_state_ == READ_STATE_NONE) { | |
| 451 read_next_state_ = READ_STATE_UNUSABLE; | |
| 452 DoReadHeadersLoop(OK); | |
| 453 } | |
| 454 break; | |
| 455 | |
| 456 case STREAM_ACTIVE: | |
| 457 stream_state_map_[pipeline_id] = STREAM_CLOSED; | |
| 458 if (not_reusable) { | |
| 459 usable_ = false; | |
| 460 } | |
| 461 read_next_state_ = READ_STATE_STREAM_CLOSED; | |
| 462 read_user_callback_ = NULL; | |
| 463 DoReadHeadersLoop(OK); | |
| 464 break; | |
| 465 | |
| 466 case STREAM_CLOSED: | |
| 467 case STREAM_UNUSED: | |
| 468 // TODO(simonjam): Why is Close() sometimes called twice? | |
| 469 break; | |
| 470 | |
| 471 default: | |
| 472 NOTREACHED(); | |
| 473 break; | |
| 474 } | |
| 475 } | |
| 476 | |
| 477 int HttpPipelinedConnectionImpl::ReadResponseBody( | |
| 478 int pipeline_id, | |
| 479 IOBuffer* buf, | |
| 480 int buf_len, | |
| 481 CompletionCallback* callback) { | |
| 482 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 483 DCHECK(!request_order_.empty()); | |
| 484 DCHECK(pipeline_id == request_order_.front()); | |
| 485 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 486 return parser_map_[pipeline_id]->ReadResponseBody(buf, buf_len, callback); | |
| 487 } | |
| 488 | |
| 489 uint64 HttpPipelinedConnectionImpl::GetUploadProgress(int pipeline_id) const { | |
| 490 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 491 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 492 return parser_map_.find(pipeline_id)->second->GetUploadProgress(); | |
| 493 } | |
| 494 | |
| 495 HttpResponseInfo* HttpPipelinedConnectionImpl::GetResponseInfo( | |
| 496 int pipeline_id) { | |
| 497 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 498 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 499 return parser_map_[pipeline_id]->GetResponseInfo(); | |
| 500 } | |
| 501 | |
| 502 bool HttpPipelinedConnectionImpl::IsResponseBodyComplete( | |
| 503 int pipeline_id) const { | |
| 504 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 505 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 506 return parser_map_.find(pipeline_id)->second->IsResponseBodyComplete(); | |
| 507 } | |
| 508 | |
| 509 bool HttpPipelinedConnectionImpl::CanFindEndOfResponse(int pipeline_id) const { | |
| 510 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 511 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 512 return parser_map_.find(pipeline_id)->second->CanFindEndOfResponse(); | |
| 513 } | |
| 514 | |
| 515 bool HttpPipelinedConnectionImpl::IsMoreDataBuffered(int pipeline_id) const { | |
| 516 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 517 return read_buf_->offset(); | |
| 518 } | |
| 519 | |
| 520 bool HttpPipelinedConnectionImpl::IsConnectionReused(int pipeline_id) const { | |
| 521 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 522 if (pipeline_id > 1) { | |
| 523 return true; | |
| 524 } | |
| 525 ClientSocketHandle::SocketReuseType reuse_type = connection_->reuse_type(); | |
| 526 return connection_->is_reused() || | |
| 527 reuse_type == ClientSocketHandle::UNUSED_IDLE; | |
| 528 } | |
| 529 | |
| 530 void HttpPipelinedConnectionImpl::SetConnectionReused(int pipeline_id) { | |
| 531 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 532 connection_->set_is_reused(true); | |
| 533 } | |
| 534 | |
| 535 void HttpPipelinedConnectionImpl::GetSSLInfo(int pipeline_id, | |
| 536 SSLInfo* ssl_info) { | |
| 537 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 538 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 539 return parser_map_[pipeline_id]->GetSSLInfo(ssl_info); | |
| 540 } | |
| 541 | |
| 542 void HttpPipelinedConnectionImpl::GetSSLCertRequestInfo( | |
| 543 int pipeline_id, | |
| 544 SSLCertRequestInfo* cert_request_info) { | |
| 545 DCHECK(ContainsKey(stream_state_map_, pipeline_id)); | |
| 546 DCHECK(ContainsKey(parser_map_, pipeline_id)); | |
| 547 return parser_map_[pipeline_id]->GetSSLCertRequestInfo(cert_request_info); | |
| 548 } | |
| 549 | |
| 550 void HttpPipelinedConnectionImpl::FireReadUserCallback( | |
| 551 int result) { | |
| 552 if (read_user_callback_) { | |
| 553 read_user_callback_->Run(result); | |
| 554 read_user_callback_ = NULL; | |
| 555 } | |
| 556 } | |
| 557 | |
| 558 } // namespace net | |
| OLD | NEW |