| 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" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // Call ConfigUpdatedDelayed after a short delay, so that this object won't | 139 // Call ConfigUpdatedDelayed after a short delay, so that this object won't |
| 140 // try to read the updated configuration file before it has been | 140 // try to read the updated configuration file before it has been |
| 141 // completely written. | 141 // completely written. |
| 142 // If the writer moves the new configuration file into place atomically, | 142 // If the writer moves the new configuration file into place atomically, |
| 143 // this delay may not be necessary. | 143 // this delay may not be necessary. |
| 144 config_updated_timer_->Reset(); | 144 config_updated_timer_->Reset(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void ConfigUpdatedDelayed() { | 147 void ConfigUpdatedDelayed() { |
| 148 if (LoadConfig()) { | 148 if (LoadConfig()) { |
| 149 context_->network_message_loop()->PostTask( | 149 context_->network_task_runner()->PostTask( |
| 150 FROM_HERE, | 150 FROM_HERE, |
| 151 base::Bind(&HostProcess::CreateAuthenticatorFactory, | 151 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
| 152 base::Unretained(this))); | 152 base::Unretained(this))); |
| 153 } else { | 153 } else { |
| 154 LOG(ERROR) << "Invalid configuration."; | 154 LOG(ERROR) << "Invalid configuration."; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
| 159 class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { | 159 class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { |
| 160 public: | 160 public: |
| 161 ConfigChangedDelegate(base::MessageLoopProxy* message_loop, | 161 ConfigChangedDelegate( |
| 162 const base::Closure& callback) | 162 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 163 : message_loop_(message_loop), | 163 const base::Closure& callback) |
| 164 : task_runner_(task_runner), |
| 164 callback_(callback) { | 165 callback_(callback) { |
| 165 } | 166 } |
| 166 | 167 |
| 167 void OnFilePathChanged(const FilePath& path) OVERRIDE { | 168 void OnFilePathChanged(const FilePath& path) OVERRIDE { |
| 168 message_loop_->PostTask(FROM_HERE, callback_); | 169 task_runner_->PostTask(FROM_HERE, callback_); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void OnFilePathError(const FilePath& path) OVERRIDE { | 172 void OnFilePathError(const FilePath& path) OVERRIDE { |
| 172 } | 173 } |
| 173 | 174 |
| 174 private: | 175 private: |
| 175 scoped_refptr<base::MessageLoopProxy> message_loop_; | 176 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 176 base::Closure callback_; | 177 base::Closure callback_; |
| 177 | 178 |
| 178 DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); | 179 DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); |
| 179 }; | 180 }; |
| 180 #endif // defined(OS_WIN) | 181 #endif // defined(OS_WIN) |
| 181 | 182 |
| 182 void ListenForConfigChanges() { | 183 void ListenForConfigChanges() { |
| 183 #if defined(OS_MACOSX) | 184 #if defined(OS_MACOSX) |
| 184 remoting::RegisterHupSignalHandler( | 185 remoting::RegisterHupSignalHandler( |
| 185 base::Bind(&HostProcess::ConfigUpdatedDelayed, base::Unretained(this))); | 186 base::Bind(&HostProcess::ConfigUpdatedDelayed, base::Unretained(this))); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 208 return kInvalidHostConfigurationExitCode; | 209 return kInvalidHostConfigurationExitCode; |
| 209 } | 210 } |
| 210 | 211 |
| 211 #if defined(OS_MACOSX) || defined(OS_WIN) | 212 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 212 host_user_interface_.reset(new HostUserInterface(context_.get())); | 213 host_user_interface_.reset(new HostUserInterface(context_.get())); |
| 213 #endif | 214 #endif |
| 214 | 215 |
| 215 StartWatchingNatPolicy(); | 216 StartWatchingNatPolicy(); |
| 216 | 217 |
| 217 #if defined(OS_MACOSX) || defined(OS_WIN) | 218 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 218 context_->file_message_loop()->PostTask( | 219 context_->file_task_runner()->PostTask( |
| 219 FROM_HERE, | 220 FROM_HERE, |
| 220 base::Bind(&HostProcess::ListenForConfigChanges, | 221 base::Bind(&HostProcess::ListenForConfigChanges, |
| 221 base::Unretained(this))); | 222 base::Unretained(this))); |
| 222 #endif | 223 #endif |
| 223 message_loop_.Run(); | 224 message_loop_.Run(); |
| 224 | 225 |
| 225 #if defined(OS_MACOSX) || defined(OS_WIN) | 226 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 226 host_user_interface_.reset(); | 227 host_user_interface_.reset(); |
| 227 #endif | 228 #endif |
| 228 | 229 |
| 229 base::WaitableEvent done_event(true, false); | 230 base::WaitableEvent done_event(true, false); |
| 230 nat_policy_->StopWatching(&done_event); | 231 nat_policy_->StopWatching(&done_event); |
| 231 done_event.Wait(); | 232 done_event.Wait(); |
| 232 nat_policy_.reset(); | 233 nat_policy_.reset(); |
| 233 | 234 |
| 234 return exit_code_; | 235 return exit_code_; |
| 235 } | 236 } |
| 236 | 237 |
| 237 // Overridden from HeartbeatSender::Listener | 238 // Overridden from HeartbeatSender::Listener |
| 238 virtual void OnUnknownHostIdError() OVERRIDE { | 239 virtual void OnUnknownHostIdError() OVERRIDE { |
| 239 LOG(ERROR) << "Host ID not found."; | 240 LOG(ERROR) << "Host ID not found."; |
| 240 Shutdown(kInvalidHostIdExitCode); | 241 Shutdown(kInvalidHostIdExitCode); |
| 241 } | 242 } |
| 242 | 243 |
| 243 private: | 244 private: |
| 244 void StartWatchingNatPolicy() { | 245 void StartWatchingNatPolicy() { |
| 245 nat_policy_.reset( | 246 nat_policy_.reset( |
| 246 policy_hack::NatPolicy::Create(context_->file_message_loop())); | 247 policy_hack::NatPolicy::Create(context_->file_task_runner())); |
| 247 nat_policy_->StartWatching( | 248 nat_policy_->StartWatching( |
| 248 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this))); | 249 base::Bind(&HostProcess::OnNatPolicyUpdate, base::Unretained(this))); |
| 249 } | 250 } |
| 250 | 251 |
| 251 // Read Host config from disk, returning true if successful. | 252 // Read Host config from disk, returning true if successful. |
| 252 bool LoadConfig() { | 253 bool LoadConfig() { |
| 253 JsonHostConfig host_config(host_config_path_); | 254 JsonHostConfig host_config(host_config_path_); |
| 254 JsonHostConfig auth_config(auth_config_path_); | 255 JsonHostConfig auth_config(auth_config_path_); |
| 255 | 256 |
| 256 FilePath failed_path; | 257 FilePath failed_path; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 &xmpp_auth_service_)) { | 308 &xmpp_auth_service_)) { |
| 308 // For the me2me host, we default to ClientLogin token for chromiumsync | 309 // For the me2me host, we default to ClientLogin token for chromiumsync |
| 309 // because earlier versions of the host had no HTTP stack with which to | 310 // because earlier versions of the host had no HTTP stack with which to |
| 310 // request an OAuth2 access token. | 311 // request an OAuth2 access token. |
| 311 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; | 312 xmpp_auth_service_ = kChromotingTokenDefaultServiceName; |
| 312 } | 313 } |
| 313 return true; | 314 return true; |
| 314 } | 315 } |
| 315 | 316 |
| 316 void OnNatPolicyUpdate(bool nat_traversal_enabled) { | 317 void OnNatPolicyUpdate(bool nat_traversal_enabled) { |
| 317 if (!context_->network_message_loop()->BelongsToCurrentThread()) { | 318 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 318 context_->network_message_loop()->PostTask(FROM_HERE, base::Bind( | 319 context_->network_task_runner()->PostTask(FROM_HERE, base::Bind( |
| 319 &HostProcess::OnNatPolicyUpdate, base::Unretained(this), | 320 &HostProcess::OnNatPolicyUpdate, base::Unretained(this), |
| 320 nat_traversal_enabled)); | 321 nat_traversal_enabled)); |
| 321 return; | 322 return; |
| 322 } | 323 } |
| 323 | 324 |
| 324 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled; | 325 bool policy_changed = allow_nat_traversal_ != nat_traversal_enabled; |
| 325 allow_nat_traversal_ = nat_traversal_enabled; | 326 allow_nat_traversal_ = nat_traversal_enabled; |
| 326 | 327 |
| 327 if (host_) { | 328 if (host_) { |
| 328 // Restart the host if the policy has changed while the host was | 329 // Restart the host if the policy has changed while the host was |
| 329 // online. | 330 // online. |
| 330 if (policy_changed) | 331 if (policy_changed) |
| 331 RestartHost(); | 332 RestartHost(); |
| 332 } else { | 333 } else { |
| 333 // Just start the host otherwise. | 334 // Just start the host otherwise. |
| 334 StartHost(); | 335 StartHost(); |
| 335 } | 336 } |
| 336 } | 337 } |
| 337 | 338 |
| 338 void StartHost() { | 339 void StartHost() { |
| 339 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 340 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 340 DCHECK(!host_); | 341 DCHECK(!host_); |
| 341 | 342 |
| 342 if (!signal_strategy_.get()) { | 343 if (!signal_strategy_.get()) { |
| 343 signal_strategy_.reset( | 344 signal_strategy_.reset( |
| 344 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login_, | 345 new XmppSignalStrategy(context_->jingle_thread(), xmpp_login_, |
| 345 xmpp_auth_token_, xmpp_auth_service_)); | 346 xmpp_auth_token_, xmpp_auth_service_)); |
| 346 | 347 |
| 347 signaling_connector_.reset(new SignalingConnector( | 348 signaling_connector_.reset(new SignalingConnector( |
| 348 signal_strategy_.get(), | 349 signal_strategy_.get(), |
| 349 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); | 350 base::Bind(&HostProcess::OnAuthFailed, base::Unretained(this)))); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 | 423 |
| 423 // Invoked when the user uses the Disconnect windows to terminate | 424 // Invoked when the user uses the Disconnect windows to terminate |
| 424 // the sessions. | 425 // the sessions. |
| 425 void OnDisconnectRequested() { | 426 void OnDisconnectRequested() { |
| 426 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 427 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 427 | 428 |
| 428 host_->DisconnectAllClients(); | 429 host_->DisconnectAllClients(); |
| 429 } | 430 } |
| 430 | 431 |
| 431 void RestartHost() { | 432 void RestartHost() { |
| 432 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 433 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 433 | 434 |
| 434 if (restarting_ || shutting_down_) | 435 if (restarting_ || shutting_down_) |
| 435 return; | 436 return; |
| 436 | 437 |
| 437 restarting_ = true; | 438 restarting_ = true; |
| 438 host_->Shutdown(base::Bind( | 439 host_->Shutdown(base::Bind( |
| 439 &HostProcess::RestartOnHostShutdown, base::Unretained(this))); | 440 &HostProcess::RestartOnHostShutdown, base::Unretained(this))); |
| 440 } | 441 } |
| 441 | 442 |
| 442 void RestartOnHostShutdown() { | 443 void RestartOnHostShutdown() { |
| 443 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 444 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 444 | 445 |
| 445 if (shutting_down_) | 446 if (shutting_down_) |
| 446 return; | 447 return; |
| 447 | 448 |
| 448 restarting_ = false; | 449 restarting_ = false; |
| 449 host_ = NULL; | 450 host_ = NULL; |
| 450 log_to_server_.reset(); | 451 log_to_server_.reset(); |
| 451 host_event_logger_.reset(); | 452 host_event_logger_.reset(); |
| 452 heartbeat_sender_.reset(); | 453 heartbeat_sender_.reset(); |
| 453 | 454 |
| 454 StartHost(); | 455 StartHost(); |
| 455 } | 456 } |
| 456 | 457 |
| 457 void Shutdown(int exit_code) { | 458 void Shutdown(int exit_code) { |
| 458 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 459 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 459 | 460 |
| 460 if (shutting_down_) | 461 if (shutting_down_) |
| 461 return; | 462 return; |
| 462 | 463 |
| 463 shutting_down_ = true; | 464 shutting_down_ = true; |
| 464 exit_code_ = exit_code; | 465 exit_code_ = exit_code; |
| 465 host_->Shutdown(base::Bind( | 466 host_->Shutdown(base::Bind( |
| 466 &HostProcess::OnShutdownFinished, base::Unretained(this))); | 467 &HostProcess::OnShutdownFinished, base::Unretained(this))); |
| 467 } | 468 } |
| 468 | 469 |
| 469 void OnShutdownFinished() { | 470 void OnShutdownFinished() { |
| 470 DCHECK(context_->network_message_loop()->BelongsToCurrentThread()); | 471 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); |
| 471 | 472 |
| 472 // Destroy networking objects while we are on the network thread. | 473 // Destroy networking objects while we are on the network thread. |
| 473 host_ = NULL; | 474 host_ = NULL; |
| 474 host_event_logger_.reset(); | 475 host_event_logger_.reset(); |
| 475 log_to_server_.reset(); | 476 log_to_server_.reset(); |
| 476 heartbeat_sender_.reset(); | 477 heartbeat_sender_.reset(); |
| 477 signaling_connector_.reset(); | 478 signaling_connector_.reset(); |
| 478 signal_strategy_.reset(); | 479 signal_strategy_.reset(); |
| 479 | 480 |
| 480 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 481 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 user32.GetFunctionPointer("SetProcessDPIAware")); | 603 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 603 set_process_dpi_aware(); | 604 set_process_dpi_aware(); |
| 604 } | 605 } |
| 605 | 606 |
| 606 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 607 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 607 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 608 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 608 return main(0, NULL); | 609 return main(0, NULL); |
| 609 } | 610 } |
| 610 | 611 |
| 611 #endif // defined(OS_WIN) | 612 #endif // defined(OS_WIN) |
| OLD | NEW |