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
3// found in the LICENSE file.
4
5#ifndef REMOTING_HOST_DESKTOP_PROCESS_H_
6#define REMOTING_HOST_DESKTOP_PROCESS_H_
7
8#include <string>
9
10#include "base/basictypes.h"
11#include "base/callback_forward.h"
12#include "base/compiler_specific.h"
13#include "base/memory/ref_counted.h"
14#include "base/memory/scoped_ptr.h"
15#include "base/memory/weak_ptr.h"
16#include "ipc/ipc_listener.h"
17#include "remoting/host/desktop_session_agent.h"
18
19namespace IPC {
20class ChannelProxy;
21}  // namespace IPC
22
23namespace remoting {
24
25class AutoThreadTaskRunner;
26class DesktopEnvironment;
27class DesktopEnvironmentFactory;
28class DesktopSessionAgent;
29
30class DesktopProcess : public DesktopSessionAgent::Delegate,
31                       public IPC::Listener,
32                       public base::SupportsWeakPtr<DesktopProcess> {
33 public:
34  DesktopProcess(
35      scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
36      scoped_refptr<AutoThreadTaskRunner> input_task_runner,
37      const std::string& daemon_channel_name);
38  virtual ~DesktopProcess();
39
40  // DesktopSessionAgent::Delegate implementation.
41  virtual DesktopEnvironmentFactory& desktop_environment_factory() OVERRIDE;
42  virtual void OnNetworkProcessDisconnected() OVERRIDE;
43
44  // IPC::Listener implementation.
45  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
46  virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
47  virtual void OnChannelError() OVERRIDE;
48
49  // Injects Secure Attention Sequence.
50  void InjectSas();
51
52  // Creates the desktop agent and required threads and IPC channels. Returns
53  // true on success.
54  bool Start(scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory);
55
56 private:
57  // Crashes the process in response to a daemon's request. The daemon passes
58  // the location of the code that detected the fatal error resulted in this
59  // request. See the declaration of ChromotingDaemonMsg_Crash message.
60  void OnCrash(const std::string& function_name,
61               const std::string& file_name,
62               const int& line_number);
63
64  // Task runner on which public methods of this class should be called.
65  scoped_refptr<AutoThreadTaskRunner> caller_task_runner_;
66
67  // Used to run input-related tasks.
68  scoped_refptr<AutoThreadTaskRunner> input_task_runner_;
69
70  // Factory used to create integration components for use by |desktop_agent_|.
71  scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
72
73  // Name of the IPC channel connecting the desktop process with the daemon
74  // process.
75  std::string daemon_channel_name_;
76
77  // IPC channel connecting the desktop process with the daemon process.
78  scoped_ptr<IPC::ChannelProxy> daemon_channel_;
79
80  // Provides screen/audio capturing and input injection services for
81  // the network process.
82  scoped_refptr<DesktopSessionAgent> desktop_agent_;
83
84  DISALLOW_COPY_AND_ASSIGN(DesktopProcess);
85};
86
87}  // namespace remoting
88
89#endif  // REMOTING_HOST_DESKTOP_PROCESS_H_
90