| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/curtaining_host_observer.h" | 5 #include "remoting/host/curtaining_host_observer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "remoting/host/curtain_mode.h" | 8 #include "remoting/host/curtain_mode.h" |
| 9 #include "remoting/host/chromoting_host.h" | 9 #include "remoting/host/chromoting_host.h" |
| 10 | 10 |
| 11 namespace remoting { | 11 namespace remoting { |
| 12 | 12 |
| 13 CurtainingHostObserver::CurtainingHostObserver( | 13 CurtainingHostObserver::CurtainingHostObserver( |
| 14 CurtainMode *curtain, scoped_refptr<ChromotingHost> host) | 14 CurtainMode *curtain, scoped_refptr<ChromotingHost> host) |
| 15 : curtain_(curtain), host_(host) { | 15 : curtain_(curtain), host_(host) { |
| 16 host_->AddStatusObserver(this); | 16 host_->AddStatusObserver(this); |
| 17 } | 17 } |
| 18 | 18 |
| 19 CurtainingHostObserver::~CurtainingHostObserver() { | 19 CurtainingHostObserver::~CurtainingHostObserver() { |
| 20 host_->RemoveStatusObserver(this); | 20 host_->RemoveStatusObserver(this); |
| 21 curtain_->SetActivated(false); | 21 curtain_->SetActivated(false); |
| 22 } | 22 } |
| 23 | 23 |
| 24 // TODO(jamiewalch): This code assumes at most one client connection at a time. | 24 void CurtainingHostObserver::SetEnableCurtaining(bool enable) { |
| 25 // Add OnFirstClientConnected and OnLastClientDisconnected optional callbacks | 25 enable_curtaining_ = enable; |
| 26 // to the HostStatusObserver interface to address this. | 26 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); |
| 27 } |
| 28 |
| 27 void CurtainingHostObserver::OnClientAuthenticated(const std::string& jid) { | 29 void CurtainingHostObserver::OnClientAuthenticated(const std::string& jid) { |
| 28 if (curtain_->required()) { | 30 active_clients_.insert(jid); |
| 29 curtain_->SetActivated(true); | 31 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); |
| 30 } | |
| 31 } | 32 } |
| 32 | 33 |
| 33 void CurtainingHostObserver::OnClientDisconnected(const std::string& jid) { | 34 void CurtainingHostObserver::OnClientDisconnected(const std::string& jid) { |
| 34 curtain_->SetActivated(false); | 35 active_clients_.erase(jid); |
| 36 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); |
| 35 } | 37 } |
| 36 | 38 |
| 37 } // namespace remoting | 39 } // namespace remoting |
| OLD | NEW |