OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "base/task.h" | 8 #include "base/task.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "remoting/base/constants.h" | 10 #include "remoting/base/constants.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 //////////////////////////////////////////////////////////////////////////// | 133 //////////////////////////////////////////////////////////////////////////// |
134 // JingleClient::Callback implementations | 134 // JingleClient::Callback implementations |
135 void ChromotingHost::OnStateChange(JingleClient* jingle_client, | 135 void ChromotingHost::OnStateChange(JingleClient* jingle_client, |
136 JingleClient::State state) { | 136 JingleClient::State state) { |
137 if (state == JingleClient::CONNECTED) { | 137 if (state == JingleClient::CONNECTED) { |
138 DCHECK_EQ(jingle_client_.get(), jingle_client); | 138 DCHECK_EQ(jingle_client_.get(), jingle_client); |
139 LOG(INFO) << "Host connected as " | 139 LOG(INFO) << "Host connected as " |
140 << jingle_client->GetFullJid() << "." << std::endl; | 140 << jingle_client->GetFullJid() << "." << std::endl; |
141 | 141 |
142 // Start heartbeating after we connected | 142 // Start heartbeating after we've connected. |
143 heartbeat_sender_ = new HeartbeatSender(); | 143 heartbeat_sender_->Start(); |
144 heartbeat_sender_->Start(config_, jingle_client_.get()); | |
145 } else if (state == JingleClient::CLOSED) { | 144 } else if (state == JingleClient::CLOSED) { |
146 LOG(INFO) << "Host disconnected from talk network." << std::endl; | 145 LOG(INFO) << "Host disconnected from talk network." << std::endl; |
147 heartbeat_sender_ = NULL; | 146 |
| 147 // Stop heartbeating. |
| 148 heartbeat_sender_->Stop(); |
148 | 149 |
149 // TODO(sergeyu): We should try reconnecting here instead of terminating | 150 // TODO(sergeyu): We should try reconnecting here instead of terminating |
150 // the host. | 151 // the host. |
151 // Post a shutdown task to properly shutdown the chromoting host. | 152 // Post a shutdown task to properly shutdown the chromoting host. |
152 context_->main_message_loop()->PostTask( | 153 context_->main_message_loop()->PostTask( |
153 FROM_HERE, NewRunnableMethod(this, &ChromotingHost::DoShutdown)); | 154 FROM_HERE, NewRunnableMethod(this, &ChromotingHost::DoShutdown)); |
154 } | 155 } |
155 } | 156 } |
156 | 157 |
157 bool ChromotingHost::OnAcceptConnection( | 158 bool ChromotingHost::OnAcceptConnection( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) || | 213 if (!config_->GetString(kXmppLoginConfigPath, &xmpp_login) || |
213 !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token)) { | 214 !config_->GetString(kXmppAuthTokenConfigPath, &xmpp_auth_token)) { |
214 LOG(ERROR) << "XMMP credentials are not defined in config."; | 215 LOG(ERROR) << "XMMP credentials are not defined in config."; |
215 return; | 216 return; |
216 } | 217 } |
217 | 218 |
218 // Connect to the talk network with a JingleClient. | 219 // Connect to the talk network with a JingleClient. |
219 jingle_client_ = new JingleClient(context_->jingle_thread()); | 220 jingle_client_ = new JingleClient(context_->jingle_thread()); |
220 jingle_client_->Init(xmpp_login, xmpp_auth_token, | 221 jingle_client_->Init(xmpp_login, xmpp_auth_token, |
221 kChromotingTokenServiceName, this); | 222 kChromotingTokenServiceName, this); |
| 223 |
| 224 heartbeat_sender_ = new HeartbeatSender(); |
| 225 if (!heartbeat_sender_->Init(config_, jingle_client_.get())) { |
| 226 LOG(ERROR) << "Failed to initialize HeartbeatSender."; |
| 227 return; |
| 228 } |
222 } | 229 } |
223 | 230 |
224 void ChromotingHost::DoShutdown() { | 231 void ChromotingHost::DoShutdown() { |
225 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); | 232 DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); |
226 | 233 |
227 // No-op if this object is not started yet. | 234 // No-op if this object is not started yet. |
228 { | 235 { |
229 AutoLock auto_lock(lock_); | 236 AutoLock auto_lock(lock_); |
230 if (state_ != kStarted) | 237 if (state_ != kStarted) |
231 return; | 238 return; |
(...skipping 16 matching lines...) Expand all Loading... |
248 jingle_client_->Close(); | 255 jingle_client_->Close(); |
249 } | 256 } |
250 | 257 |
251 // Lastly call the shutdown task. | 258 // Lastly call the shutdown task. |
252 if (shutdown_task_.get()) { | 259 if (shutdown_task_.get()) { |
253 shutdown_task_->Run(); | 260 shutdown_task_->Run(); |
254 } | 261 } |
255 } | 262 } |
256 | 263 |
257 } // namespace remoting | 264 } // namespace remoting |
OLD | NEW |