summaryrefslogtreecommitdiffstats
path: root/remoting/host/desktop_environment.h
blob: 99fd33dd6b0d1dc7a4b4521329ab337d658df205 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright (c) 2011 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_DESKTOP_ENVIRONMENT_H_
#define REMOTING_HOST_DESKTOP_ENVIRONMENT_H_

#include <string>

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer.h"

namespace remoting {

class Capturer;
class ChromotingHost;
class ChromotingHostContext;
class ContinueWindow;
class Curtain;
class DisconnectWindow;
class EventExecutor;
class LocalInputMonitor;
class UIThreadProxy;

class DesktopEnvironment {
 public:
  static DesktopEnvironment* Create(ChromotingHostContext* context);

  // DesktopEnvironment takes ownership of all the objects passed the ctor.
  DesktopEnvironment(ChromotingHostContext* context,
                     Capturer* capturer,
                     EventExecutor* event_executor,
                     Curtain* curtain,
                     DisconnectWindow* disconnect_window,
                     ContinueWindow* continue_window,
                     LocalInputMonitor* monitor);
  virtual ~DesktopEnvironment();

  // Shuts down the object and all its resources synchronously. Must
  // be called on the UI thread.
  void Shutdown();

  void set_host(ChromotingHost* host) { host_ = host; }

  Capturer* capturer() const { return capturer_.get(); }
  EventExecutor* event_executor() const { return event_executor_.get(); }
  Curtain* curtain() const { return curtain_.get(); }

  // Called whenever a new client has connected.
  void OnConnect(const std::string& username);

  // Called when the last client has disconnected.
  void OnLastDisconnect();

  // Called when the remote connection has been paused/unpaused.
  void OnPause(bool pause);

 private:
  void ProcessOnConnect(const std::string& username);
  void ProcessOnLastDisconnect();
  void ProcessOnPause(bool pause);

  void MonitorLocalInputs(bool enable);

  // Show or hide the Disconnect window on the UI thread.  If |show| is false,
  // hide the window, ignoring the |username| parameter.
  void ShowDisconnectWindow(bool show, const std::string& username);

  // Show or hide the Continue Sharing window on the UI thread.
  void ShowContinueWindow(bool show);

  void StartContinueWindowTimer(bool start);

  void ContinueWindowTimerFunc();

  // The host that owns this DesktopEnvironment.
  ChromotingHost* host_;

  // Host context used to make sure operations are run on the correct thread.
  // This is owned by the ChromotingHost.
  ChromotingHostContext* context_;

  // Capturer to be used by ScreenRecorder.
  scoped_ptr<Capturer> capturer_;

  // Executes input events received from the client.
  scoped_ptr<EventExecutor> event_executor_;

  // Curtain ensures privacy for the remote user.
  scoped_ptr<Curtain> curtain_;

  // Provide a user interface allowing the host user to close the connection.
  scoped_ptr<DisconnectWindow> disconnect_window_;

  // Provide a user interface requiring the user to periodically re-confirm
  // the connection.
  scoped_ptr<ContinueWindow> continue_window_;

  // Monitor local inputs to allow remote inputs to be blocked while the local
  // user is trying to do something.
  scoped_ptr<LocalInputMonitor> local_input_monitor_;

  bool is_monitoring_local_inputs_;

  // Timer controlling the "continue session" dialog. The timer is started when
  // a connection is made or re-confirmed. On expiry, inputs to the host are
  // blocked and the dialog is shown.
  //
  // TODO(sergeyu): It is wrong that we use OneShotTimer on the UI
  // thread of the plugin. UI thread runs MessageLoop that is compiled
  // as part of chrome, but the timer compiled as part of the
  // plugin. This will crash when plugin and chrome are compiled with
  // different version of MessageLoop. See crbug.com/90785 .
  base::OneShotTimer<DesktopEnvironment> continue_window_timer_;

  scoped_refptr<UIThreadProxy> proxy_;

  DISALLOW_COPY_AND_ASSIGN(DesktopEnvironment);
};

}  // namespace remoting

#endif  // REMOTING_HOST_DESKTOP_ENVIRONMENT_H_