summaryrefslogtreecommitdiffstats
path: root/remoting/host/curtain_mode_mac.h
blob: b439b1140fda341f36affbbf23361abe7b8e468f (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
// 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_CURTAIN_MODE_MAC_H_
#define REMOTING_HOST_CURTAIN_MODE_MAC_H_

#include <Carbon/Carbon.h>

#include <string>

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "remoting/host/host_status_observer.h"

namespace remoting {

class CurtainMode : public HostStatusObserver {
 public:
  // Set callbacks to be invoked when the switched-out session is switched back
  // to the console, or in case of errors activating curtain-mode.  Typically,
  // remote clients should be disconnected in both cases: for errors, because
  // the privacy guarantee of curtain-mode cannot be honoured; for switch-in,
  // to ensure that only one connection (console or remote) exists to a session.
  // Note that only the session's owner (or someone who knows the password) can
  // attach it to the console, so this is safe.
  CurtainMode(const base::Closure& on_session_activate,
              const base::Closure& on_error);
  virtual ~CurtainMode();

  // Enable or disable curtain-mode. Note that disabling curtain-mode does not
  // deactivate the curtain, but it does remove the switch-in handler, meaning
  // that on_session_activate will not be invoked if curtain-mode is disabled.
  // Conversely, enabling curtain-mode *does* activate the curtain if there is
  // a connected client at the time.
  void SetEnabled(bool enabled);

  // Overridden from HostStatusObserver
  virtual void OnClientAuthenticated(const std::string& jid) OVERRIDE;
  virtual void OnClientDisconnected(const std::string& jid) OVERRIDE;

 private:
  // If the current session is attached to the console and is not showing
  // the logon screen then switch it out to ensure privacy.
  bool ActivateCurtain();

  // Add or remove the switch-in event handler.
  bool InstallEventHandler();
  bool RemoveEventHandler();

  // Handlers for the switch-in event.
  static OSStatus SessionActivateHandler(EventHandlerCallRef handler,
                                         EventRef event,
                                         void* user_data);
  void OnSessionActivate();

  base::Closure on_session_activate_;
  base::Closure on_error_;
  bool connection_active_;
  EventHandlerRef event_handler_;
};

}

#endif