Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: remoting/host/daemon_process.cc

Issue 2950993003: [Chromoting] Use ProcessStatsSender in DaemonProcess (daemon process) (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 179 }
174 180
175 DaemonProcess::DaemonProcess( 181 DaemonProcess::DaemonProcess(
176 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, 182 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
177 scoped_refptr<AutoThreadTaskRunner> io_task_runner, 183 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
178 const base::Closure& stopped_callback) 184 const base::Closure& stopped_callback)
179 : caller_task_runner_(caller_task_runner), 185 : caller_task_runner_(caller_task_runner),
180 io_task_runner_(io_task_runner), 186 io_task_runner_(io_task_runner),
181 next_terminal_id_(0), 187 next_terminal_id_(0),
182 stopped_callback_(stopped_callback), 188 stopped_callback_(stopped_callback),
189 current_process_stats_("DaemonProcess"),
183 weak_factory_(this) { 190 weak_factory_(this) {
184 DCHECK(caller_task_runner->BelongsToCurrentThread()); 191 DCHECK(caller_task_runner->BelongsToCurrentThread());
185 // TODO(sammc): On OSX, mojo::edk::SetMachPortProvider() should be called with 192 // 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 193 // a base::PortProvider implementation. Add it here when this code is used on
187 // OSX. 194 // OSX.
188 } 195 }
189 196
190 void DaemonProcess::CreateDesktopSession(int terminal_id, 197 void DaemonProcess::CreateDesktopSession(int terminal_id,
191 const ScreenResolution& resolution, 198 const ScreenResolution& resolution,
192 bool virtual_terminal) { 199 bool virtual_terminal) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 host_event_logger_ = 287 host_event_logger_ =
281 HostEventLogger::Create(weak_factory_.GetWeakPtr(), kApplicationName); 288 HostEventLogger::Create(weak_factory_.GetWeakPtr(), kApplicationName);
282 289
283 // Launch the process. 290 // Launch the process.
284 LaunchNetworkProcess(); 291 LaunchNetworkProcess();
285 } 292 }
286 293
287 void DaemonProcess::Stop() { 294 void DaemonProcess::Stop() {
288 DCHECK(caller_task_runner()->BelongsToCurrentThread()); 295 DCHECK(caller_task_runner()->BelongsToCurrentThread());
289 296
297 stats_sender_.reset();
298
290 if (!stopped_callback_.is_null()) { 299 if (!stopped_callback_.is_null()) {
291 base::ResetAndReturn(&stopped_callback_).Run(); 300 base::ResetAndReturn(&stopped_callback_).Run();
292 } 301 }
293 } 302 }
294 303
295 bool DaemonProcess::WasTerminalIdAllocated(int terminal_id) { 304 bool DaemonProcess::WasTerminalIdAllocated(int terminal_id) {
296 return terminal_id < next_terminal_id_; 305 return terminal_id < next_terminal_id_;
297 } 306 }
298 307
299 void DaemonProcess::OnAccessDenied(const std::string& jid) { 308 void DaemonProcess::OnAccessDenied(const std::string& jid) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 observer.OnShutdown(); 367 observer.OnShutdown();
359 } 368 }
360 369
361 void DaemonProcess::DeleteAllDesktopSessions() { 370 void DaemonProcess::DeleteAllDesktopSessions() {
362 while (!desktop_sessions_.empty()) { 371 while (!desktop_sessions_.empty()) {
363 delete desktop_sessions_.front(); 372 delete desktop_sessions_.front();
364 desktop_sessions_.pop_front(); 373 desktop_sessions_.pop_front();
365 } 374 }
366 } 375 }
367 376
377 void DaemonProcess::StartProcessStatsReport(base::TimeDelta interval) {
378 DCHECK(caller_task_runner()->BelongsToCurrentThread());
379 if (interval <= base::TimeDelta::FromSeconds(0)) {
380 interval = kDefaultProcessStatsInterval;
381 }
382
383 process_stats_request_count_++;
384 DCHECK(process_stats_request_count_ > 0);
385 if (process_stats_request_count_ == 1 ||
386 stats_sender_->interval() > interval) {
387 DCHECK_EQ(process_stats_request_count_ == 1, !stats_sender_);
388 stats_sender_.reset(new ProcessStatsSender(
389 this,
390 interval,
391 { &current_process_stats_ }));
392 }
393 }
394
395 void DaemonProcess::StopProcessStatsReport() {
396 DCHECK(caller_task_runner()->BelongsToCurrentThread());
397 process_stats_request_count_--;
398 DCHECK(process_stats_request_count_ >= 0);
399 if (process_stats_request_count_ == 0) {
400 DCHECK(stats_sender_);
401 stats_sender_.reset();
402 }
403 }
404
405 void DaemonProcess::OnProcessStats(
406 const protocol::AggregatedProcessResourceUsage& usage) {
407 SendToNetwork(new ChromotingAnyToNetworkMsg_ReportProcessStats(usage));
408 }
409
368 } // namespace remoting 410 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698