diff options
author | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 14:20:06 +0000 |
---|---|---|
committer | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-31 14:20:06 +0000 |
commit | 4ea2c7cfa0f6a2177dedcf69b117408a868a4eb8 (patch) | |
tree | f3423e34f77859d918ed5af5b4345a7dd646f4c0 /remoting | |
parent | 22efa086fc27f192a1805d4bd62c576fe23580a4 (diff) | |
download | chromium_src-4ea2c7cfa0f6a2177dedcf69b117408a868a4eb8.zip chromium_src-4ea2c7cfa0f6a2177dedcf69b117408a868a4eb8.tar.gz chromium_src-4ea2c7cfa0f6a2177dedcf69b117408a868a4eb8.tar.bz2 |
The authenticated_ fields are moved out of stubs and into
ClientSession. Messages to the stubs are dispatched via
ClientSession, and the stub classes are pure virtual.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6724033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79991 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
23 files changed, 329 insertions, 328 deletions
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc index f6dfc5d..ae5ef68 100644 --- a/remoting/host/chromoting_host.cc +++ b/remoting/host/chromoting_host.cc @@ -4,6 +4,7 @@ #include "remoting/host/chromoting_host.h" +#include "base/bind.h" #include "base/stl_util-inl.h" #include "base/task.h" #include "build/build_config.h" @@ -19,6 +20,7 @@ #include "remoting/host/host_config.h" #include "remoting/host/host_key_pair.h" #include "remoting/host/screen_recorder.h" +#include "remoting/host/user_authenticator.h" #include "remoting/proto/auth.pb.h" #include "remoting/protocol/connection_to_client.h" #include "remoting/protocol/client_stub.h" @@ -180,13 +182,22 @@ void ChromotingHost::OnClientConnected(ConnectionToClient* connection) { void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { DCHECK_EQ(context_->main_message_loop(), MessageLoop::current()); + // Find the client session corresponding to the given connection. + std::vector<scoped_refptr<ClientSession> >::iterator client; + for (client = clients_.begin(); client != clients_.end(); ++client) { + if (client->get()->connection() == connection) + break; + } + if (client == clients_.end()) + return; + // Remove the connection from the session manager and stop the session. // TODO(hclam): Stop only if the last connection disconnected. if (recorder_.get()) { recorder_->RemoveConnection(connection); // The recorder only exists to serve the unique authenticated client. // If that client has disconnected, then we can kill the recorder. - if (connection->client_authenticated()) { + if (client->get()->authenticated()) { recorder_->Stop(NULL); recorder_ = NULL; } @@ -196,13 +207,8 @@ void ChromotingHost::OnClientDisconnected(ConnectionToClient* connection) { connection->Disconnect(); // Also remove reference to ConnectionToClient from this object. - std::vector<scoped_refptr<ClientSession> >::iterator it; - for (it = clients_.begin(); it != clients_.end(); ++it) { - if (it->get()->connection() == connection) { - clients_.erase(it); - break; - } - } + clients_.erase(client); + if (!HasAuthenticatedClients()) EnableCurtainMode(false); } @@ -321,13 +327,16 @@ void ChromotingHost::OnNewClientSession( // We accept the connection, so create a connection object. ConnectionToClient* connection = new ConnectionToClient( - context_->network_message_loop(), - this, - desktop_environment_->input_stub()); + context_->network_message_loop(), this); // Create a client object. - ClientSession* client = new ClientSession(this, connection); + ClientSession* client = new ClientSession( + this, + base::Bind(UserAuthenticator::Create), + connection, + desktop_environment_->input_stub()); connection->set_host_stub(client); + connection->set_input_stub(client); connection->Init(session); @@ -377,7 +386,7 @@ std::string ChromotingHost::GenerateHostAuthToken( bool ChromotingHost::HasAuthenticatedClients() const { std::vector<scoped_refptr<ClientSession> >::const_iterator it; for (it = clients_.begin(); it != clients_.end(); ++it) { - if (it->get()->connection()->client_authenticated()) + if (it->get()->authenticated()) return true; } return false; @@ -408,8 +417,6 @@ void ChromotingHost::LocalLoginSucceeded( connection->client_stub()->BeginSessionResponse( status, new DeleteTask<protocol::LocalLoginStatus>(status)); - connection->OnClientAuthenticated(); - // Disconnect all other clients. // Iterate over a copy of the list of clients, to avoid mutating the list // while iterating over it. diff --git a/remoting/host/chromoting_host_unittest.cc b/remoting/host/chromoting_host_unittest.cc index 8864533..6fa50a1 100644 --- a/remoting/host/chromoting_host_unittest.cc +++ b/remoting/host/chromoting_host_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/bind.h" #include "base/scoped_ptr.h" #include "base/task.h" #include "remoting/host/capturer_fake.h" @@ -9,6 +10,7 @@ #include "remoting/host/chromoting_host_context.h" #include "remoting/host/host_mock_objects.h" #include "remoting/host/in_memory_host_config.h" +#include "remoting/host/user_authenticator_fake.h" #include "remoting/proto/video.pb.h" #include "remoting/protocol/protocol_mock_objects.h" #include "remoting/protocol/session_config.h" @@ -41,6 +43,10 @@ namespace remoting { namespace { +UserAuthenticator* MakeUserAuthenticator() { + return new UserAuthenticatorFake(); +} + void PostQuitTask(MessageLoop* message_loop) { message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } @@ -56,6 +62,9 @@ ACTION_P(QuitMainMessageLoop, message_loop) { PostQuitTask(message_loop); } +void DummyDoneTask() { +} + } // namespace class ChromotingHostTest : public testing::Test { @@ -87,6 +96,12 @@ class ChromotingHostTest : public testing::Test { DesktopEnvironment* desktop = new DesktopEnvironment(capturer, input_stub_, curtain_); host_ = ChromotingHost::Create(&context_, config_, desktop); + credentials_good_.set_type(protocol::PASSWORD); + credentials_good_.set_username("user"); + credentials_good_.set_credential("password"); + credentials_bad_.set_type(protocol::PASSWORD); + credentials_bad_.set_username(UserAuthenticatorFake::fail_username()); + credentials_bad_.set_credential(UserAuthenticatorFake::fail_password()); connection_ = new MockConnectionToClient( &message_loop_, &handler_, host_stub_, input_stub_); connection2_ = new MockConnectionToClient( @@ -143,8 +158,13 @@ class ChromotingHostTest : public testing::Test { void SimulateClientConnection(int connection_index, bool authenticate) { scoped_refptr<MockConnectionToClient> connection = (connection_index == 0) ? connection_ : connection2_; - scoped_refptr<ClientSession> client = new ClientSession(host_.get(), - connection); + protocol::LocalLoginCredentials& credentials = + authenticate ? credentials_good_ : credentials_bad_; + scoped_refptr<ClientSession> client = new ClientSession( + host_.get(), + base::Bind(MakeUserAuthenticator), + connection, + input_stub_); connection->set_host_stub(client.get()); context_.network_message_loop()->PostTask( @@ -157,19 +177,12 @@ class ChromotingHostTest : public testing::Test { NewRunnableMethod(host_.get(), &ChromotingHost::OnClientConnected, connection)); - if (authenticate) { - context_.network_message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(host_.get(), - &ChromotingHost::LocalLoginSucceeded, - connection)); - } else { - context_.network_message_loop()->PostTask( - FROM_HERE, - NewRunnableMethod(host_.get(), - &ChromotingHost::LocalLoginFailed, - connection)); - } + context_.network_message_loop()->PostTask( + FROM_HERE, + NewRunnableMethod(client.get(), + &ClientSession::BeginSessionRequest, + &credentials, + NewRunnableFunction(&DummyDoneTask))); } // Helper method to remove a client connection from ChromotingHost. @@ -187,6 +200,8 @@ class ChromotingHostTest : public testing::Test { scoped_refptr<ChromotingHost> host_; scoped_refptr<InMemoryHostConfig> config_; MockChromotingHostContext context_; + protocol::LocalLoginCredentials credentials_good_; + protocol::LocalLoginCredentials credentials_bad_; scoped_refptr<MockConnectionToClient> connection_; scoped_refptr<MockSession> session_; scoped_ptr<SessionConfig> session_config_; diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc index 72cd5ba..b946a0a 100644 --- a/remoting/host/client_session.cc +++ b/remoting/host/client_session.cc @@ -6,6 +6,7 @@ #include "base/memory/scoped_ptr.h" #include "base/task.h" +#include "media/base/callback.h" #include "remoting/host/user_authenticator.h" #include "remoting/proto/auth.pb.h" @@ -13,9 +14,14 @@ namespace remoting { ClientSession::ClientSession( EventHandler* event_handler, - scoped_refptr<protocol::ConnectionToClient> connection) + const base::Callback<UserAuthenticatorFactory>& auth_factory, + scoped_refptr<protocol::ConnectionToClient> connection, + protocol::InputStub* input_stub) : event_handler_(event_handler), - connection_(connection) { + auth_factory_(auth_factory), + connection_(connection), + input_stub_(input_stub), + authenticated_(false) { } ClientSession::~ClientSession() { @@ -23,16 +29,23 @@ ClientSession::~ClientSession() { void ClientSession::SuggestResolution( const protocol::SuggestResolutionRequest* msg, Task* done) { - done->Run(); - delete done; + media::AutoTaskRunner done_runner(done); + + if (!authenticated_) { + LOG(WARNING) << "Invalid control message received " + << "(client not authenticated)."; + return; + } } void ClientSession::BeginSessionRequest( const protocol::LocalLoginCredentials* credentials, Task* done) { DCHECK(event_handler_); + media::AutoTaskRunner done_runner(done); + bool success = false; - scoped_ptr<UserAuthenticator> authenticator(UserAuthenticator::Create()); + scoped_ptr<UserAuthenticator> authenticator(auth_factory_.Run()); switch (credentials->type()) { case protocol::PASSWORD: success = authenticator->Authenticate(credentials->username(), @@ -45,22 +58,35 @@ void ClientSession::BeginSessionRequest( } if (success) { + authenticated_ = true; event_handler_->LocalLoginSucceeded(connection_.get()); } else { LOG(WARNING) << "Login failed for user " << credentials->username(); event_handler_->LocalLoginFailed(connection_.get()); } +} + +void ClientSession::InjectKeyEvent(const protocol::KeyEvent* event, + Task* done) { + media::AutoTaskRunner done_runner(done); + if (authenticated_) { + done_runner.release(); + input_stub_->InjectKeyEvent(event, done); + } +} - done->Run(); - delete done; +void ClientSession::InjectMouseEvent(const protocol::MouseEvent* event, + Task* done) { + media::AutoTaskRunner done_runner(done); + if (authenticated_) { + done_runner.release(); + input_stub_->InjectMouseEvent(event, done); + } } void ClientSession::Disconnect() { connection_->Disconnect(); -} - -protocol::ConnectionToClient* ClientSession::connection() const { - return connection_.get(); + authenticated_ = false; } } // namespace remoting diff --git a/remoting/host/client_session.h b/remoting/host/client_session.h index 620923f..e5ef81a 100644 --- a/remoting/host/client_session.h +++ b/remoting/host/client_session.h @@ -7,12 +7,16 @@ #include "remoting/protocol/connection_to_client.h" #include "remoting/protocol/host_stub.h" +#include "remoting/protocol/input_stub.h" namespace remoting { +class UserAuthenticator; + // A ClientSession keeps a reference to a connection to a client, and maintains // per-client state. class ClientSession : public protocol::HostStub, + public protocol::InputStub, public base::RefCountedThreadSafe<ClientSession> { public: // Callback interface for passing events to the ChromotingHost. @@ -30,8 +34,12 @@ class ClientSession : public protocol::HostStub, scoped_refptr<protocol::ConnectionToClient> client) = 0; }; + typedef UserAuthenticator* UserAuthenticatorFactory(); + ClientSession(EventHandler* event_handler, - scoped_refptr<protocol::ConnectionToClient> connection); + const base::Callback<UserAuthenticatorFactory>& auth_factory, + scoped_refptr<protocol::ConnectionToClient> connection, + protocol::InputStub* input_stub); // protocol::HostStub interface. virtual void SuggestResolution( @@ -39,19 +47,39 @@ class ClientSession : public protocol::HostStub, virtual void BeginSessionRequest( const protocol::LocalLoginCredentials* credentials, Task* done); + // protocol::InputStub interface. + virtual void InjectKeyEvent(const protocol::KeyEvent* event, Task* done); + virtual void InjectMouseEvent(const protocol::MouseEvent* event, Task* done); + // Disconnect this client session. void Disconnect(); - protocol::ConnectionToClient* connection() const; + protocol::ConnectionToClient* connection() const { + return connection_.get(); + } - protected: - friend class base::RefCountedThreadSafe<ClientSession>; - ~ClientSession(); + bool authenticated() const { + return authenticated_; + } private: + friend class base::RefCountedThreadSafe<ClientSession>; + virtual ~ClientSession(); + EventHandler* event_handler_; + + // A factory for user authenticators. + base::Callback<UserAuthenticatorFactory> auth_factory_; + + // The connection to the client. scoped_refptr<protocol::ConnectionToClient> connection_; + // The input stub to which this object delegates. + protocol::InputStub* input_stub_; + + // Whether this client is authenticated. + bool authenticated_; + DISALLOW_COPY_AND_ASSIGN(ClientSession); }; diff --git a/remoting/host/client_session_unittest.cc b/remoting/host/client_session_unittest.cc new file mode 100644 index 0000000..c7568b1 --- /dev/null +++ b/remoting/host/client_session_unittest.cc @@ -0,0 +1,119 @@ +// 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. + +#include "base/bind.h" +#include "remoting/host/client_session.h" +#include "remoting/host/host_mock_objects.h" +#include "remoting/host/user_authenticator_fake.h" +#include "remoting/protocol/protocol_mock_objects.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace remoting { + +namespace { + +UserAuthenticator* MakeUserAuthenticator() { + return new UserAuthenticatorFake(); +} + +// A task that does nothing. +class DummyTask : public Task { + public: + void Run() {} +}; + +} // namespace + +using protocol::MockConnectionToClient; +using protocol::MockConnectionToClientEventHandler; +using protocol::MockHostStub; +using protocol::MockInputStub; + +using testing::_; +using testing::InSequence; + +class ClientSessionTest : public testing::Test { + public: + ClientSessionTest() { + } + + virtual void SetUp() { + connection_ = new MockConnectionToClient(&message_loop_, + &connection_event_handler_, + &host_stub_, + &input_stub_); + client_session_ = new ClientSession(&session_event_handler_, + base::Bind(MakeUserAuthenticator), + connection_, + &input_stub_); + credentials_.set_type(protocol::PASSWORD); + credentials_.set_username("user"); + credentials_.set_credential("password"); + } + + virtual void TearDown() { + } + + protected: + MessageLoop message_loop_; + MockConnectionToClientEventHandler connection_event_handler_; + MockHostStub host_stub_; + MockInputStub input_stub_; + MockClientSessionEventHandler session_event_handler_; + scoped_refptr<MockConnectionToClient> connection_; + scoped_refptr<ClientSession> client_session_; + protocol::LocalLoginCredentials credentials_; +}; + +TEST_F(ClientSessionTest, InputStubFilter) { + protocol::KeyEvent key_event1; + key_event1.set_pressed(true); + key_event1.set_keycode(1); + + protocol::KeyEvent key_event2; + key_event2.set_pressed(true); + key_event2.set_keycode(2); + + protocol::KeyEvent key_event3; + key_event3.set_pressed(true); + key_event3.set_keycode(3); + + protocol::MouseEvent mouse_event1; + mouse_event1.set_x(100); + mouse_event1.set_y(101); + + protocol::MouseEvent mouse_event2; + mouse_event2.set_x(200); + mouse_event2.set_y(201); + + protocol::MouseEvent mouse_event3; + mouse_event3.set_x(300); + mouse_event3.set_y(301); + + credentials_.set_type(protocol::PASSWORD); + credentials_.set_username("user"); + credentials_.set_credential("password"); + + InSequence s; + EXPECT_CALL(session_event_handler_, LocalLoginSucceeded(_)); + EXPECT_CALL(input_stub_, InjectKeyEvent(&key_event2, _)); + EXPECT_CALL(input_stub_, InjectMouseEvent(&mouse_event2, _)); + EXPECT_CALL(*connection_.get(), Disconnect()); + + // These events should not get through to the input stub, + // because the client isn't authenticated yet. + client_session_->InjectKeyEvent(&key_event1, new DummyTask()); + client_session_->InjectMouseEvent(&mouse_event1, new DummyTask()); + client_session_->BeginSessionRequest(&credentials_, new DummyTask()); + // These events should get through to the input stub. + client_session_->InjectKeyEvent(&key_event2, new DummyTask()); + client_session_->InjectMouseEvent(&mouse_event2, new DummyTask()); + client_session_->Disconnect(); + // These events should not get through to the input stub, + // because the client has disconnected. + client_session_->InjectKeyEvent(&key_event3, new DummyTask()); + client_session_->InjectMouseEvent(&mouse_event3, new DummyTask()); +} + +} // namespace remoting diff --git a/remoting/host/host_mock_objects.cc b/remoting/host/host_mock_objects.cc index a08179b..14dd4db 100644 --- a/remoting/host/host_mock_objects.cc +++ b/remoting/host/host_mock_objects.cc @@ -23,4 +23,8 @@ MockChromotingHostContext::MockChromotingHostContext() MockChromotingHostContext::~MockChromotingHostContext() {} +MockClientSessionEventHandler::MockClientSessionEventHandler() {} + +MockClientSessionEventHandler::~MockClientSessionEventHandler() {} + } // namespace remoting diff --git a/remoting/host/host_mock_objects.h b/remoting/host/host_mock_objects.h index bb3ae2d..31d0ba4 100644 --- a/remoting/host/host_mock_objects.h +++ b/remoting/host/host_mock_objects.h @@ -8,6 +8,7 @@ #include "remoting/host/capturer.h" #include "remoting/host/curtain.h" #include "remoting/host/chromoting_host_context.h" +#include "remoting/host/client_session.h" #include "testing/gmock/include/gmock/gmock.h" namespace remoting { @@ -54,6 +55,20 @@ class MockChromotingHostContext : public ChromotingHostContext { DISALLOW_COPY_AND_ASSIGN(MockChromotingHostContext); }; +class MockClientSessionEventHandler : public ClientSession::EventHandler { + public: + MockClientSessionEventHandler(); + virtual ~MockClientSessionEventHandler(); + + MOCK_METHOD1(LocalLoginSucceeded, + void(scoped_refptr<protocol::ConnectionToClient>)); + MOCK_METHOD1(LocalLoginFailed, + void(scoped_refptr<protocol::ConnectionToClient>)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockClientSessionEventHandler); +}; + } // namespace remoting #endif // REMOTING_HOST_HOST_MOCK_OBJECTS_H_ diff --git a/remoting/host/user_authenticator_fake.cc b/remoting/host/user_authenticator_fake.cc index ae8e013..61b19f7 100644 --- a/remoting/host/user_authenticator_fake.cc +++ b/remoting/host/user_authenticator_fake.cc @@ -13,7 +13,16 @@ UserAuthenticatorFake::~UserAuthenticatorFake() {} bool UserAuthenticatorFake::Authenticate(const std::string& username, const std::string& password) { - return true; + return (username.compare(fail_username()) || + password.compare(fail_password())); +} + +const char* UserAuthenticatorFake::fail_username() { + return "userfail"; +} + +const char* UserAuthenticatorFake::fail_password() { + return "passwordfail"; } } // namespace remoting diff --git a/remoting/host/user_authenticator_fake.h b/remoting/host/user_authenticator_fake.h index f351931..faf1171 100644 --- a/remoting/host/user_authenticator_fake.h +++ b/remoting/host/user_authenticator_fake.h @@ -12,10 +12,7 @@ namespace remoting { -// Temporary stub for platforms where this hasn't been implemented yet. - -// TODO(lambroslambrou): Implement properly on those platforms, then -// delete this stub when it's no longer needed. +// A fake UserAuthenticator, which accepts all but one user/password pair. class UserAuthenticatorFake : public UserAuthenticator { public: UserAuthenticatorFake(); @@ -24,6 +21,10 @@ class UserAuthenticatorFake : public UserAuthenticator { virtual bool Authenticate(const std::string& username, const std::string& password); + // Get the user/password pair that a UserAuthenticatorFake rejects. + static const char* fail_username(); + static const char* fail_password(); + private: DISALLOW_COPY_AND_ASSIGN(UserAuthenticatorFake); }; diff --git a/remoting/protocol/client_message_dispatcher.cc b/remoting/protocol/client_message_dispatcher.cc index a1020d2..e0c2758 100644 --- a/remoting/protocol/client_message_dispatcher.cc +++ b/remoting/protocol/client_message_dispatcher.cc @@ -39,30 +39,19 @@ void ClientMessageDispatcher::Initialize( void ClientMessageDispatcher::OnControlMessageReceived( ControlMessage* message, Task* done_task) { - if (!client_stub_->authenticated()) { - // When the client has not authenticated with the host, we restrict the - // control messages that we support. - if (message->has_begin_session_response()) { - client_stub_->BeginSessionResponse( - &message->begin_session_response().login_status(), done_task); - return; - } else { - LOG(WARNING) << "Invalid control message received " - << "(client not authenticated)."; - } + // TODO(sergeyu): Add message validation. + if (message->has_notify_resolution()) { + client_stub_->NotifyResolution( + &message->notify_resolution(), done_task); + return; + } else if (message->has_begin_session_response()) { + client_stub_->BeginSessionResponse( + &message->begin_session_response().login_status(), done_task); + return; } else { - // TODO(sergeyu): Add message validation. - if (message->has_notify_resolution()) { - client_stub_->NotifyResolution( - &message->notify_resolution(), done_task); - return; - } else if (message->has_begin_session_response()) { - LOG(WARNING) << "BeginSessionResponse sent after client already " - << "authorized."; - } else { - LOG(WARNING) << "Invalid control message received."; - } + LOG(WARNING) << "Invalid control message received."; } + done_task->Run(); delete done_task; } diff --git a/remoting/protocol/client_stub.cc b/remoting/protocol/client_stub.cc deleted file mode 100644 index cd5bf05..0000000 --- a/remoting/protocol/client_stub.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2010 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. - -// Interface of a client that receives commands from a Chromoting host. -// -// This interface is responsible for a subset of control messages sent to -// the Chromoting client. - -#include "remoting/protocol/client_stub.h" - -namespace remoting { -namespace protocol { - -ClientStub::ClientStub() : authenticated_(false) { -} - -ClientStub::~ClientStub() { -} - -void ClientStub::OnAuthenticated() { - authenticated_ = true; -} - -void ClientStub::OnClosed() { - authenticated_ = false; -} - -bool ClientStub::authenticated() { - return authenticated_; -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/client_stub.h b/remoting/protocol/client_stub.h index d6550ec..4a75e05 100644 --- a/remoting/protocol/client_stub.h +++ b/remoting/protocol/client_stub.h @@ -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. @@ -22,35 +22,15 @@ class NotifyResolutionRequest; class ClientStub { public: - ClientStub(); - virtual ~ClientStub(); + ClientStub() {} + virtual ~ClientStub() {} virtual void NotifyResolution(const NotifyResolutionRequest* msg, Task* done) = 0; virtual void BeginSessionResponse(const LocalLoginStatus* msg, Task* done) = 0; - // TODO(lambroslambrou): Remove OnAuthenticated() and OnClosed() when stubs - // are refactored not to store authentication state. - - // Called when the client has authenticated with the host to enable the - // host->client control channel. - // Before this is called, only a limited set of control messages will be - // processed. - void OnAuthenticated(); - - // Called when the client is no longer connected. - void OnClosed(); - - // Has the client successfully authenticated with the host? - // I.e., should we be processing control events? - bool authenticated(); - private: - // Initially false, this records whether the client has authenticated with - // the host. - bool authenticated_; - DISALLOW_COPY_AND_ASSIGN(ClientStub); }; diff --git a/remoting/protocol/connection_to_client.cc b/remoting/protocol/connection_to_client.cc index 4ec9a0b..96c11e4 100644 --- a/remoting/protocol/connection_to_client.cc +++ b/remoting/protocol/connection_to_client.cc @@ -22,13 +22,11 @@ namespace protocol { static const size_t kAverageUpdateStream = 10; ConnectionToClient::ConnectionToClient(MessageLoop* message_loop, - EventHandler* handler, - InputStub* input_stub) - : client_authenticated_(false), - loop_(message_loop), + EventHandler* handler) + : loop_(message_loop), handler_(handler), host_stub_(NULL), - input_stub_(input_stub) { + input_stub_(NULL) { DCHECK(loop_); DCHECK(handler_); } @@ -75,14 +73,14 @@ ClientStub* ConnectionToClient::client_stub() { return client_stub_.get(); } -protocol::HostStub* ConnectionToClient::host_stub() { - return host_stub_; -} - void ConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { host_stub_ = host_stub; } +void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { + input_stub_ = input_stub; +} + void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { if (state == protocol::Session::CONNECTED) { client_stub_.reset(new ClientControlSender(session_->control_channel())); @@ -128,32 +126,6 @@ void ConnectionToClient::StateChangeTask(protocol::Session::State state) { // OnClosed() is used as a callback for protocol::Session::Close(). void ConnectionToClient::OnClosed() { - client_authenticated_ = false; - - // TODO(lambroslambrou): Remove these when stubs are refactored not to - // store authentication state. - if (input_stub_) - input_stub_->OnClosed(); - if (host_stub_) - host_stub_->OnClosed(); - if (client_stub_.get()) - client_stub_->OnClosed(); -} - -void ConnectionToClient::OnClientAuthenticated() { - client_authenticated_ = true; - - // Enable/disable each of the channels. - if (input_stub_) - input_stub_->OnAuthenticated(); - if (host_stub_) - host_stub_->OnAuthenticated(); - if (client_stub_.get()) - client_stub_->OnAuthenticated(); -} - -bool ConnectionToClient::client_authenticated() { - return client_authenticated_; } } // namespace protocol diff --git a/remoting/protocol/connection_to_client.h b/remoting/protocol/connection_to_client.h index 0196f84..19dbdf5 100644 --- a/remoting/protocol/connection_to_client.h +++ b/remoting/protocol/connection_to_client.h @@ -47,10 +47,9 @@ class ConnectionToClient : // Constructs a ConnectionToClient object. |message_loop| is the message loop // that this object runs on. A viewer object receives events and messages from // a libjingle channel, these events are delegated to |handler|. - // It is guranteed that |handler| is called only on the |message_loop|. + // It is guaranteed that |handler| is called only on the |message_loop|. ConnectionToClient(MessageLoop* message_loop, - EventHandler* handler, - InputStub* input_stub); + EventHandler* handler); virtual void Init(Session* session); @@ -69,14 +68,9 @@ class ConnectionToClient : // Return pointer to ClientStub. virtual ClientStub* client_stub(); - virtual HostStub* host_stub(); + // These two setters should be called before Init(). virtual void set_host_stub(HostStub* host_stub); - - // Called when the host accepts the client authentication. - void OnClientAuthenticated(); - - // Whether the client has been authenticated. - bool client_authenticated(); + virtual void set_input_stub(InputStub* input_stub); protected: friend class base::RefCountedThreadSafe<ConnectionToClient>; @@ -91,11 +85,6 @@ class ConnectionToClient : void OnClosed(); - // Initially false, this is set to true once the client has authenticated - // properly. When this is false, many client messages (like input events) - // will be ignored. - bool client_authenticated_; - // The libjingle channel used to send and receive data from the remote client. scoped_refptr<Session> session_; diff --git a/remoting/protocol/connection_to_client_unittest.cc b/remoting/protocol/connection_to_client_unittest.cc index 7a21096..bb73a8f 100644 --- a/remoting/protocol/connection_to_client_unittest.cc +++ b/remoting/protocol/connection_to_client_unittest.cc @@ -27,8 +27,9 @@ class ConnectionToClientTest : public testing::Test { session_->set_message_loop(&message_loop_); // Allocate a ClientConnection object with the mock objects. - viewer_ = new ConnectionToClient(&message_loop_, &handler_, &input_stub_); + viewer_ = new ConnectionToClient(&message_loop_, &handler_); viewer_->set_host_stub(&host_stub_); + viewer_->set_input_stub(&input_stub_); viewer_->Init(session_); EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); session_->state_change_callback()->Run( diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc index bdf6f8b..9383d06 100644 --- a/remoting/protocol/connection_to_host.cc +++ b/remoting/protocol/connection_to_host.cc @@ -238,13 +238,6 @@ void ConnectionToHost::OnClientAuthenticated() { // Create and enable the input stub now that we're authenticated. input_stub_.reset(new InputSender(session_->event_channel())); - input_stub_->OnAuthenticated(); - - // Enable control channel stubs. - if (host_stub_.get()) - host_stub_->OnAuthenticated(); - if (client_stub_) - client_stub_->OnAuthenticated(); } ConnectionToHost::State ConnectionToHost::state() const { diff --git a/remoting/protocol/host_message_dispatcher.cc b/remoting/protocol/host_message_dispatcher.cc index c4964e1..c793ce7 100644 --- a/remoting/protocol/host_message_dispatcher.cc +++ b/remoting/protocol/host_message_dispatcher.cc @@ -49,44 +49,35 @@ void HostMessageDispatcher::Initialize( void HostMessageDispatcher::OnControlMessageReceived( ControlMessage* message, Task* done_task) { - // BeginSessionRequest is always allowed. + // TODO(sergeyu): Add message validation. if (message->has_begin_session_request()) { host_stub_->BeginSessionRequest( &message->begin_session_request().credentials(), done_task); return; } - if (!host_stub_->authenticated()) { - // When the client has not authenticated with the host, no other messages - // are allowed. - LOG(WARNING) << "Invalid control message received " - << "(client not authenticated)."; - } else { - // TODO(sergeyu): Add message validation. - if (message->has_suggest_resolution()) { - host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); - return; - } else { - LOG(WARNING) << "Invalid control message received."; - } + if (message->has_suggest_resolution()) { + host_stub_->SuggestResolution(&message->suggest_resolution(), done_task); + return; } + LOG(WARNING) << "Invalid control message received."; done_task->Run(); delete done_task; } void HostMessageDispatcher::OnEventMessageReceived( EventMessage* message, Task* done_task) { - if (input_stub_->authenticated()) { - // TODO(sergeyu): Add message validation. - if (message->has_key_event()) { - input_stub_->InjectKeyEvent(&message->key_event(), done_task); - } else if (message->has_mouse_event()) { - input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); - } else { - LOG(WARNING) << "Invalid event message received."; - done_task->Run(); - delete done_task; - } + // TODO(sergeyu): Add message validation. + if (message->has_key_event()) { + input_stub_->InjectKeyEvent(&message->key_event(), done_task); + return; + } + if (message->has_mouse_event()) { + input_stub_->InjectMouseEvent(&message->mouse_event(), done_task); + return; } + LOG(WARNING) << "Invalid event message received."; + done_task->Run(); + delete done_task; } } // namespace protocol diff --git a/remoting/protocol/host_stub.cc b/remoting/protocol/host_stub.cc deleted file mode 100644 index 6543652..0000000 --- a/remoting/protocol/host_stub.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2010 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. - -// Interface of a host that receives commands from a Chromoting client. -// -// This interface handles control messages defined in contro.proto. - -#include "remoting/protocol/host_stub.h" - -namespace remoting { -namespace protocol { - -HostStub::HostStub() : authenticated_(false) { -} - -HostStub::~HostStub() { -} - -void HostStub::OnAuthenticated() { - authenticated_ = true; -} - -void HostStub::OnClosed() { - authenticated_ = false; -} - -bool HostStub::authenticated() { - return authenticated_; -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/host_stub.h b/remoting/protocol/host_stub.h index 737154d..2a18ffe 100644 --- a/remoting/protocol/host_stub.h +++ b/remoting/protocol/host_stub.h @@ -4,7 +4,7 @@ // Interface of a host that receives commands from a Chromoting client. // -// This interface handles control messages defined in contro.proto. +// This interface handles control messages defined in control.proto. #ifndef REMOTING_PROTOCOL_HOST_STUB_H_ #define REMOTING_PROTOCOL_HOST_STUB_H_ @@ -21,35 +21,15 @@ class SuggestResolutionRequest; class HostStub { public: - HostStub(); - virtual ~HostStub(); + HostStub() {}; + virtual ~HostStub() {}; virtual void SuggestResolution( const SuggestResolutionRequest* msg, Task* done) = 0; virtual void BeginSessionRequest( const LocalLoginCredentials* credentials, Task* done) = 0; - // TODO(lambroslambrou): Remove OnAuthenticated() and OnClosed() when stubs - // are refactored not to store authentication state. - - // Called when the client has authenticated with the host to enable the - // client->host control channel. - // Before this is called, only a limited set of control messages will be - // processed. - void OnAuthenticated(); - - // Called when the client is no longer connected. - void OnClosed(); - - // Has the client successfully authenticated with the host? - // I.e., should we be processing control events? - bool authenticated(); - private: - // Initially false, this records whether the client has authenticated with - // the host. - bool authenticated_; - DISALLOW_COPY_AND_ASSIGN(HostStub); }; diff --git a/remoting/protocol/input_stub.cc b/remoting/protocol/input_stub.cc deleted file mode 100644 index a9e5427..0000000 --- a/remoting/protocol/input_stub.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2010 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. - -// Interface for a device that receives input events. -// This interface handles event messages defined in event.proto. - -#include "remoting/protocol/input_stub.h" - -namespace remoting { -namespace protocol { - - -InputStub::InputStub() : authenticated_(false) { -} - -InputStub::~InputStub() { -} - -void InputStub::OnAuthenticated() { - authenticated_ = true; -} - -void InputStub::OnClosed() { - authenticated_ = false; -} - -bool InputStub::authenticated() { - return authenticated_; -} - -} // namespace protocol -} // namespace remoting diff --git a/remoting/protocol/input_stub.h b/remoting/protocol/input_stub.h index 0bc60c3..464454f 100644 --- a/remoting/protocol/input_stub.h +++ b/remoting/protocol/input_stub.h @@ -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. @@ -20,32 +20,13 @@ class MouseEvent; class InputStub { public: - InputStub(); - virtual ~InputStub(); + InputStub() {}; + virtual ~InputStub() {}; virtual void InjectKeyEvent(const KeyEvent* event, Task* done) = 0; virtual void InjectMouseEvent(const MouseEvent* event, Task* done) = 0; - // TODO(lambroslambrou): Remove OnAuthenticated() and OnClosed() when stubs - // are refactored not to store authentication state. - - // Called when the client has authenticated with the host to enable the - // input event channel. - // Before this is called, all input event will be ignored. - void OnAuthenticated(); - - // Called when the client is no longer connected. - void OnClosed(); - - // Has the client successfully authenticated with the host? - // I.e., should we be processing input events? - bool authenticated(); - private: - // Initially false, this records whether the client has authenticated with - // the host. - bool authenticated_; - DISALLOW_COPY_AND_ASSIGN(InputStub); }; diff --git a/remoting/protocol/protocol_mock_objects.cc b/remoting/protocol/protocol_mock_objects.cc index 85aad65a..316dd01 100644 --- a/remoting/protocol/protocol_mock_objects.cc +++ b/remoting/protocol/protocol_mock_objects.cc @@ -11,8 +11,9 @@ MockConnectionToClient::MockConnectionToClient(MessageLoop* message_loop, EventHandler* handler, HostStub* host_stub, InputStub* input_stub) - : ConnectionToClient(message_loop, handler, input_stub) { + : ConnectionToClient(message_loop, handler) { set_host_stub(host_stub); + set_input_stub(input_stub); } MockConnectionToClient::~MockConnectionToClient() {} diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 6f1e88c..9c6f056 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -398,7 +398,6 @@ 'protocol/client_control_Sender.h', 'protocol/client_message_dispatcher.cc', 'protocol/client_message_dispatcher.h', - 'protocol/client_stub.cc', 'protocol/client_stub.h', 'protocol/connection_to_client.cc', 'protocol/connection_to_client.h', @@ -408,11 +407,9 @@ 'protocol/host_control_sender.h', 'protocol/host_message_dispatcher.cc', 'protocol/host_message_dispatcher.h', - 'protocol/host_stub.cc', 'protocol/host_stub.h', 'protocol/input_sender.cc', 'protocol/input_sender.h', - 'protocol/input_stub.cc', 'protocol/input_stub.h', 'protocol/jingle_session.cc', 'protocol/jingle_session.h', @@ -546,6 +543,7 @@ 'host/access_verifier_unittest.cc', 'host/chromoting_host_context_unittest.cc', 'host/chromoting_host_unittest.cc', + 'host/client_session_unittest.cc', 'host/differ_block_unittest.cc', 'host/differ_unittest.cc', 'host/heartbeat_sender_unittest.cc', @@ -555,6 +553,8 @@ 'host/json_host_config_unittest.cc', 'host/screen_recorder_unittest.cc', 'host/test_key_pair.h', + 'host/user_authenticator_fake.cc', + 'host/user_authenticator_fake.h', 'jingle_glue/iq_request_unittest.cc', 'jingle_glue/jingle_client_unittest.cc', 'jingle_glue/jingle_thread_unittest.cc', |