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