| 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 file implements a standalone host process for Me2Me, which is currently | 5 // This file implements a standalone host process for Me2Me, which is currently |
| 6 // used for the Linux-only Virtual Me2Me build. | 6 // used for the Linux-only Virtual Me2Me build. |
| 7 | 7 |
| 8 #if defined(OS_WIN) |
| 9 #include <windows.h> |
| 10 #endif |
| 11 |
| 8 #include <string> | 12 #include <string> |
| 9 | 13 |
| 10 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
| 11 #include "base/bind.h" | 15 #include "base/bind.h" |
| 12 #include "base/callback.h" | 16 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 14 #include "base/file_path.h" | 18 #include "base/file_path.h" |
| 15 #include "base/file_util.h" | 19 #include "base/file_util.h" |
| 16 #include "base/logging.h" | 20 #include "base/logging.h" |
| 17 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
| 22 #include "base/path_service.h" |
| 18 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
| 19 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 20 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
| 21 #include "net/base/network_change_notifier.h" | 26 #include "net/base/network_change_notifier.h" |
| 22 #include "remoting/base/constants.h" | 27 #include "remoting/base/constants.h" |
| 23 #include "remoting/host/capturer.h" | 28 #include "remoting/host/capturer.h" |
| 24 #include "remoting/host/chromoting_host.h" | 29 #include "remoting/host/chromoting_host.h" |
| 25 #include "remoting/host/chromoting_host_context.h" | 30 #include "remoting/host/chromoting_host_context.h" |
| 26 #include "remoting/host/desktop_environment.h" | 31 #include "remoting/host/desktop_environment.h" |
| 27 #include "remoting/host/event_executor.h" | 32 #include "remoting/host/event_executor.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 52 const FilePath::CharType kDefaultConfigDir[] = | 57 const FilePath::CharType kDefaultConfigDir[] = |
| 53 FILE_PATH_LITERAL(".config/chrome-remote-desktop"); | 58 FILE_PATH_LITERAL(".config/chrome-remote-desktop"); |
| 54 const FilePath::CharType kDefaultAuthConfigFile[] = | 59 const FilePath::CharType kDefaultAuthConfigFile[] = |
| 55 FILE_PATH_LITERAL("auth.json"); | 60 FILE_PATH_LITERAL("auth.json"); |
| 56 const FilePath::CharType kDefaultHostConfigFile[] = | 61 const FilePath::CharType kDefaultHostConfigFile[] = |
| 57 FILE_PATH_LITERAL("host.json"); | 62 FILE_PATH_LITERAL("host.json"); |
| 58 | 63 |
| 59 const int kMinPortNumber = 12400; | 64 const int kMinPortNumber = 12400; |
| 60 const int kMaxPortNumber = 12409; | 65 const int kMaxPortNumber = 12409; |
| 61 | 66 |
| 67 FilePath GetDefaultConfigDir() { |
| 68 FilePath default_config_dir; |
| 69 |
| 70 #if defined(OS_WIN) |
| 71 PathService::Get(base::DIR_PROFILE, &default_config_dir); |
| 72 #else |
| 73 default_config_dir = file_util::GetHomeDir(); |
| 74 #endif |
| 75 |
| 76 return default_config_dir.Append(kDefaultConfigDir); |
| 77 } |
| 78 |
| 62 } // namespace | 79 } // namespace |
| 63 | 80 |
| 64 namespace remoting { | 81 namespace remoting { |
| 65 | 82 |
| 66 class HostProcess { | 83 class HostProcess { |
| 67 public: | 84 public: |
| 68 HostProcess() | 85 HostProcess() |
| 69 : message_loop_(MessageLoop::TYPE_UI), | 86 : message_loop_(MessageLoop::TYPE_UI), |
| 70 file_io_thread_("FileIO"), | 87 file_io_thread_("FileIO"), |
| 71 context_(message_loop_.message_loop_proxy()), | 88 context_(message_loop_.message_loop_proxy()), |
| 72 allow_nat_traversal_(true), | 89 allow_nat_traversal_(true), |
| 73 restarting_(false) { | 90 restarting_(false) { |
| 74 context_.Start(); | 91 context_.Start(); |
| 75 file_io_thread_.StartWithOptions( | 92 file_io_thread_.StartWithOptions( |
| 76 base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 93 base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
| 77 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 94 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 78 } | 95 } |
| 79 | 96 |
| 80 void InitWithCommandLine(const CommandLine* cmd_line) { | 97 void InitWithCommandLine(const CommandLine* cmd_line) { |
| 81 FilePath default_config_dir = | 98 FilePath default_config_dir = GetDefaultConfigDir(); |
| 82 file_util::GetHomeDir().Append(kDefaultConfigDir); | |
| 83 | |
| 84 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | 99 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { |
| 85 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); | 100 auth_config_path_ = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); |
| 86 } else { | 101 } else { |
| 87 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); | 102 auth_config_path_ = default_config_dir.Append(kDefaultAuthConfigFile); |
| 88 } | 103 } |
| 89 | 104 |
| 90 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 105 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
| 91 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 106 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 92 } else { | 107 } else { |
| 93 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 108 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 114 } | 129 } |
| 115 | 130 |
| 116 private: | 131 private: |
| 117 // Read Host config from disk, returning true if successful. | 132 // Read Host config from disk, returning true if successful. |
| 118 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { | 133 bool LoadConfig(base::MessageLoopProxy* io_message_loop) { |
| 119 scoped_refptr<JsonHostConfig> host_config = | 134 scoped_refptr<JsonHostConfig> host_config = |
| 120 new JsonHostConfig(host_config_path_, io_message_loop); | 135 new JsonHostConfig(host_config_path_, io_message_loop); |
| 121 scoped_refptr<JsonHostConfig> auth_config = | 136 scoped_refptr<JsonHostConfig> auth_config = |
| 122 new JsonHostConfig(auth_config_path_, io_message_loop); | 137 new JsonHostConfig(auth_config_path_, io_message_loop); |
| 123 | 138 |
| 124 std::string failed_path; | 139 FilePath failed_path; |
| 125 if (!host_config->Read()) { | 140 if (!host_config->Read()) { |
| 126 failed_path = host_config_path_.value(); | 141 failed_path = host_config_path_; |
| 127 } else if (!auth_config->Read()) { | 142 } else if (!auth_config->Read()) { |
| 128 failed_path = auth_config_path_.value(); | 143 failed_path = auth_config_path_; |
| 129 } | 144 } |
| 130 if (!failed_path.empty()) { | 145 if (!failed_path.empty()) { |
| 131 LOG(ERROR) << "Failed to read configuration file " << failed_path; | 146 LOG(ERROR) << "Failed to read configuration file " << failed_path.value(); |
| 132 return false; | 147 return false; |
| 133 } | 148 } |
| 134 | 149 |
| 135 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { | 150 if (!host_config->GetString(kHostIdConfigPath, &host_id_)) { |
| 136 LOG(ERROR) << "host_id is not defined in the config."; | 151 LOG(ERROR) << "host_id is not defined in the config."; |
| 137 return false; | 152 return false; |
| 138 } | 153 } |
| 139 | 154 |
| 140 if (!key_pair_.Load(host_config)) { | 155 if (!key_pair_.Load(host_config)) { |
| 141 return false; | 156 return false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 232 |
| 218 host_ = new ChromotingHost( | 233 host_ = new ChromotingHost( |
| 219 &context_, signal_strategy_.get(), desktop_environment_.get(), | 234 &context_, signal_strategy_.get(), desktop_environment_.get(), |
| 220 network_settings); | 235 network_settings); |
| 221 | 236 |
| 222 heartbeat_sender_.reset( | 237 heartbeat_sender_.reset( |
| 223 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); | 238 new HeartbeatSender(host_id_, signal_strategy_.get(), &key_pair_)); |
| 224 | 239 |
| 225 log_to_server_.reset( | 240 log_to_server_.reset( |
| 226 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); | 241 new LogToServer(host_, ServerLogEntry::ME2ME, signal_strategy_.get())); |
| 227 host_event_logger_.reset(new HostEventLogger(host_, kApplicationName)); | 242 host_event_logger_ = HostEventLogger::Create(host_, kApplicationName); |
| 228 | 243 |
| 229 host_->Start(); | 244 host_->Start(); |
| 230 | 245 |
| 231 // Create authenticator factory. | 246 // Create authenticator factory. |
| 232 scoped_ptr<protocol::AuthenticatorFactory> factory( | 247 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 233 new protocol::Me2MeHostAuthenticatorFactory( | 248 new protocol::Me2MeHostAuthenticatorFactory( |
| 234 xmpp_login_, key_pair_.GenerateCertificate(), | 249 xmpp_login_, key_pair_.GenerateCertificate(), |
| 235 *key_pair_.private_key(), host_secret_hash_)); | 250 *key_pair_.private_key(), host_secret_hash_)); |
| 236 host_->SetAuthenticatorFactory(factory.Pass()); | 251 host_->SetAuthenticatorFactory(factory.Pass()); |
| 237 } | 252 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // Continue windows, though these should not be used for the Me2Me case | 320 // Continue windows, though these should not be used for the Me2Me case |
| 306 // (crbug.com/104377). | 321 // (crbug.com/104377). |
| 307 gfx::GtkInitFromCommandLine(*cmd_line); | 322 gfx::GtkInitFromCommandLine(*cmd_line); |
| 308 #endif // TOOLKIT_USES_GTK | 323 #endif // TOOLKIT_USES_GTK |
| 309 | 324 |
| 310 remoting::HostProcess me2me_host; | 325 remoting::HostProcess me2me_host; |
| 311 me2me_host.InitWithCommandLine(cmd_line); | 326 me2me_host.InitWithCommandLine(cmd_line); |
| 312 | 327 |
| 313 return me2me_host.Run(); | 328 return me2me_host.Run(); |
| 314 } | 329 } |
| 330 |
| 331 #if defined(OS_WIN) |
| 332 |
| 333 int CALLBACK WinMain(HINSTANCE instance, |
| 334 HINSTANCE previous_instance, |
| 335 LPSTR command_line, |
| 336 int show_command) { |
| 337 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 338 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 339 return main(0, NULL); |
| 340 } |
| 341 |
| 342 #endif |
| OLD | NEW |