Commit 0de37001 authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Add AUTHENTICATED session state.

Also removed AUTHENTICATED state from ConnectionToHost - We no longer need it there.

BUG=105214


Review URL: http://codereview.chromium.org/8774017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113146 0039d316-1c4b-4281-b951-d872f2087c98
parent c443fe4e
...@@ -162,8 +162,7 @@ void ChromotingClient::OnConnectionState( ...@@ -162,8 +162,7 @@ void ChromotingClient::OnConnectionState(
protocol::ConnectionToHost::Error error) { protocol::ConnectionToHost::Error error) {
DCHECK(message_loop()->BelongsToCurrentThread()); DCHECK(message_loop()->BelongsToCurrentThread());
VLOG(1) << "ChromotingClient::OnConnectionState(" << state << ")"; VLOG(1) << "ChromotingClient::OnConnectionState(" << state << ")";
if (state == protocol::ConnectionToHost::CONNECTED || if (state == protocol::ConnectionToHost::CONNECTED)
state == protocol::ConnectionToHost::AUTHENTICATED)
Initialize(); Initialize();
view_->SetConnectionState(state, error); view_->SetConnectionState(state, error);
} }
......
...@@ -238,9 +238,6 @@ void PepperView::SetConnectionState(protocol::ConnectionToHost::State state, ...@@ -238,9 +238,6 @@ void PepperView::SetConnectionState(protocol::ConnectionToHost::State state,
break; break;
case protocol::ConnectionToHost::CONNECTED: case protocol::ConnectionToHost::CONNECTED:
break;
case protocol::ConnectionToHost::AUTHENTICATED:
UnsetSolidFill(); UnsetSolidFill();
scriptable_obj->SetConnectionStatus( scriptable_obj->SetConnectionStatus(
ChromotingScriptableObject::STATUS_CONNECTED, ChromotingScriptableObject::STATUS_CONNECTED,
......
...@@ -88,16 +88,18 @@ void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { ...@@ -88,16 +88,18 @@ void ConnectionToClient::set_input_stub(protocol::InputStub* input_stub) {
input_stub_ = input_stub; input_stub_ = input_stub;
} }
void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { void ConnectionToClient::OnSessionStateChange(Session::State state) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK(handler_); DCHECK(handler_);
switch(state) { switch(state) {
case protocol::Session::CONNECTING: case Session::INITIALIZING:
// Don't care about this message. case Session::CONNECTING:
case Session::CONNECTED:
// Don't care about these events.
break; break;
case protocol::Session::CONNECTED: case Session::AUTHENTICATED:
// Initialize channels. // Initialize channels.
control_dispatcher_.reset(new HostControlDispatcher()); control_dispatcher_.reset(new HostControlDispatcher());
control_dispatcher_->Init(session_.get(), base::Bind( control_dispatcher_->Init(session_.get(), base::Bind(
...@@ -118,18 +120,14 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) { ...@@ -118,18 +120,14 @@ void ConnectionToClient::OnSessionStateChange(protocol::Session::State state) {
break; break;
case protocol::Session::CLOSED: case Session::CLOSED:
CloseChannels(); CloseChannels();
handler_->OnConnectionClosed(this); handler_->OnConnectionClosed(this);
break; break;
case protocol::Session::FAILED: case Session::FAILED:
CloseOnError(); CloseOnError();
break; break;
default:
// We shouldn't receive other states.
NOTREACHED();
} }
} }
......
...@@ -37,6 +37,8 @@ class ConnectionToClientTest : public testing::Test { ...@@ -37,6 +37,8 @@ class ConnectionToClientTest : public testing::Test {
EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get())); EXPECT_CALL(handler_, OnConnectionOpened(viewer_.get()));
session_->state_change_callback().Run( session_->state_change_callback().Run(
protocol::Session::CONNECTED); protocol::Session::CONNECTED);
session_->state_change_callback().Run(
protocol::Session::AUTHENTICATED);
message_loop_.RunAllPending(); message_loop_.RunAllPending();
} }
......
...@@ -159,6 +159,33 @@ void ConnectionToHost::OnSessionStateChange( ...@@ -159,6 +159,33 @@ void ConnectionToHost::OnSessionStateChange(
DCHECK(event_callback_); DCHECK(event_callback_);
switch (state) { switch (state) {
case Session::INITIALIZING:
case Session::CONNECTING:
case Session::CONNECTED:
// Don't care about these events.
break;
case Session::AUTHENTICATED:
video_reader_.reset(VideoReader::Create(
message_loop_, session_->config()));
video_reader_->Init(session_.get(), video_stub_, base::Bind(
&ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
control_dispatcher_.reset(new ClientControlDispatcher());
control_dispatcher_->Init(session_.get(), base::Bind(
&ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
control_dispatcher_->set_client_stub(client_stub_);
event_dispatcher_.reset(new ClientEventDispatcher());
event_dispatcher_->Init(session_.get(), base::Bind(
&ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
break;
case Session::CLOSED:
CloseChannels();
SetState(CLOSED, OK);
break;
case Session::FAILED: case Session::FAILED:
switch (session_->error()) { switch (session_->error()) {
case Session::PEER_IS_OFFLINE: case Session::PEER_IS_OFFLINE:
...@@ -179,31 +206,6 @@ void ConnectionToHost::OnSessionStateChange( ...@@ -179,31 +206,6 @@ void ConnectionToHost::OnSessionStateChange(
CloseOnError(NETWORK_FAILURE); CloseOnError(NETWORK_FAILURE);
} }
break; break;
case Session::CLOSED:
CloseChannels();
SetState(CLOSED, OK);
break;
case Session::CONNECTED:
video_reader_.reset(VideoReader::Create(
message_loop_, session_->config()));
video_reader_->Init(session_.get(), video_stub_, base::Bind(
&ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
control_dispatcher_.reset(new ClientControlDispatcher());
control_dispatcher_->Init(session_.get(), base::Bind(
&ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
control_dispatcher_->set_client_stub(client_stub_);
event_dispatcher_.reset(new ClientEventDispatcher());
event_dispatcher_->Init(session_.get(), base::Bind(
&ConnectionToHost::OnChannelInitialized, base::Unretained(this)));
break;
default:
// Ignore the other states by default.
break;
} }
} }
...@@ -223,7 +225,6 @@ void ConnectionToHost::NotifyIfChannelsReady() { ...@@ -223,7 +225,6 @@ void ConnectionToHost::NotifyIfChannelsReady() {
video_reader_.get() && video_reader_->is_connected() && video_reader_.get() && video_reader_->is_connected() &&
state_ == CONNECTING) { state_ == CONNECTING) {
SetState(CONNECTED, OK); SetState(CONNECTED, OK);
SetState(AUTHENTICATED, OK);
} }
} }
......
...@@ -45,11 +45,7 @@ class ConnectionToHost : public SignalStrategy::StatusObserver, ...@@ -45,11 +45,7 @@ class ConnectionToHost : public SignalStrategy::StatusObserver,
public: public:
enum State { enum State {
CONNECTING, CONNECTING,
// TODO(sergeyu): Currently CONNECTED state is not used and state
// is set to AUTHENTICATED after we are connected. Remove it and
// renamed AUTHENTICATED to CONNECTED?
CONNECTED, CONNECTED,
AUTHENTICATED,
FAILED, FAILED,
CLOSED, CLOSED,
}; };
......
...@@ -325,6 +325,9 @@ void JingleSession::OnAccept() { ...@@ -325,6 +325,9 @@ void JingleSession::OnAccept() {
} }
SetState(CONNECTED); SetState(CONNECTED);
if (authenticator_->state() == Authenticator::ACCEPTED)
SetState(AUTHENTICATED);
} }
void JingleSession::OnTerminate() { void JingleSession::OnTerminate() {
......
...@@ -349,6 +349,9 @@ class JingleSessionTest : public testing::Test { ...@@ -349,6 +349,9 @@ class JingleSessionTest : public testing::Test {
EXPECT_CALL(host_connection_callback_, EXPECT_CALL(host_connection_callback_,
OnStateChange(Session::CONNECTED)) OnStateChange(Session::CONNECTED))
.Times(1);
EXPECT_CALL(host_connection_callback_,
OnStateChange(Session::AUTHENTICATED))
.Times(1) .Times(1)
.WillOnce(QuitThreadOnCounter(&not_connected_peers)); .WillOnce(QuitThreadOnCounter(&not_connected_peers));
// Expect that the connection will be closed eventually. // Expect that the connection will be closed eventually.
...@@ -365,6 +368,9 @@ class JingleSessionTest : public testing::Test { ...@@ -365,6 +368,9 @@ class JingleSessionTest : public testing::Test {
.Times(1); .Times(1);
EXPECT_CALL(client_connection_callback_, EXPECT_CALL(client_connection_callback_,
OnStateChange(Session::CONNECTED)) OnStateChange(Session::CONNECTED))
.Times(1);
EXPECT_CALL(client_connection_callback_,
OnStateChange(Session::AUTHENTICATED))
.Times(1) .Times(1)
.WillOnce(QuitThreadOnCounter(&not_connected_peers)); .WillOnce(QuitThreadOnCounter(&not_connected_peers));
// Expect that the connection will be closed eventually. // Expect that the connection will be closed eventually.
......
...@@ -163,7 +163,7 @@ void PepperSession::set_config(const SessionConfig& config) { ...@@ -163,7 +163,7 @@ void PepperSession::set_config(const SessionConfig& config) {
void PepperSession::Close() { void PepperSession::Close() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (state_ == CONNECTING || state_ == CONNECTED) { if (state_ == CONNECTING || state_ == CONNECTED || state_ == AUTHENTICATED) {
// Send session-terminate message. // Send session-terminate message.
JingleMessage message(peer_jid_, JingleMessage::SESSION_TERMINATE, JingleMessage message(peer_jid_, JingleMessage::SESSION_TERMINATE,
session_id_); session_id_);
...@@ -237,6 +237,9 @@ void PepperSession::OnAccept(const JingleMessage& message, ...@@ -237,6 +237,9 @@ void PepperSession::OnAccept(const JingleMessage& message,
SetState(CONNECTED); SetState(CONNECTED);
if (authenticator_->state() == Authenticator::ACCEPTED)
SetState(AUTHENTICATED);
// In case there is transport information in the accept message. // In case there is transport information in the accept message.
ProcessTransportInfo(message); ProcessTransportInfo(message);
} }
...@@ -274,7 +277,7 @@ void PepperSession::OnTerminate(const JingleMessage& message, ...@@ -274,7 +277,7 @@ void PepperSession::OnTerminate(const JingleMessage& message,
return; return;
} }
if (state_ == CONNECTED) { if (state_ == CONNECTED || state_ == AUTHENTICATED) {
if (message.reason == JingleMessage::GENERAL_ERROR) { if (message.reason == JingleMessage::GENERAL_ERROR) {
OnError(CHANNEL_CONNECTION_ERROR); OnError(CHANNEL_CONNECTION_ERROR);
} else { } else {
......
...@@ -36,11 +36,15 @@ class Session : public base::NonThreadSafe { ...@@ -36,11 +36,15 @@ class Session : public base::NonThreadSafe {
// Sent or received session-initiate, but haven't sent or received // Sent or received session-initiate, but haven't sent or received
// session-accept. // session-accept.
// TODO(sergeyu): Do we really need this state?
CONNECTING, CONNECTING,
// Session has been accepted. // Session has been accepted and is pending authentication.
CONNECTED, CONNECTED,
// Session has been connected and authenticated.
AUTHENTICATED,
// Session has been closed. // Session has been closed.
CLOSED, CLOSED,
...@@ -58,7 +62,10 @@ class Session : public base::NonThreadSafe { ...@@ -58,7 +62,10 @@ class Session : public base::NonThreadSafe {
CHANNEL_CONNECTION_ERROR, CHANNEL_CONNECTION_ERROR,
}; };
typedef base::Callback<void(State)> StateChangeCallback; // State change callbacks are called after session state has
// changed. It is not safe to destroy the session from within the
// handler unless |state| is CLOSED or FAILED.
typedef base::Callback<void(State state)> StateChangeCallback;
// TODO(sergeyu): Specify connection error code when channel // TODO(sergeyu): Specify connection error code when channel
// connection fails. // connection fails.
...@@ -80,8 +87,8 @@ class Session : public base::NonThreadSafe { ...@@ -80,8 +87,8 @@ class Session : public base::NonThreadSafe {
// callback is called with NULL if connection failed for any reason. // callback is called with NULL if connection failed for any reason.
// Ownership of the channel socket is given to the caller when the // Ownership of the channel socket is given to the caller when the
// callback is called. All channels must be destroyed before the // callback is called. All channels must be destroyed before the
// session is destroyed. Can be called only when in CONNECTING or // session is destroyed. Can be called only when in CONNECTING,
// CONNECTED state. // CONNECTED or AUTHENTICATED states.
virtual void CreateStreamChannel( virtual void CreateStreamChannel(
const std::string& name, const StreamChannelCallback& callback) = 0; const std::string& name, const StreamChannelCallback& callback) = 0;
virtual void CreateDatagramChannel( virtual void CreateDatagramChannel(
......
...@@ -18,12 +18,20 @@ ...@@ -18,12 +18,20 @@
// The callback function decides whether the session should be accepted or // The callback function decides whether the session should be accepted or
// rejected. // rejected.
// //
// AUTHENTICATION
// Implementations of the Session and SessionManager interfaces
// delegate authentication to an Authenticator implementation. For
// incoming connections authenticators are created using an
// AuthenticatorFactory set via the set_authenticator_factory()
// method. For outgoing sessions authenticator must be passed to the
// Connect() method. The Session's state changes to AUTHENTICATED once
// authentication succeeds.
//
// SESSION OWNERSHIP AND SHUTDOWN // SESSION OWNERSHIP AND SHUTDOWN
// SessionManager owns all Sessions it creates. The manager must not // The SessionManager must not be closed or destroyed before all sessions
// be closed or destroyed before all sessions created by that // created by that SessionManager are destroyed. Caller owns Sessions
// SessionManager are destroyed. Caller owns Sessions created by a // created by a SessionManager (except rejected
// SessionManager (except rejected sessions). Sessions must outlive // sessions). The SignalStrategy must outlive the SessionManager.
// SessionManager, and SignalStrategy must outlive SessionManager.
// //
// PROTOCOL VERSION NEGOTIATION // PROTOCOL VERSION NEGOTIATION
// When client connects to a host it sends a session-initiate stanza with list // When client connects to a host it sends a session-initiate stanza with list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment