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

Unified Diff: remoting/host/chromoting_host.cc

Issue 2420183002: Don't use barcodes in ProtocolPerfTests (Closed)
Patch Set: Update ChromotingHost::OnSessionAuthenticated() to fix test crash Created 4 years, 2 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 | « remoting/host/chromoting_host.h ('k') | remoting/host/chromoting_host_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/chromoting_host.cc
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index c137d55d2ba337923ff3b32d6cae3aef6cbf7c04..eb9e182c548aaa28402891be547fb562d9182270 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -177,30 +177,24 @@ void ChromotingHost::OnSessionAuthenticated(ClientSession* client) {
login_backoff_.Reset();
- // Disconnect all other clients. |it| should be advanced before Disconnect()
- // is called to avoid it becoming invalid when the client is removed from
- // the list.
- ClientList::iterator it = clients_.begin();
+ // Disconnect all clients, except |client|.
base::WeakPtr<ChromotingHost> self = weak_factory_.GetWeakPtr();
- while (it != clients_.end()) {
- ClientSession* other_client = *it++;
- if (other_client != client) {
- other_client->DisconnectSession(protocol::OK);
-
- // Quit if the host was destroyed.
- if (!self)
- return;
- }
+ while (clients_.size() > 1) {
+ clients_[(clients_.front().get() == client) ? 1 : 0]->DisconnectSession(
+ protocol::OK);
+
+ // Quit if the host was destroyed.
+ if (!self)
+ return;
}
// Disconnects above must have destroyed all other clients.
DCHECK_EQ(clients_.size(), 1U);
+ DCHECK(clients_.front().get() == client);
// Notify observers that there is at least one authenticated client.
- const std::string& jid = client->client_jid();
-
for (auto& observer : status_observers_)
- observer.OnClientAuthenticated(jid);
+ observer.OnClientAuthenticated(client->client_jid());
}
void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) {
@@ -222,13 +216,16 @@ void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) {
void ChromotingHost::OnSessionClosed(ClientSession* client) {
DCHECK(CalledOnValidThread());
- ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client);
+ ClientSessions::iterator it =
+ std::find_if(clients_.begin(), clients_.end(),
+ [client](const std::unique_ptr<ClientSession>& item) {
+ return item.get() == client;
+ });
CHECK(it != clients_.end());
bool was_authenticated = client->is_authenticated();
std::string jid = client->client_jid();
clients_.erase(it);
- delete client;
if (was_authenticated) {
for (auto& observer : status_observers_)
@@ -277,11 +274,9 @@ void ChromotingHost::OnIncomingSession(
}
// Create a ClientSession object.
- ClientSession* client = new ClientSession(
+ clients_.push_back(base::MakeUnique<ClientSession>(
this, std::move(connection), desktop_environment_factory_,
- max_session_duration_, pairing_registry_, extensions_.get());
-
- clients_.push_back(client);
+ max_session_duration_, pairing_registry_, extensions_.get()));
}
void ChromotingHost::DisconnectAllClients() {
« no previous file with comments | « remoting/host/chromoting_host.h ('k') | remoting/host/chromoting_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698