| 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 // JingleHostConnection implements the HostConnection interface using | 5 // JingleHostConnection implements the HostConnection interface using |
| 6 // libjingle as the transport protocol. | 6 // libjingle as the transport protocol. |
| 7 // | 7 // |
| 8 // Much of this class focuses on translating JingleClient and | 8 // Much of this class focuses on translating JingleClient and |
| 9 // ChromotingConnection callbacks into HostConnection::HostEventCallback | 9 // ChromotingConnection callbacks into HostConnection::HostEventCallback |
| 10 // messages. | 10 // messages. |
| 11 // | 11 // |
| 12 // The public API of this class is designed to be asynchronous, and thread | 12 // The public API of this class is designed to be asynchronous, and thread |
| 13 // safe for invocation from other threads. | 13 // safe for invocation from other threads. |
| 14 // | 14 // |
| 15 // Internally though, all work delegeated to the |network_thread| given | 15 // Internally though, all work delegeated to the |network_thread| given |
| 16 // during construction. Any event handlers running on the |network_thread| | 16 // during construction. Any event handlers running on the |network_thread| |
| 17 // should not block. | 17 // should not block. |
| 18 | 18 |
| 19 #ifndef REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_ | 19 #ifndef REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_ |
| 20 #define REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_ | 20 #define REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_ |
| 21 | 21 |
| 22 #include "base/ref_counted.h" | 22 #include "base/ref_counted.h" |
| 23 #include "base/scoped_ptr.h" | 23 #include "base/scoped_ptr.h" |
| 24 #include "base/task.h" | 24 #include "base/task.h" |
| 25 #include "remoting/client/client_context.h" | 25 #include "remoting/client/client_context.h" |
| 26 #include "remoting/client/host_connection.h" | 26 #include "remoting/client/host_connection.h" |
| 27 #include "remoting/jingle_glue/jingle_client.h" | 27 #include "remoting/jingle_glue/jingle_client.h" |
| 28 #include "remoting/protocol/message_reader.h" | 28 #include "remoting/protocol/message_reader.h" |
| 29 #include "remoting/protocol/chromotocol_connection.h" | 29 #include "remoting/protocol/session.h" |
| 30 #include "remoting/protocol/chromotocol_server.h" | 30 #include "remoting/protocol/session_manager.h" |
| 31 #include "remoting/protocol/stream_writer.h" | 31 #include "remoting/protocol/stream_writer.h" |
| 32 #include "remoting/protocol/video_reader.h" | 32 #include "remoting/protocol/video_reader.h" |
| 33 | 33 |
| 34 class MessageLoop; | 34 class MessageLoop; |
| 35 | 35 |
| 36 namespace remoting { | 36 namespace remoting { |
| 37 | 37 |
| 38 class JingleThread; | 38 namespace protocol { |
| 39 class VideoStub; | 39 class VideoStub; |
| 40 } // namespace protocol |
| 40 | 41 |
| 41 struct ClientConfig; | 42 struct ClientConfig; |
| 42 | 43 |
| 43 class JingleHostConnection : public HostConnection, | 44 class JingleHostConnection : public HostConnection, |
| 44 public JingleClient::Callback { | 45 public JingleClient::Callback { |
| 45 public: | 46 public: |
| 46 explicit JingleHostConnection(ClientContext* context); | 47 explicit JingleHostConnection(ClientContext* context); |
| 47 virtual ~JingleHostConnection(); | 48 virtual ~JingleHostConnection(); |
| 48 | 49 |
| 49 virtual void Connect(const ClientConfig& config, | 50 virtual void Connect(const ClientConfig& config, |
| 50 HostEventCallback* event_callback, | 51 HostEventCallback* event_callback, |
| 51 VideoStub* video_stub); | 52 VideoStub* video_stub); |
| 52 virtual void Disconnect(); | 53 virtual void Disconnect(); |
| 53 | 54 |
| 54 virtual void SendEvent(const ChromotingClientMessage& msg); | 55 virtual void SendEvent(const ChromotingClientMessage& msg); |
| 55 | 56 |
| 56 // JingleClient::Callback interface. | 57 // JingleClient::Callback interface. |
| 57 virtual void OnStateChange(JingleClient* client, JingleClient::State state); | 58 virtual void OnStateChange(JingleClient* client, JingleClient::State state); |
| 58 | 59 |
| 59 // Callback for ChromotocolServer. | 60 // Callback for chromotocol SessionManager. |
| 60 void OnNewChromotocolConnection( | 61 void OnNewSession( |
| 61 ChromotocolConnection* connection, | 62 protocol::Session* connection, |
| 62 ChromotocolServer::IncomingConnectionResponse* response); | 63 protocol::SessionManager::IncomingSessionResponse* response); |
| 63 | 64 |
| 64 // Callback for ChromotocolConnection. | 65 // Callback for chromotocol Session. |
| 65 void OnConnectionStateChange(ChromotocolConnection::State state); | 66 void OnSessionStateChange(protocol::Session::State state); |
| 66 | 67 |
| 67 private: | 68 private: |
| 68 // The message loop for the jingle thread this object works on. | 69 // The message loop for the jingle thread this object works on. |
| 69 MessageLoop* message_loop(); | 70 MessageLoop* message_loop(); |
| 70 | 71 |
| 71 // Called on the jingle thread after we've successfully to XMPP server. Starts | 72 // Called on the jingle thread after we've successfully to XMPP server. Starts |
| 72 // P2P connection to the host. | 73 // P2P connection to the host. |
| 73 void InitConnection(); | 74 void InitSession(); |
| 74 | 75 |
| 75 // Callback for |control_reader_|. | 76 // Callback for |control_reader_|. |
| 76 void OnControlMessage(ChromotingHostMessage* msg); | 77 void OnControlMessage(ChromotingHostMessage* msg); |
| 77 | 78 |
| 78 // Callback for |video_reader_|. | 79 // Callback for |video_reader_|. |
| 79 void OnVideoPacket(VideoPacket* packet); | 80 void OnVideoPacket(VideoPacket* packet); |
| 80 | 81 |
| 81 // Used by Disconnect() to disconnect chromoting connection, stop chromoting | 82 // Used by Disconnect() to disconnect chromoting connection, stop chromoting |
| 82 // server, and then disconnect XMPP connection. | 83 // server, and then disconnect XMPP connection. |
| 83 void OnDisconnected(); | 84 void OnDisconnected(); |
| 84 void OnServerClosed(); | 85 void OnServerClosed(); |
| 85 | 86 |
| 86 ClientContext* context_; | 87 ClientContext* context_; |
| 87 | 88 |
| 88 scoped_refptr<JingleClient> jingle_client_; | 89 scoped_refptr<JingleClient> jingle_client_; |
| 89 scoped_refptr<ChromotocolServer> chromotocol_server_; | 90 scoped_refptr<protocol::SessionManager> session_manager_; |
| 90 scoped_refptr<ChromotocolConnection> connection_; | 91 scoped_refptr<protocol::Session> session_; |
| 91 | 92 |
| 92 MessageReader control_reader_; | 93 MessageReader control_reader_; |
| 93 EventStreamWriter event_writer_; | 94 EventStreamWriter event_writer_; |
| 94 scoped_ptr<VideoReader> video_reader_; | 95 scoped_ptr<VideoReader> video_reader_; |
| 95 | 96 |
| 96 HostEventCallback* event_callback_; | 97 HostEventCallback* event_callback_; |
| 97 VideoStub* video_stub_; | 98 VideoStub* video_stub_; |
| 98 | 99 |
| 99 std::string host_jid_; | 100 std::string host_jid_; |
| 100 | 101 |
| 101 DISALLOW_COPY_AND_ASSIGN(JingleHostConnection); | 102 DISALLOW_COPY_AND_ASSIGN(JingleHostConnection); |
| 102 }; | 103 }; |
| 103 | 104 |
| 104 } // namespace remoting | 105 } // namespace remoting |
| 105 | 106 |
| 106 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::JingleHostConnection); | 107 DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::JingleHostConnection); |
| 107 | 108 |
| 108 #endif // REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_ | 109 #endif // REMOTING_CLIENT_JINGLE_HOST_CONNECTION_H_ |
| OLD | NEW |