diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 19:00:36 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 19:00:36 +0000 |
commit | 564e40d0a0fdd1a05fda979ec3f6bfa36a621be1 (patch) | |
tree | ce3612160deb27e8bebeebd553e56f23a7e4fadc /remoting | |
parent | 6af9c3f863479cd66f5f7e625dbcdc765ff0b79b (diff) | |
download | chromium_src-564e40d0a0fdd1a05fda979ec3f6bfa36a621be1.zip chromium_src-564e40d0a0fdd1a05fda979ec3f6bfa36a621be1.tar.gz chromium_src-564e40d0a0fdd1a05fda979ec3f6bfa36a621be1.tar.bz2 |
Notify calling web-app when Host plugin becomes connected to a client.
BUG=85110
TEST=
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=89370
Review URL: http://codereview.chromium.org/7134023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89873 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/chromoting_host.cc | 28 | ||||
-rw-r--r-- | remoting/host/chromoting_host.h | 2 | ||||
-rw-r--r-- | remoting/host/heartbeat_sender.cc | 3 | ||||
-rw-r--r-- | remoting/host/heartbeat_sender.h | 1 | ||||
-rw-r--r-- | remoting/host/host_script_object.cc | 5 | ||||
-rw-r--r-- | remoting/host/host_script_object.h | 1 | ||||
-rw-r--r-- | remoting/host/host_status_observer.h | 5 | ||||
-rw-r--r-- | remoting/host/register_support_host_request.cc | 1 | ||||
-rw-r--r-- | remoting/host/register_support_host_request.h | 1 |
9 files changed, 40 insertions, 7 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index d5f37f3c..4f7db33 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -278,7 +278,7 @@ void ChromotingHost::OnNewClientSession( // If we are running Me2Mom and already have an authenticated client then // reject the connection immediately. - if (is_it2me_ && HasAuthenticatedClients()) { + if (is_it2me_ && AuthenticatedClientsCount() > 0) { *response = protocol::SessionManager::DECLINE; return; } @@ -400,9 +400,20 @@ void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { connection->Disconnect(); // Also remove reference to ConnectionToClient from this object. + int old_authenticated_clients = AuthenticatedClientsCount(); clients_.erase(client); - if (!HasAuthenticatedClients()) { + // Notify the observers of the change, if any. + int authenticated_clients = AuthenticatedClientsCount(); + if (old_authenticated_clients != authenticated_clients) { + for (StatusObserverList::iterator it = status_observers_.begin(); + it != status_observers_.end(); ++it) { + (*it)->OnAuthenticatedClientsChanged(authenticated_clients); + } + } + + // Enable the "curtain", if at least one client is actually authenticated. + if (AuthenticatedClientsCount() > 0) { EnableCurtainMode(false); if (is_it2me_) { MonitorLocalInputs(false); @@ -438,13 +449,14 @@ std::string ChromotingHost::GenerateHostAuthToken( return encoded_client_token; } -bool ChromotingHost::HasAuthenticatedClients() const { +int ChromotingHost::AuthenticatedClientsCount() const { + int authenticated_clients = 0; for (ClientList::const_iterator it = clients_.begin(); it != clients_.end(); ++it) { if (it->get()->authenticated()) - return true; + ++authenticated_clients; } - return false; + return authenticated_clients; } void ChromotingHost::EnableCurtainMode(bool enable) { @@ -524,6 +536,12 @@ void ChromotingHost::LocalLoginSucceeded( ShowDisconnectWindow(true, username); StartContinueWindowTimer(true); } + + // Notify observers that there is at least one authenticated client. + for (StatusObserverList::iterator it = status_observers_.begin(); + it != status_observers_.end(); ++it) { + (*it)->OnAuthenticatedClientsChanged(AuthenticatedClientsCount()); + } } void ChromotingHost::LocalLoginFailed( diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h index 6ae11e9..6f969d4 100644 --- a/remoting/host/chromoting_host.h +++ b/remoting/host/chromoting_host.h @@ -169,7 +169,7 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, std::string GenerateHostAuthToken(const std::string& encoded_client_token); - bool HasAuthenticatedClients() const; + int AuthenticatedClientsCount() const; void EnableCurtainMode(bool enable); diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc index b011313..da552c5 100644 --- a/remoting/host/heartbeat_sender.cc +++ b/remoting/host/heartbeat_sender.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -89,6 +89,7 @@ void HeartbeatSender::OnSignallingDisconnected() { // Ignore any notifications other than signalling // connected/disconnected events. void HeartbeatSender::OnAccessDenied() { } +void HeartbeatSender::OnAuthenticatedClientsChanged(int clients) { } void HeartbeatSender::OnShutdown() { } void HeartbeatSender::DoSendStanza() { diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h index c7394a0..0cb71bb 100644 --- a/remoting/host/heartbeat_sender.h +++ b/remoting/host/heartbeat_sender.h @@ -70,6 +70,7 @@ class HeartbeatSender : public HostStatusObserver { virtual void OnSignallingConnected(SignalStrategy* signal_strategy, const std::string& full_jid) OVERRIDE; virtual void OnSignallingDisconnected() OVERRIDE; + virtual void OnAuthenticatedClientsChanged(int clients) OVERRIDE; virtual void OnAccessDenied() OVERRIDE; virtual void OnShutdown() OVERRIDE; diff --git a/remoting/host/host_script_object.cc b/remoting/host/host_script_object.cc index dab16d1..0808066 100644 --- a/remoting/host/host_script_object.cc +++ b/remoting/host/host_script_object.cc @@ -283,6 +283,11 @@ void HostNPScriptObject::OnAccessDenied() { DisconnectInternal(); } +void HostNPScriptObject::OnAuthenticatedClientsChanged(int clients_connected) { + DCHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); + OnStateChanged(clients_connected ? kConnected : kDisconnected); +} + void HostNPScriptObject::OnShutdown() { DCHECK_EQ(MessageLoop::current(), host_context_.main_message_loop()); diff --git a/remoting/host/host_script_object.h b/remoting/host/host_script_object.h index ea953f1..b12ed7b 100644 --- a/remoting/host/host_script_object.h +++ b/remoting/host/host_script_object.h @@ -64,6 +64,7 @@ class HostNPScriptObject : public HostStatusObserver { const std::string& full_jid) OVERRIDE; virtual void OnSignallingDisconnected() OVERRIDE; virtual void OnAccessDenied() OVERRIDE; + virtual void OnAuthenticatedClientsChanged(int clients_connected) OVERRIDE; virtual void OnShutdown() OVERRIDE; private: diff --git a/remoting/host/host_status_observer.h b/remoting/host/host_status_observer.h index 45bdd22..fc158ec 100644 --- a/remoting/host/host_status_observer.h +++ b/remoting/host/host_status_observer.h @@ -25,6 +25,11 @@ class HostStatusObserver { // to connect to the host. virtual void OnAccessDenied() = 0; + // Called on the main thread when a client authenticates, or disconnects. + // The observer must not tear-down ChromotingHost state on receipt of + // this callback; it is purely informational. + virtual void OnAuthenticatedClientsChanged(int authenticated_clients) = 0; + // Called on the main thread when the host shuts down. virtual void OnShutdown() = 0; }; diff --git a/remoting/host/register_support_host_request.cc b/remoting/host/register_support_host_request.cc index 5b6b9f0..0e716dc 100644 --- a/remoting/host/register_support_host_request.cc +++ b/remoting/host/register_support_host_request.cc @@ -81,6 +81,7 @@ void RegisterSupportHostRequest::OnSignallingDisconnected() { // Ignore any notifications other than signalling // connected/disconnected events. void RegisterSupportHostRequest::OnAccessDenied() { } +void RegisterSupportHostRequest::OnAuthenticatedClientsChanged(int clients) { } void RegisterSupportHostRequest::OnShutdown() { } XmlElement* RegisterSupportHostRequest::CreateRegistrationRequest( diff --git a/remoting/host/register_support_host_request.h b/remoting/host/register_support_host_request.h index 3ba6baf..efe3d48 100644 --- a/remoting/host/register_support_host_request.h +++ b/remoting/host/register_support_host_request.h @@ -53,6 +53,7 @@ class RegisterSupportHostRequest : public HostStatusObserver { virtual void OnSignallingConnected(SignalStrategy* signal_strategy, const std::string& full_jid) OVERRIDE; virtual void OnSignallingDisconnected() OVERRIDE; + virtual void OnAuthenticatedClientsChanged(int clients_connected) OVERRIDE; virtual void OnAccessDenied() OVERRIDE; virtual void OnShutdown() OVERRIDE; |