| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_CHROMOTOCOL_SERVER_H_ | 5 #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ |
| 6 #define REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_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/lock.h" | 11 #include "base/lock.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "remoting/protocol/chromotocol_server.h" | 13 #include "remoting/protocol/jingle_session.h" |
| 14 #include "remoting/protocol/jingle_chromotocol_connection.h" | 14 #include "remoting/protocol/session_manager.h" |
| 15 #include "third_party/libjingle/source/talk/p2p/base/session.h" | 15 #include "third_party/libjingle/source/talk/p2p/base/session.h" |
| 16 #include "third_party/libjingle/source/talk/p2p/base/sessionclient.h" | 16 #include "third_party/libjingle/source/talk/p2p/base/sessionclient.h" |
| 17 #include "third_party/libjingle/source/talk/p2p/base/sessiondescription.h" | 17 #include "third_party/libjingle/source/talk/p2p/base/sessiondescription.h" |
| 18 | 18 |
| 19 class MessageLoop; | 19 class MessageLoop; |
| 20 | 20 |
| 21 namespace cricket { | 21 namespace cricket { |
| 22 class SessionManager; | 22 class SessionManager; |
| 23 } // namespace cricket | 23 } // namespace cricket |
| 24 | 24 |
| 25 namespace remoting { | 25 namespace remoting { |
| 26 | 26 |
| 27 class JingleThread; | 27 class JingleThread; |
| 28 | 28 |
| 29 namespace protocol { |
| 30 |
| 29 // ContentDescription used for chromoting sessions. It simply wraps | 31 // ContentDescription used for chromoting sessions. It simply wraps |
| 30 // CandidateChromotocolConfig. CandidateChromotocolConfig doesn't inherit | 32 // CandidateChromotocolConfig. CandidateChromotocolConfig doesn't inherit |
| 31 // from ContentDescription to avoid dependency on libjingle in | 33 // from ContentDescription to avoid dependency on libjingle in |
| 32 // ChromotocolConnection interface. | 34 // Chromotocol Session interface. |
| 33 class ChromotocolContentDescription : public cricket::ContentDescription { | 35 class ContentDescription : public cricket::ContentDescription { |
| 34 public: | 36 public: |
| 35 explicit ChromotocolContentDescription( | 37 explicit ContentDescription(const CandidateChromotocolConfig* config); |
| 36 const CandidateChromotocolConfig* config); | 38 ~ContentDescription(); |
| 37 ~ChromotocolContentDescription(); | |
| 38 | 39 |
| 39 const CandidateChromotocolConfig* config() const { | 40 const CandidateChromotocolConfig* config() const { |
| 40 return candidate_config_.get(); | 41 return candidate_config_.get(); |
| 41 } | 42 } |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 scoped_ptr<const CandidateChromotocolConfig> candidate_config_; | 45 scoped_ptr<const CandidateChromotocolConfig> candidate_config_; |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 // This class implements SessionClient for Chromoting sessions. It acts as a | 48 // This class implements SessionClient for Chromoting sessions. It acts as a |
| 48 // server that accepts chromoting connections and can also make new connections | 49 // server that accepts chromoting connections and can also make new connections |
| 49 // to other hosts. | 50 // to other hosts. |
| 50 class JingleChromotocolServer | 51 class JingleSessionManager |
| 51 : public ChromotocolServer, | 52 : public protocol::SessionManager, |
| 52 public cricket::SessionClient { | 53 public cricket::SessionClient { |
| 53 public: | 54 public: |
| 54 explicit JingleChromotocolServer(JingleThread* jingle_thread); | 55 explicit JingleSessionManager(remoting::JingleThread* jingle_thread); |
| 55 | 56 |
| 56 // Initializes the session client. Doesn't accept ownership of the | 57 // Initializes the session client. Doesn't accept ownership of the |
| 57 // |session_manager|. Close() must be called _before_ the |session_manager| | 58 // |session_manager|. Close() must be called _before_ the |session_manager| |
| 58 // is destroyed. | 59 // is destroyed. |
| 59 virtual void Init(const std::string& local_jid, | 60 virtual void Init(const std::string& local_jid, |
| 60 cricket::SessionManager* session_manager, | 61 cricket::SessionManager* cricket_session_manager, |
| 61 IncomingConnectionCallback* incoming_connection_callback); | 62 IncomingSessionCallback* incoming_session_callback); |
| 62 | 63 |
| 63 // ChromotocolServer interface. | 64 // ChromotocolServer interface. |
| 64 virtual scoped_refptr<ChromotocolConnection> Connect( | 65 virtual scoped_refptr<protocol::Session> Connect( |
| 65 const std::string& jid, | 66 const std::string& jid, |
| 66 CandidateChromotocolConfig* chromotocol_config, | 67 CandidateChromotocolConfig* chromotocol_config, |
| 67 ChromotocolConnection::StateChangeCallback* state_change_callback); | 68 protocol::Session::StateChangeCallback* state_change_callback); |
| 68 virtual void Close(Task* closed_task); | 69 virtual void Close(Task* closed_task); |
| 69 | 70 |
| 70 void set_allow_local_ips(bool allow_local_ips); | 71 void set_allow_local_ips(bool allow_local_ips); |
| 71 | 72 |
| 72 protected: | 73 protected: |
| 73 virtual ~JingleChromotocolServer(); | 74 virtual ~JingleSessionManager(); |
| 74 | 75 |
| 75 private: | 76 private: |
| 76 friend class JingleChromotocolConnection; | 77 friend class JingleSession; |
| 77 | 78 |
| 78 // The jingle thread used by this object. | 79 // The jingle thread used by this object. |
| 79 JingleThread* jingle_thread(); | 80 JingleThread* jingle_thread(); |
| 80 | 81 |
| 81 // Message loop that corresponds to jingle_thread(). | 82 // Message loop that corresponds to jingle_thread(). |
| 82 MessageLoop* message_loop(); | 83 MessageLoop* message_loop(); |
| 83 | 84 |
| 84 // Called by JingleChromotocolConnection when a new connection is initiated. | 85 // Called by JingleChromotocolConnection when a new connection is initiated. |
| 85 void AcceptConnection(JingleChromotocolConnection* connection, | 86 void AcceptConnection(JingleSession* jingle_session, |
| 86 cricket::Session* session); | 87 cricket::Session* cricket_session); |
| 87 | 88 |
| 88 void DoConnect( | 89 void DoConnect( |
| 89 scoped_refptr<JingleChromotocolConnection> connection, | 90 scoped_refptr<JingleSession> jingle_session, |
| 90 const std::string& jid, | 91 const std::string& jid, |
| 91 ChromotocolConnection::StateChangeCallback* state_change_callback); | 92 protocol::Session::StateChangeCallback* state_change_callback); |
| 92 | 93 |
| 93 // Creates outgoing session description for an incoming connection. | 94 // Creates outgoing session description for an incoming session. |
| 94 cricket::SessionDescription* CreateSessionDescription( | 95 cricket::SessionDescription* CreateSessionDescription( |
| 95 const CandidateChromotocolConfig* config); | 96 const CandidateChromotocolConfig* config); |
| 96 | 97 |
| 97 // cricket::SessionClient interface. | 98 // cricket::SessionClient interface. |
| 98 virtual void OnSessionCreate(cricket::Session* session, | 99 virtual void OnSessionCreate(cricket::Session* cricket_session, |
| 99 bool received_initiate); | 100 bool received_initiate); |
| 100 virtual void OnSessionDestroy(cricket::Session* session); | 101 virtual void OnSessionDestroy(cricket::Session* cricket_session); |
| 101 | 102 |
| 102 virtual bool ParseContent(cricket::SignalingProtocol protocol, | 103 virtual bool ParseContent(cricket::SignalingProtocol protocol, |
| 103 const buzz::XmlElement* elem, | 104 const buzz::XmlElement* elem, |
| 104 const cricket::ContentDescription** content, | 105 const cricket::ContentDescription** content, |
| 105 cricket::ParseError* error); | 106 cricket::ParseError* error); |
| 106 virtual bool WriteContent(cricket::SignalingProtocol protocol, | 107 virtual bool WriteContent(cricket::SignalingProtocol protocol, |
| 107 const cricket::ContentDescription* content, | 108 const cricket::ContentDescription* content, |
| 108 buzz::XmlElement** elem, | 109 buzz::XmlElement** elem, |
| 109 cricket::WriteError* error); | 110 cricket::WriteError* error); |
| 110 | 111 |
| 111 std::string local_jid_; | 112 std::string local_jid_; |
| 112 JingleThread* jingle_thread_; | 113 JingleThread* jingle_thread_; |
| 113 cricket::SessionManager* session_manager_; | 114 cricket::SessionManager* cricket_session_manager_; |
| 114 scoped_ptr<IncomingConnectionCallback> incoming_connection_callback_; | 115 scoped_ptr<IncomingSessionCallback> incoming_session_callback_; |
| 115 bool allow_local_ips_; | 116 bool allow_local_ips_; |
| 116 | 117 |
| 117 bool closed_; | 118 bool closed_; |
| 118 | 119 |
| 119 std::list<scoped_refptr<JingleChromotocolConnection> > connections_; | 120 std::list<scoped_refptr<JingleSession> > sessions_; |
| 120 | 121 |
| 121 DISALLOW_COPY_AND_ASSIGN(JingleChromotocolServer); | 122 DISALLOW_COPY_AND_ASSIGN(JingleSessionManager); |
| 122 }; | 123 }; |
| 123 | 124 |
| 125 } // namespace protocol |
| 126 |
| 124 } // namespace remoting | 127 } // namespace remoting |
| 125 | 128 |
| 126 #endif // REMOTING_PROTOCOL_JINGLE_CHROMOTOCOL_SERVER_H_ | 129 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_MANAGER_H_ |
| OLD | NEW |