| Index: net/http/http_pipelined_connection_impl.cc
|
| diff --git a/net/http/http_pipelined_connection_impl.cc b/net/http/http_pipelined_connection_impl.cc
|
| index 05bc9b846fe139f127c6becbfe87b2c0dad61a00..d8206b18cb0826e528e6bcc83db84bce0eee30e2 100644
|
| --- a/net/http/http_pipelined_connection_impl.cc
|
| +++ b/net/http/http_pipelined_connection_impl.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "net/http/http_pipelined_connection_impl.h"
|
|
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| #include "base/message_loop.h"
|
| #include "base/stl_util.h"
|
| #include "net/base/io_buffer.h"
|
| @@ -35,16 +37,12 @@ HttpPipelinedConnectionImpl::HttpPipelinedConnectionImpl(
|
| active_(false),
|
| usable_(true),
|
| completed_one_request_(false),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
|
| send_next_state_(SEND_STATE_NONE),
|
| send_still_on_call_stack_(false),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(send_io_callback_(
|
| - this, &HttpPipelinedConnectionImpl::OnSendIOCallback)),
|
| read_next_state_(READ_STATE_NONE),
|
| active_read_id_(0),
|
| - read_still_on_call_stack_(false),
|
| - ALLOW_THIS_IN_INITIALIZER_LIST(read_io_callback_(
|
| - this, &HttpPipelinedConnectionImpl::OnReadIOCallback)) {
|
| + read_still_on_call_stack_(false) {
|
| CHECK(connection_.get());
|
| }
|
|
|
| @@ -86,8 +84,8 @@ void HttpPipelinedConnectionImpl::InitializeParser(
|
| if (pipeline_id == 1) {
|
| MessageLoop::current()->PostTask(
|
| FROM_HERE,
|
| - method_factory_.NewRunnableMethod(
|
| - &HttpPipelinedConnectionImpl::ActivatePipeline));
|
| + base::Bind(&HttpPipelinedConnectionImpl::ActivatePipeline,
|
| + weak_factory_.GetWeakPtr()));
|
| }
|
| }
|
|
|
| @@ -114,12 +112,10 @@ void HttpPipelinedConnectionImpl::OnStreamDeleted(int pipeline_id) {
|
| delegate_->OnPipelineHasCapacity(this);
|
| }
|
|
|
| -int HttpPipelinedConnectionImpl::SendRequest(int pipeline_id,
|
| - const std::string& request_line,
|
| - const HttpRequestHeaders& headers,
|
| - UploadDataStream* request_body,
|
| - HttpResponseInfo* response,
|
| - OldCompletionCallback* callback) {
|
| +int HttpPipelinedConnectionImpl::SendRequest(
|
| + int pipeline_id, const std::string& request_line,
|
| + const HttpRequestHeaders& headers, UploadDataStream* request_body,
|
| + HttpResponseInfo* response, const CompletionCallback& callback) {
|
| CHECK(ContainsKey(stream_info_map_, pipeline_id));
|
| CHECK_EQ(stream_info_map_[pipeline_id].state, STREAM_BOUND);
|
| if (!usable_) {
|
| @@ -222,7 +218,8 @@ int HttpPipelinedConnectionImpl::DoSendActiveRequest(int result) {
|
| active_send_request_->headers,
|
| active_send_request_->request_body,
|
| active_send_request_->response,
|
| - &send_io_callback_);
|
| + base::Bind(&HttpPipelinedConnectionImpl::OnSendIOCallback,
|
| + base::Unretained(this)));
|
| stream_info_map_[active_send_request_->pipeline_id].state = STREAM_SENDING;
|
| send_next_state_ = SEND_STATE_COMPLETE;
|
| return rv;
|
| @@ -269,24 +266,21 @@ int HttpPipelinedConnectionImpl::DoEvictPendingSendRequests(int result) {
|
| scoped_ptr<PendingSendRequest> evicted_send(
|
| pending_send_request_queue_.front());
|
| pending_send_request_queue_.pop();
|
| - if (stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED) {
|
| - evicted_send->callback->Run(ERR_PIPELINE_EVICTION);
|
| - }
|
| + if (stream_info_map_[evicted_send->pipeline_id].state != STREAM_CLOSED)
|
| + evicted_send->callback.Run(ERR_PIPELINE_EVICTION);
|
| }
|
| send_next_state_ = SEND_STATE_NONE;
|
| return result;
|
| }
|
|
|
| int HttpPipelinedConnectionImpl::ReadResponseHeaders(
|
| - int pipeline_id,
|
| - OldCompletionCallback* callback) {
|
| + int pipeline_id, const CompletionCallback& callback) {
|
| CHECK(ContainsKey(stream_info_map_, pipeline_id));
|
| CHECK_EQ(STREAM_SENT, stream_info_map_[pipeline_id].state);
|
| - CHECK(!stream_info_map_[pipeline_id].read_headers_callback);
|
| + CHECK(stream_info_map_[pipeline_id].read_headers_callback.is_null());
|
|
|
| - if (!usable_) {
|
| + if (!usable_)
|
| return ERR_PIPELINE_EVICTION;
|
| - }
|
|
|
| stream_info_map_[pipeline_id].state = STREAM_READ_PENDING;
|
| stream_info_map_[pipeline_id].read_headers_callback = callback;
|
| @@ -408,7 +402,8 @@ int HttpPipelinedConnectionImpl::DoReadHeaders(int result) {
|
| CHECK_EQ(STREAM_READ_PENDING, stream_info_map_[active_read_id_].state);
|
| stream_info_map_[active_read_id_].state = STREAM_ACTIVE;
|
| int rv = stream_info_map_[active_read_id_].parser->ReadResponseHeaders(
|
| - &read_io_callback_);
|
| + base::Bind(&HttpPipelinedConnectionImpl::OnReadIOCallback,
|
| + base::Unretained(this)));
|
| read_next_state_ = READ_STATE_READ_HEADERS_COMPLETE;
|
| return rv;
|
| }
|
| @@ -455,8 +450,8 @@ int HttpPipelinedConnectionImpl::DoReadStreamClosed() {
|
| completed_one_request_ = true;
|
| MessageLoop::current()->PostTask(
|
| FROM_HERE,
|
| - method_factory_.NewRunnableMethod(
|
| - &HttpPipelinedConnectionImpl::StartNextDeferredRead));
|
| + base::Bind(&HttpPipelinedConnectionImpl::StartNextDeferredRead,
|
| + weak_factory_.GetWeakPtr()));
|
| read_next_state_ = READ_STATE_NONE;
|
| return OK;
|
| }
|
| @@ -537,10 +532,8 @@ void HttpPipelinedConnectionImpl::Close(int pipeline_id,
|
| }
|
|
|
| int HttpPipelinedConnectionImpl::ReadResponseBody(
|
| - int pipeline_id,
|
| - IOBuffer* buf,
|
| - int buf_len,
|
| - OldCompletionCallback* callback) {
|
| + int pipeline_id, IOBuffer* buf, int buf_len,
|
| + const CompletionCallback& callback) {
|
| CHECK(ContainsKey(stream_info_map_, pipeline_id));
|
| CHECK_EQ(active_read_id_, pipeline_id);
|
| CHECK(stream_info_map_[pipeline_id].parser.get());
|
| @@ -600,7 +593,7 @@ void HttpPipelinedConnectionImpl::GetSSLInfo(int pipeline_id,
|
| SSLInfo* ssl_info) {
|
| CHECK(ContainsKey(stream_info_map_, pipeline_id));
|
| CHECK(stream_info_map_[pipeline_id].parser.get());
|
| - return stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info);
|
| + stream_info_map_[pipeline_id].parser->GetSSLInfo(ssl_info);
|
| }
|
|
|
| void HttpPipelinedConnectionImpl::GetSSLCertRequestInfo(
|
| @@ -608,7 +601,7 @@ void HttpPipelinedConnectionImpl::GetSSLCertRequestInfo(
|
| SSLCertRequestInfo* cert_request_info) {
|
| CHECK(ContainsKey(stream_info_map_, pipeline_id));
|
| CHECK(stream_info_map_[pipeline_id].parser.get());
|
| - return stream_info_map_[pipeline_id].parser->GetSSLCertRequestInfo(
|
| + stream_info_map_[pipeline_id].parser->GetSSLCertRequestInfo(
|
| cert_request_info);
|
| }
|
|
|
| @@ -661,28 +654,24 @@ void HttpPipelinedConnectionImpl::CheckHeadersForPipelineCompatibility(
|
| }
|
|
|
| void HttpPipelinedConnectionImpl::QueueUserCallback(
|
| - int pipeline_id,
|
| - OldCompletionCallback* callback,
|
| - int rv,
|
| + int pipeline_id, const CompletionCallback& callback, int rv,
|
| const tracked_objects::Location& from_here) {
|
| - CHECK(!stream_info_map_[pipeline_id].pending_user_callback);
|
| + CHECK(stream_info_map_[pipeline_id].pending_user_callback.is_null());
|
| stream_info_map_[pipeline_id].pending_user_callback = callback;
|
| MessageLoop::current()->PostTask(
|
| from_here,
|
| - method_factory_.NewRunnableMethod(
|
| - &HttpPipelinedConnectionImpl::FireUserCallback,
|
| - pipeline_id,
|
| - rv));
|
| + base::Bind(&HttpPipelinedConnectionImpl::FireUserCallback,
|
| + weak_factory_.GetWeakPtr(), pipeline_id, rv));
|
| }
|
|
|
| void HttpPipelinedConnectionImpl::FireUserCallback(int pipeline_id,
|
| int result) {
|
| if (ContainsKey(stream_info_map_, pipeline_id)) {
|
| - CHECK(stream_info_map_[pipeline_id].pending_user_callback);
|
| - OldCompletionCallback* callback =
|
| + CHECK(!stream_info_map_[pipeline_id].pending_user_callback.is_null());
|
| + CompletionCallback callback =
|
| stream_info_map_[pipeline_id].pending_user_callback;
|
| - stream_info_map_[pipeline_id].pending_user_callback = NULL;
|
| - callback->Run(result);
|
| + stream_info_map_[pipeline_id].pending_user_callback.Reset();
|
| + callback.Run(result);
|
| }
|
| }
|
|
|
| @@ -721,9 +710,7 @@ HttpPipelinedConnectionImpl::PendingSendRequest::~PendingSendRequest() {
|
| }
|
|
|
| HttpPipelinedConnectionImpl::StreamInfo::StreamInfo()
|
| - : read_headers_callback(NULL),
|
| - pending_user_callback(NULL),
|
| - state(STREAM_CREATED) {
|
| + : state(STREAM_CREATED) {
|
| }
|
|
|
| HttpPipelinedConnectionImpl::StreamInfo::~StreamInfo() {
|
|
|