| 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 #include "remoting/host/security_key/fake_security_key_ipc_client.h" | 5 #include "remoting/host/security_key/fake_security_key_ipc_client.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 base::WeakPtr<FakeSecurityKeyIpcClient> FakeSecurityKeyIpcClient::AsWeakPtr() { | 31 base::WeakPtr<FakeSecurityKeyIpcClient> FakeSecurityKeyIpcClient::AsWeakPtr() { |
| 32 return weak_factory_.GetWeakPtr(); | 32 return weak_factory_.GetWeakPtr(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool FakeSecurityKeyIpcClient::CheckForSecurityKeyIpcServerChannel() { | 35 bool FakeSecurityKeyIpcClient::CheckForSecurityKeyIpcServerChannel() { |
| 36 return check_for_ipc_channel_return_value_; | 36 return check_for_ipc_channel_return_value_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void FakeSecurityKeyIpcClient::EstablishIpcConnection( | 39 void FakeSecurityKeyIpcClient::EstablishIpcConnection( |
| 40 const base::Closure& connection_ready_callback, | 40 const ConnectedCallback& connected_callback, |
| 41 const base::Closure& connection_error_callback) { | 41 const base::Closure& connection_error_callback) { |
| 42 if (establish_ipc_connection_should_succeed_) { | 42 if (establish_ipc_connection_should_succeed_) { |
| 43 connection_ready_callback.Run(); | 43 connected_callback.Run(/*connection_usable=*/true); |
| 44 } else { | 44 } else { |
| 45 connection_error_callback.Run(); | 45 connection_error_callback.Run(); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool FakeSecurityKeyIpcClient::SendSecurityKeyRequest( | 49 bool FakeSecurityKeyIpcClient::SendSecurityKeyRequest( |
| 50 const std::string& request_payload, | 50 const std::string& request_payload, |
| 51 const ResponseCallback& response_callback) { | 51 const ResponseCallback& response_callback) { |
| 52 if (send_security_request_should_succeed_) { | 52 if (send_security_request_should_succeed_) { |
| 53 base::ThreadTaskRunnerHandle::Get()->PostTask( | 53 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 79 const std::string& request_payload) { | 79 const std::string& request_payload) { |
| 80 client_channel_->Send( | 80 client_channel_->Send( |
| 81 new ChromotingRemoteSecurityKeyToNetworkMsg_Request(request_payload)); | 81 new ChromotingRemoteSecurityKeyToNetworkMsg_Request(request_payload)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 bool FakeSecurityKeyIpcClient::OnMessageReceived(const IPC::Message& message) { | 84 bool FakeSecurityKeyIpcClient::OnMessageReceived(const IPC::Message& message) { |
| 85 bool handled = true; | 85 bool handled = true; |
| 86 IPC_BEGIN_MESSAGE_MAP(FakeSecurityKeyIpcClient, message) | 86 IPC_BEGIN_MESSAGE_MAP(FakeSecurityKeyIpcClient, message) |
| 87 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_Response, | 87 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_Response, |
| 88 OnSecurityKeyResponse) | 88 OnSecurityKeyResponse) |
| 89 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_ConnectionReady, |
| 90 OnConnectionReady) |
| 91 IPC_MESSAGE_HANDLER(ChromotingNetworkToRemoteSecurityKeyMsg_InvalidSession, |
| 92 OnInvalidSession) |
| 89 IPC_MESSAGE_UNHANDLED(handled = false) | 93 IPC_MESSAGE_UNHANDLED(handled = false) |
| 90 IPC_END_MESSAGE_MAP() | 94 IPC_END_MESSAGE_MAP() |
| 91 | 95 |
| 92 CHECK(handled) << "Received unexpected IPC type: " << message.type(); | 96 CHECK(handled) << "Received unexpected IPC type: " << message.type(); |
| 93 return handled; | 97 return handled; |
| 94 } | 98 } |
| 95 | 99 |
| 100 void FakeSecurityKeyIpcClient::OnConnectionReady() { |
| 101 connection_ready_ = true; |
| 102 channel_event_callback_.Run(); |
| 103 } |
| 104 |
| 105 void FakeSecurityKeyIpcClient::OnInvalidSession() { |
| 106 invalid_session_error_ = true; |
| 107 channel_event_callback_.Run(); |
| 108 } |
| 109 |
| 96 void FakeSecurityKeyIpcClient::OnChannelConnected(int32_t peer_pid) { | 110 void FakeSecurityKeyIpcClient::OnChannelConnected(int32_t peer_pid) { |
| 97 ipc_channel_connected_ = true; | 111 ipc_channel_connected_ = true; |
| 98 channel_event_callback_.Run(); | 112 channel_event_callback_.Run(); |
| 99 } | 113 } |
| 100 | 114 |
| 101 void FakeSecurityKeyIpcClient::OnChannelError() { | 115 void FakeSecurityKeyIpcClient::OnChannelError() { |
| 102 ipc_channel_connected_ = false; | 116 ipc_channel_connected_ = false; |
| 103 channel_event_callback_.Run(); | 117 channel_event_callback_.Run(); |
| 104 } | 118 } |
| 105 | 119 |
| 106 void FakeSecurityKeyIpcClient::OnSecurityKeyResponse( | 120 void FakeSecurityKeyIpcClient::OnSecurityKeyResponse( |
| 107 const std::string& request_data) { | 121 const std::string& request_data) { |
| 108 last_message_received_ = request_data; | 122 last_message_received_ = request_data; |
| 109 channel_event_callback_.Run(); | 123 channel_event_callback_.Run(); |
| 110 } | 124 } |
| 111 | 125 |
| 112 } // namespace remoting | 126 } // namespace remoting |
| OLD | NEW |