OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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_HOST_GNUBBY_AUTH_HANDLER_H_ |
| 6 #define REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/non_thread_safe.h" |
| 15 #include "net/socket/stream_socket.h" |
| 16 #include "net/socket/tcp_server_socket.h" |
| 17 |
| 18 namespace base { |
| 19 class SingleThreadTaskRunner; |
| 20 } // namespace base |
| 21 |
| 22 namespace remoting { |
| 23 namespace protocol { |
| 24 class ClientStub; |
| 25 } // namespace protocol |
| 26 |
| 27 class GnubbyConnection; |
| 28 class GnubbyConnectionFactory; |
| 29 |
| 30 // Class responsible for proxying authentication data between a local gnubbyd |
| 31 // and the client. |
| 32 |
| 33 class GnubbyAuthHandler : public base::NonThreadSafe { |
| 34 public: |
| 35 GnubbyAuthHandler( |
| 36 GnubbyConnectionFactory* gnubby_connection_factory, |
| 37 protocol::ClientStub* client_stub); |
| 38 virtual ~GnubbyAuthHandler(); |
| 39 |
| 40 // A message was received from the client. |
| 41 virtual void DeliverClientMessage(const std::string message); |
| 42 |
| 43 // The local gnubbyd closed the connection. |
| 44 virtual void ConnectionClosed(int connection_id); |
| 45 |
| 46 // A error occurred with the connection to the local gnubbyd. |
| 47 virtual void ConnectionError(int connection_id, int result); |
| 48 |
| 49 // Send control message to client. |
| 50 virtual void DeliverHostControlMessage(const std::string control_type, |
| 51 const std::string data) const; |
| 52 |
| 53 // Send data to client. |
| 54 virtual void DeliverHostDataMessage(int connection_id, |
| 55 const std::string data) const; |
| 56 |
| 57 // Set the server socket. Takes ownership of |gnubbyd_socket|. |
| 58 void SetGnubbydSocketForTesting(net::TCPServerSocket* gnubbyd_socket); |
| 59 |
| 60 // Add a new connection for unit testing. Takes ownership of |pending_socket| |
| 61 // and returns the connection id. |
| 62 int AddGnubbyConnectionForTesting(net::StreamSocket* pending_socket); |
| 63 |
| 64 // Returns true if there is a connection with the given id. |
| 65 bool HasGnubbyConnectionForTesting(int connection_id) const; |
| 66 |
| 67 private: |
| 68 // Create socket for local gnubbyd. |
| 69 void CreateGnubbydSocket(); |
| 70 |
| 71 // Listen for gnubbyd connections. |
| 72 void AcceptGnubbydConnections(); |
| 73 |
| 74 // Called when gnubbyd makes a connection. |
| 75 void OnAccept(int result); |
| 76 |
| 77 // Factory to create GnubbyConnection objects. |
| 78 GnubbyConnectionFactory* gnubby_connection_factory_; |
| 79 |
| 80 // Interfaces through which communication with the client occurs. |
| 81 protocol::ClientStub* client_stub_; |
| 82 |
| 83 // Socket used to listen for local gnubbyd connections. |
| 84 scoped_ptr<net::TCPServerSocket> gnubbyd_socket_; |
| 85 |
| 86 // Socket that gnubbyd will connect to. |
| 87 scoped_ptr<net::StreamSocket> pending_socket_; |
| 88 |
| 89 // The current gnubby connection id. |
| 90 int current_connection_id_; |
| 91 |
| 92 // Active connections by connection id. |
| 93 typedef std::map<int, GnubbyConnection*> ConnectionMap; |
| 94 ConnectionMap active_connections_; |
| 95 |
| 96 // The port number that gnubbyd will establish connections with. |
| 97 int gnubbyd_listener_port_; |
| 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandler); |
| 100 }; |
| 101 |
| 102 } // namespace remoting |
| 103 |
| 104 #endif // REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |
OLD | NEW |