Revert of Remove OneClickSigninHelper since it is no longer used. (patchset #5 id...
[chromium-blink-merge.git] / remoting / host / gnubby_auth_handler_posix.h
blobd1af652877215311bb064ba64d36ae552304d932
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.
5 #ifndef REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_
6 #define REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_
8 #include <map>
9 #include <string>
11 #include "base/memory/scoped_ptr.h"
12 #include "base/threading/non_thread_safe.h"
13 #include "net/socket/stream_listen_socket.h"
14 #include "remoting/host/gnubby_auth_handler.h"
16 namespace base {
17 class DictionaryValue;
18 } // namespace base
20 namespace remoting {
22 namespace protocol {
23 class ClientStub;
24 } // namespace protocol
26 class GnubbySocket;
28 class GnubbyAuthHandlerPosix : public GnubbyAuthHandler,
29 public base::NonThreadSafe,
30 public net::StreamListenSocket::Delegate {
31 public:
32 explicit GnubbyAuthHandlerPosix(protocol::ClientStub* client_stub);
33 ~GnubbyAuthHandlerPosix() override;
35 bool HasActiveSocketForTesting(net::StreamListenSocket* socket) const;
36 int GetConnectionIdForTesting(net::StreamListenSocket* socket) const;
37 GnubbySocket* GetGnubbySocketForTesting(
38 net::StreamListenSocket* socket) const;
40 private:
41 typedef std::map<int, GnubbySocket*> ActiveSockets;
43 // GnubbyAuthHandler interface.
44 void DeliverClientMessage(const std::string& message) override;
45 void DeliverHostDataMessage(int connection_id,
46 const std::string& data) const override;
48 // StreamListenSocket::Delegate interface.
49 void DidAccept(net::StreamListenSocket* server,
50 scoped_ptr<net::StreamListenSocket> socket) override;
51 void DidRead(net::StreamListenSocket* socket,
52 const char* data,
53 int len) override;
54 void DidClose(net::StreamListenSocket* socket) override;
56 // Create socket for authorization.
57 void CreateAuthorizationSocket();
59 // Process a gnubby request.
60 void ProcessGnubbyRequest(int connection_id, const std::string& request_data);
62 // Gets an active socket iterator for the connection id in |message|.
63 ActiveSockets::iterator GetSocketForMessage(base::DictionaryValue* message);
65 // Send an error and close an active socket.
66 void SendErrorAndCloseActiveSocket(const ActiveSockets::iterator& iter);
68 // A request timed out.
69 void RequestTimedOut(int connection_id);
71 // Interface through which communication with the client occurs.
72 protocol::ClientStub* client_stub_;
74 // Socket used to listen for authorization requests.
75 scoped_ptr<net::StreamListenSocket> auth_socket_;
77 // The last assigned gnubby connection id.
78 int last_connection_id_;
80 // Sockets by connection id used to process gnubbyd requests.
81 ActiveSockets active_sockets_;
83 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerPosix);
86 } // namespace remoting
88 #endif // REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_