Remove many naked new statements from net/websockets.
This change is fairly mechanical and purely cosmetic.
Use make_unique instead of creating an object with new and passing that
into a unique_ptr constructor. (This often changes local variable type,
but when passed as an argument an implicitly cast takes care of this).
Use MakeRefCounted instead of creating an object with new and passing
that into a scoped_refptr constructor. (This never changes variable
type in this CL). Do these in constructor initializer lists as well.
Remove unnecessary namespace qualifiers in a few places (where
unique_ptr template parameter has it but new statement does not in the
same line).
Use assignment operator instead of reset() method of unique_ptr.
Use std::move instead of two-step WrapUnique(unique_ptr.release()).
Where object needs to be constructed with new statement and raw pointer
is already available, use WrapUnique instead of passing the raw pointer
to a unique_ptr constructor.
Use auto where appropriate.
Replace NULL by nullptr in one line which is touched anyway.
Make sure to include memory for new, unique_ptr.
Include scoped_refptr.h for scoped_refptr and MakeRefCounted.
Delete unnecessary ref_counted.h include (only needed for RefCounted*
base classes).
Delete unnecessary memory include where corresponding header file
already included it.
Change-Id: I6fa58780e5ae89e2684aabdd21452b76be52a4f8
Reviewed-on: https://chromium-review.googlesource.com/946053
Commit-Queue: Bence Béky <[email protected]>
Reviewed-by: Adam Rice <[email protected]>
Cr-Commit-Position: refs/heads/master@{#540826}
diff --git a/net/websockets/websocket_basic_stream.cc b/net/websockets/websocket_basic_stream.cc
index 22d0c68..31267ba 100644
--- a/net/websockets/websocket_basic_stream.cc
+++ b/net/websockets/websocket_basic_stream.cc
@@ -99,7 +99,7 @@
const scoped_refptr<GrowableIOBuffer>& http_read_buffer,
const std::string& sub_protocol,
const std::string& extensions)
- : read_buffer_(new IOBufferWithSize(kReadBufferSize)),
+ : read_buffer_(base::MakeRefCounted<IOBufferWithSize>(kReadBufferSize)),
connection_(std::move(connection)),
http_read_buffer_(http_read_buffer),
sub_protocol_(sub_protocol),
@@ -166,8 +166,7 @@
//
// First calculate the size of the buffer we need to allocate.
int total_size = CalculateSerializedSizeAndTurnOnMaskBit(frames);
- scoped_refptr<IOBufferWithSize> combined_buffer(
- new IOBufferWithSize(total_size));
+ auto combined_buffer = base::MakeRefCounted<IOBufferWithSize>(total_size);
char* dest = combined_buffer->data();
int remaining_size = total_size;
@@ -195,8 +194,8 @@
}
DCHECK_EQ(0, remaining_size) << "Buffer size calculation was wrong; "
<< remaining_size << " bytes left over.";
- scoped_refptr<DrainableIOBuffer> drainable_buffer(
- new DrainableIOBuffer(combined_buffer.get(), total_size));
+ auto drainable_buffer = base::MakeRefCounted<DrainableIOBuffer>(
+ combined_buffer.get(), total_size);
return WriteEverything(drainable_buffer, callback);
}
@@ -348,7 +347,8 @@
AddToIncompleteControlFrameBody(data_buffer);
} else {
DVLOG(3) << "Creating new storage for an incomplete control frame.";
- incomplete_control_frame_body_ = new GrowableIOBuffer();
+ incomplete_control_frame_body_ =
+ base::MakeRefCounted<GrowableIOBuffer>();
// This method checks for oversize control frames above, so as long as
// the frame parser is working correctly, this won't overflow. If a bug
// does cause it to overflow, it will CHECK() in
@@ -364,7 +364,7 @@
const int body_size = incomplete_control_frame_body_->offset();
DCHECK_EQ(body_size,
static_cast<int>(current_frame_header_->payload_length));
- scoped_refptr<IOBufferWithSize> body = new IOBufferWithSize(body_size);
+ auto body = base::MakeRefCounted<IOBufferWithSize>(body_size);
memcpy(body->data(),
incomplete_control_frame_body_->StartOfBuffer(),
body_size);
@@ -402,7 +402,7 @@
if (is_final_chunk_in_message || data_size > 0 ||
current_frame_header_->opcode !=
WebSocketFrameHeader::kOpCodeContinuation) {
- result_frame.reset(new WebSocketFrame(opcode));
+ result_frame = std::make_unique<WebSocketFrame>(opcode);
result_frame->header.CopyFrom(*current_frame_header_);
result_frame->header.final = is_final_chunk_in_message;
result_frame->header.payload_length = data_size;