| 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_PEPPER_SESSION_H_ | 5 #ifndef REMOTING_PROTOCOL_PEPPER_SESSION_H_ |
| 6 #define REMOTING_PROTOCOL_PEPPER_SESSION_H_ | 6 #define REMOTING_PROTOCOL_PEPPER_SESSION_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 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/timer.h" | 13 #include "base/timer.h" |
| 14 #include "crypto/rsa_private_key.h" | 14 #include "crypto/rsa_private_key.h" |
| 15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 16 #include "remoting/jingle_glue/iq_sender.h" | |
| 17 #include "remoting/protocol/authenticator.h" | 16 #include "remoting/protocol/authenticator.h" |
| 18 #include "remoting/protocol/jingle_messages.h" | 17 #include "remoting/protocol/jingle_messages.h" |
| 19 #include "remoting/protocol/session.h" | 18 #include "remoting/protocol/session.h" |
| 20 #include "remoting/protocol/session_config.h" | 19 #include "remoting/protocol/session_config.h" |
| 21 #include "remoting/protocol/transport.h" | 20 #include "remoting/protocol/transport.h" |
| 22 | 21 |
| 23 namespace net { | 22 namespace net { |
| 24 class Socket; | 23 class Socket; |
| 25 class StreamSocket; | 24 class StreamSocket; |
| 26 } // namespace net | 25 } // namespace net |
| 27 | 26 |
| 28 namespace remoting { | 27 namespace remoting { |
| 28 |
| 29 class IqRequest; |
| 30 |
| 29 namespace protocol { | 31 namespace protocol { |
| 30 | 32 |
| 31 class JingleSessionManager; | 33 class JingleSessionManager; |
| 32 | 34 |
| 33 // JingleSessionManager and JingleSession implement the subset of the | 35 // JingleSessionManager and JingleSession implement the subset of the |
| 34 // Jingle protocol used in Chromoting. Instances of this class are | 36 // Jingle protocol used in Chromoting. Instances of this class are |
| 35 // created by the JingleSessionManager. | 37 // created by the JingleSessionManager. |
| 36 class JingleSession : public Session, | 38 class JingleSession : public Session, |
| 37 public Transport::EventHandler { | 39 public Transport::EventHandler { |
| 38 public: | 40 public: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 void StartConnection(const std::string& peer_jid, | 79 void StartConnection(const std::string& peer_jid, |
| 78 scoped_ptr<Authenticator> authenticator, | 80 scoped_ptr<Authenticator> authenticator, |
| 79 scoped_ptr<CandidateSessionConfig> config, | 81 scoped_ptr<CandidateSessionConfig> config, |
| 80 const StateChangeCallback& state_change_callback); | 82 const StateChangeCallback& state_change_callback); |
| 81 | 83 |
| 82 // Called by JingleSessionManager for incoming connections. | 84 // Called by JingleSessionManager for incoming connections. |
| 83 void InitializeIncomingConnection(const JingleMessage& initiate_message, | 85 void InitializeIncomingConnection(const JingleMessage& initiate_message, |
| 84 scoped_ptr<Authenticator> authenticator); | 86 scoped_ptr<Authenticator> authenticator); |
| 85 void AcceptIncomingConnection(const JingleMessage& initiate_message); | 87 void AcceptIncomingConnection(const JingleMessage& initiate_message); |
| 86 | 88 |
| 87 // Helper to send IqRequests to the peer. It sets up the response | 89 // Handler for session-initiate response. |
| 88 // callback to OnMessageResponse() which simply terminates the | 90 void OnSessionInitiateResponse(const buzz::XmlElement* response); |
| 89 // session whenever a request fails or times out. This method should | |
| 90 // not be used for messages that need to be handled differently. | |
| 91 void SendMessage(const JingleMessage& message); | |
| 92 void OnMessageResponse(JingleMessage::ActionType request_type, | |
| 93 IqRequest* request, | |
| 94 const buzz::XmlElement* response); | |
| 95 void CleanupPendingRequests(IqRequest* request); | |
| 96 | 91 |
| 97 // Called by JingleSessionManager on incoming |message|. Must call | 92 // Called by JingleSessionManager on incoming |message|. Must call |
| 98 // |reply_callback| to send reply message before sending any other | 93 // |reply_callback| to send reply message before sending any other |
| 99 // messages. | 94 // messages. |
| 100 void OnIncomingMessage(const JingleMessage& message, | 95 void OnIncomingMessage(const JingleMessage& message, |
| 101 const ReplyCallback& reply_callback); | 96 const ReplyCallback& reply_callback); |
| 102 | 97 |
| 103 // Message handlers for incoming messages. | 98 // Message handlers for incoming messages. |
| 104 void OnAccept(const JingleMessage& message, | 99 void OnAccept(const JingleMessage& message, |
| 105 const ReplyCallback& reply_callback); | 100 const ReplyCallback& reply_callback); |
| 106 void OnSessionInfo(const JingleMessage& message, | 101 void OnSessionInfo(const JingleMessage& message, |
| 107 const ReplyCallback& reply_callback); | 102 const ReplyCallback& reply_callback); |
| 108 void OnTerminate(const JingleMessage& message, | 103 void OnTerminate(const JingleMessage& message, |
| 109 const ReplyCallback& reply_callback); | 104 const ReplyCallback& reply_callback); |
| 110 void ProcessTransportInfo(const JingleMessage& message); | 105 void ProcessTransportInfo(const JingleMessage& message); |
| 111 | 106 |
| 112 // Called from OnAccept() to initialize session config. | 107 // Called from OnAccept() to initialize session config. |
| 113 bool InitializeConfigFromDescription(const ContentDescription* description); | 108 bool InitializeConfigFromDescription(const ContentDescription* description); |
| 114 | 109 |
| 115 void ProcessAuthenticationStep(); | 110 void ProcessAuthenticationStep(); |
| 111 void OnSessionInfoResponse(const buzz::XmlElement* response); |
| 116 | 112 |
| 117 void SendTransportInfo(); | 113 void SendTransportInfo(); |
| 114 void OnTransportInfoResponse(const buzz::XmlElement* response); |
| 118 | 115 |
| 119 // Terminates the session and sends session-terminate if it is | 116 // Terminates the session and sends session-terminate if it is |
| 120 // necessary. |error| specifies the error code in case when the | 117 // necessary. |error| specifies the error code in case when the |
| 121 // session is being closed due to an error. | 118 // session is being closed due to an error. |
| 122 void CloseInternal(Error error); | 119 void CloseInternal(Error error); |
| 123 | 120 |
| 124 // Sets |state_| to |new_state| and calls state change callback. | 121 // Sets |state_| to |new_state| and calls state change callback. |
| 125 void SetState(State new_state); | 122 void SetState(State new_state); |
| 126 | 123 |
| 127 JingleSessionManager* session_manager_; | 124 JingleSessionManager* session_manager_; |
| 128 std::string peer_jid_; | 125 std::string peer_jid_; |
| 129 scoped_ptr<CandidateSessionConfig> candidate_config_; | 126 scoped_ptr<CandidateSessionConfig> candidate_config_; |
| 130 StateChangeCallback state_change_callback_; | 127 StateChangeCallback state_change_callback_; |
| 131 RouteChangeCallback route_change_callback_; | 128 RouteChangeCallback route_change_callback_; |
| 132 | 129 |
| 133 std::string session_id_; | 130 std::string session_id_; |
| 134 State state_; | 131 State state_; |
| 135 Error error_; | 132 Error error_; |
| 136 | 133 |
| 137 SessionConfig config_; | 134 SessionConfig config_; |
| 138 bool config_is_set_; | 135 bool config_is_set_; |
| 139 | 136 |
| 140 scoped_ptr<Authenticator> authenticator_; | 137 scoped_ptr<Authenticator> authenticator_; |
| 141 | 138 |
| 142 // Container for pending Iq requests. Requests are removed in | 139 scoped_ptr<IqRequest> initiate_request_; |
| 143 // CleanupPendingRequests() which is called when a response is | 140 scoped_ptr<IqRequest> session_info_request_; |
| 144 // received or one of the requests times out. | 141 scoped_ptr<IqRequest> transport_info_request_; |
| 145 std::list<IqRequest*> pending_requests_; | |
| 146 | 142 |
| 147 ChannelsMap channels_; | 143 ChannelsMap channels_; |
| 148 | 144 |
| 149 base::OneShotTimer<JingleSession> transport_infos_timer_; | 145 base::OneShotTimer<JingleSession> transport_infos_timer_; |
| 150 std::list<cricket::Candidate> pending_candidates_; | 146 std::list<cricket::Candidate> pending_candidates_; |
| 151 | 147 |
| 152 DISALLOW_COPY_AND_ASSIGN(JingleSession); | 148 DISALLOW_COPY_AND_ASSIGN(JingleSession); |
| 153 }; | 149 }; |
| 154 | 150 |
| 155 } // namespace protocol | 151 } // namespace protocol |
| 156 } // namespace remoting | 152 } // namespace remoting |
| 157 | 153 |
| 158 #endif // REMOTING_PROTOCOL_PEPPER_SESSION_H_ | 154 #endif // REMOTING_PROTOCOL_PEPPER_SESSION_H_ |
| OLD | NEW |