Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Unified Diff: net/server/http_server.cc

Issue 2341393002: Remove stl_util's STLDeleteContainerPairSecondPointers from net/. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/server/http_server.h ('k') | net/test/embedded_test_server/embedded_test_server.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/server/http_server.cc
diff --git a/net/server/http_server.cc b/net/server/http_server.cc
index c362e1b080f40b749d973fa2bbf34e0624af4a87..5c876f877481dfe5cd8277696d67651ba6884247 100644
--- a/net/server/http_server.cc
+++ b/net/server/http_server.cc
@@ -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,10 +105,11 @@ 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;
+ std::unique_ptr<HttpConnection> connection = std::move(it->second);
id_to_connection_.erase(connection_id);
davidben 2016/09/16 22:11:13 Nit: id_to_connection_.erase(it) to save a lookup?
Avi (use Gerrit) 2016/09/16 22:14:40 Done.
delegate_->OnClose(connection_id);
@@ -119,7 +117,8 @@ void HttpServer::Close(int connection_id) {
// 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()
« no previous file with comments | « net/server/http_server.h ('k') | net/test/embedded_test_server/embedded_test_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698