| 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. | 5 // This file implements a standalone host process for Me2Me. |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_path_watcher.h" | |
| 16 #include "base/logging.h" | 15 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 19 #include "base/scoped_native_library.h" | 18 #include "base/scoped_native_library.h" |
| 20 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 21 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
| 22 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
| 23 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
| 24 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 25 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 26 #include "crypto/nss_util.h" | 25 #include "crypto/nss_util.h" |
| 27 #include "ipc/ipc_channel.h" | 26 #include "ipc/ipc_channel.h" |
| 28 #include "ipc/ipc_channel_proxy.h" | 27 #include "ipc/ipc_channel_proxy.h" |
| 29 #include "net/base/network_change_notifier.h" | 28 #include "net/base/network_change_notifier.h" |
| 30 #include "net/socket/ssl_server_socket.h" | 29 #include "net/socket/ssl_server_socket.h" |
| 31 #include "remoting/base/breakpad.h" | 30 #include "remoting/base/breakpad.h" |
| 32 #include "remoting/base/constants.h" | 31 #include "remoting/base/constants.h" |
| 33 #include "remoting/host/branding.h" | 32 #include "remoting/host/branding.h" |
| 34 #include "remoting/host/chromoting_host.h" | 33 #include "remoting/host/chromoting_host.h" |
| 35 #include "remoting/host/chromoting_host_context.h" | 34 #include "remoting/host/chromoting_host_context.h" |
| 36 #include "remoting/host/composite_host_config.h" | 35 #include "remoting/host/chromoting_messages.h" |
| 37 #include "remoting/host/constants.h" | 36 #include "remoting/host/constants.h" |
| 38 #include "remoting/host/desktop_environment.h" | 37 #include "remoting/host/desktop_environment.h" |
| 39 #include "remoting/host/event_executor.h" | 38 #include "remoting/host/event_executor.h" |
| 40 #include "remoting/host/heartbeat_sender.h" | 39 #include "remoting/host/heartbeat_sender.h" |
| 41 #include "remoting/host/host_config.h" | 40 #include "remoting/host/host_config.h" |
| 42 #include "remoting/host/host_event_logger.h" | 41 #include "remoting/host/host_event_logger.h" |
| 43 #include "remoting/host/host_user_interface.h" | 42 #include "remoting/host/host_user_interface.h" |
| 44 #include "remoting/host/log_to_server.h" | 43 #include "remoting/host/log_to_server.h" |
| 45 #include "remoting/host/network_settings.h" | 44 #include "remoting/host/network_settings.h" |
| 46 #include "remoting/host/policy_hack/policy_watcher.h" | 45 #include "remoting/host/policy_hack/policy_watcher.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 63 | 62 |
| 64 // N.B. OS_WIN is defined by including src/base headers. | 63 // N.B. OS_WIN is defined by including src/base headers. |
| 65 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 66 #include <commctrl.h> | 65 #include <commctrl.h> |
| 67 #endif // defined(OS_WIN) | 66 #endif // defined(OS_WIN) |
| 68 | 67 |
| 69 #if defined(TOOLKIT_GTK) | 68 #if defined(TOOLKIT_GTK) |
| 70 #include "ui/gfx/gtk_util.h" | 69 #include "ui/gfx/gtk_util.h" |
| 71 #endif // defined(TOOLKIT_GTK) | 70 #endif // defined(TOOLKIT_GTK) |
| 72 | 71 |
| 72 #if defined(REMOTING_MULTI_PROCESS) |
| 73 #include "remoting/host/json_host_config.h" |
| 74 #else // !defined(REMOTING_MULTI_PROCESS) |
| 75 #include "base/files/file_path_watcher.h" |
| 76 #include "remoting/host/composite_host_config.h" |
| 77 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 78 |
| 73 namespace { | 79 namespace { |
| 74 | 80 |
| 75 // This is used for tagging system event logs. | 81 // This is used for tagging system event logs. |
| 76 const char kApplicationName[] = "chromoting"; | 82 const char kApplicationName[] = "chromoting"; |
| 77 | 83 |
| 78 // The command line switch specifying the name of the Chromoting IPC channel. | 84 // The command line switch specifying the name of the daemon IPC endpoint. |
| 79 const char kDaemonIpcSwitchName[] = "chromoting-ipc"; | 85 const char kDaemonIpcSwitchName[] = "daemon-pipe"; |
| 86 |
| 87 #if !defined(REMOTING_MULTI_PROCESS) |
| 80 | 88 |
| 81 // These are used for parsing the config-file locations from the command line, | 89 // These are used for parsing the config-file locations from the command line, |
| 82 // and for defining the default locations if the switches are not present. | 90 // and for defining the default locations if the switches are not present. |
| 83 const char kAuthConfigSwitchName[] = "auth-config"; | 91 const char kAuthConfigSwitchName[] = "auth-config"; |
| 84 const char kHostConfigSwitchName[] = "host-config"; | 92 const char kHostConfigSwitchName[] = "host-config"; |
| 85 | 93 |
| 86 const FilePath::CharType kDefaultHostConfigFile[] = | 94 const FilePath::CharType kDefaultHostConfigFile[] = |
| 87 FILE_PATH_LITERAL("host.json"); | 95 FILE_PATH_LITERAL("host.json"); |
| 88 | 96 |
| 97 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 98 |
| 89 const int kMinPortNumber = 12400; | 99 const int kMinPortNumber = 12400; |
| 90 const int kMaxPortNumber = 12409; | 100 const int kMaxPortNumber = 12409; |
| 91 | 101 |
| 92 const char kUnofficialOAuth2ClientId[] = | 102 const char kUnofficialOAuth2ClientId[] = |
| 93 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; | 103 "440925447803-2pi3v45bff6tp1rde2f7q6lgbor3o5uj.apps.googleusercontent.com"; |
| 94 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; | 104 const char kUnofficialOAuth2ClientSecret[] = "W2ieEsG-R1gIA4MMurGrgMc_"; |
| 95 | 105 |
| 96 const char kOfficialOAuth2ClientId[] = | 106 const char kOfficialOAuth2ClientId[] = |
| 97 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; | 107 "440925447803-avn2sj1kc099s0r7v62je5s339mu0am1.apps.googleusercontent.com"; |
| 98 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; | 108 const char kOfficialOAuth2ClientSecret[] = "Bgur6DFiOMM1h8x-AQpuTQlK"; |
| 99 | 109 |
| 100 } // namespace | 110 } // namespace |
| 101 | 111 |
| 102 namespace remoting { | 112 namespace remoting { |
| 103 | 113 |
| 104 class HostProcess | 114 class HostProcess |
| 105 : public HeartbeatSender::Listener, | 115 : public HeartbeatSender::Listener, |
| 106 public IPC::Listener { | 116 public IPC::Listener { |
| 107 public: | 117 public: |
| 108 HostProcess() | 118 HostProcess() |
| 109 : message_loop_(MessageLoop::TYPE_UI), | 119 : message_loop_(MessageLoop::TYPE_UI), |
| 120 #if defined(REMOTING_MULTI_PROCESS) |
| 121 config_(FilePath()), |
| 122 #endif // defined(REMOTING_MULTI_PROCESS) |
| 110 #ifdef OFFICIAL_BUILD | 123 #ifdef OFFICIAL_BUILD |
| 111 oauth_use_official_client_id_(true), | 124 oauth_use_official_client_id_(true), |
| 112 #else | 125 #else |
| 113 oauth_use_official_client_id_(false), | 126 oauth_use_official_client_id_(false), |
| 114 #endif | 127 #endif |
| 115 allow_nat_traversal_(true), | 128 allow_nat_traversal_(true), |
| 116 restarting_(false), | 129 restarting_(false), |
| 117 shutting_down_(false), | 130 shutting_down_(false), |
| 118 exit_code_(kSuccessExitCode) | 131 exit_code_(kSuccessExitCode) |
| 119 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
| 120 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, | 133 , curtain_(base::Bind(&HostProcess::OnDisconnectRequested, |
| 121 base::Unretained(this)), | 134 base::Unretained(this)), |
| 122 base::Bind(&HostProcess::OnDisconnectRequested, | 135 base::Bind(&HostProcess::OnDisconnectRequested, |
| 123 base::Unretained(this))) | 136 base::Unretained(this))) |
| 124 #endif | 137 #endif |
| 125 { | 138 { |
| 126 context_.reset( | 139 context_.reset( |
| 127 new ChromotingHostContext(message_loop_.message_loop_proxy())); | 140 new ChromotingHostContext(message_loop_.message_loop_proxy())); |
| 128 context_->Start(); | 141 context_->Start(); |
| 129 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 142 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
| 143 |
| 144 #if !defined(REMOTING_MULTI_PROCESS) |
| 130 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( | 145 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( |
| 131 FROM_HERE, base::TimeDelta::FromSeconds(2), this, | 146 FROM_HERE, base::TimeDelta::FromSeconds(2), this, |
| 132 &HostProcess::ConfigUpdatedDelayed)); | 147 &HostProcess::ConfigUpdatedDelayed)); |
| 148 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 133 } | 149 } |
| 134 | 150 |
| 135 bool InitWithCommandLine(const CommandLine* cmd_line) { | 151 bool InitWithCommandLine(const CommandLine* cmd_line) { |
| 136 // Connect to the daemon process. | 152 // Connect to the daemon process. |
| 137 std::string channel_name = | 153 std::string channel_name = |
| 138 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); | 154 cmd_line->GetSwitchValueASCII(kDaemonIpcSwitchName); |
| 139 | 155 |
| 140 #if defined(REMOTING_MULTI_PROCESS) | 156 #if defined(REMOTING_MULTI_PROCESS) |
| 141 if (channel_name.empty()) | 157 if (channel_name.empty()) |
| 142 return false; | 158 return false; |
| 143 #endif // defined(REMOTING_MULTI_PROCESS) | 159 #endif // defined(REMOTING_MULTI_PROCESS) |
| 144 | 160 |
| 145 if (!channel_name.empty()) { | 161 if (!channel_name.empty()) { |
| 146 daemon_channel_.reset(new IPC::ChannelProxy( | 162 daemon_channel_.reset(new IPC::ChannelProxy( |
| 147 channel_name, IPC::Channel::MODE_CLIENT, this, | 163 channel_name, IPC::Channel::MODE_CLIENT, this, |
| 148 context_->network_task_runner())); | 164 context_->network_task_runner())); |
| 149 } | 165 } |
| 150 | 166 |
| 167 #if !defined(REMOTING_MULTI_PROCESS) |
| 151 FilePath default_config_dir = remoting::GetConfigDir(); | 168 FilePath default_config_dir = remoting::GetConfigDir(); |
| 152 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { | 169 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { |
| 153 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); | 170 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); |
| 154 config_.AddConfigPath(path); | 171 config_.AddConfigPath(path); |
| 155 } | 172 } |
| 156 | 173 |
| 157 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 174 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); |
| 158 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 175 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
| 159 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 176 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 160 } | 177 } |
| 161 config_.AddConfigPath(host_config_path_); | 178 config_.AddConfigPath(host_config_path_); |
| 179 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 162 | 180 |
| 163 return true; | 181 return true; |
| 164 } | 182 } |
| 165 | 183 |
| 184 #if defined(REMOTING_MULTI_PROCESS) |
| 185 |
| 186 void OnConfigUpdated(const std::string& config) { |
| 187 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 188 |
| 189 LOG(INFO) << "Processing new host configuration."; |
| 190 |
| 191 if (!config_.SetSerializedData(config)) { |
| 192 LOG(ERROR) << "Invalid configuration."; |
| 193 return; |
| 194 } |
| 195 |
| 196 if (!ApplyConfig()) { |
| 197 // TODO(alexeypa): make the process exit with |
| 198 // |kInvalidHostConfigurationExitCode| |
| 199 LOG(ERROR) << "Failed to apply the configuration."; |
| 200 return; |
| 201 } |
| 202 |
| 203 // Start watching the policy (and eventually start the host) if this is |
| 204 // the first configuration update. Otherwise, post a task to create new |
| 205 // authenticator factory in case PIN has changed. |
| 206 if (policy_watcher_.get() == NULL) { |
| 207 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 208 host_user_interface_.reset(new HostUserInterface(context_.get())); |
| 209 #endif |
| 210 |
| 211 StartWatchingPolicy(); |
| 212 } else { |
| 213 // PostTask to create new authenticator factory in case PIN has changed. |
| 214 context_->network_task_runner()->PostTask( |
| 215 FROM_HERE, |
| 216 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
| 217 base::Unretained(this))); |
| 218 } |
| 219 } |
| 220 |
| 221 #else // !defined(REMOTING_MULTI_PROCESS) |
| 222 |
| 166 void ConfigUpdated() { | 223 void ConfigUpdated() { |
| 167 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 224 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 168 | 225 |
| 169 // Call ConfigUpdatedDelayed after a short delay, so that this object won't | 226 // Call ConfigUpdatedDelayed after a short delay, so that this object won't |
| 170 // try to read the updated configuration file before it has been | 227 // try to read the updated configuration file before it has been |
| 171 // completely written. | 228 // completely written. |
| 172 // If the writer moves the new configuration file into place atomically, | 229 // If the writer moves the new configuration file into place atomically, |
| 173 // this delay may not be necessary. | 230 // this delay may not be necessary. |
| 174 config_updated_timer_->Reset(); | 231 config_updated_timer_->Reset(); |
| 175 } | 232 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 new ConfigChangedDelegate( | 279 new ConfigChangedDelegate( |
| 223 message_loop_.message_loop_proxy(), | 280 message_loop_.message_loop_proxy(), |
| 224 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)))); | 281 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)))); |
| 225 config_watcher_.reset(new base::files::FilePathWatcher()); | 282 config_watcher_.reset(new base::files::FilePathWatcher()); |
| 226 if (!config_watcher_->Watch(host_config_path_, delegate)) { | 283 if (!config_watcher_->Watch(host_config_path_, delegate)) { |
| 227 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); | 284 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); |
| 228 } | 285 } |
| 229 #endif // defined (OS_WIN) | 286 #endif // defined (OS_WIN) |
| 230 } | 287 } |
| 231 | 288 |
| 289 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 290 |
| 232 void CreateAuthenticatorFactory() { | 291 void CreateAuthenticatorFactory() { |
| 233 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | 292 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 234 scoped_ptr<protocol::AuthenticatorFactory> factory( | 293 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 235 new protocol::Me2MeHostAuthenticatorFactory( | 294 new protocol::Me2MeHostAuthenticatorFactory( |
| 236 key_pair_.GenerateCertificate(), | 295 key_pair_.GenerateCertificate(), |
| 237 *key_pair_.private_key(), host_secret_hash_)); | 296 *key_pair_.private_key(), host_secret_hash_)); |
| 238 host_->SetAuthenticatorFactory(factory.Pass()); | 297 host_->SetAuthenticatorFactory(factory.Pass()); |
| 239 } | 298 } |
| 240 | 299 |
| 241 // IPC::Listener implementation. | 300 // IPC::Listener implementation. |
| 242 virtual bool OnMessageReceived(const IPC::Message& message) { | 301 virtual bool OnMessageReceived(const IPC::Message& message) { |
| 302 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 303 |
| 304 #if defined(REMOTING_MULTI_PROCESS) |
| 305 bool handled = true; |
| 306 IPC_BEGIN_MESSAGE_MAP(HostProcess, message) |
| 307 IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration, |
| 308 OnConfigUpdated) |
| 309 IPC_MESSAGE_UNHANDLED(handled = false) |
| 310 IPC_END_MESSAGE_MAP() |
| 311 return handled; |
| 312 #else // !defined(REMOTING_MULTI_PROCESS) |
| 243 return false; | 313 return false; |
| 314 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 244 } | 315 } |
| 245 | 316 |
| 246 int Run() { | 317 int Run() { |
| 318 #if !defined(REMOTING_MULTI_PROCESS) |
| 247 if (!LoadConfig()) { | 319 if (!LoadConfig()) { |
| 248 return kInvalidHostConfigurationExitCode; | 320 return kInvalidHostConfigurationExitCode; |
| 249 } | 321 } |
| 250 | 322 |
| 251 #if defined(OS_MACOSX) || defined(OS_WIN) | 323 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 252 host_user_interface_.reset(new HostUserInterface(context_.get())); | 324 host_user_interface_.reset(new HostUserInterface(context_.get())); |
| 253 #endif | 325 #endif |
| 254 | 326 |
| 255 StartWatchingPolicy(); | 327 StartWatchingPolicy(); |
| 256 | 328 |
| 257 #if defined(OS_MACOSX) || defined(OS_WIN) | 329 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 258 context_->file_task_runner()->PostTask( | 330 context_->file_task_runner()->PostTask( |
| 259 FROM_HERE, | 331 FROM_HERE, |
| 260 base::Bind(&HostProcess::ListenForConfigChanges, | 332 base::Bind(&HostProcess::ListenForConfigChanges, |
| 261 base::Unretained(this))); | 333 base::Unretained(this))); |
| 262 #endif | 334 #endif |
| 335 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 336 |
| 263 message_loop_.Run(); | 337 message_loop_.Run(); |
| 264 | 338 |
| 265 #if defined(OS_MACOSX) || defined(OS_WIN) | 339 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 266 host_user_interface_.reset(); | 340 host_user_interface_.reset(); |
| 267 #endif | 341 #endif |
| 268 | 342 |
| 269 daemon_channel_.reset(); | 343 daemon_channel_.reset(); |
| 270 base::WaitableEvent done_event(true, false); | 344 base::WaitableEvent done_event(true, false); |
| 271 policy_watcher_->StopWatching(&done_event); | 345 policy_watcher_->StopWatching(&done_event); |
| 272 done_event.Wait(); | 346 done_event.Wait(); |
| 273 policy_watcher_.reset(); | 347 policy_watcher_.reset(); |
| 274 | 348 |
| 275 return exit_code_; | 349 return exit_code_; |
| 276 } | 350 } |
| 277 | 351 |
| 278 // Overridden from HeartbeatSender::Listener | 352 // Overridden from HeartbeatSender::Listener |
| 279 virtual void OnUnknownHostIdError() OVERRIDE { | 353 virtual void OnUnknownHostIdError() OVERRIDE { |
| 280 LOG(ERROR) << "Host ID not found."; | 354 LOG(ERROR) << "Host ID not found."; |
| 281 Shutdown(kInvalidHostIdExitCode); | 355 Shutdown(kInvalidHostIdExitCode); |
| 282 } | 356 } |
| 283 | 357 |
| 284 private: | 358 private: |
| 285 void StartWatchingPolicy() { | 359 void StartWatchingPolicy() { |
| 286 policy_watcher_.reset( | 360 policy_watcher_.reset( |
| 287 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); | 361 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); |
| 288 policy_watcher_->StartWatching( | 362 policy_watcher_->StartWatching( |
| 289 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); | 363 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); |
| 290 } | 364 } |
| 291 | 365 |
| 292 // Read host config, returning true if successful. | 366 // Applies the host config, returning true if successful. |
| 293 bool LoadConfig() { | 367 bool ApplyConfig() { |
| 294 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 368 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 295 | 369 |
| 296 // TODO(sergeyu): There is a potential race condition: this function is | |
| 297 // called on the main thread while the class members it mutates are used on | |
| 298 // the network thread. Fix it. http://crbug.com/140986 . | |
| 299 | |
| 300 if (!config_.Read()) { | |
| 301 LOG(ERROR) << "Failed to read config file."; | |
| 302 return false; | |
| 303 } | |
| 304 | |
| 305 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { | 370 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { |
| 306 LOG(ERROR) << "host_id is not defined in the config."; | 371 LOG(ERROR) << "host_id is not defined in the config."; |
| 307 return false; | 372 return false; |
| 308 } | 373 } |
| 309 | 374 |
| 310 if (!key_pair_.Load(config_)) { | 375 if (!key_pair_.Load(config_)) { |
| 311 return false; | 376 return false; |
| 312 } | 377 } |
| 313 | 378 |
| 314 std::string host_secret_hash_string; | 379 std::string host_secret_hash_string; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 344 } else if (!config_.GetString(kXmppAuthServiceConfigPath, | 409 } else if (!config_.GetString(kXmppAuthServiceConfigPath, |
| 345 &xmpp_auth_service_)) { | 410 &xmpp_auth_service_)) { |
| 346 // For the me2me host, we default to ClientLogin token for chromiumsync | 411 // For the me2me host, we default to ClientLogin token for chromiumsync |
| 347 // because earlier versions of the host had no HTTP stack with which to | 412 // because earlier versions of the host had no HTTP stack with which to |
| 348 // request an OAuth2 access token. | 413 // request an OAuth2 access token. |
| 349 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; | 414 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; |
| 350 } | 415 } |
| 351 return true; | 416 return true; |
| 352 } | 417 } |
| 353 | 418 |
| 419 #if !defined(REMOTING_MULTI_PROCESS) |
| 420 // Read host config, returning true if successful. |
| 421 bool LoadConfig() { |
| 422 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 423 |
| 424 // TODO(sergeyu): There is a potential race condition: this function is |
| 425 // called on the main thread while the class members it mutates are used on |
| 426 // the network thread. Fix it. http://crbug.com/140986. |
| 427 if (!config_.Read()) { |
| 428 LOG(ERROR) << "Failed to read config file."; |
| 429 return false; |
| 430 } |
| 431 |
| 432 return ApplyConfig(); |
| 433 } |
| 434 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 435 |
| 354 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { | 436 void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) { |
| 355 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 437 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 356 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( | 438 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 357 &HostProcess::OnPolicyUpdate, base::Unretained(this), | 439 &HostProcess::OnPolicyUpdate, base::Unretained(this), |
| 358 base::Passed(&policies))); | 440 base::Passed(&policies))); |
| 359 return; | 441 return; |
| 360 } | 442 } |
| 361 | 443 |
| 362 if (!host_) { | 444 if (!host_) { |
| 363 StartHost(); | 445 StartHost(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 signal_strategy_.reset(); | 678 signal_strategy_.reset(); |
| 597 | 679 |
| 598 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 680 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 599 } | 681 } |
| 600 | 682 |
| 601 MessageLoop message_loop_; | 683 MessageLoop message_loop_; |
| 602 scoped_ptr<ChromotingHostContext> context_; | 684 scoped_ptr<ChromotingHostContext> context_; |
| 603 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 685 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 604 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 686 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 605 | 687 |
| 688 #if defined(REMOTING_MULTI_PROCESS) |
| 689 JsonHostConfig config_; |
| 690 #else // !defined(REMOTING_MULTI_PROCESS) |
| 691 CompositeHostConfig config_; |
| 606 FilePath host_config_path_; | 692 FilePath host_config_path_; |
| 607 CompositeHostConfig config_; | 693 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; |
| 694 scoped_ptr<base::files::FilePathWatcher> config_watcher_; |
| 695 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 608 | 696 |
| 609 std::string host_id_; | 697 std::string host_id_; |
| 610 HostKeyPair key_pair_; | 698 HostKeyPair key_pair_; |
| 611 protocol::SharedSecretHash host_secret_hash_; | 699 protocol::SharedSecretHash host_secret_hash_; |
| 612 std::string xmpp_login_; | 700 std::string xmpp_login_; |
| 613 std::string xmpp_auth_token_; | 701 std::string xmpp_auth_token_; |
| 614 std::string xmpp_auth_service_; | 702 std::string xmpp_auth_service_; |
| 615 | 703 |
| 616 std::string oauth_refresh_token_; | 704 std::string oauth_refresh_token_; |
| 617 bool oauth_use_official_client_id_; | 705 bool oauth_use_official_client_id_; |
| 618 | 706 |
| 619 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; | 707 scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_; |
| 620 bool allow_nat_traversal_; | 708 bool allow_nat_traversal_; |
| 621 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | |
| 622 scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_; | |
| 623 | 709 |
| 624 bool restarting_; | 710 bool restarting_; |
| 625 bool shutting_down_; | 711 bool shutting_down_; |
| 626 | 712 |
| 627 scoped_ptr<XmppSignalStrategy> signal_strategy_; | 713 scoped_ptr<XmppSignalStrategy> signal_strategy_; |
| 628 scoped_ptr<SignalingConnector> signaling_connector_; | 714 scoped_ptr<SignalingConnector> signaling_connector_; |
| 629 scoped_ptr<DesktopEnvironment> desktop_environment_; | 715 scoped_ptr<DesktopEnvironment> desktop_environment_; |
| 630 scoped_ptr<HeartbeatSender> heartbeat_sender_; | 716 scoped_ptr<HeartbeatSender> heartbeat_sender_; |
| 631 scoped_ptr<LogToServer> log_to_server_; | 717 scoped_ptr<LogToServer> log_to_server_; |
| 632 scoped_ptr<HostEventLogger> host_event_logger_; | 718 scoped_ptr<HostEventLogger> host_event_logger_; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 user32.GetFunctionPointer("SetProcessDPIAware")); | 817 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 732 set_process_dpi_aware(); | 818 set_process_dpi_aware(); |
| 733 } | 819 } |
| 734 | 820 |
| 735 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 821 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 736 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 822 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 737 return main(0, NULL); | 823 return main(0, NULL); |
| 738 } | 824 } |
| 739 | 825 |
| 740 #endif // defined(OS_WIN) | 826 #endif // defined(OS_WIN) |
| OLD | NEW |