Commit c58e7851 authored by avi's avatar avi Committed by Commit bot

Remove stl_util's deletion functions from remoting/.

BUG=555865

Review-Url: https://codereview.chromium.org/2386733002
Cr-Commit-Position: refs/heads/master@{#422304}
parent 07739134
......@@ -6,7 +6,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/stl_util.h"
#include "base/memory/ptr_util.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/socket/socket.h"
......@@ -46,9 +46,7 @@ std::unique_ptr<BufferedSocketWriter> BufferedSocketWriter::CreateForSocket(
BufferedSocketWriter::BufferedSocketWriter() : weak_factory_(this) {}
BufferedSocketWriter::~BufferedSocketWriter() {
base::STLDeleteElements(&queue_);
}
BufferedSocketWriter::~BufferedSocketWriter() {}
void BufferedSocketWriter::Start(
const WriteCallback& write_callback,
......@@ -68,7 +66,7 @@ void BufferedSocketWriter::Write(
if (closed_)
return;
queue_.push_back(new PendingPacket(
queue_.push_back(base::MakeUnique<PendingPacket>(
new net::DrainableIOBuffer(data.get(), data->size()), done_task));
DoWrite();
......@@ -107,7 +105,6 @@ void BufferedSocketWriter::HandleWriteResult(int result) {
if (queue_.front()->data->BytesRemaining() == 0) {
base::Closure done_task = queue_.front()->done_task;
delete queue_.front();
queue_.pop_front();
if (!done_task.is_null())
......
......@@ -6,6 +6,7 @@
#define REMOTING_BASE_BUFFERED_SOCKET_WRITER_H_
#include <list>
#include <memory>
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
......@@ -52,7 +53,6 @@ class BufferedSocketWriter {
private:
struct PendingPacket;
typedef std::list<PendingPacket*> DataQueue;
void DoWrite();
void HandleWriteResult(int result);
......@@ -65,7 +65,7 @@ class BufferedSocketWriter {
bool closed_ = false;
DataQueue queue_;
std::list<std::unique_ptr<PendingPacket>> queue_;
bool write_pending_ = false;
......
......@@ -14,8 +14,8 @@
#include "base/callback_helpers.h"
#include "base/location.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/threading/thread_task_runner_handle.h"
#include "net/base/net_errors.h"
#include "remoting/protocol/message_serialization.h"
......@@ -91,7 +91,7 @@ class ChannelMultiplexer::MuxChannel {
bool id_sent_;
int receive_id_;
MuxSocket* socket_;
std::list<PendingPacket*> pending_packets_;
std::list<std::unique_ptr<PendingPacket>> pending_packets_;
DISALLOW_COPY_AND_ASSIGN(MuxChannel);
};
......@@ -145,7 +145,6 @@ ChannelMultiplexer::MuxChannel::MuxChannel(
ChannelMultiplexer::MuxChannel::~MuxChannel() {
// Socket must be destroyed before the channel.
DCHECK(!socket_);
base::STLDeleteElements(&pending_packets_);
}
std::unique_ptr<P2PStreamSocket>
......@@ -160,7 +159,8 @@ void ChannelMultiplexer::MuxChannel::OnIncomingPacket(
std::unique_ptr<MultiplexPacket> packet) {
DCHECK_EQ(packet->channel_id(), receive_id_);
if (packet->data().size() > 0) {
pending_packets_.push_back(new PendingPacket(std::move(packet)));
pending_packets_.push_back(
base::MakeUnique<PendingPacket>(std::move(packet)));
if (socket_) {
// Notify the socket that we have more data.
socket_->OnPacketReceived();
......@@ -200,10 +200,8 @@ int ChannelMultiplexer::MuxChannel::DoRead(
DCHECK_LE(result, buffer_len);
pos += result;
buffer_len -= pos;
if (pending_packets_.front()->is_empty()) {
delete pending_packets_.front();
pending_packets_.erase(pending_packets_.begin());
}
if (pending_packets_.front()->is_empty())
pending_packets_.pop_front();
}
return pos;
}
......@@ -310,7 +308,6 @@ ChannelMultiplexer::ChannelMultiplexer(StreamChannelFactory* factory,
ChannelMultiplexer::~ChannelMultiplexer() {
DCHECK(pending_channels_.empty());
base::STLDeleteValues(&channels_);
// Cancel creation of the base channel if it hasn't finished.
if (base_channel_factory_)
......@@ -393,22 +390,19 @@ void ChannelMultiplexer::DoCreatePendingChannels() {
ChannelMultiplexer::MuxChannel* ChannelMultiplexer::GetOrCreateChannel(
const std::string& name) {
// Check if we already have a channel with the requested name.
std::map<std::string, MuxChannel*>::iterator it = channels_.find(name);
if (it != channels_.end())
return it->second;
std::unique_ptr<MuxChannel>& channel = channels_[name];
if (!channel) {
// Create a new channel if we haven't found existing one.
channel = base::MakeUnique<MuxChannel>(this, name, next_channel_id_);
++next_channel_id_;
}
// Create a new channel if we haven't found existing one.
MuxChannel* channel = new MuxChannel(this, name, next_channel_id_);
++next_channel_id_;
channels_[channel->name()] = channel;
return channel;
return channel.get();
}
void ChannelMultiplexer::OnBaseChannelError(int error) {
for (std::map<std::string, MuxChannel*>::iterator it = channels_.begin();
it != channels_.end(); ++it) {
for (auto it = channels_.begin(); it != channels_.end(); ++it) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&ChannelMultiplexer::NotifyBaseChannelError,
......@@ -418,7 +412,7 @@ void ChannelMultiplexer::OnBaseChannelError(int error) {
void ChannelMultiplexer::NotifyBaseChannelError(const std::string& name,
int error) {
std::map<std::string, MuxChannel*>::iterator it = channels_.find(name);
auto it = channels_.find(name);
if (it != channels_.end())
it->second->OnBaseChannelError(error);
}
......
......@@ -5,6 +5,8 @@
#ifndef REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_
#define REMOTING_PROTOCOL_CHANNEL_MULTIPLEXER_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "remoting/base/buffered_socket_writer.h"
......@@ -72,7 +74,7 @@ class ChannelMultiplexer : public StreamChannelFactory {
std::list<PendingChannel> pending_channels_;
int next_channel_id_;
std::map<std::string, MuxChannel*> channels_;
std::map<std::string, std::unique_ptr<MuxChannel>> channels_;
// Channels are added to |channels_by_receive_id_| only after we receive
// receive_id from the remote peer.
......
......@@ -10,7 +10,7 @@
#include <string>
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "remoting/proto/event.pb.h"
#include "remoting/proto/internal.pb.h"
......@@ -64,7 +64,7 @@ void SimulateReadSequence(const int read_sequence[], int sequence_size) {
// Then feed the protocol decoder using the above generated data and the
// read pattern.
std::list<EventMessage*> message_list;
std::list<std::unique_ptr<EventMessage>> message_list;
for (int pos = 0; pos < size;) {
SCOPED_TRACE("Input position: " + base::IntToString(pos));
......@@ -80,10 +80,10 @@ void SimulateReadSequence(const int read_sequence[], int sequence_size) {
if (!message.get())
break;
EventMessage* event = new EventMessage();
std::unique_ptr<EventMessage> event = base::MakeUnique<EventMessage>();
CompoundBufferInputStream stream(message.get());
ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream));
message_list.push_back(event);
message_list.push_back(std::move(event));
}
pos += read;
}
......@@ -92,12 +92,9 @@ void SimulateReadSequence(const int read_sequence[], int sequence_size) {
EXPECT_EQ(10u, message_list.size());
unsigned int index = 0;
for (std::list<EventMessage*>::iterator it =
message_list.begin();
it != message_list.end(); ++it) {
for (const auto& message : message_list) {
SCOPED_TRACE("Message " + base::UintToString(index));
EventMessage* message = *it;
// Partial update stream.
EXPECT_TRUE(message->has_key_event());
......@@ -107,7 +104,6 @@ void SimulateReadSequence(const int read_sequence[], int sequence_size) {
EXPECT_EQ((index % 2) != 0, message->key_event().pressed());
++index;
}
base::STLDeleteElements(&message_list);
}
TEST(MessageDecoderTest, SmallReads) {
......
......@@ -9,7 +9,6 @@
#include "base/callback.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/synchronization/waitable_event.h"
#include "net/base/net_errors.h"
#include "net/socket/socket.h"
......@@ -50,8 +49,6 @@ class MessageReaderTest : public testing::Test {
reader_.reset(new MessageReader());
}
void TearDown() override { base::STLDeleteElements(&messages_); }
void InitReader() {
reader_->StartReading(
&socket_,
......@@ -78,7 +75,7 @@ class MessageReaderTest : public testing::Test {
}
void OnMessage(std::unique_ptr<CompoundBuffer> buffer) {
messages_.push_back(buffer.release());
messages_.push_back(std::move(buffer));
callback_.OnMessage();
}
......@@ -87,7 +84,7 @@ class MessageReaderTest : public testing::Test {
FakeStreamSocket socket_;
MockMessageReceivedCallback callback_;
int read_error_ = 0;
std::vector<CompoundBuffer*> messages_;
std::vector<std::unique_ptr<CompoundBuffer>> messages_;
};
// Receive one message.
......@@ -116,8 +113,8 @@ TEST_F(MessageReaderTest, TwoMessages_Together) {
Mock::VerifyAndClearExpectations(&callback_);
Mock::VerifyAndClearExpectations(&socket_);
EXPECT_TRUE(CompareResult(messages_[0], kTestMessage1));
EXPECT_TRUE(CompareResult(messages_[1], kTestMessage2));
EXPECT_TRUE(CompareResult(messages_[0].get(), kTestMessage1));
EXPECT_TRUE(CompareResult(messages_[1].get(), kTestMessage2));
EXPECT_TRUE(socket_.read_pending());
}
......@@ -135,7 +132,7 @@ TEST_F(MessageReaderTest, TwoMessages_Separately) {
Mock::VerifyAndClearExpectations(&callback_);
Mock::VerifyAndClearExpectations(&socket_);
EXPECT_TRUE(CompareResult(messages_[0], kTestMessage1));
EXPECT_TRUE(CompareResult(messages_[0].get(), kTestMessage1));
EXPECT_TRUE(socket_.read_pending());
......@@ -145,7 +142,7 @@ TEST_F(MessageReaderTest, TwoMessages_Separately) {
AddMessage(kTestMessage2);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(CompareResult(messages_[1], kTestMessage2));
EXPECT_TRUE(CompareResult(messages_[1].get(), kTestMessage2));
EXPECT_TRUE(socket_.read_pending());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment