| 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 |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "mojo/edk/embedder/named_platform_handle.h" |
| 14 #include "remoting/host/security_key/security_key_ipc_client.h" | 15 #include "remoting/host/security_key/security_key_ipc_client.h" |
| 15 | 16 |
| 16 namespace IPC { | 17 namespace IPC { |
| 17 class Channel; | 18 class Channel; |
| 18 class Message; | 19 class Message; |
| 19 } // IPC | 20 } // IPC |
| 20 | 21 |
| 21 namespace remoting { | 22 namespace remoting { |
| 22 | 23 |
| 23 // Simulates the SecurityKeyIpcClient and provides access to data members | 24 // Simulates the SecurityKeyIpcClient and provides access to data members |
| 24 // for testing. This class is used for scenarios which require an IPC channel | 25 // for testing. This class is used for scenarios which require an IPC channel |
| 25 // as well as for tests which only need callbacks activated. | 26 // as well as for tests which only need callbacks activated. |
| 26 class FakeSecurityKeyIpcClient : public SecurityKeyIpcClient { | 27 class FakeSecurityKeyIpcClient : public SecurityKeyIpcClient { |
| 27 public: | 28 public: |
| 28 explicit FakeSecurityKeyIpcClient( | 29 explicit FakeSecurityKeyIpcClient( |
| 29 const base::Closure& channel_event_callback); | 30 const base::Closure& channel_event_callback); |
| 30 ~FakeSecurityKeyIpcClient() override; | 31 ~FakeSecurityKeyIpcClient() override; |
| 31 | 32 |
| 32 // SecurityKeyIpcClient interface. | 33 // SecurityKeyIpcClient interface. |
| 33 bool WaitForSecurityKeyIpcServerChannel() override; | 34 bool WaitForSecurityKeyIpcServerChannel() override; |
| 34 void EstablishIpcConnection( | 35 void EstablishIpcConnection( |
| 35 const base::Closure& connection_ready_callback, | 36 const base::Closure& connection_ready_callback, |
| 36 const base::Closure& connection_error_callback) override; | 37 const base::Closure& connection_error_callback) override; |
| 37 bool SendSecurityKeyRequest( | 38 bool SendSecurityKeyRequest( |
| 38 const std::string& request_payload, | 39 const std::string& request_payload, |
| 39 const ResponseCallback& response_callback) override; | 40 const ResponseCallback& response_callback) override; |
| 40 void CloseIpcConnection() override; | 41 void CloseIpcConnection() override; |
| 41 | 42 |
| 42 // Connects as a client to the |channel_name| IPC Channel. | 43 // Connects as a client to the |channel_name| IPC Channel. |
| 43 bool ConnectViaIpc(const std::string& channel_name); | 44 bool ConnectViaIpc(const mojo::edk::NamedPlatformHandle& channel_handle); |
| 44 | 45 |
| 45 // Override of SendSecurityKeyRequest() interface method for tests which use | 46 // Override of SendSecurityKeyRequest() interface method for tests which use |
| 46 // an IPC channel for testing. | 47 // an IPC channel for testing. |
| 47 void SendSecurityKeyRequestViaIpc(const std::string& request_payload); | 48 void SendSecurityKeyRequestViaIpc(const std::string& request_payload); |
| 48 | 49 |
| 49 base::WeakPtr<FakeSecurityKeyIpcClient> AsWeakPtr(); | 50 base::WeakPtr<FakeSecurityKeyIpcClient> AsWeakPtr(); |
| 50 | 51 |
| 51 const std::string& last_message_received() const { | 52 const std::string& last_message_received() const { |
| 52 return last_message_received_; | 53 return last_message_received_; |
| 53 } | 54 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 void set_security_key_response_payload(const std::string& response_payload) { | 70 void set_security_key_response_payload(const std::string& response_payload) { |
| 70 security_key_response_payload_ = response_payload; | 71 security_key_response_payload_ = response_payload; |
| 71 } | 72 } |
| 72 | 73 |
| 73 private: | 74 private: |
| 74 // IPC::Listener implementation. | 75 // IPC::Listener implementation. |
| 75 bool OnMessageReceived(const IPC::Message& message) override; | 76 bool OnMessageReceived(const IPC::Message& message) override; |
| 76 void OnChannelConnected(int32_t peer_pid) override; | 77 void OnChannelConnected(int32_t peer_pid) override; |
| 77 void OnChannelError() override; | 78 void OnChannelError() override; |
| 78 | 79 |
| 79 // Handles the initial IPC message used to establish a side channel with this | |
| 80 // IPC Client instance. | |
| 81 void OnConnectionDetails(const std::string& request_data); | |
| 82 | |
| 83 // Handles security key response IPC messages. | 80 // Handles security key response IPC messages. |
| 84 void OnSecurityKeyResponse(const std::string& request_data); | 81 void OnSecurityKeyResponse(const std::string& request_data); |
| 85 | 82 |
| 86 // Called when a change in the IPC channel state has occurred. | 83 // Called when a change in the IPC channel state has occurred. |
| 87 base::Closure channel_event_callback_; | 84 base::Closure channel_event_callback_; |
| 88 | 85 |
| 89 // Used for sending/receiving security key messages between processes. | 86 // Used for sending/receiving security key messages between processes. |
| 90 std::unique_ptr<IPC::Channel> client_channel_; | 87 std::unique_ptr<IPC::Channel> client_channel_; |
| 91 | 88 |
| 92 // Provides the contents of the last IPC message received. | 89 // Provides the contents of the last IPC message received. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 std::string security_key_response_payload_; | 105 std::string security_key_response_payload_; |
| 109 | 106 |
| 110 base::WeakPtrFactory<FakeSecurityKeyIpcClient> weak_factory_; | 107 base::WeakPtrFactory<FakeSecurityKeyIpcClient> weak_factory_; |
| 111 | 108 |
| 112 DISALLOW_COPY_AND_ASSIGN(FakeSecurityKeyIpcClient); | 109 DISALLOW_COPY_AND_ASSIGN(FakeSecurityKeyIpcClient); |
| 113 }; | 110 }; |
| 114 | 111 |
| 115 } // namespace remoting | 112 } // namespace remoting |
| 116 | 113 |
| 117 #endif // REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ | 114 #endif // REMOTING_HOST_SECURITY_KEY_FAKE_SECURITY_KEY_IPC_CLIENT_H_ |
| OLD | NEW |