// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ #define REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ #include #include #include "base/memory/ref_counted.h" #include "net/base/x509_certificate.h" #include "remoting/protocol/content_description.h" #include "remoting/protocol/jingle_session.h" #include "remoting/protocol/session_manager.h" #include "third_party/libjingle/source/talk/p2p/base/session.h" #include "third_party/libjingle/source/talk/p2p/base/sessionclient.h" class MessageLoop; namespace crypto { class RSAPrivateKey; } // namespace base namespace cricket { class SessionManager; } // namespace cricket namespace remoting { namespace protocol { // This class implements SessionClient for Chromoting sessions. It acts as a // server that accepts chromoting connections and can also make new connections // to other hosts. class JingleSessionManager : public protocol::SessionManager, public cricket::SessionClient { public: explicit JingleSessionManager(MessageLoop* message_loop); // Initializes the session client. Doesn't accept ownership of the // |session_manager|. Close() must be called _before_ the |session_manager| // is destroyed. // 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. // In case this is used in client mode, pass in NULL for both private key and // certificate. virtual void Init(const std::string& local_jid, cricket::SessionManager* cricket_session_manager, IncomingSessionCallback* incoming_session_callback, crypto::RSAPrivateKey* private_key, scoped_refptr certificate); // SessionManager interface. virtual scoped_refptr Connect( const std::string& host_jid, const std::string& host_public_key, const std::string& client_token, CandidateSessionConfig* config, protocol::Session::StateChangeCallback* state_change_callback); virtual void Close(Task* closed_task); void set_allow_local_ips(bool allow_local_ips); // cricket::SessionClient interface. virtual void OnSessionCreate(cricket::Session* cricket_session, bool received_initiate); virtual void OnSessionDestroy(cricket::Session* cricket_session); virtual bool ParseContent(cricket::SignalingProtocol protocol, const buzz::XmlElement* elem, const cricket::ContentDescription** content, cricket::ParseError* error); virtual bool WriteContent(cricket::SignalingProtocol protocol, const cricket::ContentDescription* content, buzz::XmlElement** elem, cricket::WriteError* error); protected: virtual ~JingleSessionManager(); private: friend class JingleSession; // Message loop that corresponds to the network thread. MessageLoop* message_loop(); // Called by JingleChromotocolConnection when a new connection is initiated. void AcceptConnection(JingleSession* jingle_session, cricket::Session* cricket_session); void DoConnect( scoped_refptr jingle_session, const std::string& host_jid, const std::string& host_public_key, const std::string& client_token, protocol::Session::StateChangeCallback* state_change_callback); // Creates session description for outgoing session. cricket::SessionDescription* CreateClientSessionDescription( const CandidateSessionConfig* candidate_config, const std::string& auth_token, const std::string& master_key); // Creates session description for incoming session. cricket::SessionDescription* CreateHostSessionDescription( const CandidateSessionConfig* candidate_config, scoped_refptr certificate); std::string local_jid_; // Full jid for the local side of the session. MessageLoop* message_loop_; cricket::SessionManager* cricket_session_manager_; scoped_ptr incoming_session_callback_; bool allow_local_ips_; bool closed_; std::list > sessions_; scoped_refptr certificate_; scoped_ptr private_key_; DISALLOW_COPY_AND_ASSIGN(JingleSessionManager); }; } // namespace protocol } // namespace remoting #endif // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_