summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 19:55:23 +0000
committerrsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-14 19:55:23 +0000
commit5f9205f215b19ab7ee4842fdc9820743b1061de6 (patch)
treec1a0b69293d43c0e47c722409dcc6a23ac47ec14 /net
parent4e402ec675af5dcff41e206ff9d0d985aceaab07 (diff)
downloadchromium_src-5f9205f215b19ab7ee4842fdc9820743b1061de6.zip
chromium_src-5f9205f215b19ab7ee4842fdc9820743b1061de6.tar.gz
chromium_src-5f9205f215b19ab7ee4842fdc9820743b1061de6.tar.bz2
Make HttpStream take a scoped_ptr<UploadDataStream>, to clearly communicate transfer of ownership
HttpStream assumes ownership of the passed in UploadDataStream when SendRequest is called. However, there existed a few call sites where the passed in UploadDataStream may have been leaked, primarily during error handling. Using scoped_ptr<> & Pass() provide clear API-level contracts as to the ownership of pointers. BUG=none TEST=existing R=willchan@chromium.org Review URL: https://chromiumcodereview.appspot.com/10539137 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_basic_stream.cc8
-rw-r--r--net/http/http_basic_stream.h5
-rw-r--r--net/http/http_network_transaction.cc2
-rw-r--r--net/http/http_pipelined_connection_impl.cc13
-rw-r--r--net/http/http_pipelined_connection_impl.h4
-rw-r--r--net/http/http_pipelined_connection_impl_unittest.cc345
-rw-r--r--net/http/http_pipelined_stream.cc11
-rw-r--r--net/http/http_pipelined_stream.h2
-rw-r--r--net/http/http_proxy_client_socket.cc5
-rw-r--r--net/http/http_response_body_drainer_unittest.cc5
-rw-r--r--net/http/http_stream.h8
-rw-r--r--net/http/http_stream_parser.cc6
-rw-r--r--net/http/http_stream_parser.h3
-rw-r--r--net/spdy/spdy_http_stream.cc8
-rw-r--r--net/spdy/spdy_http_stream.h2
-rw-r--r--net/spdy/spdy_http_stream_spdy2_unittest.cc16
-rw-r--r--net/spdy/spdy_http_stream_spdy3_unittest.cc26
17 files changed, 275 insertions, 194 deletions
diff --git a/net/http/http_basic_stream.cc b/net/http/http_basic_stream.cc
index 621fdd5..25772e8 100644
--- a/net/http/http_basic_stream.cc
+++ b/net/http/http_basic_stream.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -46,7 +46,7 @@ int HttpBasicStream::InitializeStream(
int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) {
DCHECK(parser_.get());
@@ -58,8 +58,8 @@ int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers,
request_info_->method.c_str(),
path.c_str());
response_ = response;
- return parser_->SendRequest(request_line_, headers, request_body, response,
- callback);
+ return parser_->SendRequest(request_line_, headers, request_body.Pass(),
+ response, callback);
}
uint64 HttpBasicStream::GetUploadProgress() const {
diff --git a/net/http/http_basic_stream.h b/net/http/http_basic_stream.h
index 42693c87..c6c7603 100644
--- a/net/http/http_basic_stream.h
+++ b/net/http/http_basic_stream.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -13,7 +13,6 @@
#include <string>
#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
#include "net/http/http_stream.h"
namespace net {
@@ -45,7 +44,7 @@ class HttpBasicStream : public HttpStream {
const CompletionCallback& callback) OVERRIDE;
virtual int SendRequest(const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) OVERRIDE;
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 48060e9..51b5a6e 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -777,7 +777,7 @@ int HttpNetworkTransaction::DoSendRequest() {
next_state_ = STATE_SEND_REQUEST_COMPLETE;
return stream_->SendRequest(
- request_headers_, request_body_.release(), &response_, io_callback_);
+ request_headers_, request_body_.Pass(), &response_, io_callback_);
}
int HttpNetworkTransaction::DoSendRequestComplete(int result) {
diff --git a/net/http/http_pipelined_connection_impl.cc b/net/http/http_pipelined_connection_impl.cc
index 531d959..1679cbc 100644
--- a/net/http/http_pipelined_connection_impl.cc
+++ b/net/http/http_pipelined_connection_impl.cc
@@ -155,9 +155,12 @@ void HttpPipelinedConnectionImpl::OnStreamDeleted(int pipeline_id) {
}
int HttpPipelinedConnectionImpl::SendRequest(
- int pipeline_id, const std::string& request_line,
- const HttpRequestHeaders& headers, UploadDataStream* request_body,
- HttpResponseInfo* response, const CompletionCallback& callback) {
+ int pipeline_id,
+ const std::string& request_line,
+ const HttpRequestHeaders& headers,
+ scoped_ptr<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_) {
@@ -168,7 +171,7 @@ int HttpPipelinedConnectionImpl::SendRequest(
send_request->pipeline_id = pipeline_id;
send_request->request_line = request_line;
send_request->headers = headers;
- send_request->request_body = request_body;
+ send_request->request_body.reset(request_body.release());
send_request->response = response;
send_request->callback = callback;
pending_send_request_queue_.push(send_request);
@@ -258,7 +261,7 @@ int HttpPipelinedConnectionImpl::DoSendActiveRequest(int result) {
int rv = stream_info_map_[active_send_request_->pipeline_id].parser->
SendRequest(active_send_request_->request_line,
active_send_request_->headers,
- active_send_request_->request_body,
+ active_send_request_->request_body.Pass(),
active_send_request_->response,
base::Bind(&HttpPipelinedConnectionImpl::OnSendIOCallback,
base::Unretained(this)));
diff --git a/net/http/http_pipelined_connection_impl.h b/net/http/http_pipelined_connection_impl.h
index a20361d..89071aa 100644
--- a/net/http/http_pipelined_connection_impl.h
+++ b/net/http/http_pipelined_connection_impl.h
@@ -106,7 +106,7 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
int SendRequest(int pipeline_id,
const std::string& request_line,
const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback);
@@ -182,7 +182,7 @@ class NET_EXPORT_PRIVATE HttpPipelinedConnectionImpl
int pipeline_id;
std::string request_line;
HttpRequestHeaders headers;
- UploadDataStream* request_body;
+ scoped_ptr<UploadDataStream> request_body;
HttpResponseInfo* response;
CompletionCallback callback;
};
diff --git a/net/http/http_pipelined_connection_impl_unittest.cc b/net/http/http_pipelined_connection_impl_unittest.cc
index 819b47a..cc4648b 100644
--- a/net/http/http_pipelined_connection_impl_unittest.cc
+++ b/net/http/http_pipelined_connection_impl_unittest.cc
@@ -137,7 +137,8 @@ class HttpPipelinedConnectionImplTest : public testing::Test {
HttpRequestHeaders headers;
HttpResponseInfo response;
EXPECT_EQ(OK, stream->SendRequest(
- headers, NULL, &response, callback_.callback()));
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse(filename, stream, false);
@@ -208,8 +209,9 @@ TEST_F(HttpPipelinedConnectionImplTest, AsyncSingleRequest) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
data_->RunFor(1);
EXPECT_LE(OK, callback_.WaitForResult());
@@ -242,13 +244,15 @@ TEST_F(HttpPipelinedConnectionImplTest, LockStepAsyncRequests) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
data_->RunFor(1);
EXPECT_LE(OK, callback_.WaitForResult());
@@ -294,12 +298,14 @@ TEST_F(HttpPipelinedConnectionImplTest, TwoResponsesInOnePacket) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", stream1, false);
@@ -352,13 +358,13 @@ TEST_F(HttpPipelinedConnectionImplTest, ReadOrderSwapped) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
EXPECT_EQ(ERR_IO_PENDING, stream2->ReadResponseHeaders(callback_.callback()));
@@ -393,14 +399,14 @@ TEST_F(HttpPipelinedConnectionImplTest, SendWhileReading) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
ExpectResponse("ok.html", stream1, false);
stream1->Close(false);
@@ -430,8 +436,8 @@ TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
TestCompletionCallback callback1;
std::string expected = "ok.html";
@@ -444,8 +450,8 @@ TEST_F(HttpPipelinedConnectionImplTest, AsyncSendWhileAsyncReadBlocked) {
HttpResponseInfo response2;
TestCompletionCallback callback2;
EXPECT_EQ(ERR_IO_PENDING,
- stream2->SendRequest(headers2, NULL, &response2,
- callback2.callback()));
+ stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback2.callback()));
data_->RunFor(1);
EXPECT_LE(OK, callback2.WaitForResult());
@@ -500,14 +506,17 @@ TEST_F(HttpPipelinedConnectionImplTest, UnsentStreamAllowsLaterUse) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
scoped_ptr<HttpStream> unsent_stream(NewTestStream("unsent.html"));
HttpRequestHeaders unsent_headers;
HttpResponseInfo unsent_response;
EXPECT_EQ(ERR_IO_PENDING,
- unsent_stream->SendRequest(unsent_headers, NULL, &unsent_response,
+ unsent_stream->SendRequest(unsent_headers,
+ scoped_ptr<UploadDataStream>(),
+ &unsent_response,
callback_.callback()));
unsent_stream->Close(false);
@@ -542,14 +551,17 @@ TEST_F(HttpPipelinedConnectionImplTest, FailedSend) {
HttpResponseInfo response;
TestCompletionCallback failed_callback;
EXPECT_EQ(ERR_IO_PENDING,
- failed_stream->SendRequest(headers, NULL, &response,
- failed_callback.callback()));
+ failed_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, failed_callback.callback()));
TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->SendRequest(headers, NULL, &response,
+ evicted_stream->SendRequest(headers,
+ scoped_ptr<UploadDataStream>(),
+ &response,
evicted_callback.callback()));
EXPECT_EQ(ERR_IO_PENDING,
- closed_stream->SendRequest(headers, NULL, &response,
+ closed_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response,
callback_.callback()));
closed_stream->Close(false);
@@ -557,8 +569,9 @@ TEST_F(HttpPipelinedConnectionImplTest, FailedSend) {
EXPECT_EQ(ERR_FAILED, failed_callback.WaitForResult());
EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- rejected_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ rejected_stream->SendRequest(headers,
+ scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
failed_stream->Close(true);
evicted_stream->Close(true);
@@ -592,20 +605,27 @@ TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, closed_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, read_evicted_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, read_rejected_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ closed_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ read_evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
+ EXPECT_EQ(OK,
+ read_rejected_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
TestCompletionCallback send_closed_callback;
EXPECT_EQ(ERR_IO_PENDING,
- send_closed_stream->SendRequest(headers, NULL, &response,
- send_closed_callback.callback()));
+ send_closed_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ send_closed_callback.callback()));
TestCompletionCallback send_evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- send_evicted_stream->SendRequest(headers, NULL, &response,
- send_evicted_callback.callback()));
+ send_evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ send_evicted_callback.callback()));
TestCompletionCallback read_evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
@@ -631,8 +651,9 @@ TEST_F(HttpPipelinedConnectionImplTest, ConnectionSuddenlyClosedAfterResponse) {
send_evicted_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- send_rejected_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ send_rejected_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
send_rejected_stream->Close(true);
}
@@ -649,12 +670,14 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSending) {
HttpResponseInfo response;
TestCompletionCallback aborted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- aborted_stream->SendRequest(headers, NULL, &response,
- aborted_callback.callback()));
+ aborted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ aborted_callback.callback()));
TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->SendRequest(headers, NULL, &response,
- evicted_callback.callback()));
+ evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ evicted_callback.callback()));
aborted_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION, evicted_callback.WaitForResult());
@@ -677,16 +700,18 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendingSecondRequest) {
HttpResponseInfo response;
TestCompletionCallback ok_callback;
EXPECT_EQ(ERR_IO_PENDING,
- ok_stream->SendRequest(headers, NULL, &response,
- ok_callback.callback()));
+ ok_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, ok_callback.callback()));
TestCompletionCallback aborted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- aborted_stream->SendRequest(headers, NULL, &response,
- aborted_callback.callback()));
+ aborted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ aborted_callback.callback()));
TestCompletionCallback evicted_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_stream->SendRequest(headers, NULL, &response,
- evicted_callback.callback()));
+ evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ evicted_callback.callback()));
data_->RunFor(1);
EXPECT_LE(OK, ok_callback.WaitForResult());
@@ -714,10 +739,14 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, aborted_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ aborted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
+ EXPECT_EQ(OK,
+ evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
EXPECT_EQ(ERR_IO_PENDING,
aborted_stream->ReadResponseHeaders(callback_.callback()));
@@ -730,8 +759,9 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileReadingHeaders) {
evicted_stream->Close(true);
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- rejected_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ rejected_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
rejected_stream->Close(true);
}
@@ -754,12 +784,17 @@ TEST_F(HttpPipelinedConnectionImplTest, PendingResponseAbandoned) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, abandoned_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ ok_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ abandoned_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
+ EXPECT_EQ(OK,
+ evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
TestCompletionCallback abandoned_callback;
@@ -801,10 +836,13 @@ TEST_F(HttpPipelinedConnectionImplTest, DisconnectedAfterOneRequestRecovery) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, rejected_read_stream->SendRequest(
- headers, NULL, &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ ok_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ rejected_read_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
@@ -812,16 +850,18 @@ TEST_F(HttpPipelinedConnectionImplTest, DisconnectedAfterOneRequestRecovery) {
TestCompletionCallback read_callback;
EXPECT_EQ(ERR_IO_PENDING,
- evicted_send_stream->SendRequest(headers, NULL, &response,
- read_callback.callback()));
+ evicted_send_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ read_callback.callback()));
data_->RunFor(1);
EXPECT_EQ(ERR_PIPELINE_EVICTION, read_callback.WaitForResult());
EXPECT_EQ(ERR_PIPELINE_EVICTION,
rejected_read_stream->ReadResponseHeaders(callback_.callback()));
EXPECT_EQ(ERR_PIPELINE_EVICTION,
- rejected_send_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ rejected_send_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
rejected_read_stream->Close(true);
rejected_send_stream->Close(true);
@@ -845,10 +885,13 @@ TEST_F(HttpPipelinedConnectionImplTest, DisconnectedPendingReadRecovery) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, evicted_stream->SendRequest(
- headers, NULL, &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ ok_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
@@ -881,10 +924,13 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeNextReadLoop) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, evicted_stream->SendRequest(
- headers, NULL, &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ ok_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
@@ -915,10 +961,13 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseCalledBeforeReadCallback) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, evicted_stream->SendRequest(
- headers, NULL, &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ ok_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ evicted_stream->SendRequest(
+ headers, scoped_ptr<UploadDataStream>(), &response,
+ callback_.callback()));
EXPECT_EQ(OK, ok_stream->ReadResponseHeaders(callback_.callback()));
ExpectResponse("ok.html", ok_stream, false);
@@ -968,8 +1017,9 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringSendCallback) {
StreamDeleter deleter(stream);
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(headers, NULL, &response,
- deleter.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, deleter.callback()));
data_->RunFor(1);
}
@@ -987,8 +1037,8 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseCalledDuringReadCallback) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK, stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
StreamDeleter deleter(stream);
EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(deleter.callback()));
@@ -1012,10 +1062,13 @@ TEST_F(HttpPipelinedConnectionImplTest,
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, failed_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ failed_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ evicted_stream->SendRequest(headers,
+ scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
StreamDeleter failed_deleter(failed_stream);
EXPECT_EQ(ERR_IO_PENDING,
@@ -1042,10 +1095,13 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseOtherDuringReadCallback) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, deleter_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, deleted_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK, deleter_stream->SendRequest(headers,
+ scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ deleted_stream->SendRequest(headers,
+ scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
StreamDeleter deleter(deleted_stream);
EXPECT_EQ(ERR_IO_PENDING,
@@ -1069,8 +1125,9 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeSendCallbackRuns) {
new TestCompletionCallback);
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(ERR_IO_PENDING, close_stream->SendRequest(
- headers, NULL, &response, close_callback->callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ close_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, close_callback->callback()));
data_->RunFor(1);
EXPECT_FALSE(close_callback->have_result());
@@ -1098,8 +1155,9 @@ TEST_F(HttpPipelinedConnectionImplTest, CloseBeforeReadCallbackRuns) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ close_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
scoped_ptr<TestCompletionCallback> close_callback(
new TestCompletionCallback);
@@ -1129,14 +1187,16 @@ TEST_F(HttpPipelinedConnectionImplTest, AbortWhileSendQueued) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
TestCompletionCallback callback1;
- EXPECT_EQ(ERR_IO_PENDING, stream1->SendRequest(headers1, NULL, &response1,
- callback1.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback1.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
TestCompletionCallback callback2;
- EXPECT_EQ(ERR_IO_PENDING, stream2->SendRequest(headers2, NULL, &response2,
- callback2.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback2.callback()));
stream2.reset();
stream1->Close(true);
@@ -1160,15 +1220,17 @@ TEST_F(HttpPipelinedConnectionImplTest, NoGapBetweenCloseAndEviction) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, close_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ close_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
TestCompletionCallback close_callback;
EXPECT_EQ(ERR_IO_PENDING,
close_stream->ReadResponseHeaders(close_callback.callback()));
- EXPECT_EQ(OK, dummy_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ dummy_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
TestCompletionCallback dummy_callback;
EXPECT_EQ(ERR_IO_PENDING,
@@ -1206,12 +1268,12 @@ TEST_F(HttpPipelinedConnectionImplTest, RecoverFromDrainOnRedirect) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
@@ -1238,12 +1300,12 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictAfterDrainOfUnknownSize) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
@@ -1271,12 +1333,13 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictAfterFailedDrain) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
+
EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
@@ -1305,12 +1368,13 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictIfDrainingChunkedEncoding) {
HttpRequestHeaders headers1;
HttpResponseInfo response1;
- EXPECT_EQ(OK, stream1->SendRequest(headers1, NULL, &response1,
- callback_.callback()));
+ EXPECT_EQ(OK, stream1->SendRequest(headers1, scoped_ptr<UploadDataStream>(),
+ &response1, callback_.callback()));
HttpRequestHeaders headers2;
HttpResponseInfo response2;
- EXPECT_EQ(OK, stream2->SendRequest(headers2, NULL, &response2,
- callback_.callback()));
+ EXPECT_EQ(OK, stream2->SendRequest(headers2, scoped_ptr<UploadDataStream>(),
+ &response2, callback_.callback()));
+
EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback()));
stream1.release()->Drain(NULL);
@@ -1339,12 +1403,17 @@ TEST_F(HttpPipelinedConnectionImplTest, EvictionDueToMissingContentLength) {
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, ok_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, evicted_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
- EXPECT_EQ(OK, rejected_stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK,
+ ok_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ evicted_stream->SendRequest(headers,
+ scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
+ EXPECT_EQ(OK,
+ rejected_stream->SendRequest(headers,
+ scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
TestCompletionCallback ok_callback;
EXPECT_EQ(ERR_IO_PENDING,
@@ -1386,8 +1455,8 @@ TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnSocketError) {
scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK, stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
EXPECT_EQ(ERR_FAILED, stream->ReadResponseHeaders(callback_.callback()));
}
@@ -1406,8 +1475,8 @@ TEST_F(HttpPipelinedConnectionImplTest, FeedbackOnNoInternetConnection) {
scoped_ptr<HttpStream> stream(NewTestStream("ok.html"));
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK, stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
stream->ReadResponseHeaders(callback_.callback()));
}
@@ -1509,8 +1578,8 @@ TEST_F(HttpPipelinedConnectionImplTest, OnPipelineHasCapacity) {
EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(1);
HttpRequestHeaders headers;
HttpResponseInfo response;
- EXPECT_EQ(OK, stream->SendRequest(headers, NULL, &response,
- callback_.callback()));
+ EXPECT_EQ(OK, stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback_.callback()));
EXPECT_CALL(delegate_, OnPipelineHasCapacity(pipeline_.get())).Times(0);
MessageLoop::current()->RunAllPending();
diff --git a/net/http/http_pipelined_stream.cc b/net/http/http_pipelined_stream.cc
index 2756c02..0bcb564 100644
--- a/net/http/http_pipelined_stream.cc
+++ b/net/http/http_pipelined_stream.cc
@@ -26,7 +26,8 @@ HttpPipelinedStream::~HttpPipelinedStream() {
}
int HttpPipelinedStream::InitializeStream(
- const HttpRequestInfo* request_info, const BoundNetLog& net_log,
+ const HttpRequestInfo* request_info,
+ const BoundNetLog& net_log,
const CompletionCallback& callback) {
request_info_ = request_info;
pipeline_->InitializeParser(pipeline_id_, request_info, net_log);
@@ -35,8 +36,10 @@ int HttpPipelinedStream::InitializeStream(
int HttpPipelinedStream::SendRequest(
- const HttpRequestHeaders& headers, UploadDataStream* request_body,
- HttpResponseInfo* response, const CompletionCallback& callback) {
+ const HttpRequestHeaders& headers,
+ scoped_ptr<UploadDataStream> request_body,
+ HttpResponseInfo* response,
+ const CompletionCallback& callback) {
CHECK(pipeline_id_);
CHECK(request_info_);
// TODO(simonjam): Proxy support will be needed here.
@@ -45,7 +48,7 @@ int HttpPipelinedStream::SendRequest(
request_info_->method.c_str(),
path.c_str());
return pipeline_->SendRequest(pipeline_id_, request_line_, headers,
- request_body, response, callback);
+ request_body.Pass(), response, callback);
}
uint64 HttpPipelinedStream::GetUploadProgress() const {
diff --git a/net/http/http_pipelined_stream.h b/net/http/http_pipelined_stream.h
index 83fca26..ee60ce5 100644
--- a/net/http/http_pipelined_stream.h
+++ b/net/http/http_pipelined_stream.h
@@ -44,7 +44,7 @@ class HttpPipelinedStream : public HttpStream {
const CompletionCallback& callback) OVERRIDE;
virtual int SendRequest(const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) OVERRIDE;
diff --git a/net/http/http_proxy_client_socket.cc b/net/http/http_proxy_client_socket.cc
index c606544..826bf09 100644
--- a/net/http/http_proxy_client_socket.cc
+++ b/net/http/http_proxy_client_socket.cc
@@ -416,8 +416,9 @@ int HttpProxyClientSocket::DoSendRequest() {
parser_buf_ = new GrowableIOBuffer();
http_stream_parser_.reset(
new HttpStreamParser(transport_.get(), &request_, parser_buf_, net_log_));
- return http_stream_parser_->SendRequest(request_line_, request_headers_, NULL,
- &response_, io_callback_);
+ return http_stream_parser_->SendRequest(
+ request_line_, request_headers_, scoped_ptr<UploadDataStream>(),
+ &response_, io_callback_);
}
int HttpProxyClientSocket::DoSendRequestComplete(int result) {
diff --git a/net/http/http_response_body_drainer_unittest.cc b/net/http/http_response_body_drainer_unittest.cc
index 79d9f6f..cf08f55 100644
--- a/net/http/http_response_body_drainer_unittest.cc
+++ b/net/http/http_response_body_drainer_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,6 +14,7 @@
#include "net/base/net_errors.h"
#include "net/base/ssl_config_service_defaults.h"
#include "net/base/test_completion_callback.h"
+#include "net/base/upload_data_stream.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties_impl.h"
#include "net/http/http_stream.h"
@@ -79,7 +80,7 @@ class MockHttpStream : public HttpStream {
return ERR_UNEXPECTED;
}
virtual int SendRequest(const HttpRequestHeaders& request_headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) OVERRIDE {
return ERR_UNEXPECTED;
diff --git a/net/http/http_stream.h b/net/http/http_stream.h
index e52b957..c343b2d 100644
--- a/net/http/http_stream.h
+++ b/net/http/http_stream.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -17,6 +17,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
@@ -46,10 +47,9 @@ class NET_EXPORT_PRIVATE HttpStream {
// Writes the headers and uploads body data to the underlying socket.
// ERR_IO_PENDING is returned if the operation could not be completed
// synchronously, in which case the result will be passed to the callback
- // when available. Returns OK on success. The HttpStream takes ownership
- // of the request_body.
+ // when available. Returns OK on success.
virtual int SendRequest(const HttpRequestHeaders& request_headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) = 0;
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc
index 92f62d3..d368f90 100644
--- a/net/http/http_stream_parser.cc
+++ b/net/http/http_stream_parser.cc
@@ -189,7 +189,7 @@ HttpStreamParser::~HttpStreamParser() {
int HttpStreamParser::SendRequest(const std::string& request_line,
const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) {
DCHECK_EQ(STATE_NONE, io_state_);
@@ -216,7 +216,7 @@ int HttpStreamParser::SendRequest(const std::string& request_line,
response_->socket_address = HostPortPair::FromIPEndPoint(ip_endpoint);
std::string request = request_line + headers.ToString();
- request_body_.reset(request_body);
+ request_body_.reset(request_body.release());
if (request_body_ != NULL) {
request_body_buf_ = new SeekableIOBuffer(kRequestBodyBufferSize);
if (request_body_->is_chunked()) {
@@ -234,7 +234,7 @@ int HttpStreamParser::SendRequest(const std::string& request_line,
// single write.
bool did_merge = false;
if (ShouldMergeRequestHeadersAndBody(request, request_body_.get())) {
- size_t merged_size = request.size() + request_body->size();
+ size_t merged_size = request.size() + request_body_->size();
scoped_refptr<IOBuffer> merged_request_headers_and_body(
new IOBuffer(merged_size));
// We'll repurpose |request_headers_| to store the merged headers and
diff --git a/net/http/http_stream_parser.h b/net/http/http_stream_parser.h
index 3d63123..aee5236 100644
--- a/net/http/http_stream_parser.h
+++ b/net/http/http_stream_parser.h
@@ -9,6 +9,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
#include "base/string_piece.h"
#include "net/base/completion_callback.h"
#include "net/base/net_export.h"
@@ -46,7 +47,7 @@ class NET_EXPORT_PRIVATE HttpStreamParser : public ChunkCallback {
// some additional functionality
int SendRequest(const std::string& request_line,
const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback);
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc
index 9af52e4..170e3e1 100644
--- a/net/spdy/spdy_http_stream.cc
+++ b/net/spdy/spdy_http_stream.cc
@@ -188,7 +188,7 @@ void SpdyHttpStream::set_chunk_callback(ChunkCallback* callback) {
}
int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) {
base::Time request_time = base::Time::Now();
@@ -210,16 +210,14 @@ int SpdyHttpStream::SendRequest(const HttpRequestHeaders& request_headers,
response_info_->request_time = request_time;
CHECK(!request_body_stream_.get());
- if (request_body) {
+ if (request_body != NULL) {
if (request_body->size() || request_body->is_chunked()) {
- request_body_stream_.reset(request_body);
+ request_body_stream_.reset(request_body.release());
// Use kMaxSpdyFrameChunkSize as the buffer size, since the request
// body data is written with this size at a time.
raw_request_body_buf_ = new IOBufferWithSize(kMaxSpdyFrameChunkSize);
// The request body buffer is empty at first.
request_body_buf_ = new DrainableIOBuffer(raw_request_body_buf_, 0);
- } else {
- delete request_body;
}
}
diff --git a/net/spdy/spdy_http_stream.h b/net/spdy/spdy_http_stream.h
index da99777..abab9bf 100644
--- a/net/spdy/spdy_http_stream.h
+++ b/net/spdy/spdy_http_stream.h
@@ -49,7 +49,7 @@ class NET_EXPORT_PRIVATE SpdyHttpStream : public SpdyStream::Delegate,
const BoundNetLog& net_log,
const CompletionCallback& callback) OVERRIDE;
virtual int SendRequest(const HttpRequestHeaders& headers,
- UploadDataStream* request_body,
+ scoped_ptr<UploadDataStream> request_body,
HttpResponseInfo* response,
const CompletionCallback& callback) OVERRIDE;
virtual uint64 GetUploadProgress() const OVERRIDE;
diff --git a/net/spdy/spdy_http_stream_spdy2_unittest.cc b/net/spdy/spdy_http_stream_spdy2_unittest.cc
index 27358f0..c3c37a6 100644
--- a/net/spdy/spdy_http_stream_spdy2_unittest.cc
+++ b/net/spdy/spdy_http_stream_spdy2_unittest.cc
@@ -99,8 +99,9 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendRequest) {
OK,
http_stream->InitializeStream(&request, net_log, CompletionCallback()));
- EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response,
- callback.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ http_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback.callback()));
EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
// This triggers the MockWrite and read 2
@@ -156,11 +157,11 @@ TEST_F(SpdyHttpStreamSpdy2Test, SendChunkedPost) {
OK,
http_stream.InitializeStream(&request, net_log, CompletionCallback()));
- // http_stream.SendRequest() will take ownership of upload_stream.
- UploadDataStream* upload_stream = new UploadDataStream(request.upload_data);
+ scoped_ptr<UploadDataStream> upload_stream(
+ new UploadDataStream(request.upload_data));
ASSERT_EQ(OK, upload_stream->Init());
EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest(
- headers, upload_stream, &response, callback.callback()));
+ headers, upload_stream.Pass(), &response, callback.callback()));
EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
// This triggers the MockWrite and read 2
@@ -208,8 +209,9 @@ TEST_F(SpdyHttpStreamSpdy2Test, SpdyURLTest) {
OK,
http_stream->InitializeStream(&request, net_log, CompletionCallback()));
- EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response,
- callback.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ http_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback.callback()));
SpdyHeaderBlock* spdy_header =
http_stream->stream()->spdy_headers().get();
diff --git a/net/spdy/spdy_http_stream_spdy3_unittest.cc b/net/spdy/spdy_http_stream_spdy3_unittest.cc
index d15934b..6d81a97 100644
--- a/net/spdy/spdy_http_stream_spdy3_unittest.cc
+++ b/net/spdy/spdy_http_stream_spdy3_unittest.cc
@@ -107,8 +107,9 @@ TEST_F(SpdyHttpStreamSpdy3Test, SendRequest) {
OK,
http_stream->InitializeStream(&request, net_log, CompletionCallback()));
- EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response,
- callback.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ http_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback.callback()));
EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
// This triggers the MockWrite and read 2
@@ -164,11 +165,11 @@ TEST_F(SpdyHttpStreamSpdy3Test, SendChunkedPost) {
OK,
http_stream.InitializeStream(&request, net_log, CompletionCallback()));
- // http_stream.SendRequest() will take ownership of upload_stream.
- UploadDataStream* upload_stream = new UploadDataStream(request.upload_data);
+ scoped_ptr<UploadDataStream> upload_stream(
+ new UploadDataStream(request.upload_data));
ASSERT_EQ(OK, upload_stream->Init());
EXPECT_EQ(ERR_IO_PENDING, http_stream.SendRequest(
- headers, upload_stream, &response, callback.callback()));
+ headers, upload_stream.Pass(), &response, callback.callback()));
EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
// This triggers the MockWrite and read 2
@@ -216,8 +217,9 @@ TEST_F(SpdyHttpStreamSpdy3Test, SpdyURLTest) {
OK,
http_stream->InitializeStream(&request, net_log, CompletionCallback()));
- EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response,
- callback.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ http_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback.callback()));
SpdyHeaderBlock* spdy_header =
http_stream->stream()->spdy_headers().get();
@@ -436,8 +438,9 @@ void SpdyHttpStreamSpdy3Test::TestSendCredentials(
// GURL new_origin(kUrl2);
// EXPECT_TRUE(session_->NeedsCredentials(new_origin));
- EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(headers, NULL, &response,
- callback.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ http_stream->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback.callback()));
EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
data->RunFor(2);
@@ -450,8 +453,9 @@ void SpdyHttpStreamSpdy3Test::TestSendCredentials(
ASSERT_EQ(
OK,
http_stream2->InitializeStream(&request, net_log, CompletionCallback()));
- EXPECT_EQ(ERR_IO_PENDING, http_stream2->SendRequest(headers, NULL, &response,
- callback.callback()));
+ EXPECT_EQ(ERR_IO_PENDING,
+ http_stream2->SendRequest(headers, scoped_ptr<UploadDataStream>(),
+ &response, callback.callback()));
data->RunFor(2);
callback.WaitForResult();