Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / remoting / host / gnubby_auth_handler_posix.h
blobdb38886c8d425c88281cbbed5cf1606e76027026
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 virtual ~GnubbyAuthHandlerPosix();
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 virtual void DeliverClientMessage(const std::string& message) OVERRIDE;
45 virtual void DeliverHostDataMessage(int connection_id,
46 const std::string& data) const OVERRIDE;
48 // StreamListenSocket::Delegate interface.
49 virtual void DidAccept(net::StreamListenSocket* server,
50 scoped_ptr<net::StreamListenSocket> socket) OVERRIDE;
51 virtual void DidRead(net::StreamListenSocket* socket,
52 const char* data,
53 int len) OVERRIDE;
54 virtual 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_