summaryrefslogtreecommitdiffstats
path: root/remoting/host/curtaining_host_observer.cc
blob: 6eacabe6c08be853ac9d92e798d8a63e347ab5ac (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
// 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.

#include "remoting/host/curtaining_host_observer.h"

#include "base/logging.h"
#include "remoting/host/curtain_mode.h"
#include "remoting/host/chromoting_host.h"

namespace remoting {

CurtainingHostObserver::CurtainingHostObserver(
    CurtainMode *curtain, scoped_refptr<ChromotingHost> host)
    : curtain_(curtain), host_(host) {
  host_->AddStatusObserver(this);
}

CurtainingHostObserver::~CurtainingHostObserver() {
  host_->RemoveStatusObserver(this);
  curtain_->SetActivated(false);
}

void CurtainingHostObserver::SetEnableCurtaining(bool enable) {
  enable_curtaining_ = enable;
  curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty());
}

void CurtainingHostObserver::OnClientAuthenticated(const std::string& jid) {
  active_clients_.insert(jid);
  curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty());
}

void CurtainingHostObserver::OnClientDisconnected(const std::string& jid) {
  active_clients_.erase(jid);
  curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty());
}

}  // namespace remoting