// 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_JINGLE_SESSION_MANAGER_H_ #define REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ #include #include #include "base/memory/ref_counted.h" #include "remoting/jingle_glue/signal_strategy.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" namespace cricket { class HttpPortAllocator; class PortAllocator; class SessionManager; } // namespace cricket namespace remoting { class JingleInfoRequest; class JingleSignalingConnector; 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 SessionManager, public cricket::SessionClient, public SignalStrategy::Listener { public: virtual ~JingleSessionManager(); JingleSessionManager(base::MessageLoopProxy* message_loop); // SessionManager interface. virtual void Init(SignalStrategy* signal_strategy, SessionManager::Listener* listener, const NetworkSettings& network_settings) OVERRIDE; virtual scoped_ptr Connect( const std::string& host_jid, scoped_ptr authenticator, scoped_ptr config, const Session::StateChangeCallback& state_change_callback) OVERRIDE; virtual void Close() OVERRIDE; virtual void set_authenticator_factory( scoped_ptr authenticator_factory) OVERRIDE; // cricket::SessionClient interface. virtual void OnSessionCreate(cricket::Session* cricket_session, bool received_initiate) OVERRIDE; virtual void OnSessionDestroy(cricket::Session* cricket_session) OVERRIDE; virtual bool ParseContent(cricket::SignalingProtocol protocol, const buzz::XmlElement* elem, const cricket::ContentDescription** content, cricket::ParseError* error) OVERRIDE; virtual bool WriteContent(cricket::SignalingProtocol protocol, const cricket::ContentDescription* content, buzz::XmlElement** elem, cricket::WriteError* error) OVERRIDE; // SignalStrategy::Listener interface. virtual void OnSignalStrategyStateChange( SignalStrategy::State state) OVERRIDE; private: friend class JingleSession; // Called by JingleSession when a new connection is initiated. SessionManager::IncomingSessionResponse AcceptConnection( JingleSession* jingle_session); // Creates authenticator for incoming session. Returns NULL if // authenticator cannot be created, e.g. if |auth_message| is // invalid. scoped_ptr CreateAuthenticator( const std::string& jid, const buzz::XmlElement* auth_message); // Called by JingleSession when it is being destroyed. void SessionDestroyed(JingleSession* jingle_session); // Callback for JingleInfoRequest. void OnJingleInfo( const std::string& token, const std::vector& relay_hosts, const std::vector& stun_hosts); scoped_refptr message_loop_; scoped_ptr network_manager_; scoped_ptr socket_factory_; SignalStrategy* signal_strategy_; scoped_ptr authenticator_factory_; SessionManager::Listener* listener_; bool allow_nat_traversal_; bool ready_; scoped_ptr port_allocator_; cricket::HttpPortAllocator* http_port_allocator_; scoped_ptr cricket_session_manager_; scoped_ptr jingle_info_request_; scoped_ptr jingle_signaling_connector_; bool closed_; std::list sessions_; DISALLOW_COPY_AND_ASSIGN(JingleSessionManager); }; } // namespace protocol } // namespace remoting #endif // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_