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