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 #ifndef REMOTING_HOST_DAEMON_PROCESS_H_ | 5 #ifndef REMOTING_HOST_DAEMON_PROCESS_H_ |
6 #define REMOTING_HOST_DAEMON_PROCESS_H_ | 6 #define REMOTING_HOST_DAEMON_PROCESS_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
19 #include "base/process/process.h" | 19 #include "base/process/process.h" |
| 20 #include "base/time/time.h" |
20 #include "ipc/ipc_channel.h" | 21 #include "ipc/ipc_channel.h" |
21 #include "ipc/ipc_channel_handle.h" | 22 #include "ipc/ipc_channel_handle.h" |
22 #include "remoting/host/config_watcher.h" | 23 #include "remoting/host/config_watcher.h" |
| 24 #include "remoting/host/current_process_stats_agent.h" |
23 #include "remoting/host/host_status_monitor.h" | 25 #include "remoting/host/host_status_monitor.h" |
24 #include "remoting/host/worker_process_ipc_delegate.h" | 26 #include "remoting/host/worker_process_ipc_delegate.h" |
| 27 #include "remoting/protocol/process_stats_stub.h" |
25 | 28 |
26 struct SerializedTransportRoute; | 29 struct SerializedTransportRoute; |
27 | 30 |
28 namespace tracked_objects { | 31 namespace tracked_objects { |
29 class Location; | 32 class Location; |
30 } // namespace tracked_objects | 33 } // namespace tracked_objects |
31 | 34 |
32 namespace remoting { | 35 namespace remoting { |
33 | 36 |
34 class AutoThreadTaskRunner; | 37 class AutoThreadTaskRunner; |
35 class DesktopSession; | 38 class DesktopSession; |
36 class HostEventLogger; | 39 class HostEventLogger; |
37 class HostStatusObserver; | 40 class HostStatusObserver; |
| 41 class ProcessStatsSender; |
38 class ScreenResolution; | 42 class ScreenResolution; |
39 | 43 |
40 // This class implements core of the daemon process. It manages the networking | 44 // This class implements core of the daemon process. It manages the networking |
41 // process running at lower privileges and maintains the list of desktop | 45 // process running at lower privileges and maintains the list of desktop |
42 // sessions. | 46 // sessions. |
43 class DaemonProcess | 47 class DaemonProcess |
44 : public ConfigWatcher::Delegate, | 48 : public ConfigWatcher::Delegate, |
45 public HostStatusMonitor, | 49 public HostStatusMonitor, |
46 public WorkerProcessIpcDelegate { | 50 public WorkerProcessIpcDelegate, |
| 51 public protocol::ProcessStatsStub { |
47 public: | 52 public: |
48 typedef std::list<DesktopSession*> DesktopSessionList; | 53 typedef std::list<DesktopSession*> DesktopSessionList; |
49 | 54 |
50 ~DaemonProcess() override; | 55 ~DaemonProcess() override; |
51 | 56 |
52 // Creates a platform-specific implementation of the daemon process object | 57 // Creates a platform-specific implementation of the daemon process object |
53 // passing relevant task runners. Public methods of this class must be called | 58 // passing relevant task runners. Public methods of this class must be called |
54 // on the |caller_task_runner| thread. |io_task_runner| is used to handle IPC | 59 // on the |caller_task_runner| thread. |io_task_runner| is used to handle IPC |
55 // and background I/O tasks. | 60 // and background I/O tasks. |
56 static std::unique_ptr<DaemonProcess> Create( | 61 static std::unique_ptr<DaemonProcess> Create( |
57 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, | 62 scoped_refptr<AutoThreadTaskRunner> caller_task_runner, |
58 scoped_refptr<AutoThreadTaskRunner> io_task_runner, | 63 scoped_refptr<AutoThreadTaskRunner> io_task_runner, |
59 const base::Closure& stopped_callback); | 64 const base::Closure& stopped_callback); |
60 | 65 |
61 // ConfigWatcher::Delegate | 66 // ConfigWatcher::Delegate |
62 void OnConfigUpdated(const std::string& serialized_config) override; | 67 void OnConfigUpdated(const std::string& serialized_config) override; |
63 void OnConfigWatcherError() override; | 68 void OnConfigWatcherError() override; |
64 | 69 |
65 // HostStatusMonitor interface. | 70 // HostStatusMonitor interface. |
66 void AddStatusObserver(HostStatusObserver* observer) override; | 71 void AddStatusObserver(HostStatusObserver* observer) override; |
67 void RemoveStatusObserver(HostStatusObserver* observer) override; | 72 void RemoveStatusObserver(HostStatusObserver* observer) override; |
68 | 73 |
69 // WorkerProcessIpcDelegate implementation. | 74 // WorkerProcessIpcDelegate implementation. |
70 void OnChannelConnected(int32_t peer_pid) override; | 75 void OnChannelConnected(int32_t peer_pid) override; |
71 bool OnMessageReceived(const IPC::Message& message) override; | 76 bool OnMessageReceived(const IPC::Message& message) override; |
72 void OnPermanentError(int exit_code) override; | 77 void OnPermanentError(int exit_code) override; |
| 78 void OnWorkerProcessStopped() override; |
73 | 79 |
74 // Sends an IPC message to the network process. The message will be dropped | 80 // Sends an IPC message to the network process. The message will be dropped |
75 // unless the network process is connected over the IPC channel. | 81 // unless the network process is connected over the IPC channel. |
76 virtual void SendToNetwork(IPC::Message* message) = 0; | 82 virtual void SendToNetwork(IPC::Message* message) = 0; |
77 | 83 |
78 // Called when a desktop integration process attaches to |terminal_id|. | 84 // Called when a desktop integration process attaches to |terminal_id|. |
79 // |session_id| is the id of the desktop session being attached. | 85 // |session_id| is the id of the desktop session being attached. |
80 // |desktop_pipe| specifies the client end of the desktop pipe. Returns true | 86 // |desktop_pipe| specifies the client end of the desktop pipe. Returns true |
81 // on success, false otherwise. | 87 // on success, false otherwise. |
82 virtual bool OnDesktopSessionAgentAttached( | 88 virtual bool OnDesktopSessionAgentAttached( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // Let the test code analyze the list of desktop sessions. | 157 // Let the test code analyze the list of desktop sessions. |
152 friend class DaemonProcessTest; | 158 friend class DaemonProcessTest; |
153 const DesktopSessionList& desktop_sessions() const { | 159 const DesktopSessionList& desktop_sessions() const { |
154 return desktop_sessions_; | 160 return desktop_sessions_; |
155 } | 161 } |
156 | 162 |
157 private: | 163 private: |
158 // Deletes all desktop sessions. | 164 // Deletes all desktop sessions. |
159 void DeleteAllDesktopSessions(); | 165 void DeleteAllDesktopSessions(); |
160 | 166 |
| 167 // Starts to report process statistic data to network process. If |interval| |
| 168 // is less then or equal to 0, a default non-zero value will be used. |
| 169 void StartProcessStatsReport(base::TimeDelta interval); |
| 170 |
| 171 // Stops sending process statistic data to network process. |
| 172 void StopProcessStatsReport(); |
| 173 |
| 174 // ProcessStatsStub implementation. |
| 175 void OnProcessStats( |
| 176 const protocol::AggregatedProcessResourceUsage& usage) override; |
| 177 |
161 // Task runner on which public methods of this class must be called. | 178 // Task runner on which public methods of this class must be called. |
162 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; | 179 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_; |
163 | 180 |
164 // Handles IPC and background I/O tasks. | 181 // Handles IPC and background I/O tasks. |
165 scoped_refptr<AutoThreadTaskRunner> io_task_runner_; | 182 scoped_refptr<AutoThreadTaskRunner> io_task_runner_; |
166 | 183 |
167 std::unique_ptr<ConfigWatcher> config_watcher_; | 184 std::unique_ptr<ConfigWatcher> config_watcher_; |
168 | 185 |
169 // The configuration file contents. | 186 // The configuration file contents. |
170 std::string serialized_config_; | 187 std::string serialized_config_; |
171 | 188 |
172 // The list of active desktop sessions. | 189 // The list of active desktop sessions. |
173 DesktopSessionList desktop_sessions_; | 190 DesktopSessionList desktop_sessions_; |
174 | 191 |
175 // The highest desktop session ID that has been seen so far. | 192 // The highest desktop session ID that has been seen so far. |
176 int next_terminal_id_; | 193 int next_terminal_id_; |
177 | 194 |
178 // Keeps track of observers receiving host status notifications. | 195 // Keeps track of observers receiving host status notifications. |
179 base::ObserverList<HostStatusObserver> status_observers_; | 196 base::ObserverList<HostStatusObserver> status_observers_; |
180 | 197 |
181 // Invoked to ask the owner to delete |this|. | 198 // Invoked to ask the owner to delete |this|. |
182 base::Closure stopped_callback_; | 199 base::Closure stopped_callback_; |
183 | 200 |
184 // Writes host status updates to the system event log. | 201 // Writes host status updates to the system event log. |
185 std::unique_ptr<HostEventLogger> host_event_logger_; | 202 std::unique_ptr<HostEventLogger> host_event_logger_; |
186 | 203 |
| 204 // Reports process statistic data to network process. |
| 205 std::unique_ptr<ProcessStatsSender> stats_sender_; |
| 206 |
| 207 // The number of StartProcessStatsReport requests received. |
| 208 // Daemon and Network processes manages multiple desktop sessions. Some of |
| 209 // them may request for process statistic reports. So the resource usage of |
| 210 // daemon process and network process will be merged to each desktop session. |
| 211 // |
| 212 // As long as at least process statistic reports is enabled for one desktop |
| 213 // session, daemon process should continually send the reports. |
| 214 int process_stats_request_count_ = 0; |
| 215 |
| 216 CurrentProcessStatsAgent current_process_stats_; |
| 217 |
187 base::WeakPtrFactory<DaemonProcess> weak_factory_; | 218 base::WeakPtrFactory<DaemonProcess> weak_factory_; |
188 | 219 |
189 DISALLOW_COPY_AND_ASSIGN(DaemonProcess); | 220 DISALLOW_COPY_AND_ASSIGN(DaemonProcess); |
190 }; | 221 }; |
191 | 222 |
192 } // namespace remoting | 223 } // namespace remoting |
193 | 224 |
194 #endif // REMOTING_HOST_DAEMON_PROCESS_H_ | 225 #endif // REMOTING_HOST_DAEMON_PROCESS_H_ |
OLD | NEW |