| Index: net/server/http_server.cc
|
| diff --git a/net/server/http_server.cc b/net/server/http_server.cc
|
| index c362e1b080f40b749d973fa2bbf34e0624af4a87..a4a85cfa9371466a6fd29de14d968d271bfe3912 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,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()
|
|
|