diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-20 04:10:52 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-20 04:10:52 +0000 |
commit | 5bf5231373631d2ed940ad9eb03da77132411f57 (patch) | |
tree | ce46ce9f8c4c9b387734adef17de07ca9e306af7 /remoting | |
parent | 0bc93ad3a6030cac29eae47feba2704b92b9f15a (diff) | |
download | chromium_src-5bf5231373631d2ed940ad9eb03da77132411f57.zip chromium_src-5bf5231373631d2ed940ad9eb03da77132411f57.tar.gz chromium_src-5bf5231373631d2ed940ad9eb03da77132411f57.tar.bz2 |
Use scoped_ptr<>.Pass() to pass ownership in the remoting protocol code.
Review URL: https://chromiumcodereview.appspot.com/9240033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
41 files changed, 257 insertions, 249 deletions
diff --git a/remoting/protocol/authenticator.cc b/remoting/protocol/authenticator.cc index 23f77e1..168af76 100644 --- a/remoting/protocol/authenticator.cc +++ b/remoting/protocol/authenticator.cc @@ -21,8 +21,9 @@ bool Authenticator::IsAuthenticatorMessage(const buzz::XmlElement* message) { } // static -buzz::XmlElement* Authenticator::CreateEmptyAuthenticatorMessage() { - return new buzz::XmlElement(kAuthenticationQName); +scoped_ptr<buzz::XmlElement> Authenticator::CreateEmptyAuthenticatorMessage() { + return scoped_ptr<buzz::XmlElement>( + new buzz::XmlElement(kAuthenticationQName)); } // static diff --git a/remoting/protocol/authenticator.h b/remoting/protocol/authenticator.h index b79fe78..1a0931a 100644 --- a/remoting/protocol/authenticator.h +++ b/remoting/protocol/authenticator.h @@ -7,6 +7,8 @@ #include <string> +#include "base/memory/scoped_ptr.h" + namespace buzz { class XmlElement; } // namespace buzz @@ -57,7 +59,7 @@ class Authenticator { static bool IsAuthenticatorMessage(const buzz::XmlElement* message); // Creates an empty Authenticator message, owned by the caller. - static buzz::XmlElement* CreateEmptyAuthenticatorMessage(); + static scoped_ptr<buzz::XmlElement> CreateEmptyAuthenticatorMessage(); // Finds Authenticator message among child elements of |message|, or // returns NULL otherwise. @@ -77,12 +79,12 @@ class Authenticator { // Must be called when in MESSAGE_READY state. Returns next // authentication message that needs to be sent to the peer. - virtual buzz::XmlElement* GetNextMessage() = 0; + virtual scoped_ptr<buzz::XmlElement> GetNextMessage() = 0; - // Creates new authenticator for a channel. Caller must take - // ownership of the result. Can be called only in the ACCEPTED - // state. - virtual ChannelAuthenticator* CreateChannelAuthenticator() const = 0; + // Creates new authenticator for a channel. Can be called only in + // the ACCEPTED state. + virtual scoped_ptr<ChannelAuthenticator> + CreateChannelAuthenticator() const = 0; }; // Factory for Authenticator instances. @@ -99,7 +101,7 @@ class AuthenticatorFactory { // if the |first_message| is invalid and the session should be // rejected. ProcessMessage() should be called with |first_message| // for the result of this method. - virtual Authenticator* CreateAuthenticator( + virtual scoped_ptr<Authenticator> CreateAuthenticator( const std::string& remote_jid, const buzz::XmlElement* first_message) = 0; }; diff --git a/remoting/protocol/connection_to_host.cc b/remoting/protocol/connection_to_host.cc index 9d00f8d..879e1b2 100644 --- a/remoting/protocol/connection_to_host.cc +++ b/remoting/protocol/connection_to_host.cc @@ -124,14 +124,14 @@ void ConnectionToHost::OnSessionManagerReady() { DCHECK(message_loop_->BelongsToCurrentThread()); // After SessionManager is initialized we can try to connect to the host. - CandidateSessionConfig* candidate_config = + scoped_ptr<CandidateSessionConfig> candidate_config = CandidateSessionConfig::CreateDefault(); - V1ClientAuthenticator* authenticator = - new V1ClientAuthenticator(signal_strategy_->GetLocalJid(), access_code_); - session_.reset(session_manager_->Connect( - host_jid_, authenticator, candidate_config, + scoped_ptr<Authenticator> authenticator( + new V1ClientAuthenticator(signal_strategy_->GetLocalJid(), access_code_)); + session_ = session_manager_->Connect( + host_jid_, authenticator.Pass(), candidate_config.Pass(), base::Bind(&ConnectionToHost::OnSessionStateChange, - base::Unretained(this)))); + base::Unretained(this))); } void ConnectionToHost::OnIncomingSession( diff --git a/remoting/protocol/content_description.cc b/remoting/protocol/content_description.cc index 15583b0..5e157ad 100644 --- a/remoting/protocol/content_description.cc +++ b/remoting/protocol/content_description.cc @@ -146,10 +146,10 @@ bool ParseChannelConfig(const XmlElement* element, bool codec_required, } // namespace ContentDescription::ContentDescription( - const CandidateSessionConfig* candidate_config, - const buzz::XmlElement* authenticator_message) - : candidate_config_(candidate_config), - authenticator_message_(authenticator_message) { + scoped_ptr<CandidateSessionConfig> config, + scoped_ptr<buzz::XmlElement> authenticator_message) + : candidate_config_(config.Pass()), + authenticator_message_(authenticator_message.Pass()) { } ContentDescription::~ContentDescription() { } @@ -247,8 +247,7 @@ ContentDescription* ContentDescription::ParseXml( if (child) authenticator_message.reset(new XmlElement(*child)); - return new ContentDescription( - config.release(), authenticator_message.release()); + return new ContentDescription(config.Pass(), authenticator_message.Pass()); } LOG(ERROR) << "Invalid description: " << element->Str(); return NULL; diff --git a/remoting/protocol/content_description.h b/remoting/protocol/content_description.h index 95ccf60..cc66ac5 100644 --- a/remoting/protocol/content_description.h +++ b/remoting/protocol/content_description.h @@ -28,9 +28,8 @@ class ContentDescription : public cricket::ContentDescription { public: static const char kChromotingContentName[]; - // Takes ownership of |config| and |authenticator_message|. - ContentDescription(const CandidateSessionConfig* config, - const buzz::XmlElement* authenticator_message); + ContentDescription(scoped_ptr<CandidateSessionConfig> config, + scoped_ptr<buzz::XmlElement> authenticator_message); virtual ~ContentDescription(); const CandidateSessionConfig* config() const { diff --git a/remoting/protocol/fake_authenticator.cc b/remoting/protocol/fake_authenticator.cc index 5591221..4be9b74 100644 --- a/remoting/protocol/fake_authenticator.cc +++ b/remoting/protocol/fake_authenticator.cc @@ -97,24 +97,25 @@ void FakeAuthenticator::ProcessMessage(const buzz::XmlElement* message) { ++messages_; } -buzz::XmlElement* FakeAuthenticator::GetNextMessage() { +scoped_ptr<buzz::XmlElement> FakeAuthenticator::GetNextMessage() { EXPECT_EQ(MESSAGE_READY, state()); - buzz::XmlElement* result = new buzz::XmlElement( - buzz::QName(kChromotingXmlNamespace, "authentication")); + scoped_ptr<buzz::XmlElement> result(new buzz::XmlElement( + buzz::QName(kChromotingXmlNamespace, "authentication"))); buzz::XmlElement* id = new buzz::XmlElement( buzz::QName(kChromotingXmlNamespace, "id")); id->AddText(base::IntToString(messages_)); result->AddElement(id); ++messages_; - return result; + return result.Pass(); } -ChannelAuthenticator* +scoped_ptr<ChannelAuthenticator> FakeAuthenticator::CreateChannelAuthenticator() const { EXPECT_EQ(ACCEPTED, state()); - return new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_); + return scoped_ptr<ChannelAuthenticator>( + new FakeChannelAuthenticator(action_ != REJECT_CHANNEL, async_)); } FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( @@ -126,11 +127,11 @@ FakeHostAuthenticatorFactory::FakeHostAuthenticatorFactory( FakeHostAuthenticatorFactory::~FakeHostAuthenticatorFactory() { } -Authenticator* FakeHostAuthenticatorFactory::CreateAuthenticator( +scoped_ptr<Authenticator> FakeHostAuthenticatorFactory::CreateAuthenticator( const std::string& remote_jid, const buzz::XmlElement* first_message) { - return new FakeAuthenticator(FakeAuthenticator::HOST, round_trips_, - action_, async_); + return scoped_ptr<Authenticator>(new FakeAuthenticator( + FakeAuthenticator::HOST, round_trips_, action_, async_)); } } // namespace protocol diff --git a/remoting/protocol/fake_authenticator.h b/remoting/protocol/fake_authenticator.h index 10abe80..a1a6db5 100644 --- a/remoting/protocol/fake_authenticator.h +++ b/remoting/protocol/fake_authenticator.h @@ -54,8 +54,9 @@ class FakeAuthenticator : public Authenticator { // Authenticator interface. virtual State state() const OVERRIDE; virtual void ProcessMessage(const buzz::XmlElement* message) OVERRIDE; - virtual buzz::XmlElement* GetNextMessage() OVERRIDE; - virtual ChannelAuthenticator* CreateChannelAuthenticator() const OVERRIDE; + virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; + virtual scoped_ptr<ChannelAuthenticator> + CreateChannelAuthenticator() const OVERRIDE; protected: Type type_; @@ -76,7 +77,7 @@ class FakeHostAuthenticatorFactory : public AuthenticatorFactory { virtual ~FakeHostAuthenticatorFactory(); // AuthenticatorFactory interface. - virtual Authenticator* CreateAuthenticator( + virtual scoped_ptr<Authenticator> CreateAuthenticator( const std::string& remote_jid, const buzz::XmlElement* first_message) OVERRIDE; diff --git a/remoting/protocol/it2me_host_authenticator_factory.cc b/remoting/protocol/it2me_host_authenticator_factory.cc index 21809de..64c928c 100644 --- a/remoting/protocol/it2me_host_authenticator_factory.cc +++ b/remoting/protocol/it2me_host_authenticator_factory.cc @@ -24,7 +24,7 @@ It2MeHostAuthenticatorFactory::It2MeHostAuthenticatorFactory( It2MeHostAuthenticatorFactory::~It2MeHostAuthenticatorFactory() { } -Authenticator* It2MeHostAuthenticatorFactory::CreateAuthenticator( +scoped_ptr<Authenticator> It2MeHostAuthenticatorFactory::CreateAuthenticator( const std::string& remote_jid, const buzz::XmlElement* first_message) { // TODO(sergeyu): V2 authenticator is not finished yet. Enable it @@ -35,8 +35,8 @@ Authenticator* It2MeHostAuthenticatorFactory::CreateAuthenticator( // local_cert_, *local_private_key_, shared_secret_); // } - return new V1HostAuthenticator(local_cert_, *local_private_key_, - shared_secret_, remote_jid); + return scoped_ptr<Authenticator>(new V1HostAuthenticator( + local_cert_, *local_private_key_, shared_secret_, remote_jid)); } } // namespace protocol diff --git a/remoting/protocol/it2me_host_authenticator_factory.h b/remoting/protocol/it2me_host_authenticator_factory.h index a924334..aa04009 100644 --- a/remoting/protocol/it2me_host_authenticator_factory.h +++ b/remoting/protocol/it2me_host_authenticator_factory.h @@ -30,7 +30,7 @@ class It2MeHostAuthenticatorFactory : public AuthenticatorFactory { virtual ~It2MeHostAuthenticatorFactory(); // AuthenticatorFactory interface. - virtual Authenticator* CreateAuthenticator( + virtual scoped_ptr<Authenticator> CreateAuthenticator( const std::string& remote_jid, const buzz::XmlElement* first_message) OVERRIDE; diff --git a/remoting/protocol/jingle_channel_connector.h b/remoting/protocol/jingle_channel_connector.h index 09c8150..41c3692 100644 --- a/remoting/protocol/jingle_channel_connector.h +++ b/remoting/protocol/jingle_channel_connector.h @@ -28,9 +28,8 @@ class JingleChannelConnector : public base::NonThreadSafe { JingleChannelConnector() { } virtual ~JingleChannelConnector() { } - // Starts the connection process for the channel. Takes ownership of - // |authenticator|. - virtual void Connect(ChannelAuthenticator* authenticator, + // Starts the connection process for the channel. + virtual void Connect(scoped_ptr<ChannelAuthenticator> authenticator, cricket::TransportChannel* raw_channel) = 0; protected: diff --git a/remoting/protocol/jingle_datagram_connector.cc b/remoting/protocol/jingle_datagram_connector.cc index 4673efc..b73137e 100644 --- a/remoting/protocol/jingle_datagram_connector.cc +++ b/remoting/protocol/jingle_datagram_connector.cc @@ -24,11 +24,11 @@ JingleDatagramConnector::~JingleDatagramConnector() { } void JingleDatagramConnector::Connect( - ChannelAuthenticator* authenticator, + scoped_ptr<ChannelAuthenticator> authenticator, cricket::TransportChannel* raw_channel) { DCHECK(CalledOnValidThread()); - authenticator_.reset(authenticator); + authenticator_ = authenticator.Pass(); net::Socket* socket = new jingle_glue::TransportChannelSocketAdapter(raw_channel); diff --git a/remoting/protocol/jingle_datagram_connector.h b/remoting/protocol/jingle_datagram_connector.h index 930ec0f..7814e16 100644 --- a/remoting/protocol/jingle_datagram_connector.h +++ b/remoting/protocol/jingle_datagram_connector.h @@ -27,7 +27,7 @@ class JingleDatagramConnector : public JingleChannelConnector { // TODO(sergeyu): In the current implementation ChannelAuthenticator // cannot be used for datagram channels, so needs to be either // extended or replaced with something else here. - virtual void Connect(ChannelAuthenticator* authenticator, + virtual void Connect(scoped_ptr<ChannelAuthenticator> authenticator, cricket::TransportChannel* raw_channel) OVERRIDE; private: diff --git a/remoting/protocol/jingle_session.cc b/remoting/protocol/jingle_session.cc index ae1009e..1b3c1a9 100644 --- a/remoting/protocol/jingle_session.cc +++ b/remoting/protocol/jingle_session.cc @@ -33,9 +33,9 @@ namespace protocol { JingleSession::JingleSession( JingleSessionManager* jingle_session_manager, cricket::Session* cricket_session, - Authenticator* authenticator) + scoped_ptr<Authenticator> authenticator) : jingle_session_manager_(jingle_session_manager), - authenticator_(authenticator), + authenticator_(authenticator.Pass()), state_(INITIALIZING), error_(OK), closing_(false), @@ -62,8 +62,9 @@ JingleSession::~JingleSession() { void JingleSession::SendSessionInitiate() { DCHECK_EQ(authenticator_->state(), Authenticator::MESSAGE_READY); cricket_session_->Initiate( - jid_, CreateSessionDescription(candidate_config()->Clone(), - authenticator_->GetNextMessage())); + jid_, CreateSessionDescription( + candidate_config()->Clone(), + authenticator_->GetNextMessage()).release()); } void JingleSession::CloseInternal(int result, Error error) { @@ -172,11 +173,11 @@ const CandidateSessionConfig* JingleSession::candidate_config() { } void JingleSession::set_candidate_config( - const CandidateSessionConfig* candidate_config) { + scoped_ptr<CandidateSessionConfig> candidate_config) { DCHECK(CalledOnValidThread()); DCHECK(!candidate_config_.get()); - DCHECK(candidate_config); - candidate_config_.reset(candidate_config); + DCHECK(candidate_config.get()); + candidate_config_ = candidate_config.Pass(); } const SessionConfig& JingleSession::config() { @@ -384,7 +385,7 @@ void JingleSession::AcceptConnection() { CHECK(content); const ContentDescription* content_description = static_cast<const ContentDescription*>(content->description); - candidate_config_.reset(content_description->config()->Clone()); + candidate_config_ = content_description->config()->Clone(); SessionManager::IncomingSessionResponse response = jingle_session_manager_->AcceptConnection(this); @@ -411,8 +412,8 @@ void JingleSession::AcceptConnection() { return; } - authenticator_.reset( - jingle_session_manager_->CreateAuthenticator(jid(), auth_message)); + authenticator_ = + jingle_session_manager_->CreateAuthenticator(jid(), auth_message); if (!authenticator_.get()) { CloseInternal(net::ERR_CONNECTION_FAILED, INCOMPATIBLE_PROTOCOL); return; @@ -426,24 +427,26 @@ void JingleSession::AcceptConnection() { } // Connection must be configured by the AcceptConnection() callback. - CandidateSessionConfig* candidate_config = + scoped_ptr<CandidateSessionConfig> candidate_config = CandidateSessionConfig::CreateFrom(config()); - buzz::XmlElement* auth_reply = NULL; + scoped_ptr<buzz::XmlElement> auth_reply; if (authenticator_->state() == Authenticator::MESSAGE_READY) auth_reply = authenticator_->GetNextMessage(); DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); cricket_session_->Accept( - CreateSessionDescription(candidate_config, auth_reply)); + CreateSessionDescription(candidate_config.Pass(), + auth_reply.Pass()).release()); } void JingleSession::ProcessAuthenticationStep() { DCHECK_EQ(state_, CONNECTED); if (authenticator_->state() == Authenticator::MESSAGE_READY) { - buzz::XmlElement* auth_message = authenticator_->GetNextMessage(); + scoped_ptr<buzz::XmlElement> auth_message = + authenticator_->GetNextMessage(); cricket::XmlElements message; - message.push_back(auth_message); + message.push_back(auth_message.release()); cricket_session_->SendInfoMessage(message); } DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); @@ -471,9 +474,9 @@ void JingleSession::AddChannelConnector( } channel_connectors_[name] = connector; - ChannelAuthenticator* authenticator = + scoped_ptr<ChannelAuthenticator> authenticator = authenticator_->CreateChannelAuthenticator(); - connector->Connect(authenticator, raw_channel); + connector->Connect(authenticator.Pass(), raw_channel); // Workaround bug in libjingle - it doesn't connect channels if they // are created after the session is accepted. See crbug.com/89384. @@ -517,14 +520,15 @@ void JingleSession::SetState(State new_state) { } // static -cricket::SessionDescription* JingleSession::CreateSessionDescription( - const CandidateSessionConfig* config, - const buzz::XmlElement* authenticator_message) { - cricket::SessionDescription* desc = new cricket::SessionDescription(); +scoped_ptr<cricket::SessionDescription> JingleSession::CreateSessionDescription( + scoped_ptr<CandidateSessionConfig> config, + scoped_ptr<buzz::XmlElement> authenticator_message) { + scoped_ptr<cricket::SessionDescription> desc( + new cricket::SessionDescription()); desc->AddContent( ContentDescription::kChromotingContentName, kChromotingXmlNamespace, - new ContentDescription(config, authenticator_message)); - return desc; + new ContentDescription(config.Pass(), authenticator_message.Pass())); + return desc.Pass(); } } // namespace protocol diff --git a/remoting/protocol/jingle_session.h b/remoting/protocol/jingle_session.h index 7ab5f14..3230f57 100644 --- a/remoting/protocol/jingle_session.h +++ b/remoting/protocol/jingle_session.h @@ -25,6 +25,8 @@ class JingleSessionManager; class JingleSession : public protocol::Session, public sigslot::has_slots<> { public: + virtual ~JingleSession(); + // Session interface. virtual void SetStateChangeCallback( const StateChangeCallback& callback) OVERRIDE; @@ -49,14 +51,13 @@ class JingleSession : public protocol::Session, typedef std::map<std::string, JingleChannelConnector*> ChannelConnectorsMap; - // Takes ownership of |authenticator|. JingleSession(JingleSessionManager* jingle_session_manager, cricket::Session* cricket_session, - Authenticator* authenticator); - virtual ~JingleSession(); + scoped_ptr<Authenticator> authenticator); // Called by JingleSessionManager. - void set_candidate_config(const CandidateSessionConfig* candidate_config); + void set_candidate_config( + scoped_ptr<CandidateSessionConfig> candidate_config); // Sends session-initiate for new session. void SendSessionInitiate(); @@ -107,9 +108,9 @@ class JingleSession : public protocol::Session, void SetState(State new_state); - static cricket::SessionDescription* CreateSessionDescription( - const CandidateSessionConfig* candidate_config, - const buzz::XmlElement* authenticator_message); + static scoped_ptr<cricket::SessionDescription> CreateSessionDescription( + scoped_ptr<CandidateSessionConfig> candidate_config, + scoped_ptr<buzz::XmlElement> authenticator_message); // JingleSessionManager that created this session. Guaranteed to // exist throughout the lifetime of the session. diff --git a/remoting/protocol/jingle_session_manager.cc b/remoting/protocol/jingle_session_manager.cc index 60d84e7..b92f0f4 100644 --- a/remoting/protocol/jingle_session_manager.cc +++ b/remoting/protocol/jingle_session_manager.cc @@ -122,10 +122,10 @@ void JingleSessionManager::set_authenticator_factory( authenticator_factory_ = authenticator_factory.Pass(); } -Session* JingleSessionManager::Connect( +scoped_ptr<Session> JingleSessionManager::Connect( const std::string& host_jid, - Authenticator* authenticator, - CandidateSessionConfig* candidate_config, + scoped_ptr<Authenticator> authenticator, + scoped_ptr<CandidateSessionConfig> config, const Session::StateChangeCallback& state_change_callback) { DCHECK(CalledOnValidThread()); @@ -133,15 +133,15 @@ Session* JingleSessionManager::Connect( signal_strategy_->GetLocalJid(), kChromotingXmlNamespace); cricket_session->set_remote_name(host_jid); - JingleSession* jingle_session = - new JingleSession(this, cricket_session, authenticator); - jingle_session->set_candidate_config(candidate_config); + scoped_ptr<JingleSession> jingle_session( + new JingleSession(this, cricket_session, authenticator.Pass())); + jingle_session->set_candidate_config(config.Pass()); jingle_session->SetStateChangeCallback(state_change_callback); - sessions_.push_back(jingle_session); + sessions_.push_back(jingle_session.get()); jingle_session->SendSessionInitiate(); - return jingle_session; + return scoped_ptr<Session>(jingle_session.Pass()); } void JingleSessionManager::OnSessionCreate( @@ -153,7 +153,7 @@ void JingleSessionManager::OnSessionCreate( if (incoming) { JingleSession* jingle_session = - new JingleSession(this, cricket_session, NULL); + new JingleSession(this, cricket_session, scoped_ptr<Authenticator>()); sessions_.push_back(jingle_session); } } @@ -198,12 +198,12 @@ SessionManager::IncomingSessionResponse JingleSessionManager::AcceptConnection( return response; } -Authenticator* JingleSessionManager::CreateAuthenticator( +scoped_ptr<Authenticator> JingleSessionManager::CreateAuthenticator( const std::string& jid, const buzz::XmlElement* auth_message) { DCHECK(CalledOnValidThread()); if (!authenticator_factory_.get()) - return NULL; + return scoped_ptr<Authenticator>(NULL); return authenticator_factory_->CreateAuthenticator(jid, auth_message); } diff --git a/remoting/protocol/jingle_session_manager.h b/remoting/protocol/jingle_session_manager.h index cb5c8ab..f56ee74 100644 --- a/remoting/protocol/jingle_session_manager.h +++ b/remoting/protocol/jingle_session_manager.h @@ -44,10 +44,10 @@ class JingleSessionManager : public SessionManager, virtual void Init(SignalStrategy* signal_strategy, SessionManager::Listener* listener, const NetworkSettings& network_settings) OVERRIDE; - virtual Session* Connect( + virtual scoped_ptr<Session> Connect( const std::string& host_jid, - Authenticator* authenticator, - CandidateSessionConfig* config, + scoped_ptr<Authenticator> authenticator, + scoped_ptr<CandidateSessionConfig> config, const Session::StateChangeCallback& state_change_callback) OVERRIDE; virtual void Close() OVERRIDE; virtual void set_authenticator_factory( @@ -80,10 +80,10 @@ class JingleSessionManager : public SessionManager, // Creates authenticator for incoming session. Returns NULL if // authenticator cannot be created, e.g. if |auth_message| is - // invalid. Caller reatins ownership of |auth_message| and must - // accept ownership of the result. - Authenticator* CreateAuthenticator(const std::string& jid, - const buzz::XmlElement* auth_message); + // invalid. + scoped_ptr<Authenticator> CreateAuthenticator( + const std::string& jid, + const buzz::XmlElement* auth_message); // Called by JingleSession when it is being destroyed. void SessionDestroyed(JingleSession* jingle_session); diff --git a/remoting/protocol/jingle_session_unittest.cc b/remoting/protocol/jingle_session_unittest.cc index 441e19b..2dab493 100644 --- a/remoting/protocol/jingle_session_unittest.cc +++ b/remoting/protocol/jingle_session_unittest.cc @@ -206,14 +206,14 @@ class JingleSessionTest : public testing::Test { } } - Authenticator* authenticator = new FakeAuthenticator( - FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true); + scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( + FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); - client_session_.reset(client_server_->Connect( - kHostJid, authenticator, + client_session_ = client_server_->Connect( + kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault(), base::Bind(&MockSessionCallback::OnStateChange, - base::Unretained(&client_connection_callback_)))); + base::Unretained(&client_connection_callback_))); message_loop_.RunAllPending(); @@ -308,13 +308,12 @@ TEST_F(JingleSessionTest, RejectConnection) { .Times(1); } - Authenticator* authenticator = new FakeAuthenticator( - FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true); - client_session_.reset(client_server_->Connect( - kHostJid, authenticator, - CandidateSessionConfig::CreateDefault(), + scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( + FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); + client_session_ = client_server_->Connect( + kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault(), base::Bind(&MockSessionCallback::OnStateChange, - base::Unretained(&client_connection_callback_)))); + base::Unretained(&client_connection_callback_))); message_loop_.RunAllPending(); } diff --git a/remoting/protocol/jingle_stream_connector.cc b/remoting/protocol/jingle_stream_connector.cc index d7ce7fa..a5e2ed8 100644 --- a/remoting/protocol/jingle_stream_connector.cc +++ b/remoting/protocol/jingle_stream_connector.cc @@ -47,12 +47,13 @@ JingleStreamConnector::JingleStreamConnector( JingleStreamConnector::~JingleStreamConnector() { } -void JingleStreamConnector::Connect(ChannelAuthenticator* authenticator, - cricket::TransportChannel* raw_channel) { +void JingleStreamConnector::Connect( + scoped_ptr<ChannelAuthenticator> authenticator, + cricket::TransportChannel* raw_channel) { DCHECK(CalledOnValidThread()); DCHECK(!raw_channel_); - authenticator_.reset(authenticator); + authenticator_ = authenticator.Pass(); raw_channel_ = raw_channel; net::Socket* socket = diff --git a/remoting/protocol/jingle_stream_connector.h b/remoting/protocol/jingle_stream_connector.h index 1dd0240b..445d618 100644 --- a/remoting/protocol/jingle_stream_connector.h +++ b/remoting/protocol/jingle_stream_connector.h @@ -42,7 +42,7 @@ class JingleStreamConnector : public JingleChannelConnector { virtual ~JingleStreamConnector(); // JingleChannelConnector implementation. - virtual void Connect(ChannelAuthenticator* authenticator, + virtual void Connect(scoped_ptr<ChannelAuthenticator> authenticator, cricket::TransportChannel* raw_channel) OVERRIDE; private: diff --git a/remoting/protocol/me2me_host_authenticator_factory.cc b/remoting/protocol/me2me_host_authenticator_factory.cc index 758f531..db7cc4c 100644 --- a/remoting/protocol/me2me_host_authenticator_factory.cc +++ b/remoting/protocol/me2me_host_authenticator_factory.cc @@ -28,13 +28,13 @@ Me2MeHostAuthenticatorFactory::Me2MeHostAuthenticatorFactory( Me2MeHostAuthenticatorFactory::~Me2MeHostAuthenticatorFactory() { } -Authenticator* Me2MeHostAuthenticatorFactory::CreateAuthenticator( +scoped_ptr<Authenticator> Me2MeHostAuthenticatorFactory::CreateAuthenticator( const std::string& remote_jid, const buzz::XmlElement* first_message) { // Reject incoming connection if the client's jid is not an ASCII string. if (!IsStringASCII(remote_jid)) { LOG(ERROR) << "Rejecting incoming connection from " << remote_jid; - return NULL; + return scoped_ptr<Authenticator>(NULL); } // Check that the client has the same bare jid as the host, i.e. @@ -42,7 +42,7 @@ Authenticator* Me2MeHostAuthenticatorFactory::CreateAuthenticator( // insensitive. if (!StartsWithASCII(remote_jid, local_jid_prefix_, false)) { LOG(ERROR) << "Rejecting incoming connection from " << remote_jid; - return NULL; + return scoped_ptr<Authenticator>(NULL); } // TODO(sergeyu): V2 authenticator is not finished yet. Enable it @@ -55,8 +55,9 @@ Authenticator* Me2MeHostAuthenticatorFactory::CreateAuthenticator( // TODO(sergeyu): Old clients still use V1 auth protocol. Remove // this once we are done migrating to V2. - return new V1HostAuthenticator(local_cert_, *local_private_key_, - shared_secret_, remote_jid); + return scoped_ptr<Authenticator>(new V1HostAuthenticator( + local_cert_, *local_private_key_, + shared_secret_, remote_jid)); } } // namespace protocol diff --git a/remoting/protocol/me2me_host_authenticator_factory.h b/remoting/protocol/me2me_host_authenticator_factory.h index dfbccde..e20cea6 100644 --- a/remoting/protocol/me2me_host_authenticator_factory.h +++ b/remoting/protocol/me2me_host_authenticator_factory.h @@ -29,7 +29,7 @@ class Me2MeHostAuthenticatorFactory : public AuthenticatorFactory { virtual ~Me2MeHostAuthenticatorFactory(); // AuthenticatorFactory interface. - virtual Authenticator* CreateAuthenticator( + virtual scoped_ptr<Authenticator> CreateAuthenticator( const std::string& remote_jid, const buzz::XmlElement* first_message) OVERRIDE; diff --git a/remoting/protocol/pepper_channel.h b/remoting/protocol/pepper_channel.h index de6b93b..c673757 100644 --- a/remoting/protocol/pepper_channel.h +++ b/remoting/protocol/pepper_channel.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" #include "base/threading/non_thread_safe.h" namespace pp { @@ -31,11 +32,10 @@ class PepperChannel : public base::NonThreadSafe { virtual ~PepperChannel() { } // Connect the channel using specified |config|. The specified - // |authenticator| is used to authenticate the channel. Takes - // ownership of |authenticator|. + // |authenticator| is used to authenticate the channel. virtual void Connect(pp::Instance* pp_instance, const TransportConfig& config, - ChannelAuthenticator* authenticator) = 0; + scoped_ptr<ChannelAuthenticator> authenticator) = 0; // Adds |candidate| received from the peer. virtual void AddRemoveCandidate(const cricket::Candidate& candidate) = 0; diff --git a/remoting/protocol/pepper_session.cc b/remoting/protocol/pepper_session.cc index 7cf0139..5751aba 100644 --- a/remoting/protocol/pepper_session.cc +++ b/remoting/protocol/pepper_session.cc @@ -56,16 +56,16 @@ Session::Error PepperSession::error() { void PepperSession::StartConnection( const std::string& peer_jid, - Authenticator* authenticator, - CandidateSessionConfig* config, + scoped_ptr<Authenticator> authenticator, + scoped_ptr<CandidateSessionConfig> config, const StateChangeCallback& state_change_callback) { DCHECK(CalledOnValidThread()); - DCHECK(authenticator); + DCHECK(authenticator.get()); DCHECK_EQ(authenticator->state(), Authenticator::MESSAGE_READY); peer_jid_ = peer_jid; - authenticator_.reset(authenticator); - candidate_config_.reset(config); + authenticator_ = authenticator.Pass(); + candidate_config_ = config.Pass(); state_change_callback_ = state_change_callback; // Generate random session ID. There are usually not more than 1 @@ -113,14 +113,14 @@ void PepperSession::CreateStreamChannel( const StreamChannelCallback& callback) { DCHECK(!channels_[name]); - ChannelAuthenticator* channel_authenticator = + scoped_ptr<ChannelAuthenticator> channel_authenticator = authenticator_->CreateChannelAuthenticator(); PepperStreamChannel* channel = new PepperStreamChannel( this, name, callback); channels_[name] = channel; channel->Connect(session_manager_->pp_instance_, session_manager_->transport_config_, - channel_authenticator); + channel_authenticator.Pass()); } void PepperSession::CreateDatagramChannel( @@ -334,7 +334,7 @@ void PepperSession::ProcessAuthenticationStep() { if (authenticator_->state() == Authenticator::MESSAGE_READY) { JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_); - message.info.reset(authenticator_->GetNextMessage()); + message.info = authenticator_->GetNextMessage(); DCHECK(message.info.get()); session_info_request_.reset(session_manager_->iq_sender()->SendIq( diff --git a/remoting/protocol/pepper_session.h b/remoting/protocol/pepper_session.h index 83a0ad9..ba2a2b4 100644 --- a/remoting/protocol/pepper_session.h +++ b/remoting/protocol/pepper_session.h @@ -66,8 +66,8 @@ class PepperSession : public Session { // Start cs connection by sending session-initiate message. void StartConnection(const std::string& peer_jid, - Authenticator* authenticator, - CandidateSessionConfig* config, + scoped_ptr<Authenticator> authenticator, + scoped_ptr<CandidateSessionConfig> config, const StateChangeCallback& state_change_callback); // Handler for session-initiate response. diff --git a/remoting/protocol/pepper_session_manager.cc b/remoting/protocol/pepper_session_manager.cc index 877b650..09e0c66 100644 --- a/remoting/protocol/pepper_session_manager.cc +++ b/remoting/protocol/pepper_session_manager.cc @@ -70,16 +70,16 @@ void PepperSessionManager::OnJingleInfo( } } -Session* PepperSessionManager::Connect( +scoped_ptr<Session> PepperSessionManager::Connect( const std::string& host_jid, - Authenticator* authenticator, - CandidateSessionConfig* config, + scoped_ptr<Authenticator> authenticator, + scoped_ptr<CandidateSessionConfig> config, const Session::StateChangeCallback& state_change_callback) { - PepperSession* session = new PepperSession(this); - session->StartConnection(host_jid, authenticator, config, + scoped_ptr<PepperSession> session(new PepperSession(this)); + session->StartConnection(host_jid, authenticator.Pass(), config.Pass(), state_change_callback); - sessions_[session->session_id_] = session; - return session; + sessions_[session->session_id_] = session.get(); + return scoped_ptr<Session>(session.Pass()); } void PepperSessionManager::Close() { diff --git a/remoting/protocol/pepper_session_manager.h b/remoting/protocol/pepper_session_manager.h index 4db2f05..630684d 100644 --- a/remoting/protocol/pepper_session_manager.h +++ b/remoting/protocol/pepper_session_manager.h @@ -51,10 +51,10 @@ class PepperSessionManager : public SessionManager, virtual void Init(SignalStrategy* signal_strategy, SessionManager::Listener* listener, const NetworkSettings& network_settings) OVERRIDE; - virtual Session* Connect( + virtual scoped_ptr<Session> Connect( const std::string& host_jid, - Authenticator* authenticator, - CandidateSessionConfig* config, + scoped_ptr<Authenticator> authenticator, + scoped_ptr<CandidateSessionConfig> config, const Session::StateChangeCallback& state_change_callback) OVERRIDE; virtual void Close() OVERRIDE; virtual void set_authenticator_factory( diff --git a/remoting/protocol/pepper_session_unittest.cc b/remoting/protocol/pepper_session_unittest.cc index bec6e95..134f28f 100644 --- a/remoting/protocol/pepper_session_unittest.cc +++ b/remoting/protocol/pepper_session_unittest.cc @@ -178,14 +178,14 @@ class PepperSessionTest : public testing::Test { } } - Authenticator* authenticator = new FakeAuthenticator( - FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true); + scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( + FakeAuthenticator::CLIENT, auth_round_trips, auth_action, true)); - client_session_.reset(client_server_->Connect( - kHostJid, authenticator, + client_session_ = client_server_->Connect( + kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault(), base::Bind(&MockSessionCallback::OnStateChange, - base::Unretained(&client_connection_callback_)))); + base::Unretained(&client_connection_callback_))); message_loop_.RunAllPending(); } @@ -233,13 +233,12 @@ TEST_F(PepperSessionTest, RejectConnection) { .Times(1); } - Authenticator* authenticator = new FakeAuthenticator( - FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true); - client_session_.reset(client_server_->Connect( - kHostJid, authenticator, - CandidateSessionConfig::CreateDefault(), + scoped_ptr<Authenticator> authenticator(new FakeAuthenticator( + FakeAuthenticator::CLIENT, 1, FakeAuthenticator::ACCEPT, true)); + client_session_ = client_server_->Connect( + kHostJid, authenticator.Pass(), CandidateSessionConfig::CreateDefault(), base::Bind(&MockSessionCallback::OnStateChange, - base::Unretained(&client_connection_callback_)))); + base::Unretained(&client_connection_callback_))); message_loop_.RunAllPending(); } diff --git a/remoting/protocol/pepper_stream_channel.cc b/remoting/protocol/pepper_stream_channel.cc index 477f9fa..1f1ec79 100644 --- a/remoting/protocol/pepper_stream_channel.cc +++ b/remoting/protocol/pepper_stream_channel.cc @@ -54,12 +54,13 @@ PepperStreamChannel::~PepperStreamChannel() { DCHECK(!connected_ || channel_ == NULL); } -void PepperStreamChannel::Connect(pp::Instance* pp_instance, - const TransportConfig& transport_config, - ChannelAuthenticator* authenticator) { +void PepperStreamChannel::Connect( + pp::Instance* pp_instance, + const TransportConfig& transport_config, + scoped_ptr<ChannelAuthenticator> authenticator) { DCHECK(CalledOnValidThread()); - authenticator_.reset(authenticator); + authenticator_ = authenticator.Pass(); pp::Transport_Dev* transport = new pp::Transport_Dev(pp_instance, name_.c_str(), diff --git a/remoting/protocol/pepper_stream_channel.h b/remoting/protocol/pepper_stream_channel.h index ead43e9..e0913b6 100644 --- a/remoting/protocol/pepper_stream_channel.h +++ b/remoting/protocol/pepper_stream_channel.h @@ -37,7 +37,7 @@ class PepperStreamChannel : public PepperChannel, // PepperChannel implementation. virtual void Connect(pp::Instance* pp_instance, const TransportConfig& transport_config, - ChannelAuthenticator* authenticator) OVERRIDE; + scoped_ptr<ChannelAuthenticator> authenticator) OVERRIDE; virtual void AddRemoveCandidate(const cricket::Candidate& candidate) OVERRIDE; virtual const std::string& name() const OVERRIDE; virtual bool is_connected() const OVERRIDE; diff --git a/remoting/protocol/session_config.cc b/remoting/protocol/session_config.cc index c4a220a..528d96c 100644 --- a/remoting/protocol/session_config.cc +++ b/remoting/protocol/session_config.cc @@ -126,28 +126,28 @@ bool CandidateSessionConfig::IsChannelConfigSupported( return std::find(vector.begin(), vector.end(), value) != vector.end(); } -CandidateSessionConfig* CandidateSessionConfig::Clone() const { - return new CandidateSessionConfig(*this); +scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::Clone() const { + return scoped_ptr<CandidateSessionConfig>(new CandidateSessionConfig(*this)); } // static -CandidateSessionConfig* CandidateSessionConfig::CreateEmpty() { - return new CandidateSessionConfig(); +scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateEmpty() { + return scoped_ptr<CandidateSessionConfig>(new CandidateSessionConfig()); } // static -CandidateSessionConfig* CandidateSessionConfig::CreateFrom( +scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateFrom( const SessionConfig& config) { - CandidateSessionConfig* result = CreateEmpty(); + scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); result->mutable_control_configs()->push_back(config.control_config()); result->mutable_event_configs()->push_back(config.event_config()); result->mutable_video_configs()->push_back(config.video_config()); - return result; + return result.Pass(); } // static -CandidateSessionConfig* CandidateSessionConfig::CreateDefault() { - CandidateSessionConfig* result = CreateEmpty(); +scoped_ptr<CandidateSessionConfig> CandidateSessionConfig::CreateDefault() { + scoped_ptr<CandidateSessionConfig> result = CreateEmpty(); result->mutable_control_configs()->push_back( ChannelConfig(ChannelConfig::TRANSPORT_STREAM, kDefaultStreamVersion, @@ -160,7 +160,7 @@ CandidateSessionConfig* CandidateSessionConfig::CreateDefault() { ChannelConfig(ChannelConfig::TRANSPORT_STREAM, kDefaultStreamVersion, ChannelConfig::CODEC_VP8)); - return result; + return result.Pass(); } } // namespace protocol diff --git a/remoting/protocol/session_config.h b/remoting/protocol/session_config.h index 7ebfba6..07dcaa2 100644 --- a/remoting/protocol/session_config.h +++ b/remoting/protocol/session_config.h @@ -9,6 +9,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" namespace remoting { namespace protocol { @@ -119,11 +120,12 @@ class CandidateSessionConfig { // or undefined (e.g. no configurations for a channel) then NULL is returned. bool GetFinalConfig(SessionConfig* result) const; - CandidateSessionConfig* Clone() const; + scoped_ptr<CandidateSessionConfig> Clone() const; - static CandidateSessionConfig* CreateEmpty(); - static CandidateSessionConfig* CreateFrom(const SessionConfig& config); - static CandidateSessionConfig* CreateDefault(); + static scoped_ptr<CandidateSessionConfig> CreateEmpty(); + static scoped_ptr<CandidateSessionConfig> CreateFrom( + const SessionConfig& config); + static scoped_ptr<CandidateSessionConfig> CreateDefault(); private: CandidateSessionConfig(); diff --git a/remoting/protocol/session_manager.h b/remoting/protocol/session_manager.h index 0d1129e..f99738e 100644 --- a/remoting/protocol/session_manager.h +++ b/remoting/protocol/session_manager.h @@ -128,15 +128,7 @@ class SessionManager : public base::NonThreadSafe { }; // Initializes the session client. Caller retains ownership of the - // |signal_strategy| and |listener|. |allow_nat_traversal| must be - // set to true to enable NAT traversal. STUN/Relay servers are not - // used when NAT traversal is disabled, so P2P connection will work - // only when both peers are on the same network. If this object is - // used in server mode, then |private_key| and |certificate| are - // used to establish a secured communication with the client. It - // will also take ownership of these objects. On the client side - // pass in NULL for |private_key| and empty string for - // |certificate|. + // |signal_strategy| and |listener|. virtual void Init(SignalStrategy* signal_strategy, Listener* listener, const NetworkSettings& network_settings) = 0; @@ -146,16 +138,13 @@ class SessionManager : public base::NonThreadSafe { // Listener::OnInitialized() has been called. // // |host_jid| is the full jid of the host to connect to. - // |host_public_key| is used to for authentication. // |authenticator| is a client authenticator for the session. // |config| contains the session configurations that the client supports. // |state_change_callback| is called when the connection state changes. - // - // Ownership of the |config| is passed to the new session. - virtual Session* Connect( + virtual scoped_ptr<Session> Connect( const std::string& host_jid, - Authenticator* authenticator, - CandidateSessionConfig* config, + scoped_ptr<Authenticator> authenticator, + scoped_ptr<CandidateSessionConfig> config, const Session::StateChangeCallback& state_change_callback) = 0; // Close session manager. Can be called only after all corresponding diff --git a/remoting/protocol/ssl_hmac_channel_authenticator.cc b/remoting/protocol/ssl_hmac_channel_authenticator.cc index 85775bb..42ffe44 100644 --- a/remoting/protocol/ssl_hmac_channel_authenticator.cc +++ b/remoting/protocol/ssl_hmac_channel_authenticator.cc @@ -22,24 +22,26 @@ namespace remoting { namespace protocol { // static -SslHmacChannelAuthenticator* SslHmacChannelAuthenticator::CreateForClient( +scoped_ptr<SslHmacChannelAuthenticator> +SslHmacChannelAuthenticator::CreateForClient( const std::string& remote_cert, const std::string& auth_key) { - SslHmacChannelAuthenticator* result = - new SslHmacChannelAuthenticator(auth_key); + scoped_ptr<SslHmacChannelAuthenticator> result( + new SslHmacChannelAuthenticator(auth_key)); result->remote_cert_ = remote_cert; - return result; + return result.Pass(); } -SslHmacChannelAuthenticator* SslHmacChannelAuthenticator::CreateForHost( +scoped_ptr<SslHmacChannelAuthenticator> +SslHmacChannelAuthenticator::CreateForHost( const std::string& local_cert, crypto::RSAPrivateKey* local_private_key, const std::string& auth_key) { - SslHmacChannelAuthenticator* result = - new SslHmacChannelAuthenticator(auth_key); + scoped_ptr<SslHmacChannelAuthenticator> result( + new SslHmacChannelAuthenticator(auth_key)); result->local_cert_ = local_cert; result->local_private_key_ = local_private_key; - return result; + return result.Pass(); } SslHmacChannelAuthenticator::SslHmacChannelAuthenticator( diff --git a/remoting/protocol/ssl_hmac_channel_authenticator.h b/remoting/protocol/ssl_hmac_channel_authenticator.h index e86e25e..228f084 100644 --- a/remoting/protocol/ssl_hmac_channel_authenticator.h +++ b/remoting/protocol/ssl_hmac_channel_authenticator.h @@ -45,11 +45,11 @@ class SslHmacChannelAuthenticator : public ChannelAuthenticator, // |auth_key| is set to access code. For EKE-based authentication // |auth_key| is the key established using EKE over the signaling // channel. - static SslHmacChannelAuthenticator* CreateForClient( + static scoped_ptr<SslHmacChannelAuthenticator> CreateForClient( const std::string& remote_cert, const std::string& auth_key); - static SslHmacChannelAuthenticator* CreateForHost( + static scoped_ptr<SslHmacChannelAuthenticator> CreateForHost( const std::string& local_cert, crypto::RSAPrivateKey* local_private_key, const std::string& auth_key); diff --git a/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc b/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc index 10fdcf7..9f3db7e 100644 --- a/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc +++ b/remoting/protocol/ssl_hmac_channel_authenticator_unittest.cc @@ -117,10 +117,10 @@ class SslHmacChannelAuthenticatorTest : public testing::Test { // Verify that a channel can be connected using a valid shared secret. TEST_F(SslHmacChannelAuthenticatorTest, SuccessfulAuth) { - client_auth_.reset(SslHmacChannelAuthenticator::CreateForClient( - host_cert_, kTestSharedSecret)); - host_auth_.reset(SslHmacChannelAuthenticator::CreateForHost( - host_cert_, private_key_.get(), kTestSharedSecret)); + client_auth_ = SslHmacChannelAuthenticator::CreateForClient( + host_cert_, kTestSharedSecret); + host_auth_ = SslHmacChannelAuthenticator::CreateForHost( + host_cert_, private_key_.get(), kTestSharedSecret); RunChannelAuth(false); @@ -137,10 +137,10 @@ TEST_F(SslHmacChannelAuthenticatorTest, SuccessfulAuth) { // Verify that channels cannot be using invalid shared secret. TEST_F(SslHmacChannelAuthenticatorTest, InvalidChannelSecret) { - client_auth_.reset(SslHmacChannelAuthenticator::CreateForClient( - host_cert_, kTestSharedSecretBad)); - host_auth_.reset(SslHmacChannelAuthenticator::CreateForHost( - host_cert_, private_key_.get(), kTestSharedSecret)); + client_auth_ = SslHmacChannelAuthenticator::CreateForClient( + host_cert_, kTestSharedSecretBad); + host_auth_ = SslHmacChannelAuthenticator::CreateForHost( + host_cert_, private_key_.get(), kTestSharedSecret); RunChannelAuth(true); diff --git a/remoting/protocol/v1_authenticator.cc b/remoting/protocol/v1_authenticator.cc index 56dda8c..5811eff 100644 --- a/remoting/protocol/v1_authenticator.cc +++ b/remoting/protocol/v1_authenticator.cc @@ -59,10 +59,10 @@ void V1ClientAuthenticator::ProcessMessage(const XmlElement* message) { } } -XmlElement* V1ClientAuthenticator::GetNextMessage() { +scoped_ptr<XmlElement> V1ClientAuthenticator::GetNextMessage() { DCHECK_EQ(state_, MESSAGE_READY); - XmlElement* message = CreateEmptyAuthenticatorMessage(); + scoped_ptr<XmlElement> message = CreateEmptyAuthenticatorMessage(); std::string token = protocol::GenerateSupportAuthToken(local_jid_, shared_secret_); XmlElement* auth_token_tag = new XmlElement( @@ -71,17 +71,17 @@ XmlElement* V1ClientAuthenticator::GetNextMessage() { message->AddElement(auth_token_tag); state_ = WAITING_MESSAGE; - return message; + return message.Pass(); } -ChannelAuthenticator* +scoped_ptr<ChannelAuthenticator> V1ClientAuthenticator::CreateChannelAuthenticator() const { DCHECK_EQ(state_, ACCEPTED); - SslHmacChannelAuthenticator* result = + scoped_ptr<SslHmacChannelAuthenticator> result = SslHmacChannelAuthenticator::CreateForClient( remote_cert_, shared_secret_); result->SetLegacyOneWayMode(SslHmacChannelAuthenticator::SEND_ONLY); - return result; + return scoped_ptr<ChannelAuthenticator>(result.Pass()); }; V1HostAuthenticator::V1HostAuthenticator( @@ -117,10 +117,10 @@ void V1HostAuthenticator::ProcessMessage(const XmlElement* message) { } } -XmlElement* V1HostAuthenticator::GetNextMessage() { +scoped_ptr<XmlElement> V1HostAuthenticator::GetNextMessage() { DCHECK_EQ(state_, MESSAGE_READY); - XmlElement* message = CreateEmptyAuthenticatorMessage(); + scoped_ptr<XmlElement> message = CreateEmptyAuthenticatorMessage(); buzz::XmlElement* certificate_tag = new XmlElement( buzz::QName(kChromotingXmlNamespace, kCertificateTag)); std::string base64_cert; @@ -131,17 +131,17 @@ XmlElement* V1HostAuthenticator::GetNextMessage() { message->AddElement(certificate_tag); state_ = ACCEPTED; - return message; + return message.Pass(); } -ChannelAuthenticator* +scoped_ptr<ChannelAuthenticator> V1HostAuthenticator::CreateChannelAuthenticator() const { DCHECK_EQ(state_, ACCEPTED); - SslHmacChannelAuthenticator* result = + scoped_ptr<SslHmacChannelAuthenticator> result = SslHmacChannelAuthenticator::CreateForHost( local_cert_, local_private_key_.get(), shared_secret_); result->SetLegacyOneWayMode(SslHmacChannelAuthenticator::RECEIVE_ONLY); - return result; + return scoped_ptr<ChannelAuthenticator>(result.Pass()); }; } // namespace remoting diff --git a/remoting/protocol/v1_authenticator.h b/remoting/protocol/v1_authenticator.h index 26d44bf..db06cf5 100644 --- a/remoting/protocol/v1_authenticator.h +++ b/remoting/protocol/v1_authenticator.h @@ -26,8 +26,9 @@ class V1ClientAuthenticator : public Authenticator { // Authenticator interface. virtual State state() const OVERRIDE; virtual void ProcessMessage(const buzz::XmlElement* message) OVERRIDE; - virtual buzz::XmlElement* GetNextMessage() OVERRIDE; - virtual ChannelAuthenticator* CreateChannelAuthenticator() const OVERRIDE; + virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; + virtual scoped_ptr<ChannelAuthenticator> + CreateChannelAuthenticator() const OVERRIDE; private: std::string local_jid_; @@ -50,8 +51,9 @@ class V1HostAuthenticator : public Authenticator { // Authenticator interface. virtual State state() const OVERRIDE; virtual void ProcessMessage(const buzz::XmlElement* message) OVERRIDE; - virtual buzz::XmlElement* GetNextMessage() OVERRIDE; - virtual ChannelAuthenticator* CreateChannelAuthenticator() const OVERRIDE; + virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; + virtual scoped_ptr<ChannelAuthenticator> + CreateChannelAuthenticator() const OVERRIDE; private: std::string local_cert_; diff --git a/remoting/protocol/v1_authenticator_unittest.cc b/remoting/protocol/v1_authenticator_unittest.cc index 772661d..4869ddd 100644 --- a/remoting/protocol/v1_authenticator_unittest.cc +++ b/remoting/protocol/v1_authenticator_unittest.cc @@ -87,7 +87,7 @@ class V1AuthenticatorTest : public testing::Test { // Pass message from client to host. ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state()); - message.reset(client_->GetNextMessage()); + message = client_->GetNextMessage(); ASSERT_TRUE(message.get()); ASSERT_NE(Authenticator::MESSAGE_READY, client_->state()); @@ -103,7 +103,7 @@ class V1AuthenticatorTest : public testing::Test { // Pass message from host to client. ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state()); - message.reset(host_->GetNextMessage()); + message = host_->GetNextMessage(); ASSERT_TRUE(message.get()); ASSERT_NE(Authenticator::MESSAGE_READY, host_->state()); @@ -177,8 +177,8 @@ TEST_F(V1AuthenticatorTest, SuccessfulAuth) { ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); - client_auth_.reset(client_->CreateChannelAuthenticator()); - host_auth_.reset(host_->CreateChannelAuthenticator()); + client_auth_ = client_->CreateChannelAuthenticator(); + host_auth_ = host_->CreateChannelAuthenticator(); RunChannelAuth(false); EXPECT_TRUE(client_socket_.get() != NULL); diff --git a/remoting/protocol/v2_authenticator.cc b/remoting/protocol/v2_authenticator.cc index edfc1cef..14bced4 100644 --- a/remoting/protocol/v2_authenticator.cc +++ b/remoting/protocol/v2_authenticator.cc @@ -35,14 +35,14 @@ bool V2Authenticator::IsEkeMessage(const buzz::XmlElement* message) { } // static -V2Authenticator* V2Authenticator::CreateForClient( +scoped_ptr<Authenticator> V2Authenticator::CreateForClient( const std::string& shared_secret) { - return new V2Authenticator( - P224EncryptedKeyExchange::kPeerTypeClient, shared_secret); + return scoped_ptr<Authenticator>(new V2Authenticator( + P224EncryptedKeyExchange::kPeerTypeClient, shared_secret)); } // static -V2Authenticator* V2Authenticator::CreateForHost( +scoped_ptr<Authenticator> V2Authenticator::CreateForHost( const std::string& local_cert, const crypto::RSAPrivateKey& local_private_key, const std::string& shared_secret) { @@ -51,7 +51,7 @@ V2Authenticator* V2Authenticator::CreateForHost( result->local_cert_ = local_cert; result->local_private_key_.reset(local_private_key.Copy()); result->state_ = WAITING_MESSAGE; - return result; + return scoped_ptr<Authenticator>(result); } V2Authenticator::V2Authenticator( @@ -129,10 +129,10 @@ void V2Authenticator::ProcessMessage(const buzz::XmlElement* message) { state_ = MESSAGE_READY; } -buzz::XmlElement* V2Authenticator::GetNextMessage() { +scoped_ptr<buzz::XmlElement> V2Authenticator::GetNextMessage() { DCHECK_EQ(state(), MESSAGE_READY); - buzz::XmlElement* message = CreateEmptyAuthenticatorMessage(); + scoped_ptr<buzz::XmlElement> message = CreateEmptyAuthenticatorMessage(); DCHECK(!pending_messages_.empty()); while (!pending_messages_.empty()) { @@ -163,19 +163,22 @@ buzz::XmlElement* V2Authenticator::GetNextMessage() { if (state_ != ACCEPTED) { state_ = WAITING_MESSAGE; } - return message; + return message.Pass(); } -ChannelAuthenticator* V2Authenticator::CreateChannelAuthenticator() const { +scoped_ptr<ChannelAuthenticator> +V2Authenticator::CreateChannelAuthenticator() const { DCHECK_EQ(state(), ACCEPTED); CHECK(!auth_key_.empty()); if (is_host_side()) { - return SslHmacChannelAuthenticator::CreateForHost( - local_cert_, local_private_key_.get(), auth_key_); + return scoped_ptr<ChannelAuthenticator>( + SslHmacChannelAuthenticator::CreateForHost( + local_cert_, local_private_key_.get(), auth_key_).Pass()); } else { - return SslHmacChannelAuthenticator::CreateForClient( - remote_cert_, auth_key_); + return scoped_ptr<ChannelAuthenticator>( + SslHmacChannelAuthenticator::CreateForClient( + remote_cert_, auth_key_).Pass()); } } diff --git a/remoting/protocol/v2_authenticator.h b/remoting/protocol/v2_authenticator.h index 9828233..01e8a67 100644 --- a/remoting/protocol/v2_authenticator.h +++ b/remoting/protocol/v2_authenticator.h @@ -25,10 +25,10 @@ class V2Authenticator : public Authenticator { public: static bool IsEkeMessage(const buzz::XmlElement* message); - static V2Authenticator* CreateForClient( + static scoped_ptr<Authenticator> CreateForClient( const std::string& shared_secret); - static V2Authenticator* CreateForHost( + static scoped_ptr<Authenticator> CreateForHost( const std::string& local_cert, const crypto::RSAPrivateKey& local_private_key, const std::string& shared_secret); @@ -38,8 +38,9 @@ class V2Authenticator : public Authenticator { // Authenticator interface. virtual State state() const OVERRIDE; virtual void ProcessMessage(const buzz::XmlElement* message) OVERRIDE; - virtual buzz::XmlElement* GetNextMessage() OVERRIDE; - virtual ChannelAuthenticator* CreateChannelAuthenticator() const OVERRIDE; + virtual scoped_ptr<buzz::XmlElement> GetNextMessage() OVERRIDE; + virtual scoped_ptr<ChannelAuthenticator> + CreateChannelAuthenticator() const OVERRIDE; private: FRIEND_TEST_ALL_PREFIXES(V2AuthenticatorTest, InvalidSecret); diff --git a/remoting/protocol/v2_authenticator_unittest.cc b/remoting/protocol/v2_authenticator_unittest.cc index 812ee1d..715fa2e 100644 --- a/remoting/protocol/v2_authenticator_unittest.cc +++ b/remoting/protocol/v2_authenticator_unittest.cc @@ -75,9 +75,9 @@ class V2AuthenticatorTest : public testing::Test { void InitAuthenticators(const std::string& client_secret, const std::string& host_secret) { - host_.reset(V2Authenticator::CreateForHost( - host_cert_, *private_key_, host_secret)); - client_.reset(V2Authenticator::CreateForClient(client_secret)); + host_ = V2Authenticator::CreateForHost( + host_cert_, *private_key_, host_secret); + client_ = V2Authenticator::CreateForClient(client_secret); } void RunAuthExchange() { @@ -86,7 +86,7 @@ class V2AuthenticatorTest : public testing::Test { // Pass message from client to host. ASSERT_EQ(Authenticator::MESSAGE_READY, client_->state()); - message.reset(client_->GetNextMessage()); + message = client_->GetNextMessage(); ASSERT_TRUE(message.get()); ASSERT_NE(Authenticator::MESSAGE_READY, client_->state()); @@ -102,7 +102,7 @@ class V2AuthenticatorTest : public testing::Test { // Pass message from host to client. ASSERT_EQ(Authenticator::MESSAGE_READY, host_->state()); - message.reset(host_->GetNextMessage()); + message = host_->GetNextMessage(); ASSERT_TRUE(message.get()); ASSERT_NE(Authenticator::MESSAGE_READY, host_->state()); @@ -150,8 +150,8 @@ class V2AuthenticatorTest : public testing::Test { scoped_ptr<crypto::RSAPrivateKey> private_key_; std::string host_cert_; - scoped_ptr<V2Authenticator> host_; - scoped_ptr<V2Authenticator> client_; + scoped_ptr<Authenticator> host_; + scoped_ptr<Authenticator> client_; scoped_ptr<FakeSocket> client_fake_socket_; scoped_ptr<FakeSocket> host_fake_socket_; scoped_ptr<ChannelAuthenticator> client_auth_; @@ -172,8 +172,8 @@ TEST_F(V2AuthenticatorTest, SuccessfulAuth) { ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); ASSERT_EQ(Authenticator::ACCEPTED, client_->state()); - client_auth_.reset(client_->CreateChannelAuthenticator()); - host_auth_.reset(host_->CreateChannelAuthenticator()); + client_auth_ = client_->CreateChannelAuthenticator(); + host_auth_ = host_->CreateChannelAuthenticator(); RunChannelAuth(false); EXPECT_TRUE(client_socket_.get() != NULL); @@ -195,8 +195,9 @@ TEST_F(V2AuthenticatorTest, InvalidSecret) { ASSERT_EQ(Authenticator::REJECTED, client_->state()); - // Change |client_| so that we can get the laste message. - client_->state_ = Authenticator::MESSAGE_READY; + // Change |client_| so that we can get the last message. + reinterpret_cast<V2Authenticator*>(client_.get())->state_ = + Authenticator::MESSAGE_READY; scoped_ptr<buzz::XmlElement> message(client_->GetNextMessage()); ASSERT_TRUE(message.get()); |