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 <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "remoting/base/auto_thread_task_runner.h" | 18 #include "remoting/base/auto_thread_task_runner.h" |
19 #include "remoting/base/constants.h" | |
19 #include "remoting/host/branding.h" | 20 #include "remoting/host/branding.h" |
20 #include "remoting/host/chromoting_messages.h" | 21 #include "remoting/host/chromoting_messages.h" |
21 #include "remoting/host/config_file_watcher.h" | 22 #include "remoting/host/config_file_watcher.h" |
22 #include "remoting/host/desktop_session.h" | 23 #include "remoting/host/desktop_session.h" |
23 #include "remoting/host/host_event_logger.h" | 24 #include "remoting/host/host_event_logger.h" |
24 #include "remoting/host/host_exit_codes.h" | 25 #include "remoting/host/host_exit_codes.h" |
25 #include "remoting/host/host_status_observer.h" | 26 #include "remoting/host/host_status_observer.h" |
27 #include "remoting/host/process_stats_sender.h" | |
26 #include "remoting/host/screen_resolution.h" | 28 #include "remoting/host/screen_resolution.h" |
27 #include "remoting/protocol/transport.h" | 29 #include "remoting/protocol/transport.h" |
28 | 30 |
29 namespace remoting { | 31 namespace remoting { |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 // This is used for tagging system event logs. | 35 // This is used for tagging system event logs. |
34 const char kApplicationName[] = "chromoting"; | 36 const char kApplicationName[] = "chromoting"; |
35 | 37 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_ClientConnected, | 115 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_ClientConnected, |
114 OnClientConnected) | 116 OnClientConnected) |
115 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_ClientDisconnected, | 117 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_ClientDisconnected, |
116 OnClientDisconnected) | 118 OnClientDisconnected) |
117 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_ClientRouteChange, | 119 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_ClientRouteChange, |
118 OnClientRouteChange) | 120 OnClientRouteChange) |
119 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_HostStarted, | 121 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_HostStarted, |
120 OnHostStarted) | 122 OnHostStarted) |
121 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_HostShutdown, | 123 IPC_MESSAGE_HANDLER(ChromotingNetworkDaemonMsg_HostShutdown, |
122 OnHostShutdown) | 124 OnHostShutdown) |
125 IPC_MESSAGE_HANDLER(ChromotingNetworkToAnyMsg_StartProcessStatsReport, | |
126 StartProcessStatsReport) | |
127 IPC_MESSAGE_HANDLER(ChromotingNetworkToAnyMsg_StopProcessStatsReport, | |
128 StopProcessStatsReport) | |
123 IPC_MESSAGE_UNHANDLED(handled = false) | 129 IPC_MESSAGE_UNHANDLED(handled = false) |
124 IPC_END_MESSAGE_MAP() | 130 IPC_END_MESSAGE_MAP() |
125 | 131 |
126 if (!handled) { | 132 if (!handled) { |
127 LOG(ERROR) << "Received unexpected IPC type: " << message.type(); | 133 LOG(ERROR) << "Received unexpected IPC type: " << message.type(); |
128 CrashNetworkProcess(FROM_HERE); | 134 CrashNetworkProcess(FROM_HERE); |
129 } | 135 } |
130 | 136 |
131 return handled; | 137 return handled; |
132 } | 138 } |
133 | 139 |
134 void DaemonProcess::OnPermanentError(int exit_code) { | 140 void DaemonProcess::OnPermanentError(int exit_code) { |
135 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 141 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
136 DCHECK(kMinPermanentErrorExitCode <= exit_code && | 142 DCHECK(kMinPermanentErrorExitCode <= exit_code && |
137 exit_code <= kMaxPermanentErrorExitCode); | 143 exit_code <= kMaxPermanentErrorExitCode); |
138 | 144 |
139 Stop(); | 145 Stop(); |
140 } | 146 } |
141 | 147 |
148 void DaemonProcess::OnWorkerProcessStopped(int exit_code) { | |
joedow
2017/06/23 18:03:07
You can remove the exit_code param since it isn't
Hzj_jie
2017/06/24 00:51:40
From the perspective of WorkerProcessLauncher, it'
joedow
2017/06/29 17:24:03
I think we should prefer a cleaner function signat
Hzj_jie
2017/06/29 20:24:57
Removed.
| |
149 process_stats_request_count_ = 0; | |
150 stats_sender_.reset(); | |
151 } | |
152 | |
142 void DaemonProcess::CloseDesktopSession(int terminal_id) { | 153 void DaemonProcess::CloseDesktopSession(int terminal_id) { |
143 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 154 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
144 | 155 |
145 // Validate the supplied terminal ID. An attempt to use a desktop session ID | 156 // Validate the supplied terminal ID. An attempt to use a desktop session ID |
146 // that couldn't possibly have been allocated is considered a protocol error | 157 // that couldn't possibly have been allocated is considered a protocol error |
147 // and the network process will be restarted. | 158 // and the network process will be restarted. |
148 if (!WasTerminalIdAllocated(terminal_id)) { | 159 if (!WasTerminalIdAllocated(terminal_id)) { |
149 LOG(ERROR) << "Invalid terminal ID: " << terminal_id; | 160 LOG(ERROR) << "Invalid terminal ID: " << terminal_id; |
150 CrashNetworkProcess(FROM_HERE); | 161 CrashNetworkProcess(FROM_HERE); |
151 return; | 162 return; |
(...skipping 21 matching lines...) Expand all Loading... | |
173 } | 184 } |
174 | 185 |
175 DaemonProcess::DaemonProcess( | 186 DaemonProcess::DaemonProcess( |
176 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 187 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
177 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 188 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
178 const base::Closure& stopped_callback) | 189 const base::Closure& stopped_callback) |
179 : caller_task_runner_(caller_task_runner), | 190 : caller_task_runner_(caller_task_runner), |
180 io_task_runner_(io_task_runner), | 191 io_task_runner_(io_task_runner), |
181 next_terminal_id_(0), | 192 next_terminal_id_(0), |
182 stopped_callback_(stopped_callback), | 193 stopped_callback_(stopped_callback), |
194 current_process_stats_("DaemonProcess"), | |
183 weak_factory_(this) { | 195 weak_factory_(this) { |
184 DCHECK(caller_task_runner->BelongsToCurrentThread()); | 196 DCHECK(caller_task_runner->BelongsToCurrentThread()); |
185 // TODO(sammc): On OSX, mojo::edk::SetMachPortProvider() should be called with | 197 // TODO(sammc): On OSX, mojo::edk::SetMachPortProvider() should be called with |
186 // a base::PortProvider implementation. Add it here when this code is used on | 198 // a base::PortProvider implementation. Add it here when this code is used on |
187 // OSX. | 199 // OSX. |
188 } | 200 } |
189 | 201 |
190 void DaemonProcess::CreateDesktopSession(int terminal_id, | 202 void DaemonProcess::CreateDesktopSession(int terminal_id, |
191 const ScreenResolution& resolution, | 203 const ScreenResolution& resolution, |
192 bool virtual_terminal) { | 204 bool virtual_terminal) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 host_event_logger_ = | 292 host_event_logger_ = |
281 HostEventLogger::Create(weak_factory_.GetWeakPtr(), kApplicationName); | 293 HostEventLogger::Create(weak_factory_.GetWeakPtr(), kApplicationName); |
282 | 294 |
283 // Launch the process. | 295 // Launch the process. |
284 LaunchNetworkProcess(); | 296 LaunchNetworkProcess(); |
285 } | 297 } |
286 | 298 |
287 void DaemonProcess::Stop() { | 299 void DaemonProcess::Stop() { |
288 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | 300 DCHECK(caller_task_runner()->BelongsToCurrentThread()); |
289 | 301 |
302 OnWorkerProcessStopped(0); | |
303 | |
290 if (!stopped_callback_.is_null()) { | 304 if (!stopped_callback_.is_null()) { |
291 base::ResetAndReturn(&stopped_callback_).Run(); | 305 base::ResetAndReturn(&stopped_callback_).Run(); |
292 } | 306 } |
293 } | 307 } |
294 | 308 |
295 bool DaemonProcess::WasTerminalIdAllocated(int terminal_id) { | 309 bool DaemonProcess::WasTerminalIdAllocated(int terminal_id) { |
296 return terminal_id < next_terminal_id_; | 310 return terminal_id < next_terminal_id_; |
297 } | 311 } |
298 | 312 |
299 void DaemonProcess::OnAccessDenied(const std::string& jid) { | 313 void DaemonProcess::OnAccessDenied(const std::string& jid) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 observer.OnShutdown(); | 372 observer.OnShutdown(); |
359 } | 373 } |
360 | 374 |
361 void DaemonProcess::DeleteAllDesktopSessions() { | 375 void DaemonProcess::DeleteAllDesktopSessions() { |
362 while (!desktop_sessions_.empty()) { | 376 while (!desktop_sessions_.empty()) { |
363 delete desktop_sessions_.front(); | 377 delete desktop_sessions_.front(); |
364 desktop_sessions_.pop_front(); | 378 desktop_sessions_.pop_front(); |
365 } | 379 } |
366 } | 380 } |
367 | 381 |
382 void DaemonProcess::StartProcessStatsReport(base::TimeDelta interval) { | |
383 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | |
384 if (interval <= base::TimeDelta::FromSeconds(0)) { | |
385 interval = kDefaultProcessStatsInterval; | |
386 } | |
387 | |
388 process_stats_request_count_++; | |
389 DCHECK(process_stats_request_count_ > 0); | |
joedow
2017/06/23 18:03:07
If you want to keep the request_count, I'd prefer
Hzj_jie
2017/06/24 00:51:40
Test cases are added to cover the scenarios.
I thi
| |
390 if (process_stats_request_count_ == 1 || | |
391 stats_sender_->interval() > interval) { | |
392 DCHECK_EQ(process_stats_request_count_ == 1, !stats_sender_); | |
joedow
2017/06/23 18:03:07
I don't think you should allow calling start multi
Hzj_jie
2017/06/24 00:51:40
Here the trouble is different sessions may request
| |
393 stats_sender_.reset(new ProcessStatsSender( | |
394 this, | |
395 interval, | |
396 { ¤t_process_stats_ })); | |
397 } | |
398 } | |
399 | |
400 void DaemonProcess::StopProcessStatsReport() { | |
401 DCHECK(caller_task_runner()->BelongsToCurrentThread()); | |
402 process_stats_request_count_--; | |
403 DCHECK(process_stats_request_count_ >= 0); | |
joedow
2017/06/23 18:03:07
DCHECK_EQ(process_stats_request_count_, 0)
Hzj_jie
2017/06/24 00:51:40
Done.
joedow
2017/06/29 17:24:03
I don't see this change in the latest patchset.
I
Hzj_jie
2017/06/29 20:24:57
Sorry.
| |
404 if (process_stats_request_count_ == 0) { | |
405 DCHECK(stats_sender_); | |
406 stats_sender_.reset(); | |
407 } | |
408 } | |
409 | |
410 void DaemonProcess::OnProcessStats( | |
411 const protocol::AggregatedProcessResourceUsage& usage) { | |
412 SendToNetwork(new ChromotingAnyToNetworkMsg_ReportProcessStats(usage)); | |
413 } | |
414 | |
368 } // namespace remoting | 415 } // namespace remoting |
OLD | NEW |