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