| 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_CLIENT_H_ | 5 #ifndef REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ |
| 6 #define REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ | 6 #define REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // as well as for tests which only need callbacks activated. | 26 // as well as for tests which only need callbacks activated. |
| 27 class FakeSecurityKeyIpcClient : public SecurityKeyIpcClient { | 27 class FakeSecurityKeyIpcClient : public SecurityKeyIpcClient { |
| 28 public: | 28 public: |
| 29 explicit FakeSecurityKeyIpcClient( | 29 explicit FakeSecurityKeyIpcClient( |
| 30 const base::Closure& channel_event_callback); | 30 const base::Closure& channel_event_callback); |
| 31 ~FakeSecurityKeyIpcClient() override; | 31 ~FakeSecurityKeyIpcClient() override; |
| 32 | 32 |
| 33 // SecurityKeyIpcClient interface. | 33 // SecurityKeyIpcClient interface. |
| 34 bool CheckForSecurityKeyIpcServerChannel() override; | 34 bool CheckForSecurityKeyIpcServerChannel() override; |
| 35 void EstablishIpcConnection( | 35 void EstablishIpcConnection( |
| 36 const base::Closure& connection_ready_callback, | 36 const ConnectedCallback& connected_callback, |
| 37 const base::Closure& connection_error_callback) override; | 37 const base::Closure& connection_error_callback) override; |
| 38 bool SendSecurityKeyRequest( | 38 bool SendSecurityKeyRequest( |
| 39 const std::string& request_payload, | 39 const std::string& request_payload, |
| 40 const ResponseCallback& response_callback) override; | 40 const ResponseCallback& response_callback) override; |
| 41 void CloseIpcConnection() override; | 41 void CloseIpcConnection() override; |
| 42 | 42 |
| 43 // Connects as a client to the |channel_name| IPC Channel. | 43 // Connects as a client to the |channel_name| IPC Channel. |
| 44 bool ConnectViaIpc(const mojo::edk::NamedPlatformHandle& channel_handle); | 44 bool ConnectViaIpc(const mojo::edk::NamedPlatformHandle& channel_handle); |
| 45 | 45 |
| 46 // Override of SendSecurityKeyRequest() interface method for tests which use | 46 // Override of SendSecurityKeyRequest() interface method for tests which use |
| 47 // an IPC channel for testing. | 47 // an IPC channel for testing. |
| 48 void SendSecurityKeyRequestViaIpc(const std::string& request_payload); | 48 void SendSecurityKeyRequestViaIpc(const std::string& request_payload); |
| 49 | 49 |
| 50 base::WeakPtr<FakeSecurityKeyIpcClient> AsWeakPtr(); | 50 base::WeakPtr<FakeSecurityKeyIpcClient> AsWeakPtr(); |
| 51 | 51 |
| 52 const std::string& last_message_received() const { | 52 const std::string& last_message_received() const { |
| 53 return last_message_received_; | 53 return last_message_received_; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool ipc_channel_connected() { return ipc_channel_connected_; } | 56 bool ipc_channel_connected() { return ipc_channel_connected_; } |
| 57 | 57 |
| 58 bool connection_ready() { return connection_ready_; } |
| 59 |
| 60 bool invalid_session_error() { return invalid_session_error_; } |
| 61 |
| 58 void set_check_for_ipc_channel_return_value(bool return_value) { | 62 void set_check_for_ipc_channel_return_value(bool return_value) { |
| 59 check_for_ipc_channel_return_value_ = return_value; | 63 check_for_ipc_channel_return_value_ = return_value; |
| 60 } | 64 } |
| 61 | 65 |
| 62 void set_establish_ipc_connection_should_succeed(bool should_succeed) { | 66 void set_establish_ipc_connection_should_succeed(bool should_succeed) { |
| 63 establish_ipc_connection_should_succeed_ = should_succeed; | 67 establish_ipc_connection_should_succeed_ = should_succeed; |
| 64 } | 68 } |
| 65 | 69 |
| 66 void set_send_security_request_should_succeed(bool should_succeed) { | 70 void set_send_security_request_should_succeed(bool should_succeed) { |
| 67 send_security_request_should_succeed_ = should_succeed; | 71 send_security_request_should_succeed_ = should_succeed; |
| 68 } | 72 } |
| 69 | 73 |
| 70 void set_security_key_response_payload(const std::string& response_payload) { | 74 void set_security_key_response_payload(const std::string& response_payload) { |
| 71 security_key_response_payload_ = response_payload; | 75 security_key_response_payload_ = response_payload; |
| 72 } | 76 } |
| 73 | 77 |
| 74 private: | 78 private: |
| 75 // IPC::Listener implementation. | 79 // IPC::Listener implementation. |
| 76 bool OnMessageReceived(const IPC::Message& message) override; | 80 bool OnMessageReceived(const IPC::Message& message) override; |
| 77 void OnChannelConnected(int32_t peer_pid) override; | 81 void OnChannelConnected(int32_t peer_pid) override; |
| 78 void OnChannelError() override; | 82 void OnChannelError() override; |
| 79 | 83 |
| 80 // Handles security key response IPC messages. | 84 // Handles security key response IPC messages. |
| 81 void OnSecurityKeyResponse(const std::string& request_data); | 85 void OnSecurityKeyResponse(const std::string& request_data); |
| 82 | 86 |
| 87 // Handles the ConnectionReady IPC message. |
| 88 void OnConnectionReady(); |
| 89 |
| 90 // Handles the InvalidSession IPC message. |
| 91 void OnInvalidSession(); |
| 92 |
| 83 // Called when a change in the IPC channel state has occurred. | 93 // Called when a change in the IPC channel state has occurred. |
| 84 base::Closure channel_event_callback_; | 94 base::Closure channel_event_callback_; |
| 85 | 95 |
| 86 // Used for sending/receiving security key messages between processes. | 96 // Used for sending/receiving security key messages between processes. |
| 87 std::unique_ptr<IPC::Channel> client_channel_; | 97 std::unique_ptr<IPC::Channel> client_channel_; |
| 88 | 98 |
| 89 // Provides the contents of the last IPC message received. | 99 // Provides the contents of the last IPC message received. |
| 90 std::string last_message_received_; | 100 std::string last_message_received_; |
| 91 | 101 |
| 92 // Determines whether EstablishIpcConnection() returns success or failure. | 102 // Determines whether EstablishIpcConnection() returns success or failure. |
| 93 bool establish_ipc_connection_should_succeed_ = true; | 103 bool establish_ipc_connection_should_succeed_ = true; |
| 94 | 104 |
| 95 // Determines whether SendSecurityKeyRequest() returns success or failure. | 105 // Determines whether SendSecurityKeyRequest() returns success or failure. |
| 96 bool send_security_request_should_succeed_ = true; | 106 bool send_security_request_should_succeed_ = true; |
| 97 | 107 |
| 98 // Value returned by CheckForSecurityKeyIpcServerChannel() method. | 108 // Value returned by CheckForSecurityKeyIpcServerChannel() method. |
| 99 bool check_for_ipc_channel_return_value_ = true; | 109 bool check_for_ipc_channel_return_value_ = true; |
| 100 | 110 |
| 101 // Stores whether a connection to the server IPC channel is active. | 111 // Stores whether a connection to the server IPC channel is active. |
| 102 bool ipc_channel_connected_ = false; | 112 bool ipc_channel_connected_ = false; |
| 103 | 113 |
| 114 // Tracks whether a ConnectionReady message has been received. |
| 115 bool connection_ready_ = false; |
| 116 |
| 117 // Tracks whether an InvalidSession message has been received. |
| 118 bool invalid_session_error_ = false; |
| 119 |
| 104 // Value returned by SendSecurityKeyRequest() method. | 120 // Value returned by SendSecurityKeyRequest() method. |
| 105 std::string security_key_response_payload_; | 121 std::string security_key_response_payload_; |
| 106 | 122 |
| 107 base::WeakPtrFactory<FakeSecurityKeyIpcClient> weak_factory_; | 123 base::WeakPtrFactory<FakeSecurityKeyIpcClient> weak_factory_; |
| 108 | 124 |
| 109 DISALLOW_COPY_AND_ASSIGN(FakeSecurityKeyIpcClient); | 125 DISALLOW_COPY_AND_ASSIGN(FakeSecurityKeyIpcClient); |
| 110 }; | 126 }; |
| 111 | 127 |
| 112 } // namespace remoting | 128 } // namespace remoting |
| 113 | 129 |
| 114 #endif // REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ | 130 #endif // REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ |
| OLD | NEW |