diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-16 18:36:52 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-16 18:36:52 +0000 |
commit | db97348d16cedf07f4dc520014dd6e80cb67f1d3 (patch) | |
tree | cdacbe0f0bd4aef3937efa2e462f464487671cc9 /remoting/host | |
parent | 268b10337c65d2e6fbdf3263beeec4240e9aeb23 (diff) | |
download | chromium_src-db97348d16cedf07f4dc520014dd6e80cb67f1d3.zip chromium_src-db97348d16cedf07f4dc520014dd6e80cb67f1d3.tar.gz chromium_src-db97348d16cedf07f4dc520014dd6e80cb67f1d3.tar.bz2 |
Notify calling web-app when Host plugin becomes connected to a client.
BUG=85110
TEST=
Review URL: http://codereview.chromium.org/7134023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89370 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host')
-rw-r--r-- | remoting/host/chromoting_host.cc | 36 | ||||
-rw-r--r-- | remoting/host/chromoting_host.h | 3 | ||||
-rw-r--r-- | remoting/host/heartbeat_sender.cc | 5 | ||||
-rw-r--r-- | remoting/host/heartbeat_sender.h | 1 | ||||
-rw-r--r-- | remoting/host/host_plugin.cc | 19 | ||||
-rw-r--r-- | remoting/host/host_status_observer.h | 5 | ||||
-rw-r--r-- | remoting/host/register_support_host_request.cc | 3 | ||||
-rw-r--r-- | remoting/host/register_support_host_request.h | 1 |
8 files changed, 51 insertions, 22 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index ace4f71..81f1f86 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -186,8 +186,8 @@ void ChromotingHost::AddStatusObserver( void ChromotingHost::OnConnectionOpened(ConnectionToClient* connection) { DCHECK_EQ(context_->network_message_loop(), MessageLoop::current()); VLOG(1) << "Connection to client established."; - // TODO(wez): ChromotingHost shouldn't need to know about Me2Mom. if (is_me2mom_) { + // TODO(wez): Improve our authentication framework. context_->main_message_loop()->PostTask( FROM_HERE, NewRunnableMethod(this, &ChromotingHost::ProcessPreAuthentication, @@ -283,13 +283,6 @@ void ChromotingHost::OnNewClientSession( return; } - // If we are running Me2Mom and already have an authenticated client then - // reject the connection immediately. - if (is_me2mom_ && HasAuthenticatedClients()) { - *response = protocol::SessionManager::DECLINE; - return; - } - // Check that the client has access to the host. if (!access_verifier_->VerifyPermissions(session->jid(), session->initiator_token())) { @@ -392,9 +385,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_me2mom_) { MonitorLocalInputs(false); @@ -428,19 +432,19 @@ 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) { // TODO(jamiewalch): This will need to be more sophisticated when we think // about proper crash recovery and daemon mode. - // TODO(wez): CurtainMode shouldn't be driven directly by ChromotingHost. if (is_me2mom_ || enable == is_curtained_) return; desktop_environment_->curtain()->EnableCurtainMode(enable); @@ -515,6 +519,12 @@ void ChromotingHost::LocalLoginSucceeded( username.replace(pos, std::string::npos, ""); ShowDisconnectWindow(true, username); } + + // 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 c05b06d..5f146b2 100644 --- a/remoting/host/chromoting_host.h +++ b/remoting/host/chromoting_host.h @@ -123,7 +123,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>, // |config| is transferred to the object. Must be called before Start(). void set_protocol_config(protocol::CandidateSessionConfig* config); - // TODO(wez): ChromotingHost shouldn't need to know about Me2Mom. void set_me2mom(bool is_me2mom) { is_me2mom_ = is_me2mom; } @@ -164,7 +163,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 5ef02b7..c726773 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. @@ -86,6 +86,9 @@ void HeartbeatSender::OnSignallingDisconnected() { request_.reset(NULL); } +void HeartbeatSender::OnAuthenticatedClientsChanged(int clients) { +} + void HeartbeatSender::OnShutdown() { } diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h index 016db0f..cdeb945 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 OnShutdown() OVERRIDE; private: diff --git a/remoting/host/host_plugin.cc b/remoting/host/host_plugin.cc index 11b621e..98f8a21 100644 --- a/remoting/host/host_plugin.cc +++ b/remoting/host/host_plugin.cc @@ -131,7 +131,7 @@ NPObject* ObjectFromNPVariant(const NPVariant& variant) { } // NPAPI plugin implementation for remoting host script object. -class HostNPScriptObject { +class HostNPScriptObject : remoting::HostStatusObserver { public: HostNPScriptObject(NPP plugin, NPObject* parent) : plugin_(plugin), @@ -354,9 +354,15 @@ class HostNPScriptObject { void OnReceivedSupportID(remoting::SupportAccessVerifier* access_verifier, bool success, const std::string& support_id); - void OnConnected(); void OnHostShutdown(); + // HostStatusObserver interface. + virtual void OnSignallingConnected(remoting::SignalStrategy* signal_strategy, + const std::string& full_jid) {} + virtual void OnSignallingDisconnected() {} + virtual void OnAuthenticatedClientsChanged(int clients_connected); + virtual void OnShutdown() {} + // Call a JavaScript function wrapped as an NPObject. // If result is non-null, the result of the call will be stored in it. // Caller is responsible for releasing result if they ask for it. @@ -457,6 +463,7 @@ bool HostNPScriptObject::Connect(const NPVariant* args, remoting::ChromotingHost::Create(&host_context_, host_config, access_verifier.release()); host->AddStatusObserver(register_request); + host->AddStatusObserver(this); host->set_me2mom(true); // Nothing went wrong, so lets save the host, config and request. @@ -516,14 +523,14 @@ void HostNPScriptObject::OnReceivedSupportID( OnStateChanged(kReceivedAccessCode); } -void HostNPScriptObject::OnConnected() { +void HostNPScriptObject::OnHostShutdown() { CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); - OnStateChanged(kConnected); + OnStateChanged(kDisconnected); } -void HostNPScriptObject::OnHostShutdown() { +void HostNPScriptObject::OnAuthenticatedClientsChanged(int clients_connected) { CHECK_NE(base::PlatformThread::CurrentId(), np_thread_id_); - OnStateChanged(kDisconnected); + OnStateChanged(clients_connected ? kConnected : kDisconnected); } void HostNPScriptObject::OnStateChanged(State state) { diff --git a/remoting/host/host_status_observer.h b/remoting/host/host_status_observer.h index dd0ae85..daecba3 100644 --- a/remoting/host/host_status_observer.h +++ b/remoting/host/host_status_observer.h @@ -21,6 +21,11 @@ class HostStatusObserver const std::string& full_jid) = 0; virtual void OnSignallingDisconnected() = 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 fff4c6b..6703bf0 100644 --- a/remoting/host/register_support_host_request.cc +++ b/remoting/host/register_support_host_request.cc @@ -78,6 +78,9 @@ void RegisterSupportHostRequest::OnSignallingDisconnected() { request_.reset(); } +void RegisterSupportHostRequest::OnAuthenticatedClientsChanged(int clients) { +} + void RegisterSupportHostRequest::OnShutdown() { } diff --git a/remoting/host/register_support_host_request.h b/remoting/host/register_support_host_request.h index c9b1e60..d831cf6 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 OnShutdown() OVERRIDE; private: |