net: Make net::DrainableIOBuffer constructors take scoped_refptr.

The net::DrainableIOBuffer constructors currently take in a
net::IOBuffer base as a raw pointer, then assign it to a
scoped_refptr<net::IOBuffer> member, thus taking a reference.

This CL turns the raw pointer parameter into a scoped_refptr, and uses
std::move() during the member assignment. So, the reference-increment
operation is pushed from the constructors to the construction callsites.
No new increments are introduced.

The CL also modifies the DrainableIOBuffer construction sites, using
std::move() where possible to remove reference increments.

Bug: 479898
Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I95cd0973d5e25c2565ddecfa0e06a3fc15e1f7b9
Reviewed-on: https://chromium-review.googlesource.com/1188955
Commit-Queue: Victor Costan <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Reviewed-by: Lei Zhang <[email protected]>
Reviewed-by: Dmitry Gozman <[email protected]>
Reviewed-by: Nicolas Zea <[email protected]>
Reviewed-by: Cait Phillips <[email protected]>
Reviewed-by: Jamie Walch <[email protected]>
Cr-Commit-Position: refs/heads/master@{#587471}
diff --git a/net/socket/ssl_server_socket_unittest.cc b/net/socket/ssl_server_socket_unittest.cc
index 4a6663e8..23ec8d8 100644
--- a/net/socket/ssl_server_socket_unittest.cc
+++ b/net/socket/ssl_server_socket_unittest.cc
@@ -137,8 +137,8 @@
       return ERR_IO_PENDING;
     }
     // This function returns synchronously, so make a copy of the buffer.
-    data_.push(new DrainableIOBuffer(
-        new StringIOBuffer(std::string(buf->data(), buf_len)),
+    data_.push(base::MakeRefCounted<DrainableIOBuffer>(
+        base::MakeRefCounted<StringIOBuffer>(std::string(buf->data(), buf_len)),
         buf_len));
     base::ThreadTaskRunnerHandle::Get()->PostTask(
         FROM_HERE, base::Bind(&FakeDataChannel::DoReadCallback,
@@ -923,7 +923,8 @@
   scoped_refptr<StringIOBuffer> write_buf =
       base::MakeRefCounted<StringIOBuffer>("testing123");
   scoped_refptr<DrainableIOBuffer> read_buf =
-      new DrainableIOBuffer(new IOBuffer(kReadBufSize), kReadBufSize);
+      base::MakeRefCounted<DrainableIOBuffer>(
+          base::MakeRefCounted<IOBuffer>(kReadBufSize), kReadBufSize);
 
   // Write then read.
   TestCompletionCallback write_callback;