Chromium Code Reviews| 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_) |
|
Sergey Ulanov
2016/10/17 16:45:31
Please add {}
Eric Willigers
2016/10/17 22:32:31
Done.
| |
| 98 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, OnShutdown()); | 98 for (auto& observer : status_observers_) |
| 99 observer.OnShutdown(); | |
| 99 } | 100 } |
| 100 | 101 |
| 101 void ChromotingHost::Start(const std::string& host_owner_email) { | 102 void ChromotingHost::Start(const std::string& host_owner_email) { |
| 102 DCHECK(CalledOnValidThread()); | 103 DCHECK(CalledOnValidThread()); |
| 103 DCHECK(!started_); | 104 DCHECK(!started_); |
| 104 | 105 |
| 105 HOST_LOG << "Starting host"; | 106 HOST_LOG << "Starting host"; |
| 106 started_ = true; | 107 started_ = true; |
| 107 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 108 for (auto& observer : status_observers_) |
| 108 OnStart(host_owner_email)); | 109 observer.OnStart(host_owner_email); |
| 109 | 110 |
| 110 session_manager_->AcceptIncoming( | 111 session_manager_->AcceptIncoming( |
| 111 base::Bind(&ChromotingHost::OnIncomingSession, base::Unretained(this))); | 112 base::Bind(&ChromotingHost::OnIncomingSession, base::Unretained(this))); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { | 115 void ChromotingHost::AddStatusObserver(HostStatusObserver* observer) { |
| 115 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
| 116 status_observers_.AddObserver(observer); | 117 status_observers_.AddObserver(observer); |
| 117 } | 118 } |
| 118 | 119 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. |
| 195 DCHECK_EQ(clients_.size(), 1U); | 196 DCHECK_EQ(clients_.size(), 1U); |
| 196 | 197 |
| 197 // Notify observers that there is at least one authenticated client. | 198 // Notify observers that there is at least one authenticated client. |
| 198 const std::string& jid = client->client_jid(); | 199 const std::string& jid = client->client_jid(); |
| 199 | 200 |
| 200 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 201 for (auto& observer : status_observers_) |
| 201 OnClientAuthenticated(jid)); | 202 observer.OnClientAuthenticated(jid); |
| 202 } | 203 } |
| 203 | 204 |
| 204 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { | 205 void ChromotingHost::OnSessionChannelsConnected(ClientSession* client) { |
| 205 DCHECK(CalledOnValidThread()); | 206 DCHECK(CalledOnValidThread()); |
| 206 | 207 |
| 207 // Notify observers. | 208 // Notify observers. |
| 208 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 209 for (auto& observer : status_observers_) |
| 209 OnClientConnected(client->client_jid())); | 210 observer.OnClientConnected(client->client_jid()); |
| 210 } | 211 } |
| 211 | 212 |
| 212 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { | 213 void ChromotingHost::OnSessionAuthenticationFailed(ClientSession* client) { |
| 213 DCHECK(CalledOnValidThread()); | 214 DCHECK(CalledOnValidThread()); |
| 214 | 215 |
| 215 // Notify observers. | 216 // Notify observers. |
| 216 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 217 for (auto& observer : status_observers_) |
| 217 OnAccessDenied(client->client_jid())); | 218 observer.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 ClientList::iterator it = std::find(clients_.begin(), clients_.end(), client); |
| 224 CHECK(it != clients_.end()); | 225 CHECK(it != clients_.end()); |
| 225 | 226 |
| 226 bool was_authenticated = client->is_authenticated(); | 227 bool was_authenticated = client->is_authenticated(); |
| 227 std::string jid = client->client_jid(); | 228 std::string jid = client->client_jid(); |
| 228 clients_.erase(it); | 229 clients_.erase(it); |
| 229 delete client; | 230 delete client; |
| 230 | 231 |
| 231 if (was_authenticated) { | 232 if (was_authenticated) { |
| 232 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 233 for (auto& observer : status_observers_) |
| 233 OnClientDisconnected(jid)); | 234 observer.OnClientDisconnected(jid); |
| 234 } | 235 } |
| 235 } | 236 } |
| 236 | 237 |
| 237 void ChromotingHost::OnSessionRouteChange( | 238 void ChromotingHost::OnSessionRouteChange( |
| 238 ClientSession* session, | 239 ClientSession* session, |
| 239 const std::string& channel_name, | 240 const std::string& channel_name, |
| 240 const protocol::TransportRoute& route) { | 241 const protocol::TransportRoute& route) { |
| 241 DCHECK(CalledOnValidThread()); | 242 DCHECK(CalledOnValidThread()); |
| 242 FOR_EACH_OBSERVER(HostStatusObserver, status_observers_, | 243 for (auto& observer : status_observers_) |
| 243 OnClientRouteChange(session->client_jid(), channel_name, | 244 observer.OnClientRouteChange(session->client_jid(), channel_name, route); |
| 244 route)); | |
| 245 } | 245 } |
| 246 | 246 |
| 247 void ChromotingHost::OnIncomingSession( | 247 void ChromotingHost::OnIncomingSession( |
| 248 protocol::Session* session, | 248 protocol::Session* session, |
| 249 protocol::SessionManager::IncomingSessionResponse* response) { | 249 protocol::SessionManager::IncomingSessionResponse* response) { |
| 250 DCHECK(CalledOnValidThread()); | 250 DCHECK(CalledOnValidThread()); |
| 251 DCHECK(started_); | 251 DCHECK(started_); |
| 252 | 252 |
| 253 if (login_backoff_.ShouldRejectRequest()) { | 253 if (login_backoff_.ShouldRejectRequest()) { |
| 254 LOG(WARNING) << "Rejecting connection due to" | 254 LOG(WARNING) << "Rejecting connection due to" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 DCHECK(CalledOnValidThread()); | 287 DCHECK(CalledOnValidThread()); |
| 288 | 288 |
| 289 while (!clients_.empty()) { | 289 while (!clients_.empty()) { |
| 290 size_t size = clients_.size(); | 290 size_t size = clients_.size(); |
| 291 clients_.front()->DisconnectSession(protocol::OK); | 291 clients_.front()->DisconnectSession(protocol::OK); |
| 292 CHECK_EQ(clients_.size(), size - 1); | 292 CHECK_EQ(clients_.size(), size - 1); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 } // namespace remoting | 296 } // namespace remoting |
| OLD | NEW |