Use base::MakeRefCounted instead of new to alloc net::IOBuffer instances.
This CL only handles the files in //content. The files in //net were
tackled in https://crrev.com/c/1188959. Parallel CLs will tackle other
directories.
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
Change-Id: Ib3f9965fe92b84be3db88d0143a398079b812efd
Reviewed-on: https://chromium-review.googlesource.com/1200525
Reviewed-by: Kinuko Yasuda <[email protected]>
Commit-Queue: Victor Costan <[email protected]>
Cr-Commit-Position: refs/heads/master@{#588243}
diff --git a/content/browser/byte_stream_unittest.cc b/content/browser/byte_stream_unittest.cc
index 7335cf2..4b89fb1 100644
--- a/content/browser/byte_stream_unittest.cc
+++ b/content/browser/byte_stream_unittest.cc
@@ -35,7 +35,8 @@
// contents of the created buffer will be kept, and can be validated
// by ValidateIOBuffer.
scoped_refptr<net::IOBuffer> NewIOBuffer(size_t buffer_size) {
- scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(buffer_size));
+ scoped_refptr<net::IOBuffer> buffer =
+ base::MakeRefCounted<net::IOBuffer>(buffer_size);
char *bufferp = buffer->data();
for (size_t i = 0; i < buffer_size; i++)
bufferp[i] = (i + producing_seed_key_) % (1 << sizeof(char));