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

Remove stl_util's STLDeleteContainerPairSecondPointers from net/.

BUG=555865

Review-Url: https://codereview.chromium.org/2341393002
Cr-Commit-Position: refs/heads/master@{#419320}
parent 192eee39
......@@ -12,7 +12,6 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
......@@ -45,8 +44,6 @@ HttpServer::HttpServer(std::unique_ptr<ServerSocket> server_socket,
}
HttpServer::~HttpServer() {
base::STLDeleteContainerPairSecondPointers(id_to_connection_.begin(),
id_to_connection_.end());
}
void HttpServer::AcceptWebSocket(
......@@ -108,18 +105,20 @@ void HttpServer::Send500(int connection_id, const std::string& message) {
}
void HttpServer::Close(int connection_id) {
HttpConnection* connection = FindConnection(connection_id);
if (connection == NULL)
auto it = id_to_connection_.find(connection_id);
if (it == id_to_connection_.end())
return;
id_to_connection_.erase(connection_id);
std::unique_ptr<HttpConnection> connection = std::move(it->second);
id_to_connection_.erase(it);
delegate_->OnClose(connection_id);
// The call stack might have callbacks which still have the pointer of
// connection. Instead of referencing connection with ID all the time,
// destroys the connection in next run loop to make sure any pending
// callbacks in the call stack return.
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, connection);
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE,
connection.release());
}
int HttpServer::GetLocalAddress(IPEndPoint* address) {
......@@ -161,9 +160,10 @@ int HttpServer::HandleAcceptResult(int rv) {
return rv;
}
HttpConnection* connection =
new HttpConnection(++last_id_, std::move(accepted_socket_));
id_to_connection_[connection->id()] = connection;
std::unique_ptr<HttpConnection> connection_ptr =
base::MakeUnique<HttpConnection>(++last_id_, std::move(accepted_socket_));
HttpConnection* connection = connection_ptr.get();
id_to_connection_[connection->id()] = std::move(connection_ptr);
delegate_->OnConnect(connection->id());
if (!HasClosedConnection(connection))
DoReadLoop(connection);
......@@ -453,10 +453,10 @@ bool HttpServer::ParseHeaders(const char* data,
}
HttpConnection* HttpServer::FindConnection(int connection_id) {
IdToConnectionMap::iterator it = id_to_connection_.find(connection_id);
auto it = id_to_connection_.find(connection_id);
if (it == id_to_connection_.end())
return NULL;
return it->second;
return nullptr;
return it->second.get();
}
// This is called after any delegate callbacks are called to check if Close()
......
......@@ -82,8 +82,6 @@ class HttpServer {
private:
friend class HttpServerTest;
typedef std::map<int, HttpConnection*> IdToConnectionMap;
void DoAcceptLoop();
void OnAcceptCompleted(int rv);
int HandleAcceptResult(int rv);
......@@ -114,7 +112,7 @@ class HttpServer {
HttpServer::Delegate* const delegate_;
int last_id_;
IdToConnectionMap id_to_connection_;
std::map<int, std::unique_ptr<HttpConnection>> id_to_connection_;
base::WeakPtrFactory<HttpServer> weak_ptr_factory_;
......
......@@ -11,11 +11,11 @@
#include "base/files/file_util.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/process/process_metrics.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
......@@ -170,8 +170,6 @@ void EmbeddedTestServer::ShutdownOnIOThread() {
DCHECK(io_thread_->task_runner()->BelongsToCurrentThread());
weak_factory_.InvalidateWeakPtrs();
listen_socket_.reset();
base::STLDeleteContainerPairSecondPointers(connections_.begin(),
connections_.end());
connections_.clear();
}
......@@ -343,8 +341,6 @@ bool EmbeddedTestServer::FlushAllSocketsAndConnectionsOnUIThread() {
}
void EmbeddedTestServer::FlushAllSocketsAndConnections() {
base::STLDeleteContainerPairSecondPointers(connections_.begin(),
connections_.end());
connections_.clear();
}
......@@ -370,10 +366,12 @@ void EmbeddedTestServer::HandleAcceptResult(
if (is_using_ssl_)
socket = DoSSLUpgrade(std::move(socket));
HttpConnection* http_connection = new HttpConnection(
std::move(socket),
base::Bind(&EmbeddedTestServer::HandleRequest, base::Unretained(this)));
connections_[http_connection->socket_.get()] = http_connection;
std::unique_ptr<HttpConnection> http_connection_ptr =
base::MakeUnique<HttpConnection>(
std::move(socket), base::Bind(&EmbeddedTestServer::HandleRequest,
base::Unretained(this)));
HttpConnection* http_connection = http_connection_ptr.get();
connections_[http_connection->socket_.get()] = std::move(http_connection_ptr);
if (is_using_ssl_) {
SSLServerSocket* ssl_socket =
......@@ -429,18 +427,16 @@ void EmbeddedTestServer::DidClose(HttpConnection* connection) {
DCHECK_EQ(1u, connections_.count(connection->socket_.get()));
connections_.erase(connection->socket_.get());
delete connection;
}
HttpConnection* EmbeddedTestServer::FindConnection(StreamSocket* socket) {
DCHECK(io_thread_->task_runner()->BelongsToCurrentThread());
std::map<StreamSocket*, HttpConnection*>::iterator it =
connections_.find(socket);
auto it = connections_.find(socket);
if (it == connections_.end()) {
return NULL;
return nullptr;
}
return it->second;
return it->second.get();
}
bool EmbeddedTestServer::PostTaskToIOThreadAndWait(
......
......@@ -278,8 +278,7 @@ class EmbeddedTestServer {
GURL base_url_;
IPEndPoint local_endpoint_;
// Owns the HttpConnection objects.
std::map<StreamSocket*, HttpConnection*> connections_;
std::map<StreamSocket*, std::unique_ptr<HttpConnection>> connections_;
// Vector of registered and default request handlers and monitors.
std::vector<HandleRequestCallback> request_handlers_;
......
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