Chromium Code Reviews| Index: remoting/host/daemon_process.cc |
| diff --git a/remoting/host/daemon_process.cc b/remoting/host/daemon_process.cc |
| index 2a08284eb4dae13847613ae9b7a590961b3e75ee..ad83b9bc6f328395b2993d78fe7fd8f50a197bb1 100644 |
| --- a/remoting/host/daemon_process.cc |
| +++ b/remoting/host/daemon_process.cc |
| @@ -6,22 +6,41 @@ |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| +#include "base/command_line.h" |
| +#include "base/file_path.h" |
| +#include "base/file_util.h" |
| #include "base/single_thread_task_runner.h" |
| -#include "base/threading/thread.h" |
| +#include "remoting/host/branding.h" |
| +#include "remoting/host/chromoting_messages.h" |
| -namespace { |
| +namespace remoting { |
| -const char kIpcThreadName[] = "Daemon process IPC"; |
| +DaemonProcess::~DaemonProcess() { |
| + CHECK(!config_watcher_.get()); |
| +} |
| -} // namespace |
| +void DaemonProcess::OnConfigUpdated(const std::string& config) { |
| + if (config_ != config) { |
| + config_ = config; |
| + Send(new ChromotingDaemonNetworkMsg_Configuration(config_)); |
| + } |
| +} |
| -namespace remoting { |
| +void DaemonProcess::OnConfigWatcherError() { |
| + Stop(); |
| +} |
| -DaemonProcess::~DaemonProcess() { |
| +void DaemonProcess::OnChannelConnected() { |
| + DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| + |
| + // Send the configuration to the network process. |
| + Send(new ChromotingDaemonNetworkMsg_Configuration(config_)); |
| } |
| bool DaemonProcess::OnMessageReceived(const IPC::Message& message) { |
| - return true; |
| + DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| + |
| + return false; |
| } |
| DaemonProcess::DaemonProcess( |
| @@ -30,27 +49,53 @@ DaemonProcess::DaemonProcess( |
| const base::Closure& stopped_callback) |
| : Stoppable(main_task_runner, stopped_callback), |
| main_task_runner_(main_task_runner), |
| - io_task_runner_(io_task_runner) { |
| + io_task_runner_(io_task_runner), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| // Initialize on the same thread that will be used for shutting down. |
| main_task_runner_->PostTask( |
| FROM_HERE, |
| - base::Bind(&DaemonProcess::Init, base::Unretained(this))); |
| + base::Bind(&DaemonProcess::Initialize, base::Unretained(this))); |
| } |
| -void DaemonProcess::Init() { |
| - DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| +void DaemonProcess::Initialize() { |
| + DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| - if (!LaunchNetworkProcess()) { |
| - LOG(ERROR) << "Failed to launch the networking process."; |
| - Stop(); |
| - return; |
| + // Get the name of the host configuration file. |
| + FilePath default_config_dir = remoting::GetConfigDir(); |
| + FilePath config_path = default_config_dir.Append(kDefaultHostConfigFile); |
| + const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(kHostConfigSwitchName)) { |
| + config_path = command_line->GetSwitchValuePath(kHostConfigSwitchName); |
| } |
| + |
| + // Start watching the host configuration file. |
| + config_watcher_.reset(new ConfigFileWatcher(main_task_runner(), |
| + io_task_runner(), |
|
Wez
2012/08/30 20:36:04
nit: Indentation.
alexeypa (please no reviews)
2012/08/30 23:15:13
Done.
|
| + weak_factory_.GetWeakPtr())); |
| + config_watcher_->Watch(config_path); |
| + |
| + // Launch the process. |
| + LaunchNetworkProcess(); |
| } |
| void DaemonProcess::DoStop() { |
| - DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| + DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| + |
| + weak_factory_.InvalidateWeakPtrs(); |
| + if (config_watcher_.get()) { |
| + config_watcher_.release()->StopAndDelete(); |
| + } |
| CompleteStopping(); |
| } |
| +void DaemonProcess::SendConfig(const std::string& config) { |
| + DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| + |
| + if (config_ != config) { |
| + config_ = config; |
| + Send(new ChromotingDaemonNetworkMsg_Configuration(config_)); |
| + } |
| +} |
| + |
| } // namespace remoting |