| 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" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 void DaemonProcess::CloseDesktopSession(int terminal_id) { | 73 void DaemonProcess::CloseDesktopSession(int terminal_id) { |
| 74 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 74 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 75 | 75 |
| 76 // Validate the supplied terminal ID. An attempt to close a desktop session | 76 // Validate the supplied terminal ID. An attempt to close a desktop session |
| 77 // with an ID that couldn't possibly have been allocated is considered | 77 // with an ID that couldn't possibly have been allocated is considered |
| 78 // a protocol error and the network process will be restarted. | 78 // a protocol error and the network process will be restarted. |
| 79 if (!IsTerminalIdKnown(terminal_id)) { | 79 if (!IsTerminalIdKnown(terminal_id)) { |
| 80 LOG(ERROR) << "An invalid terminal ID. terminal_id=" << terminal_id; | 80 LOG(ERROR) << "An invalid terminal ID. terminal_id=" << terminal_id; |
| 81 RestartNetworkProcess(); | 81 CrashNetworkProcess(FROM_HERE); |
| 82 DeleteAllDesktopSessions(); | 82 DeleteAllDesktopSessions(); |
| 83 return; | 83 return; |
| 84 } | 84 } |
| 85 | 85 |
| 86 DesktopSessionList::iterator i; | 86 DesktopSessionList::iterator i; |
| 87 for (i = desktop_sessions_.begin(); i != desktop_sessions_.end(); ++i) { | 87 for (i = desktop_sessions_.begin(); i != desktop_sessions_.end(); ++i) { |
| 88 if ((*i)->id() == terminal_id) { | 88 if ((*i)->id() == terminal_id) { |
| 89 break; | 89 break; |
| 90 } | 90 } |
| 91 } | 91 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 108 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 109 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 109 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 110 const base::Closure& stopped_callback) | 110 const base::Closure& stopped_callback) |
| 111 : Stoppable(caller_task_runner, stopped_callback), | 111 : Stoppable(caller_task_runner, stopped_callback), |
| 112 caller_task_runner_(caller_task_runner), | 112 caller_task_runner_(caller_task_runner), |
| 113 io_task_runner_(io_task_runner), | 113 io_task_runner_(io_task_runner), |
| 114 next_terminal_id_(0) { | 114 next_terminal_id_(0) { |
| 115 DCHECK(caller_task_runner->BelongsToCurrentThread()); | 115 DCHECK(caller_task_runner->BelongsToCurrentThread()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void DaemonProcess::Initialize() { | |
| 119 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | |
| 120 | |
| 121 // Get the name of the host configuration file. | |
| 122 FilePath default_config_dir = remoting::GetConfigDir(); | |
| 123 FilePath config_path = default_config_dir.Append(kDefaultHostConfigFile); | |
| 124 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 125 if (command_line->HasSwitch(kHostConfigSwitchName)) { | |
| 126 config_path = command_line->GetSwitchValuePath(kHostConfigSwitchName); | |
| 127 } | |
| 128 | |
| 129 // Start watching the host configuration file. | |
| 130 config_watcher_.reset(new ConfigFileWatcher(caller_task_runner(), | |
| 131 io_task_runner(), | |
| 132 this)); | |
| 133 config_watcher_->Watch(config_path); | |
| 134 | |
| 135 // Launch the process. | |
| 136 LaunchNetworkProcess(); | |
| 137 } | |
| 138 | |
| 139 bool DaemonProcess::IsTerminalIdKnown(int terminal_id) { | 118 bool DaemonProcess::IsTerminalIdKnown(int terminal_id) { |
| 140 return terminal_id < next_terminal_id_; | 119 return terminal_id < next_terminal_id_; |
| 141 } | 120 } |
| 142 | 121 |
| 143 void DaemonProcess::CreateDesktopSession(int terminal_id) { | 122 void DaemonProcess::CreateDesktopSession(int terminal_id) { |
| 144 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 123 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 145 | 124 |
| 146 // Validate the supplied terminal ID. An attempt to create a desktop session | 125 // Validate the supplied terminal ID. An attempt to create a desktop session |
| 147 // with an ID that could possibly have been allocated already is considered | 126 // with an ID that could possibly have been allocated already is considered |
| 148 // a protocol error and the network process will be restarted. | 127 // a protocol error and the network process will be restarted. |
| 149 if (IsTerminalIdKnown(terminal_id)) { | 128 if (IsTerminalIdKnown(terminal_id)) { |
| 150 LOG(ERROR) << "An invalid terminal ID. terminal_id=" << terminal_id; | 129 LOG(ERROR) << "An invalid terminal ID. terminal_id=" << terminal_id; |
| 151 RestartNetworkProcess(); | 130 CrashNetworkProcess(FROM_HERE); |
| 152 DeleteAllDesktopSessions(); | 131 DeleteAllDesktopSessions(); |
| 153 return; | 132 return; |
| 154 } | 133 } |
| 155 | 134 |
| 156 VLOG(1) << "Daemon: opened desktop session " << terminal_id; | 135 VLOG(1) << "Daemon: opened desktop session " << terminal_id; |
| 157 desktop_sessions_.push_back( | 136 desktop_sessions_.push_back( |
| 158 DoCreateDesktopSession(terminal_id).release()); | 137 DoCreateDesktopSession(terminal_id).release()); |
| 159 next_terminal_id_ = std::max(next_terminal_id_, terminal_id + 1); | 138 next_terminal_id_ = std::max(next_terminal_id_, terminal_id + 1); |
| 160 } | 139 } |
| 161 | 140 |
| 141 void DaemonProcess::CrashNetworkProcess( |
| 142 const tracked_objects::Location& location) { |
| 143 SendToNetwork(new ChromotingDaemonNetworkMsg_Crash( |
| 144 location.function_name(), location.file_name(), location.line_number())); |
| 145 } |
| 146 |
| 147 void DaemonProcess::Initialize() { |
| 148 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 149 |
| 150 // Get the name of the host configuration file. |
| 151 FilePath default_config_dir = remoting::GetConfigDir(); |
| 152 FilePath config_path = default_config_dir.Append(kDefaultHostConfigFile); |
| 153 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 154 if (command_line->HasSwitch(kHostConfigSwitchName)) { |
| 155 config_path = command_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 156 } |
| 157 |
| 158 // Start watching the host configuration file. |
| 159 config_watcher_.reset(new ConfigFileWatcher(caller_task_runner(), |
| 160 io_task_runner(), |
| 161 this)); |
| 162 config_watcher_->Watch(config_path); |
| 163 |
| 164 // Launch the process. |
| 165 LaunchNetworkProcess(); |
| 166 } |
| 167 |
| 162 void DaemonProcess::DoStop() { | 168 void DaemonProcess::DoStop() { |
| 163 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 169 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
| 164 | 170 |
| 165 config_watcher_.reset(); | 171 config_watcher_.reset(); |
| 166 DeleteAllDesktopSessions(); | 172 DeleteAllDesktopSessions(); |
| 167 | 173 |
| 168 CompleteStopping(); | 174 CompleteStopping(); |
| 169 } | 175 } |
| 170 | 176 |
| 171 void DaemonProcess::DeleteAllDesktopSessions() { | 177 void DaemonProcess::DeleteAllDesktopSessions() { |
| 172 while (!desktop_sessions_.empty()) { | 178 while (!desktop_sessions_.empty()) { |
| 173 delete desktop_sessions_.front(); | 179 delete desktop_sessions_.front(); |
| 174 desktop_sessions_.pop_front(); | 180 desktop_sessions_.pop_front(); |
| 175 } | 181 } |
| 176 } | 182 } |
| 177 | 183 |
| 178 } // namespace remoting | 184 } // namespace remoting |
| OLD | NEW |