Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_PROTOCOL_PEPPER_SESSION_H_ | |
| 6 #define REMOTING_PROTOCOL_PEPPER_SESSION_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/timer.h" | |
| 13 #include "crypto/rsa_private_key.h" | |
| 14 #include "net/base/completion_callback.h" | |
| 15 #include "remoting/protocol/jingle_messages.h" | |
| 16 #include "remoting/protocol/session.h" | |
| 17 #include "remoting/protocol/session_config.h" | |
| 18 | |
| 19 namespace net { | |
| 20 class CertVerifier; | |
| 21 class ClientSocketFactory; | |
| 22 class Socket; | |
| 23 class StreamSocket; | |
| 24 class X509Certificate; | |
| 25 } // namespace net | |
| 26 | |
| 27 namespace pp { | |
| 28 class Instance; | |
| 29 } // namespace pp | |
| 30 | |
| 31 namespace remoting { | |
| 32 | |
| 33 class IqRequest; | |
| 34 | |
| 35 namespace protocol { | |
| 36 | |
| 37 class PepperChannel; | |
| 38 class PepperSessionManager; | |
| 39 class SocketWrapper; | |
| 40 | |
| 41 // Implements the protocol::Session interface using the Pepper P2P | |
| 42 // Transport API. Created by PepperSessionManager for incoming and | |
| 43 // outgoing connections. | |
| 44 class PepperSession : public Session { | |
| 45 public: | |
| 46 // TODO(sergeyu): Move this type and error() method to Session class. | |
|
Wez
2011/09/09 23:39:12
Isn't Session an interface, not a class?
Sergey Ulanov
2011/09/12 19:50:50
Done.
| |
| 47 enum Error { | |
| 48 ERROR_NO_ERROR = 0, | |
| 49 ERROR_HOST_IS_OFFLINE, | |
| 50 ERROR_SESSION_REJECTED, | |
| 51 ERROR_INCOMPATIBLE_PROTOCOL, | |
| 52 ERROR_CHANNEL_CONNECTION_FAILURE, | |
| 53 }; | |
| 54 | |
| 55 virtual ~PepperSession(); | |
| 56 | |
| 57 Error error(); | |
| 58 | |
| 59 // Chromotocol Session interface. | |
|
Wez
2011/09/09 23:39:12
nit: protocol::Session interface.
Sergey Ulanov
2011/09/12 19:50:50
Changed to "Session interface" Don't think we need
| |
| 60 virtual void SetStateChangeCallback(StateChangeCallback* callback) OVERRIDE; | |
| 61 virtual void CreateStreamChannel( | |
| 62 const std::string& name, | |
| 63 const StreamChannelCallback& callback) OVERRIDE; | |
| 64 virtual void CreateDatagramChannel( | |
| 65 const std::string& name, | |
| 66 const DatagramChannelCallback& callback) OVERRIDE; | |
| 67 virtual net::Socket* control_channel() OVERRIDE; | |
| 68 virtual net::Socket* event_channel() OVERRIDE; | |
| 69 virtual const std::string& jid() OVERRIDE; | |
| 70 virtual const CandidateSessionConfig* candidate_config() OVERRIDE; | |
| 71 virtual const SessionConfig* config() OVERRIDE; | |
| 72 virtual void set_config(const SessionConfig* config) OVERRIDE; | |
| 73 virtual const std::string& initiator_token() OVERRIDE; | |
| 74 virtual void set_initiator_token(const std::string& initiator_token) OVERRIDE; | |
| 75 virtual const std::string& receiver_token() OVERRIDE; | |
| 76 virtual void set_receiver_token(const std::string& receiver_token) OVERRIDE; | |
| 77 virtual void set_shared_secret(const std::string& secret) OVERRIDE; | |
| 78 virtual const std::string& shared_secret() OVERRIDE; | |
| 79 virtual void Close() OVERRIDE; | |
| 80 | |
| 81 private: | |
| 82 friend class PepperSessionManager; | |
| 83 friend class PepperStreamChannel; | |
| 84 | |
| 85 typedef std::map<std::string, PepperChannel*> ChannelsMap; | |
| 86 | |
| 87 PepperSession(PepperSessionManager* session_manager); | |
| 88 | |
| 89 void StartConnection(const std::string& host_jid, | |
| 90 const std::string& host_public_key, | |
| 91 const std::string& client_token, | |
| 92 CandidateSessionConfig* config, | |
| 93 Session::StateChangeCallback* state_change_callback); | |
| 94 void OnSessionInitiateResponse(const buzz::XmlElement* response); | |
|
Wez
2011/09/09 23:39:12
Probably best to add a brief comment for each of t
Sergey Ulanov
2011/09/12 19:50:50
Done.
| |
| 95 | |
| 96 // Called when an error occurs. Sets error code and closes the session. | |
|
Wez
2011/09/09 23:39:12
nit: "... sets |error_| and ..."
Sergey Ulanov
2011/09/12 19:50:50
Done.
| |
| 97 void OnError(Error error); | |
| 98 | |
| 99 // Called by PepperSessionManager on incoming |message|. Must fill | |
| 100 // in |reply|. | |
| 101 void OnIncomingMessage(const JingleMessage& message, | |
| 102 JingleMessageReply* reply); | |
| 103 | |
| 104 // Message handlers for incoming messages. | |
| 105 void OnAccept(const JingleMessage& message, JingleMessageReply* reply); | |
| 106 void OnReject(const JingleMessage& message, JingleMessageReply* reply); | |
| 107 void OnTerminate(const JingleMessage& message, JingleMessageReply* reply); | |
| 108 void ProcessTransportInfo(const JingleMessage& message); | |
| 109 | |
| 110 // Called from OnAccept() to initialize session config. | |
| 111 bool InitializeConfigFromDescription(const ContentDescription* description); | |
| 112 | |
| 113 // Called by PepperChannel. | |
| 114 void AddLocalCandidate(const cricket::Candidate& candidate); | |
| 115 void OnDeleteChannel(PepperChannel* channel); | |
| 116 | |
| 117 void SendTransportInfo(); | |
| 118 | |
| 119 // Helper methods to create event and control channels. | |
| 120 // TODO(sergeyu): Remove these methods. | |
| 121 void CreateChannels(); | |
| 122 void OnChannelConnected(scoped_ptr<net::Socket>* socket_container, | |
| 123 net::StreamSocket* socket); | |
| 124 | |
| 125 // Close all the channels and terminate the session. | |
| 126 void CloseInternal(bool failed); | |
| 127 | |
| 128 // Sets |state_| to |new_state| and calls state callback. | |
|
Wez
2011/09/09 23:39:12
nit: state _change_ callback.
Sergey Ulanov
2011/09/12 19:50:50
Done.
| |
| 129 void SetState(State new_state); | |
| 130 | |
| 131 PepperSessionManager* session_manager_; | |
| 132 std::string host_jid_; | |
| 133 std::string host_public_key_; | |
| 134 scoped_ptr<CandidateSessionConfig> candidate_config_; | |
| 135 scoped_ptr<StateChangeCallback> state_change_callback_; | |
| 136 | |
| 137 std::string session_id_; | |
| 138 State state_; | |
| 139 Error error_; | |
| 140 | |
| 141 std::string remote_cert_; | |
| 142 scoped_ptr<SessionConfig> config_; | |
| 143 | |
| 144 std::string shared_secret_; | |
| 145 std::string initiator_token_; | |
| 146 std::string receiver_token_; | |
| 147 | |
| 148 scoped_ptr<IqRequest> initiate_request_; | |
| 149 | |
| 150 ChannelsMap channels_; | |
| 151 | |
| 152 scoped_ptr<net::Socket> control_channel_socket_; | |
| 153 scoped_ptr<net::Socket> event_channel_socket_; | |
| 154 | |
| 155 base::OneShotTimer<PepperSession> transport_infos_timer_; | |
| 156 std::list<cricket::Candidate> pending_candidates_; | |
| 157 | |
| 158 DISALLOW_COPY_AND_ASSIGN(PepperSession); | |
| 159 }; | |
| 160 | |
| 161 } // namespace protocol | |
| 162 } // namespace remoting | |
| 163 | |
| 164 #endif // REMOTING_PROTOCOL_PEPPER_SESSION_H_ | |
| OLD | NEW |