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/protocol | |
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/protocol')
-rw-r--r-- | remoting/protocol/client_message_dispatcher.cc | 33 | ||||
-rw-r--r-- | remoting/protocol/client_stub.cc | 34 | ||||
-rw-r--r-- | remoting/protocol/client_stub.h | 26 | ||||
-rw-r--r-- | remoting/protocol/connection_to_client.cc | 42 | ||||
-rw-r--r-- | remoting/protocol/connection_to_client.h | 19 | ||||
-rw-r--r-- | remoting/protocol/connection_to_client_unittest.cc | 3 | ||||
-rw-r--r-- | remoting/protocol/connection_to_host.cc | 7 | ||||
-rw-r--r-- | remoting/protocol/host_message_dispatcher.cc | 41 | ||||
-rw-r--r-- | remoting/protocol/host_stub.cc | 33 | ||||
-rw-r--r-- | remoting/protocol/host_stub.h | 26 | ||||
-rw-r--r-- | remoting/protocol/input_stub.cc | 33 | ||||
-rw-r--r-- | remoting/protocol/input_stub.h | 25 | ||||
-rw-r--r-- | remoting/protocol/protocol_mock_objects.cc | 3 |
13 files changed, 51 insertions, 274 deletions
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() {} |