Use base::MakeRefCounted instead of new to alloc net::IOBuffer instances.
This CL only handles the files in //net. The files outside of //net are
tackled separately, in https://crrev.com/c/1189548.
net::IOBuffer is (thread-safe) ref-counted. Asides from improving the
ability to reason about instance ownership locally, creating instances
via base::MakeRefCounted makes it possible to use 1-based ref-counting
in the future (see base/memory/ref_counted.h).
This CL is mechanical, to avoid introducing any behavior changes. The
difficult cases will be tackled by follow-up CLs. The following
transformations were performed.
* new IOBufferType(args) => base::MakeRefCounted<IOBufferType>(args)
* new IOBufferType => base::MakeRefCounted<IOBufferType>()
* scoped_refptr x(base::MakeRefCounted<IOBufferType>(args)) =>
scoped_refptr x = base::MakeRefCounted<IOBufferType>(args)
* scoped_refptr<IOBufferType>(base::MakeRefCounted<IOBufferType>(args)) =>
base::MakeRefCounted<IOBufferType>(args)
* In comments: creates a new IOBufferType => creates an IOBufferType
(so it wouldn't trigger future searches for "new BufferType")
* Instantiated static members in HttpResponseBodyDrainer,
HttpNetworkTransaction, HttpProxyClientSocket, WritersTest,
UDPSocketTest, TestDelegate, UDPSocketPerfTest
(needed to fix linker errors)
* arraysize -> base::size (where needed to pass presubmit checks)
* git cl format
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs;luci.chromium.try:linux_mojo;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel;master.tryserver.chromium.android:android_cronet_tester
Change-Id: Ic2cf8eb4dccfa4a97be893aff9a6053eaaf7d7af
Reviewed-on: https://chromium-review.googlesource.com/1188959
Reviewed-by: Bence Béky <[email protected]>
Commit-Queue: Victor Costan <[email protected]>
Cr-Commit-Position: refs/heads/master@{#586281}
diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc
index 9581c0e..4a6663e8 100644
--- a/net/socket/ssl_server_socket_unittest.cc
+++ b/net/socket/ssl_server_socket_unittest.cc
@@ -316,8 +316,10 @@
const char kTestData[] = "testing123";
const int kTestDataSize = strlen(kTestData);
const int kReadBufSize = 1024;
- scoped_refptr<IOBuffer> write_buf = new StringIOBuffer(kTestData);
- scoped_refptr<IOBuffer> read_buf = new IOBuffer(kReadBufSize);
+ scoped_refptr<IOBuffer> write_buf =
+ base::MakeRefCounted<StringIOBuffer>(kTestData);
+ scoped_refptr<IOBuffer> read_buf =
+ base::MakeRefCounted<IOBuffer>(kReadBufSize);
// Write then read.
int written =
@@ -919,7 +921,7 @@
const int kReadBufSize = 1024;
scoped_refptr<StringIOBuffer> write_buf =
- new StringIOBuffer("testing123");
+ base::MakeRefCounted<StringIOBuffer>("testing123");
scoped_refptr<DrainableIOBuffer> read_buf =
new DrainableIOBuffer(new IOBuffer(kReadBufSize), kReadBufSize);
@@ -953,7 +955,7 @@
EXPECT_EQ(0, memcmp(write_buf->data(), read_buf->data(), write_buf->size()));
// Read then write.
- write_buf = new StringIOBuffer("hello123");
+ write_buf = base::MakeRefCounted<StringIOBuffer>("hello123");
server_ret = server_socket_->Read(
read_buf.get(), read_buf->BytesRemaining(), read_callback.callback());
EXPECT_TRUE(server_ret > 0 || server_ret == ERR_IO_PENDING);
@@ -1003,7 +1005,8 @@
server_ret = handshake_callback.GetResult(server_ret);
ASSERT_THAT(server_ret, IsOk());
- scoped_refptr<StringIOBuffer> write_buf = new StringIOBuffer("testing123");
+ scoped_refptr<StringIOBuffer> write_buf =
+ base::MakeRefCounted<StringIOBuffer>("testing123");
// The server closes the connection. The server needs to write some
// data first so that the client's Read() calls from the transport