| 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/host_status_monitor.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, base::WeakPtr<HostStatusMonitor> monitor) |
| 15 : curtain_(curtain), host_(host) { | 15 : curtain_(curtain), monitor_(monitor) { |
| 16 host_->AddStatusObserver(this); | 16 monitor_->AddStatusObserver(this); |
| 17 } | 17 } |
| 18 | 18 |
| 19 CurtainingHostObserver::~CurtainingHostObserver() { | 19 CurtainingHostObserver::~CurtainingHostObserver() { |
| 20 host_->RemoveStatusObserver(this); | 20 if (monitor_) |
| 21 monitor_->RemoveStatusObserver(this); |
| 21 curtain_->SetActivated(false); | 22 curtain_->SetActivated(false); |
| 22 } | 23 } |
| 23 | 24 |
| 24 void CurtainingHostObserver::SetEnableCurtaining(bool enable) { | 25 void CurtainingHostObserver::SetEnableCurtaining(bool enable) { |
| 25 enable_curtaining_ = enable; | 26 enable_curtaining_ = enable; |
| 26 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); | 27 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); |
| 27 } | 28 } |
| 28 | 29 |
| 29 void CurtainingHostObserver::OnClientAuthenticated(const std::string& jid) { | 30 void CurtainingHostObserver::OnClientAuthenticated(const std::string& jid) { |
| 30 active_clients_.insert(jid); | 31 active_clients_.insert(jid); |
| 31 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); | 32 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void CurtainingHostObserver::OnClientDisconnected(const std::string& jid) { | 35 void CurtainingHostObserver::OnClientDisconnected(const std::string& jid) { |
| 35 active_clients_.erase(jid); | 36 active_clients_.erase(jid); |
| 36 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); | 37 curtain_->SetActivated(enable_curtaining_ && !active_clients_.empty()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 } // namespace remoting | 40 } // namespace remoting |
| OLD | NEW |