summaryrefslogtreecommitdiffstats
path: root/remoting/host/daemon_process.h
blob: ed5f4cba1fc4a37598baa350fe6ec8f124ff1885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_HOST_DAEMON_PROCESS_H_
#define REMOTING_HOST_DAEMON_PROCESS_H_

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "ipc/ipc_channel.h"
#include "ipc/ipc_channel_proxy.h"
#include "remoting/base/stoppable.h"

namespace base {
class SingleThreadTaskRunner;
class Thread;
}  // namespace base

namespace IPC {
class Message;
} // namespace IPC

namespace remoting {

// This class implements core of the daemon process. It manages the networking
// process running at lower privileges and maintains the list of virtual
// terminals.
class DaemonProcess : public Stoppable, public IPC::Listener {
 public:
  virtual ~DaemonProcess();

  // Creates a platform-specific implementation of the daemon process object.
  static scoped_ptr<DaemonProcess> Create(
      scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
      scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
      const base::Closure& stopped_callback);

  // IPC::Listener implementation.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;

 protected:
  DaemonProcess(scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
                scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
                const base::Closure& stopped_callback);

  // Reads the host configuration and launches the networking process.
  void Init();

  // Stoppable implementation.
  virtual void DoStop() OVERRIDE;

  // Launches the network process and establishes an IPC channel with it.
  virtual bool LaunchNetworkProcess() = 0;

 private:
  // The main task runner. Typically it is the UI message loop.
  scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;

  // Handles IPC and background I/O tasks.
  scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;

  // The IPC channel connecting the daemon process to the networking process.
  scoped_ptr<IPC::ChannelProxy> network_process_channel_;

  DISALLOW_COPY_AND_ASSIGN(DaemonProcess);
};

}  // namespace remoting

#endif  // REMOTING_HOST_DAEMON_PROCESS_H_