| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 const char kVideoSwitchValueVerbatim[] = "verbatim"; | 83 const char kVideoSwitchValueVerbatim[] = "verbatim"; |
| 84 const char kVideoSwitchValueZip[] = "zip"; | 84 const char kVideoSwitchValueZip[] = "zip"; |
| 85 const char kVideoSwitchValueVp8[] = "vp8"; | 85 const char kVideoSwitchValueVp8[] = "vp8"; |
| 86 const char kVideoSwitchValueVp8Rtp[] = "vp8rtp"; | 86 const char kVideoSwitchValueVp8Rtp[] = "vp8rtp"; |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 namespace remoting { | 90 namespace remoting { |
| 91 | 91 |
| 92 class SimpleHost { | 92 class SimpleHost : public HeartbeatSender::Listener { |
| 93 public: | 93 public: |
| 94 SimpleHost() | 94 SimpleHost() |
| 95 : message_loop_(MessageLoop::TYPE_UI), | 95 : message_loop_(MessageLoop::TYPE_UI), |
| 96 context_(message_loop_.message_loop_proxy()), | 96 context_(message_loop_.message_loop_proxy()), |
| 97 fake_(false), | 97 fake_(false), |
| 98 is_it2me_(false) { | 98 is_it2me_(false) { |
| 99 context_.Start(); | 99 context_.Start(); |
| 100 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 100 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Overridden from HeartbeatSender::Listener |
| 104 virtual void OnUnknownHostIdError() OVERRIDE { |
| 105 LOG(ERROR) << "Host ID not found."; |
| 106 Shutdown(); |
| 107 } |
| 108 |
| 103 int Run() { | 109 int Run() { |
| 104 FilePath config_path = GetConfigPath(); | 110 FilePath config_path = GetConfigPath(); |
| 105 JsonHostConfig config(config_path); | 111 JsonHostConfig config(config_path); |
| 106 if (!config.Read()) { | 112 if (!config.Read()) { |
| 107 LOG(ERROR) << "Failed to read configuration file " | 113 LOG(ERROR) << "Failed to read configuration file " |
| 108 << config_path.value(); | 114 << config_path.value(); |
| 109 return 1; | 115 return 1; |
| 110 } | 116 } |
| 111 | 117 |
| 112 if (!config.GetString(kHostIdConfigPath, &host_id_)) { | 118 if (!config.GetString(kHostIdConfigPath, &host_id_)) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 243 |
| 238 if (protocol_config_.get()) { | 244 if (protocol_config_.get()) { |
| 239 host_->set_protocol_config(protocol_config_.release()); | 245 host_->set_protocol_config(protocol_config_.release()); |
| 240 } | 246 } |
| 241 | 247 |
| 242 if (is_it2me_) { | 248 if (is_it2me_) { |
| 243 register_request_.reset(new RegisterSupportHostRequest( | 249 register_request_.reset(new RegisterSupportHostRequest( |
| 244 signal_strategy_.get(), &key_pair_, | 250 signal_strategy_.get(), &key_pair_, |
| 245 base::Bind(&SimpleHost::SetIT2MeAccessCode, host_, &key_pair_))); | 251 base::Bind(&SimpleHost::SetIT2MeAccessCode, host_, &key_pair_))); |
| 246 } else { | 252 } else { |
| 247 heartbeat_sender_.reset( | 253 heartbeat_sender_.reset(new HeartbeatSender( |
| 248 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); | 254 this, host_id_, signal_strategy_.get(), &key_pair_)); |
| 249 } | 255 } |
| 250 | 256 |
| 251 host_->Start(); | 257 host_->Start(); |
| 252 | 258 |
| 253 // Create a Me2Me authenticator factory. | 259 // Create a Me2Me authenticator factory. |
| 254 if (!is_it2me_) { | 260 if (!is_it2me_) { |
| 255 scoped_ptr<protocol::AuthenticatorFactory> factory( | 261 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 256 new protocol::Me2MeHostAuthenticatorFactory( | 262 new protocol::Me2MeHostAuthenticatorFactory( |
| 257 xmpp_login_, key_pair_.GenerateCertificate(), | 263 xmpp_login_, key_pair_.GenerateCertificate(), |
| 258 *key_pair_.private_key(), host_secret_hash_)); | 264 *key_pair_.private_key(), host_secret_hash_)); |
| 259 host_->SetAuthenticatorFactory(factory.Pass()); | 265 host_->SetAuthenticatorFactory(factory.Pass()); |
| 260 } | 266 } |
| 261 } | 267 } |
| 262 | 268 |
| 269 void Shutdown() { |
| 270 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 271 } |
| 272 |
| 263 MessageLoop message_loop_; | 273 MessageLoop message_loop_; |
| 264 ChromotingHostContext context_; | 274 ChromotingHostContext context_; |
| 265 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 275 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 266 | 276 |
| 267 FilePath config_path_; | 277 FilePath config_path_; |
| 268 bool fake_; | 278 bool fake_; |
| 269 bool is_it2me_; | 279 bool is_it2me_; |
| 270 NetworkSettings network_settings_; | 280 NetworkSettings network_settings_; |
| 271 scoped_ptr<CandidateSessionConfig> protocol_config_; | 281 scoped_ptr<CandidateSessionConfig> protocol_config_; |
| 272 | 282 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 max_port < 0 || max_port > 65535) { | 377 max_port < 0 || max_port > 65535) { |
| 368 LOG(ERROR) << "Invalid max-port value: " << max_port | 378 LOG(ERROR) << "Invalid max-port value: " << max_port |
| 369 << ". Expected integer in range [0, 65535]."; | 379 << ". Expected integer in range [0, 65535]."; |
| 370 return 1; | 380 return 1; |
| 371 } | 381 } |
| 372 simple_host.network_settings()->max_port = max_port; | 382 simple_host.network_settings()->max_port = max_port; |
| 373 } | 383 } |
| 374 | 384 |
| 375 return simple_host.Run(); | 385 return simple_host.Run(); |
| 376 } | 386 } |
| OLD | NEW |