Commit 204a9e3b authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Cleanup error handling in the client plugin.

- Added new ErrorCode enum to pass error codes everywhere except between 
  the webapp and the plugin.
- Signaling timeout when connection now is interpreted as disconnect instead of
  error condition (see bug 112739).
- Fixed webapp to properly handle unknown error codes.

BUG=112739


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124606 0039d316-1c4b-4281-b951-d872f2087c98
parent f804b509
...@@ -166,7 +166,7 @@ void ChromotingClient::DispatchPacket() { ...@@ -166,7 +166,7 @@ void ChromotingClient::DispatchPacket() {
void ChromotingClient::OnConnectionState( void ChromotingClient::OnConnectionState(
protocol::ConnectionToHost::State state, protocol::ConnectionToHost::State state,
protocol::ConnectionToHost::Error error) { protocol::ErrorCode 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)
......
...@@ -52,7 +52,7 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback, ...@@ -52,7 +52,7 @@ class ChromotingClient : public protocol::ConnectionToHost::HostEventCallback,
// ConnectionToHost::HostEventCallback implementation. // ConnectionToHost::HostEventCallback implementation.
virtual void OnConnectionState( virtual void OnConnectionState(
protocol::ConnectionToHost::State state, protocol::ConnectionToHost::State state,
protocol::ConnectionToHost::Error error) OVERRIDE; protocol::ErrorCode error) OVERRIDE;
// VideoStub implementation. // VideoStub implementation.
virtual void ProcessVideoPacket(const VideoPacket* packet, virtual void ProcessVideoPacket(const VideoPacket* packet,
......
...@@ -25,7 +25,7 @@ class ChromotingView { ...@@ -25,7 +25,7 @@ class ChromotingView {
// Record the update the state of the connection, updating the UI as needed. // Record the update the state of the connection, updating the UI as needed.
virtual void SetConnectionState(protocol::ConnectionToHost::State state, virtual void SetConnectionState(protocol::ConnectionToHost::State state,
protocol::ConnectionToHost::Error error) = 0; protocol::ErrorCode error) = 0;
}; };
} // namespace remoting } // namespace remoting
......
...@@ -31,18 +31,30 @@ namespace { ...@@ -31,18 +31,30 @@ namespace {
// The maximum number of image buffers to be allocated at any point of time. // The maximum number of image buffers to be allocated at any point of time.
const size_t kMaxPendingBuffersCount = 2; const size_t kMaxPendingBuffersCount = 2;
// TODO(sergeyu): Ideally we should just pass ErrorCode to the webapp
// and let it handle it, but it would be hard to fix it now because
// client plugin and webapp versions may not be in sync. It should be
// easy to do after we are finished moving the client plugin to NaCl.
ChromotingInstance::ConnectionError ConvertConnectionError( ChromotingInstance::ConnectionError ConvertConnectionError(
protocol::ConnectionToHost::Error error) { protocol::ErrorCode error) {
switch (error) { switch (error) {
case protocol::ConnectionToHost::OK: case protocol::OK:
return ChromotingInstance::ERROR_NONE; return ChromotingInstance::ERROR_NONE;
case protocol::ConnectionToHost::HOST_IS_OFFLINE:
case protocol::PEER_IS_OFFLINE:
return ChromotingInstance::ERROR_HOST_IS_OFFLINE; return ChromotingInstance::ERROR_HOST_IS_OFFLINE;
case protocol::ConnectionToHost::SESSION_REJECTED:
case protocol::SESSION_REJECTED:
case protocol::AUTHENTICATION_FAILED:
return ChromotingInstance::ERROR_SESSION_REJECTED; return ChromotingInstance::ERROR_SESSION_REJECTED;
case protocol::ConnectionToHost::INCOMPATIBLE_PROTOCOL:
case protocol::INCOMPATIBLE_PROTOCOL:
return ChromotingInstance::ERROR_INCOMPATIBLE_PROTOCOL; return ChromotingInstance::ERROR_INCOMPATIBLE_PROTOCOL;
case protocol::ConnectionToHost::NETWORK_FAILURE:
case protocol::CHANNEL_CONNECTION_ERROR:
case protocol::SIGNALING_ERROR:
case protocol::SIGNALING_TIMEOUT:
case protocol::UNKNOWN_ERROR:
return ChromotingInstance::ERROR_NETWORK_FAILURE; return ChromotingInstance::ERROR_NETWORK_FAILURE;
} }
DLOG(FATAL) << "Unknown error code" << error; DLOG(FATAL) << "Unknown error code" << error;
...@@ -97,7 +109,7 @@ void PepperView::TearDown() { ...@@ -97,7 +109,7 @@ void PepperView::TearDown() {
} }
void PepperView::SetConnectionState(protocol::ConnectionToHost::State state, void PepperView::SetConnectionState(protocol::ConnectionToHost::State state,
protocol::ConnectionToHost::Error error) { protocol::ErrorCode error) {
DCHECK(context_->main_message_loop()->BelongsToCurrentThread()); DCHECK(context_->main_message_loop()->BelongsToCurrentThread());
switch (state) { switch (state) {
......
...@@ -38,7 +38,7 @@ class PepperView : public ChromotingView, ...@@ -38,7 +38,7 @@ class PepperView : public ChromotingView,
virtual void TearDown() OVERRIDE; virtual void TearDown() OVERRIDE;
virtual void SetConnectionState( virtual void SetConnectionState(
protocol::ConnectionToHost::State state, protocol::ConnectionToHost::State state,
protocol::ConnectionToHost::Error error) OVERRIDE; protocol::ErrorCode error) OVERRIDE;
// FrameConsumer implementation. // FrameConsumer implementation.
virtual void ApplyBuffer(const SkISize& view_size, virtual void ApplyBuffer(const SkISize& view_size,
......
...@@ -109,10 +109,10 @@ void ClientSession::OnConnectionClosed( ...@@ -109,10 +109,10 @@ void ClientSession::OnConnectionClosed(
void ClientSession::OnConnectionFailed( void ClientSession::OnConnectionFailed(
protocol::ConnectionToClient* connection, protocol::ConnectionToClient* connection,
protocol::Session::Error error) { protocol::ErrorCode error) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
DCHECK_EQ(connection_.get(), connection); DCHECK_EQ(connection_.get(), connection);
if (error == protocol::Session::AUTHENTICATION_FAILED) if (error == protocol::AUTHENTICATION_FAILED)
event_handler_->OnSessionAuthenticationFailed(this); event_handler_->OnSessionAuthenticationFailed(this);
// TODO(sergeyu): Log failure reason? // TODO(sergeyu): Log failure reason?
event_handler_->OnSessionClosed(this); event_handler_->OnSessionClosed(this);
......
...@@ -74,7 +74,7 @@ class ClientSession : public protocol::HostStub, ...@@ -74,7 +74,7 @@ class ClientSession : public protocol::HostStub,
virtual void OnConnectionClosed( virtual void OnConnectionClosed(
protocol::ConnectionToClient* connection) OVERRIDE; protocol::ConnectionToClient* connection) OVERRIDE;
virtual void OnConnectionFailed(protocol::ConnectionToClient* connection, virtual void OnConnectionFailed(protocol::ConnectionToClient* connection,
protocol::Session::Error error) OVERRIDE; protocol::ErrorCode error) OVERRIDE;
virtual void OnSequenceNumberUpdated( virtual void OnSequenceNumberUpdated(
protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE; protocol::ConnectionToClient* connection, int64 sequence_number) OVERRIDE;
virtual void OnRouteChange( virtual void OnRouteChange(
......
...@@ -45,7 +45,7 @@ class ConnectionToClient : public base::NonThreadSafe { ...@@ -45,7 +45,7 @@ class ConnectionToClient : public base::NonThreadSafe {
// Called when the network connection has failed. // Called when the network connection has failed.
virtual void OnConnectionFailed(ConnectionToClient* connection, virtual void OnConnectionFailed(ConnectionToClient* connection,
Session::Error error) = 0; ErrorCode error) = 0;
// Called when sequence number is updated. // Called when sequence number is updated.
virtual void OnSequenceNumberUpdated(ConnectionToClient* connection, virtual void OnSequenceNumberUpdated(ConnectionToClient* connection,
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -100,9 +100,8 @@ TEST_F(ConnectionToClientTest, StateChange) { ...@@ -100,9 +100,8 @@ TEST_F(ConnectionToClientTest, StateChange) {
session_->state_change_callback().Run(protocol::Session::CLOSED); session_->state_change_callback().Run(protocol::Session::CLOSED);
message_loop_.RunAllPending(); message_loop_.RunAllPending();
EXPECT_CALL(handler_, OnConnectionFailed( EXPECT_CALL(handler_, OnConnectionFailed(viewer_.get(), SESSION_REJECTED));
viewer_.get(), Session::SESSION_REJECTED)); session_->set_error(SESSION_REJECTED);
session_->set_error(Session::SESSION_REJECTED);
session_->state_change_callback().Run(protocol::Session::FAILED); session_->state_change_callback().Run(protocol::Session::FAILED);
message_loop_.RunAllPending(); message_loop_.RunAllPending();
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "remoting/protocol/client_control_dispatcher.h" #include "remoting/protocol/client_control_dispatcher.h"
#include "remoting/protocol/client_event_dispatcher.h" #include "remoting/protocol/client_event_dispatcher.h"
#include "remoting/protocol/client_stub.h" #include "remoting/protocol/client_stub.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/jingle_session_manager.h" #include "remoting/protocol/jingle_session_manager.h"
#include "remoting/protocol/pepper_transport_factory.h" #include "remoting/protocol/pepper_transport_factory.h"
#include "remoting/protocol/video_reader.h" #include "remoting/protocol/video_reader.h"
...@@ -114,7 +115,7 @@ void ConnectionToHost::OnSignalStrategyStateChange( ...@@ -114,7 +115,7 @@ void ConnectionToHost::OnSignalStrategyStateChange(
VLOG(1) << "Connected as: " << signal_strategy_->GetLocalJid(); VLOG(1) << "Connected as: " << signal_strategy_->GetLocalJid();
} else if (state == SignalStrategy::DISCONNECTED) { } else if (state == SignalStrategy::DISCONNECTED) {
VLOG(1) << "Connection closed."; VLOG(1) << "Connection closed.";
CloseOnError(NETWORK_FAILURE); CloseOnError(SIGNALING_ERROR);
} }
} }
...@@ -176,24 +177,19 @@ void ConnectionToHost::OnSessionStateChange( ...@@ -176,24 +177,19 @@ void ConnectionToHost::OnSessionStateChange(
break; break;
case Session::FAILED: case Session::FAILED:
switch (session_->error()) { // If we were connected then treat signaling timeout error as if
case Session::PEER_IS_OFFLINE: // the connection was closed by the peer.
CloseOnError(HOST_IS_OFFLINE); //
break; // TODO(sergeyu): This logic belongs to the webapp, but we
case Session::SESSION_REJECTED: // currently don't expose this error code to the webapp, and it
case Session::AUTHENTICATION_FAILED: // would be hard to add it because client plugin and webapp
CloseOnError(SESSION_REJECTED); // versions may not be in sync. It should be easy to do after we
break; // are finished moving the client plugin to NaCl.
case Session::INCOMPATIBLE_PROTOCOL: if (state_ == CONNECTED && session_->error() == SIGNALING_TIMEOUT) {
CloseOnError(INCOMPATIBLE_PROTOCOL); CloseChannels();
break; SetState(CLOSED, OK);
case Session::CHANNEL_CONNECTION_ERROR: } else {
case Session::UNKNOWN_ERROR: CloseOnError(session_->error());
CloseOnError(NETWORK_FAILURE);
break;
case Session::OK:
DLOG(FATAL) << "Error code isn't set";
CloseOnError(NETWORK_FAILURE);
} }
break; break;
} }
...@@ -202,7 +198,7 @@ void ConnectionToHost::OnSessionStateChange( ...@@ -202,7 +198,7 @@ void ConnectionToHost::OnSessionStateChange(
void ConnectionToHost::OnChannelInitialized(bool successful) { void ConnectionToHost::OnChannelInitialized(bool successful) {
if (!successful) { if (!successful) {
LOG(ERROR) << "Failed to connect video channel"; LOG(ERROR) << "Failed to connect video channel";
CloseOnError(NETWORK_FAILURE); CloseOnError(CHANNEL_CONNECTION_ERROR);
return; return;
} }
...@@ -220,7 +216,7 @@ void ConnectionToHost::NotifyIfChannelsReady() { ...@@ -220,7 +216,7 @@ void ConnectionToHost::NotifyIfChannelsReady() {
} }
} }
void ConnectionToHost::CloseOnError(Error error) { void ConnectionToHost::CloseOnError(ErrorCode error) {
CloseChannels(); CloseChannels();
SetState(FAILED, error); SetState(FAILED, error);
} }
...@@ -232,7 +228,7 @@ void ConnectionToHost::CloseChannels() { ...@@ -232,7 +228,7 @@ void ConnectionToHost::CloseChannels() {
video_reader_.reset(); video_reader_.reset();
} }
void ConnectionToHost::SetState(State state, Error error) { void ConnectionToHost::SetState(State state, ErrorCode error) {
DCHECK(message_loop_->BelongsToCurrentThread()); DCHECK(message_loop_->BelongsToCurrentThread());
// |error| should be specified only when |state| is set to FAILED. // |error| should be specified only when |state| is set to FAILED.
DCHECK(state == FAILED || error == OK); DCHECK(state == FAILED || error == OK);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "remoting/jingle_glue/signal_strategy.h" #include "remoting/jingle_glue/signal_strategy.h"
#include "remoting/proto/internal.pb.h" #include "remoting/proto/internal.pb.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/input_filter.h" #include "remoting/protocol/input_filter.h"
#include "remoting/protocol/message_reader.h" #include "remoting/protocol/message_reader.h"
#include "remoting/protocol/session.h" #include "remoting/protocol/session.h"
...@@ -52,20 +53,12 @@ class ConnectionToHost : public SignalStrategy::Listener, ...@@ -52,20 +53,12 @@ class ConnectionToHost : public SignalStrategy::Listener,
CLOSED, CLOSED,
}; };
enum Error {
OK,
HOST_IS_OFFLINE,
SESSION_REJECTED,
INCOMPATIBLE_PROTOCOL,
NETWORK_FAILURE,
};
class HostEventCallback { class HostEventCallback {
public: public:
virtual ~HostEventCallback() {} virtual ~HostEventCallback() {}
// Called when state of the connection changes. // Called when state of the connection changes.
virtual void OnConnectionState(State state, Error error) = 0; virtual void OnConnectionState(State state, ErrorCode error) = 0;
}; };
ConnectionToHost(base::MessageLoopProxy* message_loop, ConnectionToHost(base::MessageLoopProxy* message_loop,
...@@ -116,12 +109,12 @@ class ConnectionToHost : public SignalStrategy::Listener, ...@@ -116,12 +109,12 @@ class ConnectionToHost : public SignalStrategy::Listener,
// Callback for |video_reader_|. // Callback for |video_reader_|.
void OnVideoPacket(VideoPacket* packet); void OnVideoPacket(VideoPacket* packet);
void CloseOnError(Error error); void CloseOnError(ErrorCode error);
// Stops writing in the channels. // Stops writing in the channels.
void CloseChannels(); void CloseChannels();
void SetState(State state, Error error); void SetState(State state, ErrorCode error);
scoped_refptr<base::MessageLoopProxy> message_loop_; scoped_refptr<base::MessageLoopProxy> message_loop_;
pp::Instance* pp_instance_; pp::Instance* pp_instance_;
...@@ -148,7 +141,7 @@ class ConnectionToHost : public SignalStrategy::Listener, ...@@ -148,7 +141,7 @@ class ConnectionToHost : public SignalStrategy::Listener,
// Internal state of the connection. // Internal state of the connection.
State state_; State state_;
Error error_; ErrorCode error_;
private: private:
DISALLOW_COPY_AND_ASSIGN(ConnectionToHost); DISALLOW_COPY_AND_ASSIGN(ConnectionToHost);
......
// Copyright (c) 2012 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.
#ifndef REMOTING_PROTOCOL_ERROR_H_
#define REMOTING_PROTOCOL_ERROR_H_
namespace remoting {
namespace protocol {
enum ErrorCode {
OK = 0,
PEER_IS_OFFLINE,
SESSION_REJECTED,
INCOMPATIBLE_PROTOCOL,
AUTHENTICATION_FAILED,
CHANNEL_CONNECTION_ERROR,
SIGNALING_ERROR,
SIGNALING_TIMEOUT,
UNKNOWN_ERROR,
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_ERROR_H_
...@@ -247,7 +247,7 @@ void FakeSession::SetRouteChangeCallback(const RouteChangeCallback& callback) { ...@@ -247,7 +247,7 @@ void FakeSession::SetRouteChangeCallback(const RouteChangeCallback& callback) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
Session::Error FakeSession::error() { ErrorCode FakeSession::error() {
return error_; return error_;
} }
......
...@@ -140,7 +140,7 @@ class FakeSession : public Session { ...@@ -140,7 +140,7 @@ class FakeSession : public Session {
message_loop_ = message_loop; message_loop_ = message_loop;
} }
void set_error(Session::Error error) { error_ = error; } void set_error(ErrorCode error) { error_ = error; }
bool is_closed() const { return closed_; } bool is_closed() const { return closed_; }
...@@ -154,7 +154,7 @@ class FakeSession : public Session { ...@@ -154,7 +154,7 @@ class FakeSession : public Session {
virtual void SetRouteChangeCallback( virtual void SetRouteChangeCallback(
const RouteChangeCallback& callback) OVERRIDE; const RouteChangeCallback& callback) OVERRIDE;
virtual Session::Error error() OVERRIDE; virtual ErrorCode error() OVERRIDE;
virtual void CreateStreamChannel( virtual void CreateStreamChannel(
const std::string& name, const StreamChannelCallback& callback) OVERRIDE; const std::string& name, const StreamChannelCallback& callback) OVERRIDE;
...@@ -182,7 +182,7 @@ class FakeSession : public Session { ...@@ -182,7 +182,7 @@ class FakeSession : public Session {
std::string jid_; std::string jid_;
Session::Error error_; ErrorCode error_;
bool closed_; bool closed_;
DISALLOW_COPY_AND_ASSIGN(FakeSession); DISALLOW_COPY_AND_ASSIGN(FakeSession);
......
...@@ -38,16 +38,16 @@ const int kTransportInfoSendDelayMs = 2; ...@@ -38,16 +38,16 @@ const int kTransportInfoSendDelayMs = 2;
// |transport-info|. // |transport-info|.
const int kMessageResponseTimeoutSeconds = 10; const int kMessageResponseTimeoutSeconds = 10;
Session::Error AuthRejectionReasonToError( ErrorCode AuthRejectionReasonToErrorCode(
Authenticator::RejectionReason reason) { Authenticator::RejectionReason reason) {
switch (reason) { switch (reason) {
case Authenticator::INVALID_CREDENTIALS: case Authenticator::INVALID_CREDENTIALS:
return Session::AUTHENTICATION_FAILED; return AUTHENTICATION_FAILED;
case Authenticator::PROTOCOL_ERROR: case Authenticator::PROTOCOL_ERROR:
return Session::INCOMPATIBLE_PROTOCOL; return INCOMPATIBLE_PROTOCOL;
} }
NOTREACHED(); NOTREACHED();
return Session::UNKNOWN_ERROR; return UNKNOWN_ERROR;
} }
} // namespace } // namespace
...@@ -79,7 +79,7 @@ void JingleSession::SetRouteChangeCallback( ...@@ -79,7 +79,7 @@ void JingleSession::SetRouteChangeCallback(
route_change_callback_ = callback; route_change_callback_ = callback;
} }
Session::Error JingleSession::error() { ErrorCode JingleSession::error() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
return error_; return error_;
} }
...@@ -148,7 +148,7 @@ void JingleSession::AcceptIncomingConnection( ...@@ -148,7 +148,7 @@ void JingleSession::AcceptIncomingConnection(
DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE); DCHECK_EQ(authenticator_->state(), Authenticator::WAITING_MESSAGE);
authenticator_->ProcessMessage(first_auth_message); authenticator_->ProcessMessage(first_auth_message);
if (authenticator_->state() == Authenticator::REJECTED) { if (authenticator_->state() == Authenticator::REJECTED) {
CloseInternal(AuthRejectionReasonToError( CloseInternal(AuthRejectionReasonToErrorCode(
authenticator_->rejection_reason())); authenticator_->rejection_reason()));
return; return;
} }
...@@ -290,15 +290,12 @@ void JingleSession::OnMessageResponse( ...@@ -290,15 +290,12 @@ void JingleSession::OnMessageResponse(
JingleMessage::ActionType request_type, JingleMessage::ActionType request_type,
IqRequest* request, IqRequest* request,
const buzz::XmlElement* response) { const buzz::XmlElement* response) {
Error error = OK;
std::string type_str = JingleMessage::GetActionName(request_type); std::string type_str = JingleMessage::GetActionName(request_type);
CleanupPendingRequests(request);
if (!response) { if (!response) {
LOG(ERROR) << type_str << " request timed out."; LOG(ERROR) << type_str << " request timed out.";
// Most likely the session-initiate timeout indicates a problem CloseInternal(SIGNALING_TIMEOUT);
// with the signaling.
error = UNKNOWN_ERROR;
} else { } else {
const std::string& type = response->Attr(buzz::QName("", "type")); const std::string& type = response->Attr(buzz::QName("", "type"));
if (type != "result") { if (type != "result") {
...@@ -310,21 +307,16 @@ void JingleSession::OnMessageResponse( ...@@ -310,21 +307,16 @@ void JingleSession::OnMessageResponse(
case JingleMessage::SESSION_INFO: case JingleMessage::SESSION_INFO:
// session-info is used for the new authentication protocol, // session-info is used for the new authentication protocol,
// and wasn't previously supported. // and wasn't previously supported.
error = INCOMPATIBLE_PROTOCOL; CloseInternal(INCOMPATIBLE_PROTOCOL);
break;
default: default:
// TODO(sergeyu): There may be different reasons for error // TODO(sergeyu): There may be different reasons for error
// here. Parse the response stanza to find failure reason. // here. Parse the response stanza to find failure reason.
error = PEER_IS_OFFLINE; CloseInternal(PEER_IS_OFFLINE);
} }
} }
} }
CleanupPendingRequests(request);
if (error != OK) {
CloseInternal(error);
}
} }
void JingleSession::CleanupPendingRequests(IqRequest* request) { void JingleSession::CleanupPendingRequests(IqRequest* request) {
...@@ -528,7 +520,7 @@ void JingleSession::ProcessAuthenticationStep() { ...@@ -528,7 +520,7 @@ void JingleSession::ProcessAuthenticationStep() {
if (authenticator_->state() == Authenticator::ACCEPTED) { if (authenticator_->state() == Authenticator::ACCEPTED) {
SetState(AUTHENTICATED); SetState(AUTHENTICATED);
} else if (authenticator_->state() == Authenticator::REJECTED) { } else if (authenticator_->state() == Authenticator::REJECTED) {
CloseInternal(AuthRejectionReasonToError( CloseInternal(AuthRejectionReasonToErrorCode(
authenticator_->rejection_reason())); authenticator_->rejection_reason()));
} }
} }
...@@ -539,7 +531,7 @@ void JingleSession::SendTransportInfo() { ...@@ -539,7 +531,7 @@ void JingleSession::SendTransportInfo() {
SendMessage(message); SendMessage(message);
} }
void JingleSession::CloseInternal(Error error) { void JingleSession::CloseInternal(ErrorCode error) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
if (state_ == CONNECTING || state_ == CONNECTED || state_ == AUTHENTICATED) { if (state_ == CONNECTING || state_ == CONNECTED || state_ == AUTHENTICATED) {
......
...@@ -43,7 +43,7 @@ class JingleSession : public Session, ...@@ -43,7 +43,7 @@ class JingleSession : public Session,
const StateChangeCallback& callback) OVERRIDE; const StateChangeCallback& callback) OVERRIDE;
virtual void SetRouteChangeCallback( virtual void SetRouteChangeCallback(
const RouteChangeCallback& callback) OVERRIDE; const RouteChangeCallback& callback) OVERRIDE;
virtual Error error() OVERRIDE; virtual ErrorCode error() OVERRIDE;
virtual void CreateStreamChannel( virtual void CreateStreamChannel(
const std::string& name, const std::string& name,
const StreamChannelCallback& callback) OVERRIDE; const StreamChannelCallback& callback) OVERRIDE;
...@@ -119,7 +119,7 @@ class JingleSession : public Session, ...@@ -119,7 +119,7 @@ class JingleSession : public Session,
// Terminates the session and sends session-terminate if it is // Terminates the session and sends session-terminate if it is
// necessary. |error| specifies the error code in case when the // necessary. |error| specifies the error code in case when the
// session is being closed due to an error. // session is being closed due to an error.
void CloseInternal(Error error); void CloseInternal(ErrorCode error);
// Sets |state_| to |new_state| and calls state change callback. // Sets |state_| to |new_state| and calls state change callback.
void SetState(State new_state); void SetState(State new_state);
...@@ -132,7 +132,7 @@ class JingleSession : public Session, ...@@ -132,7 +132,7 @@ class JingleSession : public Session,
std::string session_id_; std::string session_id_;
State state_; State state_;
Error error_; ErrorCode error_;
SessionConfig config_; SessionConfig config_;
bool config_is_set_; bool config_is_set_;
......
...@@ -46,7 +46,7 @@ class MockConnectionToClientEventHandler : ...@@ -46,7 +46,7 @@ class MockConnectionToClientEventHandler :
MOCK_METHOD1(OnConnectionOpened, void(ConnectionToClient* connection)); MOCK_METHOD1(OnConnectionOpened, void(ConnectionToClient* connection));
MOCK_METHOD1(OnConnectionClosed, void(ConnectionToClient* connection)); MOCK_METHOD1(OnConnectionClosed, void(ConnectionToClient* connection));
MOCK_METHOD2(OnConnectionFailed, void(ConnectionToClient* connection, MOCK_METHOD2(OnConnectionFailed, void(ConnectionToClient* connection,
Session::Error error)); ErrorCode error));
MOCK_METHOD2(OnSequenceNumberUpdated, void(ConnectionToClient* connection, MOCK_METHOD2(OnSequenceNumberUpdated, void(ConnectionToClient* connection,
int64 sequence_number)); int64 sequence_number));
MOCK_METHOD4(OnRouteChange, void( MOCK_METHOD4(OnRouteChange, void(
...@@ -111,7 +111,7 @@ class MockSession : public Session { ...@@ -111,7 +111,7 @@ class MockSession : public Session {
void(const StateChangeCallback& callback)); void(const StateChangeCallback& callback));
MOCK_METHOD1(SetRouteChangeCallback, MOCK_METHOD1(SetRouteChangeCallback,
void(const RouteChangeCallback& callback)); void(const RouteChangeCallback& callback));
MOCK_METHOD0(error, Session::Error()); MOCK_METHOD0(error, ErrorCode());
MOCK_METHOD2(CreateStreamChannel, void( MOCK_METHOD2(CreateStreamChannel, void(
const std::string& name, const StreamChannelCallback& callback)); const std::string& name, const StreamChannelCallback& callback));
MOCK_METHOD2(CreateDatagramChannel, void( MOCK_METHOD2(CreateDatagramChannel, void(
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/threading/non_thread_safe.h" #include "base/threading/non_thread_safe.h"
#include "remoting/protocol/buffered_socket_writer.h" #include "remoting/protocol/buffered_socket_writer.h"
#include "remoting/protocol/errors.h"
#include "remoting/protocol/session_config.h" #include "remoting/protocol/session_config.h"
namespace net { namespace net {
...@@ -53,17 +54,6 @@ class Session : public base::NonThreadSafe { ...@@ -53,17 +54,6 @@ class Session : public base::NonThreadSafe {
FAILED, FAILED,
}; };
// TODO(sergeyu): Move error codes to a separate file.
enum Error {
OK = 0,
PEER_IS_OFFLINE,
SESSION_REJECTED,
INCOMPATIBLE_PROTOCOL,
AUTHENTICATION_FAILED,
CHANNEL_CONNECTION_ERROR,
UNKNOWN_ERROR,
};
// State change callbacks are called after session state has // State change callbacks are called after session state has
// changed. It is not safe to destroy the session from within the // changed. It is not safe to destroy the session from within the
// handler unless |state| is CLOSED or FAILED. // handler unless |state| is CLOSED or FAILED.
...@@ -95,7 +85,7 @@ class Session : public base::NonThreadSafe { ...@@ -95,7 +85,7 @@ class Session : public base::NonThreadSafe {
virtual void SetRouteChangeCallback(const RouteChangeCallback& callback) = 0; virtual void SetRouteChangeCallback(const RouteChangeCallback& callback) = 0;
// Returns error code for a failed session. // Returns error code for a failed session.
virtual Error error() = 0; virtual ErrorCode error() = 0;
// Creates new channels for this connection. The specified callback // Creates new channels for this connection. The specified callback
// is called when then new channel is created and connected. The // is called when then new channel is created and connected. The
......
...@@ -792,6 +792,7 @@ ...@@ -792,6 +792,7 @@
'protocol/connection_to_host.h', 'protocol/connection_to_host.h',
'protocol/content_description.cc', 'protocol/content_description.cc',
'protocol/content_description.h', 'protocol/content_description.h',
'protocol/errors.h',
'protocol/host_control_dispatcher.cc', 'protocol/host_control_dispatcher.cc',
'protocol/host_control_dispatcher.h', 'protocol/host_control_dispatcher.h',
'protocol/host_event_dispatcher.cc', 'protocol/host_event_dispatcher.cc',
......
...@@ -119,16 +119,22 @@ remoting.ClientPluginAsync.prototype.handleMessage_ = function(message_str) { ...@@ -119,16 +119,22 @@ remoting.ClientPluginAsync.prototype.handleMessage_ = function(message_str) {
} else if (message.method == 'onConnectionStatus') { } else if (message.method == 'onConnectionStatus') {
if (typeof message.data['state'] != 'string' || if (typeof message.data['state'] != 'string' ||
!(message.data['state'] in remoting.ClientSession.State) || !(message.data['state'] in remoting.ClientSession.State) ||
typeof message.data['error'] != 'string' || typeof message.data['error'] != 'string') {
!(message.data['error'] in remoting.ClientSession.ConnectionError)) {
console.error('Received invalid onConnectionState message: ' + console.error('Received invalid onConnectionState message: ' +
message_str); message_str);
return; return;
} }
/** @type {remoting.ClientSession.State} */ /** @type {remoting.ClientSession.State} */
var state = remoting.ClientSession.State[message.data['state']]; var state = remoting.ClientSession.State[message.data['state']];
/** @type {remoting.ClientSession.ConnectionError} */ var error;
var error = remoting.ClientSession.ConnectionError[message.data['error']]; if (message.data['error'] in remoting.ClientSession.ConnectionError) {
error = /** @type {remoting.ClientSession.ConnectionError} */
remoting.ClientSession.ConnectionError[message.data['error']];
} else {
error = remoting.ClientSession.ConnectionError.UNKNOWN;
}
this.onConnectionStatusUpdateHandler(state, error); this.onConnectionStatusUpdateHandler(state, error);
} else if (message.method == 'onDesktopSize') { } else if (message.method == 'onDesktopSize') {
if (typeof message.data['width'] != 'number' || if (typeof message.data['width'] != 'number' ||
......
...@@ -83,6 +83,7 @@ remoting.ClientSession.State = { ...@@ -83,6 +83,7 @@ remoting.ClientSession.State = {
/** @enum {number} */ /** @enum {number} */
remoting.ClientSession.ConnectionError = { remoting.ClientSession.ConnectionError = {
UNKNOWN: -1,
NONE: 0, NONE: 0,
HOST_IS_OFFLINE: 1, HOST_IS_OFFLINE: 1,
SESSION_REJECTED: 2, SESSION_REJECTED: 2,
......
...@@ -88,6 +88,8 @@ remoting.ServerLogEntry.getValueForConnectionError = ...@@ -88,6 +88,8 @@ remoting.ServerLogEntry.getValueForConnectionError =
return 'incompatible-protocol'; return 'incompatible-protocol';
case remoting.ClientSession.ConnectionError.NETWORK_FAILURE: case remoting.ClientSession.ConnectionError.NETWORK_FAILURE:
return 'network-failure'; return 'network-failure';
case remoting.ClientSession.ConnectionError.UNKNOWN:
return 'unknown';
default: default:
return 'unknown-' + connectionError; return 'unknown-' + connectionError;
} }
......
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