Commit e245237f authored by Bence Béky's avatar Bence Béky Committed by Commit Bot

Use unique_ptr<> in PendingConnectsMap.

PendingConnectsMap already owns WebSocketTransportConnectJob,
and the raw pointer type is not idiomatic for this case.
Using release() for taking over ownership and naked deletes
when erasing are screaming for unique_ptr<>.

Change-Id: Ibdd2a219392bdd332c6c2e477687e8dbdf6e600c
Reviewed-on: https://chromium-review.googlesource.com/1155310Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Commit-Queue: Bence Béky <bnc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579381}
parent 15099837
...@@ -450,13 +450,11 @@ void WebSocketTransportClientSocketPool::FlushWithError(int error) { ...@@ -450,13 +450,11 @@ void WebSocketTransportClientSocketPool::FlushWithError(int error) {
// anyway. // anyway.
flushing_ = true; flushing_ = true;
for (PendingConnectsMap::iterator it = pending_connects_.begin(); for (PendingConnectsMap::iterator it = pending_connects_.begin();
it != pending_connects_.end(); it != pending_connects_.end();) {
++it) {
InvokeUserCallbackLater(it->second->handle(), InvokeUserCallbackLater(it->second->handle(),
it->second->release_callback(), error); it->second->release_callback(), error);
delete it->second, it->second = nullptr; it = pending_connects_.erase(it);
} }
pending_connects_.clear();
for (StalledRequestQueue::iterator it = stalled_request_queue_.begin(); for (StalledRequestQueue::iterator it = stalled_request_queue_.begin();
it != stalled_request_queue_.end(); it != stalled_request_queue_.end();
++it) { ++it) {
...@@ -638,9 +636,10 @@ void WebSocketTransportClientSocketPool::HandOutSocket( ...@@ -638,9 +636,10 @@ void WebSocketTransportClientSocketPool::HandOutSocket(
void WebSocketTransportClientSocketPool::AddJob( void WebSocketTransportClientSocketPool::AddJob(
ClientSocketHandle* handle, ClientSocketHandle* handle,
std::unique_ptr<WebSocketTransportConnectJob> connect_job) { std::unique_ptr<WebSocketTransportConnectJob> connect_job) {
bool inserted = bool inserted = pending_connects_
pending_connects_.insert(PendingConnectsMap::value_type( .insert(PendingConnectsMap::value_type(
handle, connect_job.release())).second; handle, std::move(connect_job)))
.second;
DCHECK(inserted); DCHECK(inserted);
} }
...@@ -651,10 +650,7 @@ bool WebSocketTransportClientSocketPool::DeleteJob(ClientSocketHandle* handle) { ...@@ -651,10 +650,7 @@ bool WebSocketTransportClientSocketPool::DeleteJob(ClientSocketHandle* handle) {
// Deleting a ConnectJob which holds an endpoint lock can lead to a different // Deleting a ConnectJob which holds an endpoint lock can lead to a different
// ConnectJob proceeding to connect. If the connect proceeds synchronously // ConnectJob proceeding to connect. If the connect proceeds synchronously
// (usually because of a failure) then it can trigger that job to be // (usually because of a failure) then it can trigger that job to be
// deleted. |it| remains valid because std::map guarantees that erase() does // deleted.
// not invalid iterators to other entries.
delete it->second, it->second = nullptr;
DCHECK(pending_connects_.find(handle) == it);
pending_connects_.erase(it); pending_connects_.erase(it);
return true; return true;
} }
...@@ -664,7 +660,7 @@ WebSocketTransportClientSocketPool::LookupConnectJob( ...@@ -664,7 +660,7 @@ WebSocketTransportClientSocketPool::LookupConnectJob(
const ClientSocketHandle* handle) const { const ClientSocketHandle* handle) const {
PendingConnectsMap::const_iterator it = pending_connects_.find(handle); PendingConnectsMap::const_iterator it = pending_connects_.find(handle);
CHECK(it != pending_connects_.end()); CHECK(it != pending_connects_.end());
return it->second; return it->second.get();
} }
void WebSocketTransportClientSocketPool::ActivateStalledRequest() { void WebSocketTransportClientSocketPool::ActivateStalledRequest() {
......
...@@ -228,7 +228,8 @@ class NET_EXPORT_PRIVATE WebSocketTransportClientSocketPool ...@@ -228,7 +228,8 @@ class NET_EXPORT_PRIVATE WebSocketTransportClientSocketPool
friend class ConnectJobDelegate; friend class ConnectJobDelegate;
typedef std::map<const ClientSocketHandle*, WebSocketTransportConnectJob*> typedef std::map<const ClientSocketHandle*,
std::unique_ptr<WebSocketTransportConnectJob>>
PendingConnectsMap; PendingConnectsMap;
// This is a list so that we can remove requests from the middle, and also // This is a list so that we can remove requests from the middle, and also
// so that iterators are not invalidated unless the corresponding request is // so that iterators are not invalidated unless the corresponding request is
......
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