summaryrefslogtreecommitdiffstats
path: root/remoting/host/host_user_interface.h
blob: 942cd2a2b920241c0ec0e563464b7d18a5b991e2 (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
// 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_HOST_USER_INTERFACE_H_
#define REMOTING_HOST_HOST_USER_INTERFACE_H_

#include <string>

#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop_proxy.h"
#include "remoting/host/host_status_observer.h"

namespace remoting {

class ChromotingHost;
class ChromotingHostContext;
class DisconnectWindow;
class LocalInputMonitor;
class SignalStrategy;

class HostUserInterface : public HostStatusObserver {
 public:
  HostUserInterface(ChromotingHostContext* context);
  virtual ~HostUserInterface();

  virtual void Start(ChromotingHost* host,
                     const base::Closure& disconnect_callback);

  // HostStatusObserver implementation.  These methods will be called from the
  // network thread.
  virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE;
  virtual void OnClientDisconnected(const std::string& jid) OVERRIDE;
  virtual void OnAccessDenied(const std::string& jid) OVERRIDE;
  virtual void OnShutdown() OVERRIDE;

 protected:
  const std::string& get_authenticated_jid() const {
    return authenticated_jid_;
  }
  ChromotingHost* get_host() const { return host_; }

  // Message loop accessors.
  base::MessageLoopProxy* network_message_loop() const;
  base::MessageLoopProxy* ui_message_loop() const;

  // Invokes the session disconnect callback passed to Start().
  void DisconnectSession() const;

  virtual void ProcessOnClientAuthenticated(const std::string& username);
  virtual void ProcessOnClientDisconnected();

  // Used by unit-tests as an alternative to Start() so that mock versions of
  // internal objects can be used.
  void StartForTest(
      ChromotingHost* host,
      const base::Closure& disconnect_callback,
      scoped_ptr<DisconnectWindow> disconnect_window,
      scoped_ptr<LocalInputMonitor> local_input_monitor);

 private:
  // Invoked from the UI thread when the user clicks on the Disconnect button
  // to disconnect the session.
  void OnDisconnectCallback();

  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);

  // The JID of the currently-authenticated user (or an empty string if no user
  // is connected).
  std::string authenticated_jid_;

  ChromotingHost* host_;

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

  // Used to ask the host to disconnect the session.
  base::Closure disconnect_callback_;

  // Provide a user interface allowing the host user to close the connection.
  scoped_ptr<DisconnectWindow> disconnect_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_;

  // WeakPtr used to avoid tasks accessing the client after it is deleted.
  base::WeakPtrFactory<HostUserInterface> weak_factory_;
  base::WeakPtr<HostUserInterface> weak_ptr_;

  DISALLOW_COPY_AND_ASSIGN(HostUserInterface);
};

}  // namespace remoting

#endif  // REMOTING_HOST_HOST_USER_INTERFACE_H_