| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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_SECURITY_KEY_SECURITY_KEY_IPC_CLIENT_H_ | |
| 6 #define REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_IPC_CLIENT_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 #include "ipc/ipc_listener.h" | |
| 15 | |
| 16 namespace IPC { | |
| 17 class Channel; | |
| 18 class Message; | |
| 19 } // IPC | |
| 20 | |
| 21 namespace remoting { | |
| 22 | |
| 23 // Responsible for handing the client end of the IPC channel between the | |
| 24 // the network process (server) and remote_security_key process (client). | |
| 25 // The public methods are virtual to allow for using fake objects for testing. | |
| 26 class SecurityKeyIpcClient : public IPC::Listener { | |
| 27 public: | |
| 28 SecurityKeyIpcClient(); | |
| 29 ~SecurityKeyIpcClient() override; | |
| 30 | |
| 31 // Used to send security key extension messages to the client. | |
| 32 typedef base::Callback<void(const std::string& response_data)> | |
| 33 ResponseCallback; | |
| 34 | |
| 35 // Returns true if there is an active remoting session which supports | |
| 36 // security key request forwarding. | |
| 37 virtual bool WaitForSecurityKeyIpcServerChannel(); | |
| 38 | |
| 39 // Begins the process of connecting to the IPC channel which will be used for | |
| 40 // exchanging security key messages. | |
| 41 // |connection_ready_callback| is called when a channel has been established | |
| 42 // and security key requests can be sent. | |
| 43 // |connection_error_callback| is stored and will be called back for any | |
| 44 // unexpected errors that occur while establishing, or during, the session. | |
| 45 virtual void EstablishIpcConnection( | |
| 46 const base::Closure& connection_ready_callback, | |
| 47 const base::Closure& connection_error_callback); | |
| 48 | |
| 49 // Sends a security key request message to the network process to be forwarded | |
| 50 // to the remote client. | |
| 51 virtual bool SendSecurityKeyRequest( | |
| 52 const std::string& request_payload, | |
| 53 const ResponseCallback& response_callback); | |
| 54 | |
| 55 // Closes the IPC channel if connected. | |
| 56 virtual void CloseIpcConnection(); | |
| 57 | |
| 58 // Allows tests to override the initial IPC channel used to retrieve IPC | |
| 59 // connection details. | |
| 60 void SetInitialIpcChannelNameForTest( | |
| 61 const std::string& initial_ipc_channel_name); | |
| 62 | |
| 63 // Allows tests to override the expected session ID. | |
| 64 void SetExpectedIpcServerSessionIdForTest(uint32_t expected_session_id); | |
| 65 | |
| 66 private: | |
| 67 // IPC::Listener implementation. | |
| 68 bool OnMessageReceived(const IPC::Message& message) override; | |
| 69 void OnChannelConnected(int32_t peer_pid) override; | |
| 70 void OnChannelError() override; | |
| 71 | |
| 72 // Handles the ConnectionDetails IPC message. | |
| 73 void OnConnectionDetails(const std::string& request_data); | |
| 74 | |
| 75 // Handles security key response IPC messages. | |
| 76 void OnSecurityKeyResponse(const std::string& request_data); | |
| 77 | |
| 78 // Establishes a connection to the specified IPC Server channel. | |
| 79 void ConnectToIpcChannel(const std::string& channel_name); | |
| 80 | |
| 81 // Used to validate the IPC Server process is running in the correct session. | |
| 82 // '0' (default) corresponds to the session the network process runs in. | |
| 83 uint32_t expected_ipc_server_session_id_ = 0; | |
| 84 | |
| 85 // Name for the IPC channel used for exchanging security key messages. | |
| 86 std::string ipc_channel_name_; | |
| 87 | |
| 88 // Name of the initial IPC channel used to retrieve connection info. | |
| 89 std::string initial_ipc_channel_name_; | |
| 90 | |
| 91 // Signaled when the IPC connection is ready for security key requests. | |
| 92 base::Closure connection_ready_callback_; | |
| 93 | |
| 94 // Signaled when an error occurs in either the IPC channel or communication. | |
| 95 base::Closure connection_error_callback_; | |
| 96 | |
| 97 // Signaled when a security key response has been received. | |
| 98 ResponseCallback response_callback_; | |
| 99 | |
| 100 // Used for sending/receiving security key messages between processes. | |
| 101 std::unique_ptr<IPC::Channel> ipc_channel_; | |
| 102 | |
| 103 base::ThreadChecker thread_checker_; | |
| 104 | |
| 105 base::WeakPtrFactory<SecurityKeyIpcClient> weak_factory_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcClient); | |
| 108 }; | |
| 109 | |
| 110 } // namespace remoting | |
| 111 | |
| 112 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_IPC_CLIENT_H_ | |
| OLD | NEW |