Chromium Code Reviews| 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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/timer.h" | |
| 12 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
| 13 #include "ipc/ipc_channel_proxy.h" | 15 #include "ipc/ipc_channel_proxy.h" |
| 14 #include "remoting/base/stoppable.h" | 16 #include "remoting/base/stoppable.h" |
| 17 #include "remoting/host/worker_process_delegate.h" | |
| 15 | 18 |
| 16 namespace base { | 19 namespace base { |
| 17 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 18 class Thread; | 21 class Thread; |
| 22 | |
| 23 namespace files { | |
| 24 class FilePathWatcher; | |
| 25 } // namespace files | |
| 19 } // namespace base | 26 } // namespace base |
| 20 | 27 |
| 21 namespace IPC { | |
| 22 class Message; | |
| 23 } // namespace IPC | |
| 24 | |
| 25 namespace remoting { | 28 namespace remoting { |
| 26 | 29 |
| 27 // This class implements core of the daemon process. It manages the networking | 30 // This class implements core of the daemon process. It manages the networking |
| 28 // process running at lower privileges and maintains the list of virtual | 31 // process running at lower privileges and maintains the list of virtual |
| 29 // terminals. | 32 // terminals. |
| 30 class DaemonProcess : public Stoppable, public IPC::Listener { | 33 class DaemonProcess : public Stoppable, public WorkerProcessDelegate { |
| 31 public: | 34 public: |
| 32 virtual ~DaemonProcess(); | 35 virtual ~DaemonProcess(); |
| 33 | 36 |
| 34 // Creates a platform-specific implementation of the daemon process object. | 37 // Creates a platform-specific implementation of the daemon process object. |
| 35 static scoped_ptr<DaemonProcess> Create( | 38 static scoped_ptr<DaemonProcess> Create( |
| 36 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 39 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 37 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 40 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 38 const base::Closure& stopped_callback); | 41 const base::Closure& stopped_callback); |
| 39 | 42 |
| 40 // IPC::Listener implementation. | 43 // WorkerProcessDelegate implementation. |
| 44 virtual void OnChannelConnected() OVERRIDE; | |
| 41 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 42 | 46 |
| 47 // Sends an IPC message to the worker process. The message will be dropped | |
| 48 // unless the network process is connected over the IPC channel. | |
|
Wez
2012/08/21 00:18:57
Is this comment correct?
alexeypa (please no reviews)
2012/08/21 17:16:36
It appears correct to me.
Wez
2012/08/24 22:20:37
Why is the message to the worker process dropped i
alexeypa (please no reviews)
2012/08/27 23:16:41
We don't want to send a message that will become o
Wez
2012/08/30 20:36:04
The point I'm making is that the wording sounds li
alexeypa (please no reviews)
2012/08/30 23:15:13
This was a very obscure way of asking this questio
| |
| 49 virtual void Send(IPC::Message* message) = 0; | |
| 50 | |
| 43 protected: | 51 protected: |
| 44 DaemonProcess(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 52 DaemonProcess(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 45 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 53 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 46 const base::Closure& stopped_callback); | 54 const base::Closure& stopped_callback); |
| 47 | 55 |
| 48 // Reads the host configuration and launches the networking process. | 56 // Reads the host configuration and launches the networking process. |
| 49 void Init(); | 57 void Initialize(); |
| 50 | 58 |
| 51 // Stoppable implementation. | 59 // Stoppable implementation. |
| 52 virtual void DoStop() OVERRIDE; | 60 virtual void DoStop() OVERRIDE; |
| 53 | 61 |
| 54 // Launches the network process and establishes an IPC channel with it. | 62 // Launches the network process and establishes an IPC channel with it. |
| 55 virtual bool LaunchNetworkProcess() = 0; | 63 virtual void LaunchNetworkProcess() = 0; |
|
Wez
2012/08/21 00:18:57
nit: I think this should be public, according to t
alexeypa (please no reviews)
2012/08/23 23:53:01
The style guide said that inheritance should be pu
| |
| 64 | |
| 65 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner() { | |
| 66 return main_task_runner_; | |
| 67 } | |
| 68 | |
| 69 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() { | |
| 70 return io_task_runner_; | |
| 71 } | |
| 56 | 72 |
| 57 private: | 73 private: |
| 74 // Called every time the host configuration file is updated. | |
| 75 void ConfigUpdated(const FilePath& path, bool error); | |
| 76 | |
| 77 // Reads the configuration file and passes it to the |main_task_runner_| | |
| 78 // thread. | |
| 79 void ReloadConfig(); | |
| 80 | |
| 81 // Sends |config| to the network process. | |
| 82 void SendConfig(const std::string& config); | |
| 83 | |
| 84 // Starts monitoring the configuration file updates. | |
| 85 void StartConfigWatcher(); | |
| 86 | |
| 87 // Stops monitoring the configuration file updates. | |
| 88 void StopConfigWatcher(); | |
| 89 | |
| 90 // Notifies the |main_task_runner_| thread that the configuration file watcher | |
| 91 // has been fully stopped. | |
| 92 void StopConfigWatcherCompleted(); | |
| 93 | |
| 94 // The configuration file contents. | |
| 95 std::string config_; | |
| 96 | |
| 97 FilePath config_path_; | |
| 98 | |
| 99 scoped_ptr<base::DelayTimer<DaemonProcess> > config_updated_timer_; | |
| 100 | |
| 101 // Monitors the host configuration file changes. | |
| 102 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | |
| 103 | |
| 104 enum ConfigWatcherState { | |
| 105 kConfigWatcherRunning, | |
| 106 kConfigWatcherStopping, | |
| 107 kConfigWatcherStopped | |
| 108 }; | |
| 109 | |
| 110 ConfigWatcherState config_watcher_state_; | |
| 111 | |
| 58 // The main task runner. Typically it is the UI message loop. | 112 // The main task runner. Typically it is the UI message loop. |
| 59 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 113 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 60 | 114 |
| 61 // Handles IPC and background I/O tasks. | 115 // Handles IPC and background I/O tasks. |
| 62 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 116 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 63 | 117 |
| 64 // The IPC channel connecting the daemon process to the networking process. | |
| 65 scoped_ptr<IPC::ChannelProxy> network_process_channel_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(DaemonProcess); | 118 DISALLOW_COPY_AND_ASSIGN(DaemonProcess); |
| 68 }; | 119 }; |
| 69 | 120 |
| 70 } // namespace remoting | 121 } // namespace remoting |
| 71 | 122 |
| 72 #endif // REMOTING_HOST_DAEMON_PROCESS_H_ | 123 #endif // REMOTING_HOST_DAEMON_PROCESS_H_ |
| OLD | NEW |