| 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 // This is an application of a minimal host process in a Chromoting | 5 // This is an application of a minimal host process in a Chromoting |
| 6 // system. It serves the purpose of gluing different pieces together | 6 // system. It serves the purpose of gluing different pieces together |
| 7 // to make a functional host process for testing. | 7 // to make a functional host process for testing. |
| 8 // | 8 // |
| 9 // It peforms the following functionality: | 9 // It peforms the following functionality: |
| 10 // 1. Connect to the GTalk network and register the machine as a host. | 10 // 1. Connect to the GTalk network and register the machine as a host. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "base/path_service.h" | 28 #include "base/path_service.h" |
| 29 #include "base/string_number_conversions.h" | 29 #include "base/string_number_conversions.h" |
| 30 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
| 31 #include "base/threading/thread.h" | 31 #include "base/threading/thread.h" |
| 32 #include "crypto/nss_util.h" | 32 #include "crypto/nss_util.h" |
| 33 #include "net/base/network_change_notifier.h" | 33 #include "net/base/network_change_notifier.h" |
| 34 #include "remoting/base/constants.h" | 34 #include "remoting/base/constants.h" |
| 35 #include "remoting/host/capturer_fake.h" | 35 #include "remoting/host/capturer_fake.h" |
| 36 #include "remoting/host/chromoting_host.h" | 36 #include "remoting/host/chromoting_host.h" |
| 37 #include "remoting/host/chromoting_host_context.h" | 37 #include "remoting/host/chromoting_host_context.h" |
| 38 #include "remoting/host/constants.h" |
| 38 #include "remoting/host/desktop_environment.h" | 39 #include "remoting/host/desktop_environment.h" |
| 39 #include "remoting/host/event_executor.h" | 40 #include "remoting/host/event_executor.h" |
| 40 #include "remoting/host/heartbeat_sender.h" | 41 #include "remoting/host/heartbeat_sender.h" |
| 41 #include "remoting/host/host_key_pair.h" | 42 #include "remoting/host/host_key_pair.h" |
| 42 #include "remoting/host/host_secret.h" | 43 #include "remoting/host/host_secret.h" |
| 43 #include "remoting/host/it2me_host_user_interface.h" | 44 #include "remoting/host/it2me_host_user_interface.h" |
| 44 #include "remoting/host/json_host_config.h" | 45 #include "remoting/host/json_host_config.h" |
| 45 #include "remoting/host/log_to_server.h" | 46 #include "remoting/host/log_to_server.h" |
| 46 #include "remoting/host/register_support_host_request.h" | 47 #include "remoting/host/register_support_host_request.h" |
| 47 #include "remoting/host/signaling_connector.h" | 48 #include "remoting/host/signaling_connector.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } // namespace | 88 } // namespace |
| 88 | 89 |
| 89 namespace remoting { | 90 namespace remoting { |
| 90 | 91 |
| 91 class SimpleHost : public HeartbeatSender::Listener { | 92 class SimpleHost : public HeartbeatSender::Listener { |
| 92 public: | 93 public: |
| 93 SimpleHost() | 94 SimpleHost() |
| 94 : message_loop_(MessageLoop::TYPE_UI), | 95 : message_loop_(MessageLoop::TYPE_UI), |
| 95 context_(message_loop_.message_loop_proxy()), | 96 context_(message_loop_.message_loop_proxy()), |
| 96 fake_(false), | 97 fake_(false), |
| 97 is_it2me_(false) { | 98 is_it2me_(false), |
| 99 shutting_down_(false), |
| 100 exit_code_(kSuccessExitCode) { |
| 98 context_.Start(); | 101 context_.Start(); |
| 99 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 102 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 100 } | 103 } |
| 101 | 104 |
| 102 // Overridden from HeartbeatSender::Listener | 105 // Overridden from HeartbeatSender::Listener |
| 103 virtual void OnUnknownHostIdError() OVERRIDE { | 106 virtual void OnUnknownHostIdError() OVERRIDE { |
| 104 LOG(ERROR) << "Host ID not found."; | 107 LOG(ERROR) << "Host ID not found."; |
| 105 Shutdown(); | 108 Shutdown(kInvalidHostIdExitCode); |
| 106 } | 109 } |
| 107 | 110 |
| 108 int Run() { | 111 int Run() { |
| 109 FilePath config_path = GetConfigPath(); | 112 FilePath config_path = GetConfigPath(); |
| 110 JsonHostConfig config(config_path); | 113 JsonHostConfig config(config_path); |
| 111 if (!config.Read()) { | 114 if (!config.Read()) { |
| 112 LOG(ERROR) << "Failed to read configuration file " | 115 LOG(ERROR) << "Failed to read configuration file " |
| 113 << config_path.value(); | 116 << config_path.value(); |
| 114 return 1; | 117 return 1; |
| 115 } | 118 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 146 // easily request an OAuth2 access token even if we had a RefreshToken for | 149 // easily request an OAuth2 access token even if we had a RefreshToken for |
| 147 // the account. | 150 // the account. |
| 148 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; | 151 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; |
| 149 } | 152 } |
| 150 | 153 |
| 151 context_.network_message_loop()->PostTask(FROM_HERE, base::Bind( | 154 context_.network_message_loop()->PostTask(FROM_HERE, base::Bind( |
| 152 &SimpleHost::StartHost, base::Unretained(this))); | 155 &SimpleHost::StartHost, base::Unretained(this))); |
| 153 | 156 |
| 154 message_loop_.MessageLoop::Run(); | 157 message_loop_.MessageLoop::Run(); |
| 155 | 158 |
| 156 return 0; | 159 return exit_code_; |
| 157 } | 160 } |
| 158 | 161 |
| 159 void set_config_path(const FilePath& config_path) { | 162 void set_config_path(const FilePath& config_path) { |
| 160 config_path_ = config_path; | 163 config_path_ = config_path; |
| 161 } | 164 } |
| 162 void set_fake(bool fake) { fake_ = fake; } | 165 void set_fake(bool fake) { fake_ = fake; } |
| 163 void set_is_it2me(bool is_it2me) { is_it2me_ = is_it2me; } | 166 void set_is_it2me(bool is_it2me) { is_it2me_ = is_it2me; } |
| 164 void set_protocol_config(CandidateSessionConfig* protocol_config) { | 167 void set_protocol_config(CandidateSessionConfig* protocol_config) { |
| 165 protocol_config_.reset(protocol_config); | 168 protocol_config_.reset(protocol_config); |
| 166 } | 169 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 std::string home_path; | 210 std::string home_path; |
| 208 env->GetVar(base::env_vars::kHome, &home_path); | 211 env->GetVar(base::env_vars::kHome, &home_path); |
| 209 return FilePath(home_path).Append(kDefaultConfigPath); | 212 return FilePath(home_path).Append(kDefaultConfigPath); |
| 210 #endif | 213 #endif |
| 211 } | 214 } |
| 212 | 215 |
| 213 void StartHost() { | 216 void StartHost() { |
| 214 signal_strategy_.reset( | 217 signal_strategy_.reset( |
| 215 new XmppSignalStrategy(context_.jingle_thread(), xmpp_login_, | 218 new XmppSignalStrategy(context_.jingle_thread(), xmpp_login_, |
| 216 xmpp_auth_token_, xmpp_auth_service_)); | 219 xmpp_auth_token_, xmpp_auth_service_)); |
| 217 signaling_connector_.reset(new SignalingConnector(signal_strategy_.get())); | 220 signaling_connector_.reset(new SignalingConnector( |
| 221 signal_strategy_.get(), |
| 222 base::Bind(&SimpleHost::OnAuthFailed, base::Unretained(this)))); |
| 218 | 223 |
| 219 if (fake_) { | 224 if (fake_) { |
| 220 scoped_ptr<Capturer> capturer(new CapturerFake()); | 225 scoped_ptr<Capturer> capturer(new CapturerFake()); |
| 221 scoped_ptr<protocol::HostEventStub> event_executor = | 226 scoped_ptr<protocol::HostEventStub> event_executor = |
| 222 EventExecutor::Create( | 227 EventExecutor::Create( |
| 223 context_.desktop_message_loop(), capturer.get()); | 228 context_.desktop_message_loop(), capturer.get()); |
| 224 desktop_environment_ = DesktopEnvironment::CreateFake( | 229 desktop_environment_ = DesktopEnvironment::CreateFake( |
| 225 &context_, capturer.Pass(), event_executor.Pass()); | 230 &context_, capturer.Pass(), event_executor.Pass()); |
| 226 } else { | 231 } else { |
| 227 desktop_environment_ = DesktopEnvironment::Create(&context_); | 232 desktop_environment_ = DesktopEnvironment::Create(&context_); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 258 // Create a Me2Me authenticator factory. | 263 // Create a Me2Me authenticator factory. |
| 259 if (!is_it2me_) { | 264 if (!is_it2me_) { |
| 260 scoped_ptr<protocol::AuthenticatorFactory> factory( | 265 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 261 new protocol::Me2MeHostAuthenticatorFactory( | 266 new protocol::Me2MeHostAuthenticatorFactory( |
| 262 xmpp_login_, key_pair_.GenerateCertificate(), | 267 xmpp_login_, key_pair_.GenerateCertificate(), |
| 263 *key_pair_.private_key(), host_secret_hash_)); | 268 *key_pair_.private_key(), host_secret_hash_)); |
| 264 host_->SetAuthenticatorFactory(factory.Pass()); | 269 host_->SetAuthenticatorFactory(factory.Pass()); |
| 265 } | 270 } |
| 266 } | 271 } |
| 267 | 272 |
| 268 void Shutdown() { | 273 void OnAuthFailed() { |
| 274 Shutdown(kInvalidOauthCredentialsExitCode); |
| 275 } |
| 276 |
| 277 void Shutdown(int exit_code) { |
| 278 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); |
| 279 |
| 280 if (shutting_down_) |
| 281 return; |
| 282 |
| 283 shutting_down_ = true; |
| 284 exit_code_ = exit_code; |
| 285 host_->Shutdown(base::Bind( |
| 286 &SimpleHost::OnShutdownFinished, base::Unretained(this))); |
| 287 } |
| 288 |
| 289 void OnShutdownFinished() { |
| 290 DCHECK(context_.network_message_loop()->BelongsToCurrentThread()); |
| 291 |
| 292 // Destroy networking objects while we are on the network thread. |
| 293 host_ = NULL; |
| 294 log_to_server_.reset(); |
| 295 heartbeat_sender_.reset(); |
| 296 signaling_connector_.reset(); |
| 297 signal_strategy_.reset(); |
| 298 |
| 269 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 299 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 270 } | 300 } |
| 271 | 301 |
| 272 MessageLoop message_loop_; | 302 MessageLoop message_loop_; |
| 273 ChromotingHostContext context_; | 303 ChromotingHostContext context_; |
| 274 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 304 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 275 | 305 |
| 276 FilePath config_path_; | 306 FilePath config_path_; |
| 277 bool fake_; | 307 bool fake_; |
| 278 bool is_it2me_; | 308 bool is_it2me_; |
| 279 NetworkSettings network_settings_; | 309 NetworkSettings network_settings_; |
| 280 scoped_ptr<CandidateSessionConfig> protocol_config_; | 310 scoped_ptr<CandidateSessionConfig> protocol_config_; |
| 281 | 311 |
| 282 std::string host_id_; | 312 std::string host_id_; |
| 283 HostKeyPair key_pair_; | 313 HostKeyPair key_pair_; |
| 284 protocol::SharedSecretHash host_secret_hash_; | 314 protocol::SharedSecretHash host_secret_hash_; |
| 285 std::string xmpp_login_; | 315 std::string xmpp_login_; |
| 286 std::string xmpp_auth_token_; | 316 std::string xmpp_auth_token_; |
| 287 std::string xmpp_auth_service_; | 317 std::string xmpp_auth_service_; |
| 288 | 318 |
| 289 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 319 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 290 scoped_ptr<SignalingConnector> signaling_connector_; | 320 scoped_ptr<SignalingConnector> signaling_connector_; |
| 291 scoped_ptr<DesktopEnvironment> desktop_environment_; | 321 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 292 scoped_ptr<LogToServer> log_to_server_; | 322 scoped_ptr<LogToServer> log_to_server_; |
| 293 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; | 323 scoped_ptr<It2MeHostUserInterface> it2me_host_user_interface_; |
| 294 scoped_ptr<RegisterSupportHostRequest> register_request_; | 324 scoped_ptr<RegisterSupportHostRequest> register_request_; |
| 295 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 325 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 296 | 326 |
| 297 scoped_refptr<ChromotingHost> host_; | 327 scoped_refptr<ChromotingHost> host_; |
| 328 |
| 329 bool shutting_down_; |
| 330 int exit_code_; |
| 298 }; | 331 }; |
| 299 | 332 |
| 300 } // namespace remoting | 333 } // namespace remoting |
| 301 | 334 |
| 302 int main(int argc, char** argv) { | 335 int main(int argc, char** argv) { |
| 303 #if defined(OS_MACOSX) | 336 #if defined(OS_MACOSX) |
| 304 // Needed so we don't leak objects when threads are created. | 337 // Needed so we don't leak objects when threads are created. |
| 305 base::mac::ScopedNSAutoreleasePool pool; | 338 base::mac::ScopedNSAutoreleasePool pool; |
| 306 #endif | 339 #endif |
| 307 | 340 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 max_port < 0 || max_port > 65535) { | 409 max_port < 0 || max_port > 65535) { |
| 377 LOG(ERROR) << "Invalid max-port value: " << max_port | 410 LOG(ERROR) << "Invalid max-port value: " << max_port |
| 378 << ". Expected integer in range [0, 65535]."; | 411 << ". Expected integer in range [0, 65535]."; |
| 379 return 1; | 412 return 1; |
| 380 } | 413 } |
| 381 simple_host.network_settings()->max_port = max_port; | 414 simple_host.network_settings()->max_port = max_port; |
| 382 } | 415 } |
| 383 | 416 |
| 384 return simple_host.Run(); | 417 return simple_host.Run(); |
| 385 } | 418 } |
| OLD | NEW |