summaryrefslogtreecommitdiffstats
path: root/remoting/host/ipc_desktop_environment.h
blob: d65495fb0c644ca08d760c7c41b2071e28129fd9 (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
73
74
75
76
77
78
79
80
81
82
// 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_IPC_DESKTOP_ENVIRONMENT_H_
#define REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_

#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_platform_file.h"
#include "remoting/host/desktop_environment.h"

namespace base {
class SingleThreadTaskRunner;
}  // base

namespace IPC {
class ChannelProxy;
}  // base

namespace remoting {

class ClientSession;
class DesktopSessionConnector;

// A variant of desktop environment integrating with the desktop by means of
// a helper process and talking to that process via IPC.
class IpcDesktopEnvironment : public DesktopEnvironment, public IPC::Listener {
 public:
  // |desktop_session_connector| is used to bind the IpcDesktopEnvironment to
  // a desktop session, to be notified with a new IPC channel every time
  // the desktop process is changed. |desktop_session_connector| must outlive
  // |this|.  |client| specifies the client session owning |this|.
  IpcDesktopEnvironment(
      scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
      scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
      scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
      DesktopSessionConnector* desktop_session_connector,
      ClientSession* client);
  virtual ~IpcDesktopEnvironment();

  // IPC::Listener implementation.
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
  virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
  virtual void OnChannelError() OVERRIDE;

  virtual void Start(
      scoped_ptr<protocol::ClipboardStub> client_clipboard) OVERRIDE;

  // Disconnects the client session that owns |this|.
  void DisconnectClient();

  // Notifies |this| that it is now attached to a desktop integration process.
  // |desktop_process| specifies the process handle. |desktop_pipe| is
  // the client end of the pipe opened by the desktop process.
  void OnDesktopSessionAgentAttached(
      IPC::PlatformFileForTransit desktop_process,
      IPC::PlatformFileForTransit desktop_pipe);

 private:
  // Used for IPC I/O.
  scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;

  DesktopSessionConnector* desktop_session_connector_;

  // Specifies the client session that owns |this|.
  ClientSession* client_;

  // True if |this| has been connected to a desktop session.
  bool connected_;

  // Connects |this| with the desktop process.
  scoped_ptr<IPC::ChannelProxy> desktop_channel_;

  DISALLOW_COPY_AND_ASSIGN(IpcDesktopEnvironment);
};

}  // namespace remoting

#endif  // REMOTING_HOST_IPC_DESKTOP_ENVIRONMENT_H_