Chromium Code Reviews| 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() |