| 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 #include "remoting/host/daemon_process.h" | 5 #include "remoting/host/daemon_process.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 10 #include "base/threading/thread.h" | 13 #include "remoting/host/branding.h" |
| 11 | 14 #include "remoting/host/chromoting_messages.h" |
| 12 namespace { | |
| 13 | |
| 14 const char kIpcThreadName[] = "Daemon process IPC"; | |
| 15 | |
| 16 } // namespace | |
| 17 | 15 |
| 18 namespace remoting { | 16 namespace remoting { |
| 19 | 17 |
| 20 DaemonProcess::~DaemonProcess() { | 18 DaemonProcess::~DaemonProcess() { |
| 19 CHECK(!config_watcher_.get()); |
| 20 } |
| 21 |
| 22 void DaemonProcess::OnConfigUpdated(const std::string& serialized_config) { |
| 23 if (serialized_config_ != serialized_config) { |
| 24 serialized_config_ = serialized_config; |
| 25 Send(new ChromotingDaemonNetworkMsg_Configuration(serialized_config_)); |
| 26 } |
| 27 } |
| 28 |
| 29 void DaemonProcess::OnConfigWatcherError() { |
| 30 Stop(); |
| 31 } |
| 32 |
| 33 void DaemonProcess::OnChannelConnected() { |
| 34 DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| 35 |
| 36 // Send the configuration to the network process. |
| 37 Send(new ChromotingDaemonNetworkMsg_Configuration(serialized_config_)); |
| 21 } | 38 } |
| 22 | 39 |
| 23 bool DaemonProcess::OnMessageReceived(const IPC::Message& message) { | 40 bool DaemonProcess::OnMessageReceived(const IPC::Message& message) { |
| 24 return true; | 41 DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| 42 |
| 43 return false; |
| 25 } | 44 } |
| 26 | 45 |
| 27 DaemonProcess::DaemonProcess( | 46 DaemonProcess::DaemonProcess( |
| 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 47 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 29 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 48 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 30 const base::Closure& stopped_callback) | 49 const base::Closure& stopped_callback) |
| 31 : Stoppable(main_task_runner, stopped_callback), | 50 : Stoppable(main_task_runner, stopped_callback), |
| 32 main_task_runner_(main_task_runner), | 51 main_task_runner_(main_task_runner), |
| 33 io_task_runner_(io_task_runner) { | 52 io_task_runner_(io_task_runner) { |
| 34 // Initialize on the same thread that will be used for shutting down. | 53 // Initialize on the same thread that will be used for shutting down. |
| 35 main_task_runner_->PostTask( | 54 main_task_runner_->PostTask( |
| 36 FROM_HERE, | 55 FROM_HERE, |
| 37 base::Bind(&DaemonProcess::Init, base::Unretained(this))); | 56 base::Bind(&DaemonProcess::Initialize, base::Unretained(this))); |
| 38 } | 57 } |
| 39 | 58 |
| 40 void DaemonProcess::Init() { | 59 void DaemonProcess::Initialize() { |
| 41 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 60 DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| 42 | 61 |
| 43 if (!LaunchNetworkProcess()) { | 62 // Get the name of the host configuration file. |
| 44 LOG(ERROR) << "Failed to launch the networking process."; | 63 FilePath default_config_dir = remoting::GetConfigDir(); |
| 45 Stop(); | 64 FilePath config_path = default_config_dir.Append(kDefaultHostConfigFile); |
| 46 return; | 65 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 66 if (command_line->HasSwitch(kHostConfigSwitchName)) { |
| 67 config_path = command_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 47 } | 68 } |
| 69 |
| 70 // Start watching the host configuration file. |
| 71 config_watcher_.reset(new ConfigFileWatcher(main_task_runner(), |
| 72 io_task_runner(), |
| 73 this)); |
| 74 config_watcher_->Watch(config_path); |
| 75 |
| 76 // Launch the process. |
| 77 LaunchNetworkProcess(); |
| 48 } | 78 } |
| 49 | 79 |
| 50 void DaemonProcess::DoStop() { | 80 void DaemonProcess::DoStop() { |
| 51 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 81 DCHECK(main_task_runner()->BelongsToCurrentThread()); |
| 52 | 82 |
| 83 config_watcher_.reset(); |
| 53 CompleteStopping(); | 84 CompleteStopping(); |
| 54 } | 85 } |
| 55 | 86 |
| 56 } // namespace remoting | 87 } // namespace remoting |
| OLD | NEW |