| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_H_ | 5 #ifndef REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 6 #define REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 16 #include "crypto/rsa_private_key.h" | 16 #include "crypto/rsa_private_key.h" |
| 17 #include "net/base/completion_callback.h" | 17 #include "net/base/completion_callback.h" |
| 18 #include "remoting/protocol/authenticator.h" | 18 #include "remoting/protocol/authenticator.h" |
| 19 #include "remoting/protocol/datagram_channel_factory.h" | 19 #include "remoting/protocol/datagram_channel_factory.h" |
| 20 #include "remoting/protocol/jingle_messages.h" | 20 #include "remoting/protocol/jingle_messages.h" |
| 21 #include "remoting/protocol/session.h" | 21 #include "remoting/protocol/session.h" |
| 22 #include "remoting/protocol/session_config.h" | 22 #include "remoting/protocol/session_config.h" |
| 23 #include "remoting/protocol/transport.h" | |
| 24 #include "remoting/signaling/iq_sender.h" | 23 #include "remoting/signaling/iq_sender.h" |
| 25 | 24 |
| 26 namespace remoting { | 25 namespace remoting { |
| 27 namespace protocol { | 26 namespace protocol { |
| 28 | 27 |
| 29 class JingleSessionManager; | 28 class JingleSessionManager; |
| 29 class Transport; |
| 30 | 30 |
| 31 // JingleSessionManager and JingleSession implement the subset of the | 31 // JingleSessionManager and JingleSession implement the subset of the |
| 32 // Jingle protocol used in Chromoting. Instances of this class are | 32 // Jingle protocol used in Chromoting. Instances of this class are |
| 33 // created by the JingleSessionManager. | 33 // created by the JingleSessionManager. |
| 34 class JingleSession : public base::NonThreadSafe, | 34 class JingleSession : public Session { |
| 35 public Session, | |
| 36 public Transport::EventHandler { | |
| 37 public: | 35 public: |
| 38 ~JingleSession() override; | 36 ~JingleSession() override; |
| 39 | 37 |
| 40 // Session interface. | 38 // Session interface. |
| 41 void SetEventHandler(Session::EventHandler* event_handler) override; | 39 void SetEventHandler(Session::EventHandler* event_handler) override; |
| 42 ErrorCode error() override; | 40 ErrorCode error() override; |
| 43 const std::string& jid() override; | 41 const std::string& jid() override; |
| 44 const SessionConfig& config() override; | 42 const SessionConfig& config() override; |
| 45 Transport* GetTransport() override; | 43 void SetTransport(Transport* transport) override; |
| 46 void Close(protocol::ErrorCode error) override; | 44 void Close(protocol::ErrorCode error) override; |
| 47 | 45 |
| 48 private: | 46 private: |
| 49 friend class JingleSessionManager; | 47 friend class JingleSessionManager; |
| 50 | 48 |
| 51 typedef base::Callback<void(JingleMessageReply::ErrorType)> ReplyCallback; | 49 typedef base::Callback<void(JingleMessageReply::ErrorType)> ReplyCallback; |
| 52 | 50 |
| 53 explicit JingleSession(JingleSessionManager* session_manager); | 51 explicit JingleSession(JingleSessionManager* session_manager); |
| 54 | 52 |
| 55 // Start connection by sending session-initiate message. | 53 // Start connection by sending session-initiate message. |
| 56 void StartConnection(const std::string& peer_jid, | 54 void StartConnection(const std::string& peer_jid, |
| 57 scoped_ptr<Authenticator> authenticator); | 55 scoped_ptr<Authenticator> authenticator); |
| 58 | 56 |
| 59 // Called by JingleSessionManager for incoming connections. | 57 // Called by JingleSessionManager for incoming connections. |
| 60 void InitializeIncomingConnection(const JingleMessage& initiate_message, | 58 void InitializeIncomingConnection(const JingleMessage& initiate_message, |
| 61 scoped_ptr<Authenticator> authenticator); | 59 scoped_ptr<Authenticator> authenticator); |
| 62 void AcceptIncomingConnection(const JingleMessage& initiate_message); | 60 void AcceptIncomingConnection(const JingleMessage& initiate_message); |
| 63 | 61 |
| 62 // Callback for Transport interface to send transport-info messages. |
| 63 void SendTransportInfo(scoped_ptr<buzz::XmlElement> transport_info); |
| 64 |
| 64 // Sends |message| to the peer. The session is closed if the send fails or no | 65 // Sends |message| to the peer. The session is closed if the send fails or no |
| 65 // response is received within a reasonable time. All other responses are | 66 // response is received within a reasonable time. All other responses are |
| 66 // ignored. | 67 // ignored. |
| 67 void SendMessage(const JingleMessage& message); | 68 void SendMessage(const JingleMessage& message); |
| 68 | 69 |
| 69 // Iq response handler. | 70 // Iq response handler. |
| 70 void OnMessageResponse(JingleMessage::ActionType request_type, | 71 void OnMessageResponse(JingleMessage::ActionType request_type, |
| 71 IqRequest* request, | 72 IqRequest* request, |
| 72 const buzz::XmlElement* response); | 73 const buzz::XmlElement* response); |
| 73 | 74 |
| 74 // Transport::EventHandler interface. | |
| 75 void OnOutgoingTransportInfo( | |
| 76 scoped_ptr<buzz::XmlElement> transport_info) override; | |
| 77 void OnTransportRouteChange(const std::string& component, | |
| 78 const TransportRoute& route) override; | |
| 79 void OnTransportConnected() override; | |
| 80 void OnTransportError(ErrorCode error) override; | |
| 81 | |
| 82 // Response handler for transport-info responses. Transport-info timeouts are | 75 // Response handler for transport-info responses. Transport-info timeouts are |
| 83 // ignored and don't terminate connection. | 76 // ignored and don't terminate connection. |
| 84 void OnTransportInfoResponse(IqRequest* request, | 77 void OnTransportInfoResponse(IqRequest* request, |
| 85 const buzz::XmlElement* response); | 78 const buzz::XmlElement* response); |
| 86 | 79 |
| 87 // Called by JingleSessionManager on incoming |message|. Must call | 80 // Called by JingleSessionManager on incoming |message|. Must call |
| 88 // |reply_callback| to send reply message before sending any other | 81 // |reply_callback| to send reply message before sending any other |
| 89 // messages. | 82 // messages. |
| 90 void OnIncomingMessage(const JingleMessage& message, | 83 void OnIncomingMessage(const JingleMessage& message, |
| 91 const ReplyCallback& reply_callback); | 84 const ReplyCallback& reply_callback); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 112 | 105 |
| 113 // Called when authentication is finished. | 106 // Called when authentication is finished. |
| 114 void OnAuthenticated(); | 107 void OnAuthenticated(); |
| 115 | 108 |
| 116 // Sets |state_| to |new_state| and calls state change callback. | 109 // Sets |state_| to |new_state| and calls state change callback. |
| 117 void SetState(State new_state); | 110 void SetState(State new_state); |
| 118 | 111 |
| 119 // Returns true if the state of the session is not CLOSED or FAILED | 112 // Returns true if the state of the session is not CLOSED or FAILED |
| 120 bool is_session_active(); | 113 bool is_session_active(); |
| 121 | 114 |
| 115 base::ThreadChecker thread_checker_; |
| 116 |
| 122 JingleSessionManager* session_manager_; | 117 JingleSessionManager* session_manager_; |
| 123 std::string peer_jid_; | 118 std::string peer_jid_; |
| 124 Session::EventHandler* event_handler_; | 119 Session::EventHandler* event_handler_; |
| 125 | 120 |
| 126 std::string session_id_; | 121 std::string session_id_; |
| 127 State state_; | 122 State state_; |
| 128 ErrorCode error_; | 123 ErrorCode error_; |
| 129 | 124 |
| 130 scoped_ptr<SessionConfig> config_; | 125 scoped_ptr<SessionConfig> config_; |
| 131 | 126 |
| 132 scoped_ptr<Authenticator> authenticator_; | 127 scoped_ptr<Authenticator> authenticator_; |
| 133 | 128 |
| 134 scoped_ptr<Transport> transport_; | 129 Transport* transport_ = nullptr; |
| 135 | 130 |
| 136 // Pending Iq requests. Used for all messages except transport-info. | 131 // Pending Iq requests. Used for all messages except transport-info. |
| 137 std::set<IqRequest*> pending_requests_; | 132 std::set<IqRequest*> pending_requests_; |
| 138 | 133 |
| 139 // Pending transport-info requests. | 134 // Pending transport-info requests. |
| 140 std::list<IqRequest*> transport_info_requests_; | 135 std::list<IqRequest*> transport_info_requests_; |
| 141 | 136 |
| 142 base::WeakPtrFactory<JingleSession> weak_factory_; | 137 base::WeakPtrFactory<JingleSession> weak_factory_; |
| 143 | 138 |
| 144 DISALLOW_COPY_AND_ASSIGN(JingleSession); | 139 DISALLOW_COPY_AND_ASSIGN(JingleSession); |
| 145 }; | 140 }; |
| 146 | 141 |
| 147 } // namespace protocol | 142 } // namespace protocol |
| 148 } // namespace remoting | 143 } // namespace remoting |
| 149 | 144 |
| 150 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ | 145 #endif // REMOTING_PROTOCOL_JINGLE_SESSION_H_ |
| OLD | NEW |