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/quic/quic_proxy_client_socket_unittest.cc b/net/quic/quic_proxy_client_socket_unittest.cc
index 81e38feb..9f0ed117 100644
--- a/net/quic/quic_proxy_client_socket_unittest.cc
+++ b/net/quic/quic_proxy_client_socket_unittest.cc
@@ -452,7 +452,8 @@
   }
 
   void AssertWriteReturns(const char* data, int len, int rv) {
-    scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(len));
+    scoped_refptr<IOBufferWithSize> buf =
+        base::MakeRefCounted<IOBufferWithSize>(len);
     memcpy(buf->data(), data, len);
     EXPECT_EQ(rv,
               sock_->Write(buf.get(), buf->size(), write_callback_.callback(),
@@ -460,7 +461,8 @@
   }
 
   void AssertSyncWriteSucceeds(const char* data, int len) {
-    scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(len));
+    scoped_refptr<IOBufferWithSize> buf =
+        base::MakeRefCounted<IOBufferWithSize>(len);
     memcpy(buf->data(), data, len);
     EXPECT_EQ(len,
               sock_->Write(buf.get(), buf->size(), CompletionOnceCallback(),
@@ -468,14 +470,14 @@
   }
 
   void AssertSyncReadEquals(const char* data, int len) {
-    scoped_refptr<IOBuffer> buf(new IOBuffer(len));
+    scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(len);
     ASSERT_EQ(len, sock_->Read(buf.get(), len, CompletionOnceCallback()));
     ASSERT_EQ(spdy::SpdyString(data, len), spdy::SpdyString(buf->data(), len));
     ASSERT_TRUE(sock_->IsConnected());
   }
 
   void AssertAsyncReadEquals(const char* data, int len) {
-    scoped_refptr<IOBuffer> buf(new IOBuffer(len));
+    scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(len);
     ASSERT_EQ(ERR_IO_PENDING,
               sock_->Read(buf.get(), len, read_callback_.callback()));
     EXPECT_TRUE(sock_->IsConnected());
@@ -489,7 +491,7 @@
 
   void AssertReadStarts(const char* data, int len) {
     // Issue the read, which will be completed asynchronously.
-    read_buf_ = new IOBuffer(len);
+    read_buf_ = base::MakeRefCounted<IOBuffer>(len);
     ASSERT_EQ(ERR_IO_PENDING,
               sock_->Read(read_buf_.get(), len, read_callback_.callback()));
     EXPECT_TRUE(sock_->IsConnected());
@@ -1038,7 +1040,7 @@
   AssertSyncReadEquals(kMsg33, kLen33);
 
   // Now attempt to do a read of more data than remains buffered
-  scoped_refptr<IOBuffer> buf(new IOBuffer(kLen33));
+  scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(kLen33);
   ASSERT_EQ(kLen3, sock_->Read(buf.get(), kLen33, CompletionOnceCallback()));
   ASSERT_EQ(spdy::SpdyString(kMsg3, kLen3),
             spdy::SpdyString(buf->data(), kLen3));
@@ -1552,7 +1554,7 @@
   EXPECT_TRUE(sock_->IsConnected());
 
   DeleteSockCallback read_callback(&sock_);
-  scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1));
+  scoped_refptr<IOBuffer> read_buf = base::MakeRefCounted<IOBuffer>(kLen1);
   ASSERT_EQ(ERR_IO_PENDING,
             sock_->Read(read_buf.get(), kLen1, read_callback.callback()));