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

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

Issue 10855249: [Chromoting] The daemon process now starts the networking process and passes the host configuration… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: CR feedback and rebased on top of https://chromiumcodereview.appspot.com/10829467/ Created 8 years, 4 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 | Annotate | Revision Log
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 #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/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "ipc/ipc_channel.h" 12 #include "ipc/ipc_channel.h"
13 #include "ipc/ipc_channel_proxy.h" 13 #include "ipc/ipc_channel_proxy.h"
14 #include "remoting/base/stoppable.h" 14 #include "remoting/base/stoppable.h"
15 #include "remoting/host/daemon_config_watcher.h"
16 #include "remoting/host/worker_process_delegate.h"
17
18 class FilePath;
15 19
16 namespace base { 20 namespace base {
17 class SingleThreadTaskRunner; 21 class SingleThreadTaskRunner;
18 class Thread;
19 } // namespace base 22 } // namespace base
20 23
21 namespace IPC {
22 class Message;
23 } // namespace IPC
24
25 namespace remoting { 24 namespace remoting {
26 25
27 // This class implements core of the daemon process. It manages the networking 26 // This class implements core of the daemon process. It manages the networking
28 // process running at lower privileges and maintains the list of virtual 27 // process running at lower privileges and maintains the list of virtual
29 // terminals. 28 // terminals.
30 class DaemonProcess : public Stoppable, public IPC::Listener { 29 class DaemonProcess
30 : public Stoppable,
31 public DaemonConfigWatcher::Delegate,
32 public WorkerProcessDelegate {
31 public: 33 public:
32 virtual ~DaemonProcess(); 34 virtual ~DaemonProcess();
33 35
34 // Creates a platform-specific implementation of the daemon process object. 36 // Creates a platform-specific implementation of the daemon process object.
35 static scoped_ptr<DaemonProcess> Create( 37 static scoped_ptr<DaemonProcess> Create(
36 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 38 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
37 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 39 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
38 const base::Closure& stopped_callback); 40 const base::Closure& stopped_callback);
39 41
40 // IPC::Listener implementation. 42 // DaemonConfigWatcher::Delegate
43 virtual void OnConfigUpdated(const std::string& config) OVERRIDE;
44 virtual void OnConfigWatcherError() OVERRIDE;
45
46 // WorkerProcessDelegate implementation.
47 virtual void OnChannelConnected() OVERRIDE;
41 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 48 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
42 49
50 // Sends an IPC message to the worker process. The message will be dropped
51 // unless the network process is connected over the IPC channel.
52 virtual void Send(IPC::Message* message) = 0;
53
43 protected: 54 protected:
44 DaemonProcess(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, 55 DaemonProcess(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
45 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 56 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
46 const base::Closure& stopped_callback); 57 const base::Closure& stopped_callback);
47 58
48 // Reads the host configuration and launches the networking process. 59 // Reads the host configuration and launches the networking process.
49 void Init(); 60 void Initialize();
50 61
51 // Stoppable implementation. 62 // Stoppable implementation.
52 virtual void DoStop() OVERRIDE; 63 virtual void DoStop() OVERRIDE;
53 64
54 // Launches the network process and establishes an IPC channel with it. 65 // Launches the network process and establishes an IPC channel with it.
55 virtual bool LaunchNetworkProcess() = 0; 66 virtual void LaunchNetworkProcess() = 0;
67
68 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner() {
69 return main_task_runner_;
70 }
71
72 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner() {
73 return io_task_runner_;
74 }
56 75
57 private: 76 private:
77 // Called every time the host configuration file is updated.
78 void ConfigUpdated(const FilePath& path, bool error);
79
80 // Reads the configuration file and passes it to the |main_task_runner_|
81 // thread.
82 void ReloadConfig();
83
84 // Sends |config| to the network process.
85 void SendConfig(const std::string& config);
86
87 // Starts monitoring the configuration file updates.
88 void StartConfigWatcher();
89
90 // Stops monitoring the configuration file updates.
91 void StopConfigWatcher();
92
93 // Notifies the |main_task_runner_| thread that the configuration file watcher
94 // has been fully stopped.
95 void StopConfigWatcherCompleted();
96
97 // The configuration file contents.
98 std::string config_;
99
100 scoped_ptr<DaemonConfigWatcher> config_watcher_;
101
102 enum ConfigWatcherState {
103 kConfigWatcherUninitialized,
104 kConfigWatcherRunning,
105 kConfigWatcherStopping,
106 kConfigWatcherStopped
107 };
108
109 ConfigWatcherState config_watcher_state_;
110
58 // The main task runner. Typically it is the UI message loop. 111 // The main task runner. Typically it is the UI message loop.
59 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 112 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
60 113
61 // Handles IPC and background I/O tasks. 114 // Handles IPC and background I/O tasks.
62 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; 115 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
63 116
64 // The IPC channel connecting the daemon process to the networking process. 117 // WeakPtr used to avoid tasks accessing |this| after it is deleted.
65 scoped_ptr<IPC::ChannelProxy> network_process_channel_; 118 base::WeakPtrFactory<DaemonProcess> weak_factory_;
66 119
67 DISALLOW_COPY_AND_ASSIGN(DaemonProcess); 120 DISALLOW_COPY_AND_ASSIGN(DaemonProcess);
68 }; 121 };
69 122
70 } // namespace remoting 123 } // namespace remoting
71 124
72 #endif // REMOTING_HOST_DAEMON_PROCESS_H_ 125 #endif // REMOTING_HOST_DAEMON_PROCESS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698