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_FAKE_SECURITY_KEY_IPC_SERVER_H_ | 5 #ifndef REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_SERVER_H_ |
6 #define REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_SERVER_H_ | 6 #define REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_SERVER_H_ |
7 | 7 |
8 #include "remoting/host/security_key/security_key_ipc_server.h" | 8 #include "remoting/host/security_key/security_key_ipc_server.h" |
9 | 9 |
10 #include <cstdint> | 10 #include <cstdint> |
(...skipping 17 matching lines...) Expand all Loading... |
28 // WeakPtr reference to itself which allows tests to verify its lifetime is | 28 // WeakPtr reference to itself which allows tests to verify its lifetime is |
29 // managed properly without interfering with it. | 29 // managed properly without interfering with it. |
30 class FakeSecurityKeyIpcServer : public SecurityKeyIpcServer, | 30 class FakeSecurityKeyIpcServer : public SecurityKeyIpcServer, |
31 public IPC::Listener { | 31 public IPC::Listener { |
32 public: | 32 public: |
33 FakeSecurityKeyIpcServer( | 33 FakeSecurityKeyIpcServer( |
34 int connection_id, | 34 int connection_id, |
35 ClientSessionDetails* client_session_details, | 35 ClientSessionDetails* client_session_details, |
36 base::TimeDelta initial_connect_timeout, | 36 base::TimeDelta initial_connect_timeout, |
37 const SecurityKeyAuthHandler::SendMessageCallback& send_message_callback, | 37 const SecurityKeyAuthHandler::SendMessageCallback& send_message_callback, |
| 38 const base::Closure& connect_callback, |
38 const base::Closure& channel_closed_callback); | 39 const base::Closure& channel_closed_callback); |
39 ~FakeSecurityKeyIpcServer() override; | 40 ~FakeSecurityKeyIpcServer() override; |
40 | 41 |
41 // SecurityKeyIpcServer interface. | 42 // SecurityKeyIpcServer interface. |
42 bool CreateChannel(const std::string& channel_name, | 43 bool CreateChannel(const mojo::edk::NamedPlatformHandle& channel_handle, |
43 base::TimeDelta request_timeout) override; | 44 base::TimeDelta request_timeout) override; |
44 bool SendResponse(const std::string& message_data) override; | 45 bool SendResponse(const std::string& message_data) override; |
45 | 46 |
46 // Simulates receipt of a security key request message. | 47 // Simulates receipt of a security key request message. |
47 void SendRequest(const std::string& message_data); | 48 void SendRequest(const std::string& message_data); |
48 | 49 |
49 // Simulates the IPC channel being closed. | 50 // Simulates the IPC channel being closed. |
50 void CloseChannel(); | 51 void CloseChannel(); |
51 | 52 |
52 // Returns a WeakPtr reference to this instance. | 53 // Returns a WeakPtr reference to this instance. |
53 base::WeakPtr<FakeSecurityKeyIpcServer> AsWeakPtr(); | 54 base::WeakPtr<FakeSecurityKeyIpcServer> AsWeakPtr(); |
54 | 55 |
55 // Returns the payload for the last message received. | 56 // Returns the payload for the last message received. |
56 const std::string& last_message_received() const { | 57 const std::string& last_message_received() const { |
57 return last_message_received_; | 58 return last_message_received_; |
58 } | 59 } |
59 | 60 |
60 // The name of the IPC channel created by this instance. | |
61 const std::string& channel_name() const { return channel_name_; } | |
62 | |
63 // Signaled when a security key response message is received. | 61 // Signaled when a security key response message is received. |
64 // NOTE: Ths callback will be used instead of the IPC channel for response | 62 // NOTE: Ths callback will be used instead of the IPC channel for response |
65 // notifications if it is set. | 63 // notifications if it is set. |
66 void set_send_response_callback(const base::Closure& send_response_callback) { | 64 void set_send_response_callback(const base::Closure& send_response_callback) { |
67 send_response_callback_ = send_response_callback; | 65 send_response_callback_ = send_response_callback; |
68 } | 66 } |
69 | 67 |
70 private: | 68 private: |
71 // IPC::Listener interface. | 69 // IPC::Listener interface. |
72 bool OnMessageReceived(const IPC::Message& message) override; | 70 bool OnMessageReceived(const IPC::Message& message) override; |
73 void OnChannelConnected(int32_t peer_pid) override; | 71 void OnChannelConnected(int32_t peer_pid) override; |
74 void OnChannelError() override; | |
75 | 72 |
76 // The id assigned to this IPC connection. | 73 // The id assigned to this IPC connection. |
77 int connection_id_; | 74 int connection_id_; |
78 | 75 |
79 // Name of the IPC channel this instance was told to connect to. | |
80 std::string channel_name_; | |
81 | |
82 // The payload for the last message received. | 76 // The payload for the last message received. |
83 std::string last_message_received_; | 77 std::string last_message_received_; |
84 | 78 |
85 // Used to forward security key requests to the remote client. | 79 // Used to forward security key requests to the remote client. |
86 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_; | 80 SecurityKeyAuthHandler::SendMessageCallback send_message_callback_; |
87 | 81 |
| 82 // Signaled when the IPC channel is connected. |
| 83 base::Closure connect_callback_; |
| 84 |
88 // Signaled when the IPC channel is closed. | 85 // Signaled when the IPC channel is closed. |
89 base::Closure channel_closed_callback_; | 86 base::Closure channel_closed_callback_; |
90 | 87 |
91 // Signaled when a security key response message is received. | 88 // Signaled when a security key response message is received. |
92 base::Closure send_response_callback_; | 89 base::Closure send_response_callback_; |
93 | 90 |
94 // Used for sending/receiving security key messages between processes. | 91 // Used for sending/receiving security key messages between processes. |
95 std::unique_ptr<IPC::Channel> ipc_channel_; | 92 std::unique_ptr<IPC::Channel> ipc_channel_; |
96 | 93 |
97 // NOTE: Weak pointers must be invalidated before all other member variables. | 94 // NOTE: Weak pointers must be invalidated before all other member variables. |
(...skipping 10 matching lines...) Expand all Loading... |
108 public: | 105 public: |
109 FakeSecurityKeyIpcServerFactory(); | 106 FakeSecurityKeyIpcServerFactory(); |
110 ~FakeSecurityKeyIpcServerFactory() override; | 107 ~FakeSecurityKeyIpcServerFactory() override; |
111 | 108 |
112 // SecurityKeyIpcServerFactory implementation. | 109 // SecurityKeyIpcServerFactory implementation. |
113 std::unique_ptr<SecurityKeyIpcServer> Create( | 110 std::unique_ptr<SecurityKeyIpcServer> Create( |
114 int connection_id, | 111 int connection_id, |
115 ClientSessionDetails* client_session_details, | 112 ClientSessionDetails* client_session_details, |
116 base::TimeDelta initial_connect_timeout, | 113 base::TimeDelta initial_connect_timeout, |
117 const SecurityKeyAuthHandler::SendMessageCallback& message_callback, | 114 const SecurityKeyAuthHandler::SendMessageCallback& message_callback, |
| 115 const base::Closure& connect_callback, |
118 const base::Closure& done_callback) override; | 116 const base::Closure& done_callback) override; |
119 | 117 |
120 // Provide a WeakPtr reference to the FakeSecurityKeyIpcServer object | 118 // Provide a WeakPtr reference to the FakeSecurityKeyIpcServer object |
121 // created for the |connection_id| IPC channel. | 119 // created for the |connection_id| IPC channel. |
122 base::WeakPtr<FakeSecurityKeyIpcServer> GetIpcServerObject(int connection_id); | 120 base::WeakPtr<FakeSecurityKeyIpcServer> GetIpcServerObject(int connection_id); |
123 | 121 |
124 private: | 122 private: |
125 // Tracks each FakeSecurityKeyIpcServer instance created by this | 123 // Tracks each FakeSecurityKeyIpcServer instance created by this |
126 // factory which allows them to be retrieved and queried for tests. | 124 // factory which allows them to be retrieved and queried for tests. |
127 std::map<int, base::WeakPtr<FakeSecurityKeyIpcServer>> ipc_server_map_; | 125 std::map<int, base::WeakPtr<FakeSecurityKeyIpcServer>> ipc_server_map_; |
128 | 126 |
129 DISALLOW_COPY_AND_ASSIGN(FakeSecurityKeyIpcServerFactory); | 127 DISALLOW_COPY_AND_ASSIGN(FakeSecurityKeyIpcServerFactory); |
130 }; | 128 }; |
131 | 129 |
132 } // namespace remoting | 130 } // namespace remoting |
133 | 131 |
134 #endif // REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_SERVER_H_ | 132 #endif // REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_SERVER_H_ |
OLD | NEW |