| 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_REMOTE_SECURITY_KEY_MESSAGE_HANDLER_H_ | |
| 6 #define REMOTING_HOST_SECURITY_KEY_REMOTE_SECURITY_KEY_MESSAGE_HANDLER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/files/file.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/threading/thread_checker.h" | |
| 15 #include "remoting/host/security_key/security_key_message.h" | |
| 16 | |
| 17 namespace remoting { | |
| 18 | |
| 19 class RemoteSecurityKeyIpcClient; | |
| 20 class RemoteSecurityKeyMessageReader; | |
| 21 class RemoteSecurityKeyMessageWriter; | |
| 22 | |
| 23 // Routes security key messages to the remote client and receives response from | |
| 24 // the remote client and forwards them to the local security key tools. | |
| 25 class RemoteSecurityKeyMessageHandler { | |
| 26 public: | |
| 27 RemoteSecurityKeyMessageHandler(); | |
| 28 ~RemoteSecurityKeyMessageHandler(); | |
| 29 | |
| 30 // Sets up the handler to begin receiving and processing messages. | |
| 31 void Start(base::File message_read_stream, | |
| 32 base::File message_write_stream, | |
| 33 std::unique_ptr<RemoteSecurityKeyIpcClient> ipc_client, | |
| 34 const base::Closure& error_callback); | |
| 35 | |
| 36 // Sets |reader_| to the instance passed in via |reader|. This method should | |
| 37 // be called before Start(). | |
| 38 void SetRemoteSecurityKeyMessageReaderForTest( | |
| 39 std::unique_ptr<RemoteSecurityKeyMessageReader> reader); | |
| 40 | |
| 41 // Sets |writer_| to the instance passed in via |writer|. This method should | |
| 42 // be called before Start(). | |
| 43 void SetRemoteSecurityKeyMessageWriterForTest( | |
| 44 std::unique_ptr<RemoteSecurityKeyMessageWriter> writer); | |
| 45 | |
| 46 private: | |
| 47 // RemoteSecurityKeyMessage handler. | |
| 48 void ProcessRemoteSecurityKeyMessage( | |
| 49 std::unique_ptr<SecurityKeyMessage> message); | |
| 50 | |
| 51 // Cleans up resources when an error occurs. | |
| 52 void OnError(); | |
| 53 | |
| 54 // Writes the passed in message data using |writer_|. | |
| 55 void SendMessage(RemoteSecurityKeyMessageType message_type); | |
| 56 void SendMessageWithPayload(RemoteSecurityKeyMessageType message_type, | |
| 57 const std::string& message_payload); | |
| 58 | |
| 59 // Used to respond to IPC connection changes. | |
| 60 void HandleIpcConnectionChange(bool connection_established); | |
| 61 | |
| 62 // Handles responses received from the remote client. | |
| 63 void HandleSecurityKeyResponse(const std::string& response_data); | |
| 64 | |
| 65 // Handles requests to establich a connection with the Chromoting host. | |
| 66 void HandleConnectRequest(const std::string& message_payload); | |
| 67 | |
| 68 // handles security key requests by forwrding them to the remote client. | |
| 69 void HandleSecurityKeyRequest(const std::string& message_payload); | |
| 70 | |
| 71 // Used to communicate with the remote security key. | |
| 72 std::unique_ptr<RemoteSecurityKeyIpcClient> ipc_client_; | |
| 73 | |
| 74 // Used to listen for security key messages. | |
| 75 std::unique_ptr<RemoteSecurityKeyMessageReader> reader_; | |
| 76 | |
| 77 // Used to write security key messages to local security key tools. | |
| 78 std::unique_ptr<RemoteSecurityKeyMessageWriter> writer_; | |
| 79 | |
| 80 // Signaled when an error occurs. | |
| 81 base::Closure error_callback_; | |
| 82 | |
| 83 base::ThreadChecker thread_checker_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(RemoteSecurityKeyMessageHandler); | |
| 86 }; | |
| 87 | |
| 88 } // namespace remoting | |
| 89 | |
| 90 #endif // REMOTING_HOST_SECURITY_KEY_REMOTE_SECURITY_KEY_MESSAGE_HANDLER_H_ | |
| OLD | NEW |