| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ | 5 #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ |
| 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ | 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "remoting/jingle_glue/signal_strategy.h" |
| 12 #include "remoting/protocol/content_description.h" | 13 #include "remoting/protocol/content_description.h" |
| 13 #include "remoting/protocol/jingle_session.h" | 14 #include "remoting/protocol/jingle_session.h" |
| 14 #include "remoting/protocol/session_manager.h" | 15 #include "remoting/protocol/session_manager.h" |
| 15 #include "third_party/libjingle/source/talk/p2p/base/session.h" | 16 #include "third_party/libjingle/source/talk/p2p/base/session.h" |
| 16 #include "third_party/libjingle/source/talk/p2p/base/sessionclient.h" | 17 #include "third_party/libjingle/source/talk/p2p/base/sessionclient.h" |
| 17 | 18 |
| 18 namespace cricket { | 19 namespace cricket { |
| 19 class HttpPortAllocator; | 20 class HttpPortAllocator; |
| 20 class PortAllocator; | 21 class PortAllocator; |
| 21 class SessionManager; | 22 class SessionManager; |
| 22 } // namespace cricket | 23 } // namespace cricket |
| 23 | 24 |
| 24 namespace remoting { | 25 namespace remoting { |
| 25 | 26 |
| 26 class JingleInfoRequest; | 27 class JingleInfoRequest; |
| 27 class JingleSignalingConnector; | 28 class JingleSignalingConnector; |
| 28 | 29 |
| 29 namespace protocol { | 30 namespace protocol { |
| 30 | 31 |
| 31 // This class implements SessionClient for Chromoting sessions. It acts as a | 32 // This class implements SessionClient for Chromoting sessions. It acts as a |
| 32 // server that accepts chromoting connections and can also make new connections | 33 // server that accepts chromoting connections and can also make new connections |
| 33 // to other hosts. | 34 // to other hosts. |
| 34 class JingleSessionManager | 35 class JingleSessionManager : public SessionManager, |
| 35 : public SessionManager, | 36 public cricket::SessionClient, |
| 36 public cricket::SessionClient { | 37 public SignalStrategy::Listener { |
| 37 public: | 38 public: |
| 38 virtual ~JingleSessionManager(); | 39 virtual ~JingleSessionManager(); |
| 39 | 40 |
| 40 JingleSessionManager(base::MessageLoopProxy* message_loop); | 41 JingleSessionManager(base::MessageLoopProxy* message_loop); |
| 41 | 42 |
| 42 // SessionManager interface. | 43 // SessionManager interface. |
| 43 virtual void Init(const std::string& local_jid, | 44 virtual void Init(SignalStrategy* signal_strategy, |
| 44 SignalStrategy* signal_strategy, | 45 SessionManager::Listener* listener, |
| 45 Listener* listener, | |
| 46 bool allow_nat_traversal) OVERRIDE; | 46 bool allow_nat_traversal) OVERRIDE; |
| 47 virtual Session* Connect( | 47 virtual Session* Connect( |
| 48 const std::string& host_jid, | 48 const std::string& host_jid, |
| 49 Authenticator* authenticator, | 49 Authenticator* authenticator, |
| 50 CandidateSessionConfig* config, | 50 CandidateSessionConfig* config, |
| 51 const Session::StateChangeCallback& state_change_callback) OVERRIDE; | 51 const Session::StateChangeCallback& state_change_callback) OVERRIDE; |
| 52 virtual void Close() OVERRIDE; | 52 virtual void Close() OVERRIDE; |
| 53 virtual void set_authenticator_factory( | 53 virtual void set_authenticator_factory( |
| 54 AuthenticatorFactory* authenticator_factory) OVERRIDE; | 54 AuthenticatorFactory* authenticator_factory) OVERRIDE; |
| 55 | 55 |
| 56 // cricket::SessionClient interface. | 56 // cricket::SessionClient interface. |
| 57 virtual void OnSessionCreate(cricket::Session* cricket_session, | 57 virtual void OnSessionCreate(cricket::Session* cricket_session, |
| 58 bool received_initiate) OVERRIDE; | 58 bool received_initiate) OVERRIDE; |
| 59 virtual void OnSessionDestroy(cricket::Session* cricket_session) OVERRIDE; | 59 virtual void OnSessionDestroy(cricket::Session* cricket_session) OVERRIDE; |
| 60 | 60 |
| 61 virtual bool ParseContent(cricket::SignalingProtocol protocol, | 61 virtual bool ParseContent(cricket::SignalingProtocol protocol, |
| 62 const buzz::XmlElement* elem, | 62 const buzz::XmlElement* elem, |
| 63 const cricket::ContentDescription** content, | 63 const cricket::ContentDescription** content, |
| 64 cricket::ParseError* error) OVERRIDE; | 64 cricket::ParseError* error) OVERRIDE; |
| 65 virtual bool WriteContent(cricket::SignalingProtocol protocol, | 65 virtual bool WriteContent(cricket::SignalingProtocol protocol, |
| 66 const cricket::ContentDescription* content, | 66 const cricket::ContentDescription* content, |
| 67 buzz::XmlElement** elem, | 67 buzz::XmlElement** elem, |
| 68 cricket::WriteError* error) OVERRIDE; | 68 cricket::WriteError* error) OVERRIDE; |
| 69 | 69 |
| 70 // SignalStrategy::Listener interface. |
| 71 virtual void OnSignalStrategyStateChange( |
| 72 SignalStrategy::State state) OVERRIDE; |
| 73 |
| 70 private: | 74 private: |
| 71 friend class JingleSession; | 75 friend class JingleSession; |
| 72 | 76 |
| 73 // Called by JingleSession when a new connection is initiated. | 77 // Called by JingleSession when a new connection is initiated. |
| 74 SessionManager::IncomingSessionResponse AcceptConnection( | 78 SessionManager::IncomingSessionResponse AcceptConnection( |
| 75 JingleSession* jingle_session); | 79 JingleSession* jingle_session); |
| 76 | 80 |
| 77 // Creates authenticator for incoming session. Returns NULL if | 81 // Creates authenticator for incoming session. Returns NULL if |
| 78 // authenticator cannot be created, e.g. if |auth_message| is | 82 // authenticator cannot be created, e.g. if |auth_message| is |
| 79 // invalid. Caller reatins ownership of |auth_message| and must | 83 // invalid. Caller reatins ownership of |auth_message| and must |
| 80 // accept ownership of the result. | 84 // accept ownership of the result. |
| 81 Authenticator* CreateAuthenticator(const std::string& jid, | 85 Authenticator* CreateAuthenticator(const std::string& jid, |
| 82 const buzz::XmlElement* auth_message); | 86 const buzz::XmlElement* auth_message); |
| 83 | 87 |
| 84 // Called by JingleSession when it is being destroyed. | 88 // Called by JingleSession when it is being destroyed. |
| 85 void SessionDestroyed(JingleSession* jingle_session); | 89 void SessionDestroyed(JingleSession* jingle_session); |
| 86 | 90 |
| 87 // Callback for JingleInfoRequest. | 91 // Callback for JingleInfoRequest. |
| 88 void OnJingleInfo( | 92 void OnJingleInfo( |
| 89 const std::string& token, | 93 const std::string& token, |
| 90 const std::vector<std::string>& relay_hosts, | 94 const std::vector<std::string>& relay_hosts, |
| 91 const std::vector<talk_base::SocketAddress>& stun_hosts); | 95 const std::vector<talk_base::SocketAddress>& stun_hosts); |
| 92 | 96 |
| 93 scoped_refptr<base::MessageLoopProxy> message_loop_; | 97 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 94 | 98 |
| 95 scoped_ptr<talk_base::NetworkManager> network_manager_; | 99 scoped_ptr<talk_base::NetworkManager> network_manager_; |
| 96 scoped_ptr<talk_base::PacketSocketFactory> socket_factory_; | 100 scoped_ptr<talk_base::PacketSocketFactory> socket_factory_; |
| 97 | 101 |
| 98 std::string local_jid_; // Full jid for the local side of the session. | |
| 99 SignalStrategy* signal_strategy_; | 102 SignalStrategy* signal_strategy_; |
| 100 scoped_ptr<AuthenticatorFactory> authenticator_factory_; | 103 scoped_ptr<AuthenticatorFactory> authenticator_factory_; |
| 101 Listener* listener_; | 104 SessionManager::Listener* listener_; |
| 102 bool allow_nat_traversal_; | 105 bool allow_nat_traversal_; |
| 103 | 106 |
| 107 bool ready_; |
| 108 |
| 104 scoped_ptr<cricket::PortAllocator> port_allocator_; | 109 scoped_ptr<cricket::PortAllocator> port_allocator_; |
| 105 cricket::HttpPortAllocator* http_port_allocator_; | 110 cricket::HttpPortAllocator* http_port_allocator_; |
| 106 scoped_ptr<cricket::SessionManager> cricket_session_manager_; | 111 scoped_ptr<cricket::SessionManager> cricket_session_manager_; |
| 107 scoped_ptr<JingleInfoRequest> jingle_info_request_; | 112 scoped_ptr<JingleInfoRequest> jingle_info_request_; |
| 108 scoped_ptr<JingleSignalingConnector> jingle_signaling_connector_; | 113 scoped_ptr<JingleSignalingConnector> jingle_signaling_connector_; |
| 109 | 114 |
| 110 bool closed_; | 115 bool closed_; |
| 111 | 116 |
| 112 std::list<JingleSession*> sessions_; | 117 std::list<JingleSession*> sessions_; |
| 113 | 118 |
| 114 ScopedRunnableMethodFactory<JingleSessionManager> task_factory_; | 119 ScopedRunnableMethodFactory<JingleSessionManager> task_factory_; |
| 115 | 120 |
| 116 DISALLOW_COPY_AND_ASSIGN(JingleSessionManager); | 121 DISALLOW_COPY_AND_ASSIGN(JingleSessionManager); |
| 117 }; | 122 }; |
| 118 | 123 |
| 119 } // namespace protocol | 124 } // namespace protocol |
| 120 } // namespace remoting | 125 } // namespace remoting |
| 121 | 126 |
| 122 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ | 127 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ |
| OLD | NEW |