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) {
// anyway.
flushing_ = true;
for (PendingConnectsMap::iterator it = pending_connects_.begin();
it != pending_connects_.end();
++it) {
it != pending_connects_.end();) {
InvokeUserCallbackLater(it->second->handle(),
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();
it != stalled_request_queue_.end();
++it) {
......@@ -638,9 +636,10 @@ void WebSocketTransportClientSocketPool::HandOutSocket(
void WebSocketTransportClientSocketPool::AddJob(
ClientSocketHandle* handle,
std::unique_ptr<WebSocketTransportConnectJob> connect_job) {
bool inserted =
pending_connects_.insert(PendingConnectsMap::value_type(
handle, connect_job.release())).second;
bool inserted = pending_connects_
.insert(PendingConnectsMap::value_type(
handle, std::move(connect_job)))
.second;
DCHECK(inserted);
}
......@@ -651,10 +650,7 @@ bool WebSocketTransportClientSocketPool::DeleteJob(ClientSocketHandle* handle) {
// Deleting a ConnectJob which holds an endpoint lock can lead to a different
// ConnectJob proceeding to connect. If the connect proceeds synchronously
// (usually because of a failure) then it can trigger that job to be
// deleted. |it| remains valid because std::map guarantees that erase() does
// not invalid iterators to other entries.
delete it->second, it->second = nullptr;
DCHECK(pending_connects_.find(handle) == it);
// deleted.
pending_connects_.erase(it);
return true;
}
......@@ -664,7 +660,7 @@ WebSocketTransportClientSocketPool::LookupConnectJob(
const ClientSocketHandle* handle) const {
PendingConnectsMap::const_iterator it = pending_connects_.find(handle);
CHECK(it != pending_connects_.end());
return it->second;
return it->second.get();
}
void WebSocketTransportClientSocketPool::ActivateStalledRequest() {
......
......@@ -228,7 +228,8 @@ class NET_EXPORT_PRIVATE WebSocketTransportClientSocketPool
friend class ConnectJobDelegate;
typedef std::map<const ClientSocketHandle*, WebSocketTransportConnectJob*>
typedef std::map<const ClientSocketHandle*,
std::unique_ptr<WebSocketTransportConnectJob>>
PendingConnectsMap;
// 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
......
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