Bring the browser window to the front when clicking on deprecated accelerator notific...
[chromium-blink-merge.git] / remoting / host / gnubby_auth_handler_posix.h
blob2b4668b3291c4d15fc662842d2b64322079d57be
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/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "net/base/completion_callback.h"
15 #include "net/socket/stream_socket.h"
16 #include "remoting/host/gnubby_auth_handler.h"
18 namespace base {
19 class DictionaryValue;
20 } // namespace base
22 namespace net {
23 class UnixDomainServerSocket;
24 } // namespace net
26 namespace remoting {
28 namespace protocol {
29 class ClientStub;
30 } // namespace protocol
32 class GnubbySocket;
34 class GnubbyAuthHandlerPosix : public GnubbyAuthHandler,
35 public base::NonThreadSafe {
36 public:
37 explicit GnubbyAuthHandlerPosix(protocol::ClientStub* client_stub);
38 ~GnubbyAuthHandlerPosix() override;
40 size_t GetActiveSocketsMapSizeForTest() const;
42 void SetRequestTimeoutForTest(const base::TimeDelta& timeout);
44 private:
45 typedef std::map<int, GnubbySocket*> ActiveSockets;
47 // GnubbyAuthHandler interface.
48 void DeliverClientMessage(const std::string& message) override;
49 void DeliverHostDataMessage(int connection_id,
50 const std::string& data) const override;
52 // Starts listening for connection.
53 void DoAccept();
55 // Called when a connection is accepted.
56 void OnAccepted(int result);
58 // Called when a GnubbySocket has done reading.
59 void OnReadComplete(int connection_id);
61 // Create socket for authorization.
62 void CreateAuthorizationSocket();
64 // Process a gnubby request.
65 void ProcessGnubbyRequest(int connection_id, const std::string& request_data);
67 // Gets an active socket iterator for the connection id in |message|.
68 ActiveSockets::iterator GetSocketForMessage(base::DictionaryValue* message);
70 // Send an error and closes an active socket.
71 void SendErrorAndCloseActiveSocket(const ActiveSockets::iterator& iter);
73 // A request timed out.
74 void RequestTimedOut(int connection_id);
76 // Interface through which communication with the client occurs.
77 protocol::ClientStub* client_stub_;
79 // Socket used to listen for authorization requests.
80 scoped_ptr<net::UnixDomainServerSocket> auth_socket_;
82 // A temporary holder for an accepted connection.
83 scoped_ptr<net::StreamSocket> accept_socket_;
85 // The last assigned gnubby connection id.
86 int last_connection_id_;
88 // Sockets by connection id used to process gnubbyd requests.
89 ActiveSockets active_sockets_;
91 // Timeout used for a request.
92 base::TimeDelta request_timeout_;
94 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandlerPosix);
97 } // namespace remoting
99 #endif // REMOTING_HOST_GNUBBY_AUTH_HANDLER_POSIX_H_