| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // Disconnect all of the clients. | 87 // Disconnect all of the clients. |
| 88 while (!clients_.empty()) { | 88 while (!clients_.empty()) { |
| 89 clients_.front()->DisconnectSession(protocol::OK); | 89 clients_.front()->DisconnectSession(protocol::OK); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Destroy the session manager to make sure that |signal_strategy_| does not | 92 // Destroy the session manager to make sure that |signal_strategy_| does not |
| 93 // have any listeners registered. | 93 // have any listeners registered. |
| 94 session_manager_.reset(); | 94 session_manager_.reset(); |
| 95 | 95 |
| 96 // Notify observers. | 96 // Notify observers. |
| 97 if (started_) | 97 if (started_) { |
| 98 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnShutdown()); | 98 for (auto& observer : status_observers_) |
| 99 observer.OnShutdown(); |
| 100 } |
| 99 } | 101 } |
| 100 | 102 |
| 101 void ChromotingHost::Start(const std::string& host_owner_email) { | 103 void ChromotingHost::Start(const std::string& host_owner_email) { |
| 102 DCHECK(CalledOnValidThread()); | 104 DCHECK(CalledOnValidThread()); |
| 103 DCHECK(!started_); | 105 DCHECK(!started_); |
| 104 | 106 |
| 105 HOST_LOG << "Starting host"; | 107 HOST_LOG << "Starting host"; |
| 106 started_ = true; | 108 started_ = true; |
| 107 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 109 for (auto& observer : status_observers_) |
| 108 OnStart(host_owner_email)); | 110 observer.OnStart(host_owner_email); |
| 109 | 111 |
| 110 session_manager_->AcceptIncoming( | 112 session_manager_->AcceptIncoming( |
| 111 base::Bind(&ChromotingHost::OnIncomingSession, base::Unretained(this))); | 113 base::Bind(&ChromotingHost::OnIncomingSession, base::Unretained(this))); |
| 112 } | 114 } |
| 113 | 115 |
| 114 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 116 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
| 115 DCHECK(CalledOnValidThread()); | 117 DCHECK(CalledOnValidThread()); |
| 116 status_observers_.AddObserver(observer); | 118 status_observers_.AddObserver(observer); |
| 117 } | 119 } |
| 118 | 120 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 return; | 192 return; |
| 191 } | 193 } |
| 192 } | 194 } |
| 193 | 195 |
| 194 // Disconnects above must have destroyed all other clients. | 196 // Disconnects above must have destroyed all other clients. |
| 195 DCHECK_EQ(clients_.size(), 1U); | 197 DCHECK_EQ(clients_.size(), 1U); |
| 196 | 198 |
| 197 // Notify observers that there is at least one authenticated client. | 199 // Notify observers that there is at least one authenticated client. |
| 198 const std::string& jid = client->client_jid(); | 200 const std::string& jid = client->client_jid(); |
| 199 | 201 |
| 200 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 202 for (auto& observer : status_observers_) |
| 201 OnClientAuthenticated(jid)); | 203 observer.OnClientAuthenticated(jid); |
| 202 } | 204 } |
| 203 | 205 |
| 204 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { | 206 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { |
| 205 DCHECK(CalledOnValidThread()); | 207 DCHECK(CalledOnValidThread()); |
| 206 | 208 |
| 207 // Notify observers. | 209 // Notify observers. |
| 208 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 210 for (auto& observer : status_observers_) |
| 209 OnClientConnected(client->client_jid())); | 211 observer.OnClientConnected(client->client_jid()); |
| 210 } | 212 } |
| 211 | 213 |
| 212 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { | 214 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { |
| 213 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
| 214 | 216 |
| 215 // Notify observers. | 217 // Notify observers. |
| 216 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 218 for (auto& observer : status_observers_) |
| 217 OnAccessDenied(client->client_jid())); | 219 observer.OnAccessDenied(client->client_jid()); |
| 218 } | 220 } |
| 219 | 221 |
| 220 void ChromotingHost::OnSessionClosed(ClientSession* client) { | 222 void ChromotingHost::OnSessionClosed(ClientSession* client) { |
| 221 DCHECK(CalledOnValidThread()); | 223 DCHECK(CalledOnValidThread()); |
| 222 | 224 |
| 223 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); | 225 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); |
| 224 CHECK(it != clients_.end()); | 226 CHECK(it != clients_.end()); |
| 225 | 227 |
| 226 bool was_authenticated = client->is_authenticated(); | 228 bool was_authenticated = client->is_authenticated(); |
| 227 std::string jid = client->client_jid(); | 229 std::string jid = client->client_jid(); |
| 228 clients_.erase(it); | 230 clients_.erase(it); |
| 229 delete client; | 231 delete client; |
| 230 | 232 |
| 231 if (was_authenticated) { | 233 if (was_authenticated) { |
| 232 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 234 for (auto& observer : status_observers_) |
| 233 OnClientDisconnected(jid)); | 235 observer.OnClientDisconnected(jid); |
| 234 } | 236 } |
| 235 } | 237 } |
| 236 | 238 |
| 237 void ChromotingHost::OnSessionRouteChange( | 239 void ChromotingHost::OnSessionRouteChange( |
| 238 ClientSession* session, | 240 ClientSession* session, |
| 239 const std::string& channel_name, | 241 const std::string& channel_name, |
| 240 const protocol::TransportRoute& route) { | 242 const protocol::TransportRoute& route) { |
| 241 DCHECK(CalledOnValidThread()); | 243 DCHECK(CalledOnValidThread()); |
| 242 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 244 for (auto& observer : status_observers_) |
| 243 OnClientRouteChange(session->client_jid(), channel_name, | 245 observer.OnClientRouteChange(session->client_jid(), channel_name, route); |
| 244 route)); | |
| 245 } | 246 } |
| 246 | 247 |
| 247 void ChromotingHost::OnIncomingSession( | 248 void ChromotingHost::OnIncomingSession( |
| 248 protocol::Session* session, | 249 protocol::Session* session, |
| 249 protocol::SessionManager::IncomingSessionResponse* response) { | 250 protocol::SessionManager::IncomingSessionResponse* response) { |
| 250 DCHECK(CalledOnValidThread()); | 251 DCHECK(CalledOnValidThread()); |
| 251 DCHECK(started_); | 252 DCHECK(started_); |
| 252 | 253 |
| 253 if (login_backoff_.ShouldRejectRequest()) { | 254 if (login_backoff_.ShouldRejectRequest()) { |
| 254 LOG(WARNING) << "Rejecting connection due to" | 255 LOG(WARNING) << "Rejecting connection due to" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 DCHECK(CalledOnValidThread()); | 288 DCHECK(CalledOnValidThread()); |
| 288 | 289 |
| 289 while (!clients_.empty()) { | 290 while (!clients_.empty()) { |
| 290 size_t size = clients_.size(); | 291 size_t size = clients_.size(); |
| 291 clients_.front()->DisconnectSession(protocol::OK); | 292 clients_.front()->DisconnectSession(protocol::OK); |
| 292 CHECK_EQ(clients_.size(), size - 1); | 293 CHECK_EQ(clients_.size(), size - 1); |
| 293 } | 294 } |
| 294 } | 295 } |
| 295 | 296 |
| 296 } // namespace remoting | 297 } // namespace remoting |
| OLD | NEW |