Index: remoting/host/gnubby_auth_handler.h |
diff --git a/remoting/host/gnubby_auth_handler.h b/remoting/host/gnubby_auth_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..84d9c0e51d990e0b9c1e5fca16967076d9ad8563 |
--- /dev/null |
+++ b/remoting/host/gnubby_auth_handler.h |
@@ -0,0 +1,107 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |
+#define REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |
+ |
+#include <map> |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/single_thread_task_runner.h" |
+#include "net/socket/stream_socket.h" |
+#include "net/socket/tcp_server_socket.h" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
+} // namespace base |
+ |
+namespace remoting { |
+namespace protocol { |
+class ClientStub; |
+} // namespace protocol |
+ |
+class GnubbyConnection; |
+class GnubbyConnectionFactory; |
+ |
+// Class responsible for proxying authentication data between a local gnubbyd |
+// and the client. |
+ |
+class GnubbyAuthHandler { |
+ public: |
+ GnubbyAuthHandler( |
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
+ GnubbyConnectionFactory* gnubby_connection_factory, |
+ protocol::ClientStub* client_stub); |
+ virtual ~GnubbyAuthHandler(); |
+ |
+ // A message was received from the client. |
+ virtual void DeliverClientMessage(const std::string message); |
+ |
+ // The local gnubbyd closed the connection. |
+ virtual void ConnectionClosed(int connection_id); |
+ |
+ // A error occurred with the connection to the local gnubbyd. |
+ virtual void ConnectionError(int connection_id, int result); |
+ |
+ // Send control message to client. |
+ virtual void DeliverHostControlMessage(const std::string control_type, |
+ const std::string data) const; |
+ |
+ // Send data to client. |
+ virtual void DeliverHostDataMessage(int connection_id, |
+ const std::string data) const; |
+ |
+ // Set the server socket. Takes ownership of |gnubbyd_socket|. |
+ void SetGnubbydSocketForTesting(net::TCPServerSocket* gnubbyd_socket); |
+ |
+ // Add a new connection for unit testing. Takes ownership of |pending_socket| |
+ // and returns the connection id. |
+ int AddGnubbyConnectionForTesting(net::StreamSocket* pending_socket); |
+ |
+ // Returns true if there is a connection with the given id. |
+ bool HasGnubbyConnectionForTesting(int connection_id) const; |
+ |
+ private: |
+ // Create socket for local gnubbyd. |
+ void CreateGnubbydSocket(); |
+ |
+ // Listen for gnubbyd connections. |
+ void AcceptGnubbydConnections(); |
+ |
+ // Called when gnubbyd makes a connection. |
+ void OnAccept(int result); |
+ |
+ // Task runner used by this class. |
+ scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
+ |
+ // Factory to create GnubbyConnection objects. |
+ GnubbyConnectionFactory* gnubby_connection_factory_; |
+ |
+ // Interfaces through which communication with the client occurs. |
+ protocol::ClientStub* client_stub_; |
+ |
+ // Socket used to listen for local gnubbyd connections. |
+ scoped_ptr<net::TCPServerSocket> gnubbyd_socket_; |
+ |
+ // Socket that gnubbyd will connect to. |
+ scoped_ptr<net::StreamSocket> pending_socket_; |
+ |
+ // The current gnubby connection id. |
+ int current_connection_id_; |
+ |
+ // Active connections by connection id. |
+ typedef std::map<int, GnubbyConnection*> ConnectionMap; |
+ ConnectionMap active_connections_; |
+ |
+ // The port number that gnubbyd will establish connections with. |
+ int gnubbyd_listener_port_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandler); |
+}; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |