| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/chromoting_host.h" | 5 #include "remoting/host/chromoting_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { | 173 void ChromotingHost::OnSessionAuthenticated(ClientSession* client) { |
| 174 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
| 175 | 175 |
| 176 login_backoff_.Reset(); | 176 login_backoff_.Reset(); |
| 177 | 177 |
| 178 // Disconnect all other clients. |it| should be advanced before Disconnect() | 178 // Disconnect all other clients. |it| should be advanced before Disconnect() |
| 179 // is called to avoid it becoming invalid when the client is removed from | 179 // is called to avoid it becoming invalid when the client is removed from |
| 180 // the list. | 180 // the list. |
| 181 ClientList::iterator it = clients_.begin(); | 181 ClientSessions::iterator it = clients_.begin(); |
| 182 base::WeakPtr<ChromotingHost> self = weak_factory_.GetWeakPtr(); | 182 base::WeakPtr<ChromotingHost> self = weak_factory_.GetWeakPtr(); |
| 183 while (it != clients_.end()) { | 183 while (it != clients_.end()) { |
| 184 ClientSession* other_client = *it++; | 184 ClientSession* other_client = it->get(); |
| 185 ++it; |
| 185 if (other_client != client) { | 186 if (other_client != client) { |
| 186 other_client->DisconnectSession(protocol::OK); | 187 other_client->DisconnectSession(protocol::OK); |
| 187 | 188 |
| 188 // Quit if the host was destroyed. | 189 // Quit if the host was destroyed. |
| 189 if (!self) | 190 if (!self) |
| 190 return; | 191 return; |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Disconnects above must have destroyed all other clients. | 195 // Disconnects above must have destroyed all other clients. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 213 DCHECK(CalledOnValidThread()); | 214 DCHECK(CalledOnValidThread()); |
| 214 | 215 |
| 215 // Notify observers. | 216 // Notify observers. |
| 216 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 217 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, |
| 217 OnAccessDenied(client->client_jid())); | 218 OnAccessDenied(client->client_jid())); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void ChromotingHost::OnSessionClosed(ClientSession* client) { | 221 void ChromotingHost::OnSessionClosed(ClientSession* client) { |
| 221 DCHECK(CalledOnValidThread()); | 222 DCHECK(CalledOnValidThread()); |
| 222 | 223 |
| 223 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); | 224 ClientSessions::iterator it = |
| 225 std::find_if(clients_.begin(), clients_.end(), |
| 226 [client](const std::unique_ptr<ClientSession>& item) { |
| 227 return item.get() == client; |
| 228 }); |
| 224 CHECK(it != clients_.end()); | 229 CHECK(it != clients_.end()); |
| 225 | 230 |
| 226 bool was_authenticated = client->is_authenticated(); | 231 bool was_authenticated = client->is_authenticated(); |
| 227 std::string jid = client->client_jid(); | 232 std::string jid = client->client_jid(); |
| 228 clients_.erase(it); | 233 clients_.erase(it); |
| 229 delete client; | |
| 230 | 234 |
| 231 if (was_authenticated) { | 235 if (was_authenticated) { |
| 232 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 236 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, |
| 233 OnClientDisconnected(jid)); | 237 OnClientDisconnected(jid)); |
| 234 } | 238 } |
| 235 } | 239 } |
| 236 | 240 |
| 237 void ChromotingHost::OnSessionRouteChange( | 241 void ChromotingHost::OnSessionRouteChange( |
| 238 ClientSession* session, | 242 ClientSession* session, |
| 239 const std::string& channel_name, | 243 const std::string& channel_name, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 269 connection.reset(new protocol::WebrtcConnectionToClient( | 273 connection.reset(new protocol::WebrtcConnectionToClient( |
| 270 base::WrapUnique(session), transport_context_, | 274 base::WrapUnique(session), transport_context_, |
| 271 video_encode_task_runner_, audio_task_runner_)); | 275 video_encode_task_runner_, audio_task_runner_)); |
| 272 } else { | 276 } else { |
| 273 connection.reset(new protocol::IceConnectionToClient( | 277 connection.reset(new protocol::IceConnectionToClient( |
| 274 base::WrapUnique(session), transport_context_, | 278 base::WrapUnique(session), transport_context_, |
| 275 video_encode_task_runner_, audio_task_runner_)); | 279 video_encode_task_runner_, audio_task_runner_)); |
| 276 } | 280 } |
| 277 | 281 |
| 278 // Create a ClientSession object. | 282 // Create a ClientSession object. |
| 279 ClientSession* client = new ClientSession( | 283 clients_.push_back(base::MakeUnique<ClientSession>( |
| 280 this, std::move(connection), desktop_environment_factory_, | 284 this, std::move(connection), desktop_environment_factory_, |
| 281 max_session_duration_, pairing_registry_, extensions_.get()); | 285 max_session_duration_, pairing_registry_, extensions_.get())); |
| 282 | |
| 283 clients_.push_back(client); | |
| 284 } | 286 } |
| 285 | 287 |
| 286 void ChromotingHost::DisconnectAllClients() { | 288 void ChromotingHost::DisconnectAllClients() { |
| 287 DCHECK(CalledOnValidThread()); | 289 DCHECK(CalledOnValidThread()); |
| 288 | 290 |
| 289 while (!clients_.empty()) { | 291 while (!clients_.empty()) { |
| 290 size_t size = clients_.size(); | 292 size_t size = clients_.size(); |
| 291 clients_.front()->DisconnectSession(protocol::OK); | 293 clients_.front()->DisconnectSession(protocol::OK); |
| 292 CHECK_EQ(clients_.size(), size - 1); | 294 CHECK_EQ(clients_.size(), size - 1); |
| 293 } | 295 } |
| 294 } | 296 } |
| 295 | 297 |
| 296 } // namespace remoting | 298 } // namespace remoting |
| OLD | NEW |