Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: remoting/host/security_key/security_key_ipc_client.h

Issue 2478443002: Use ChannelMojo for remote security key channels. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_SECURITY_KEY_IPC_CLIENT_H_ 5 #ifndef REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_IPC_CLIENT_H_
6 #define REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_IPC_CLIENT_H_ 6 #define REMOTING_HOST_SECURITY_KEY_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.h" 11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h" 13 #include "base/threading/thread_checker.h"
14 #include "ipc/ipc_listener.h" 14 #include "ipc/ipc_listener.h"
15 #include "mojo/edk/embedder/named_platform_handle.h"
16 #include "mojo/edk/embedder/scoped_platform_handle.h"
15 17
16 namespace IPC { 18 namespace IPC {
17 class Channel; 19 class Channel;
18 class Message; 20 class Message;
19 } // IPC 21 } // IPC
20 22
21 namespace remoting { 23 namespace remoting {
22 24
23 // Responsible for handing the client end of the IPC channel between the 25 // Responsible for handing the client end of the IPC channel between the
24 // the network process (server) and remote_security_key process (client). 26 // the network process (server) and remote_security_key process (client).
25 // The public methods are virtual to allow for using fake objects for testing. 27 // The public methods are virtual to allow for using fake objects for testing.
26 class SecurityKeyIpcClient : public IPC::Listener { 28 class SecurityKeyIpcClient : public IPC::Listener {
27 public: 29 public:
28 SecurityKeyIpcClient(); 30 SecurityKeyIpcClient();
29 ~SecurityKeyIpcClient() override; 31 ~SecurityKeyIpcClient() override;
30 32
31 // Used to send security key extension messages to the client. 33 // Used to send security key extension messages to the client.
32 typedef base::Callback<void(const std::string& response_data)> 34 typedef base::Callback<void(const std::string& response_data)>
33 ResponseCallback; 35 ResponseCallback;
34 36
35 // Returns true if there is an active remoting session which supports 37 // Returns true if there is an active remoting session which supports
36 // security key request forwarding. 38 // security key request forwarding.
37 virtual bool WaitForSecurityKeyIpcServerChannel(); 39 virtual bool CheckForSecurityKeyIpcServerChannel();
38 40
39 // Begins the process of connecting to the IPC channel which will be used for 41 // Begins the process of connecting to the IPC channel which will be used for
40 // exchanging security key messages. 42 // exchanging security key messages.
41 // |connection_ready_callback| is called when a channel has been established 43 // |connection_ready_callback| is called when a channel has been established
42 // and security key requests can be sent. 44 // and security key requests can be sent.
43 // |connection_error_callback| is stored and will be called back for any 45 // |connection_error_callback| is stored and will be called back for any
44 // unexpected errors that occur while establishing, or during, the session. 46 // unexpected errors that occur while establishing, or during, the session.
45 virtual void EstablishIpcConnection( 47 virtual void EstablishIpcConnection(
46 const base::Closure& connection_ready_callback, 48 const base::Closure& connection_ready_callback,
47 const base::Closure& connection_error_callback); 49 const base::Closure& connection_error_callback);
48 50
49 // Sends a security key request message to the network process to be forwarded 51 // Sends a security key request message to the network process to be forwarded
50 // to the remote client. 52 // to the remote client.
51 virtual bool SendSecurityKeyRequest( 53 virtual bool SendSecurityKeyRequest(
52 const std::string& request_payload, 54 const std::string& request_payload,
53 const ResponseCallback& response_callback); 55 const ResponseCallback& response_callback);
54 56
55 // Closes the IPC channel if connected. 57 // Closes the IPC channel if connected.
56 virtual void CloseIpcConnection(); 58 virtual void CloseIpcConnection();
57 59
58 // Allows tests to override the initial IPC channel used to retrieve IPC 60 // Allows tests to override the IPC channel.
59 // connection details. 61 void SetIpcChannelHandleForTest(
60 void SetInitialIpcChannelNameForTest( 62 const mojo::edk::NamedPlatformHandle& channel_handle);
61 const std::string& initial_ipc_channel_name);
62 63
63 // Allows tests to override the expected session ID. 64 // Allows tests to override the expected session ID.
64 void SetExpectedIpcServerSessionIdForTest(uint32_t expected_session_id); 65 void SetExpectedIpcServerSessionIdForTest(uint32_t expected_session_id);
65 66
66 private: 67 private:
67 // IPC::Listener implementation. 68 // IPC::Listener implementation.
68 bool OnMessageReceived(const IPC::Message& message) override; 69 bool OnMessageReceived(const IPC::Message& message) override;
69 void OnChannelConnected(int32_t peer_pid) override; 70 void OnChannelConnected(int32_t peer_pid) override;
70 void OnChannelError() override; 71 void OnChannelError() override;
71 72
72 // Handles the ConnectionDetails IPC message. 73 // Handles the ConnectionDetails IPC message.
73 void OnConnectionDetails(const std::string& request_data); 74 void OnConnectionDetails(const std::string& request_data);
74 75
75 // Handles security key response IPC messages. 76 // Handles security key response IPC messages.
76 void OnSecurityKeyResponse(const std::string& request_data); 77 void OnSecurityKeyResponse(const std::string& request_data);
77 78
78 // Establishes a connection to the specified IPC Server channel. 79 // Establishes a connection to the specified IPC Server channel.
79 void ConnectToIpcChannel(const std::string& channel_name); 80 void ConnectToIpcChannel();
80 81
81 // Used to validate the IPC Server process is running in the correct session. 82 // Used to validate the IPC Server process is running in the correct session.
82 // '0' (default) corresponds to the session the network process runs in. 83 // '0' (default) corresponds to the session the network process runs in.
83 uint32_t expected_ipc_server_session_id_ = 0; 84 uint32_t expected_ipc_server_session_id_ = 0;
84 85
85 // Name for the IPC channel used for exchanging security key messages.
86 std::string ipc_channel_name_;
87 86
88 // Name of the initial IPC channel used to retrieve connection info. 87 // Name of the initial IPC channel used to retrieve connection info.
89 std::string initial_ipc_channel_name_; 88 mojo::edk::NamedPlatformHandle named_channel_handle_;
89
90 // A handle for the IPC channel used for exchanging security key messages.
91 mojo::edk::ScopedPlatformHandle channel_handle_;
90 92
91 // Signaled when the IPC connection is ready for security key requests. 93 // Signaled when the IPC connection is ready for security key requests.
92 base::Closure connection_ready_callback_; 94 base::Closure connection_ready_callback_;
93 95
94 // Signaled when an error occurs in either the IPC channel or communication. 96 // Signaled when an error occurs in either the IPC channel or communication.
95 base::Closure connection_error_callback_; 97 base::Closure connection_error_callback_;
96 98
97 // Signaled when a security key response has been received. 99 // Signaled when a security key response has been received.
98 ResponseCallback response_callback_; 100 ResponseCallback response_callback_;
99 101
100 // Used for sending/receiving security key messages between processes. 102 // Used for sending/receiving security key messages between processes.
101 std::unique_ptr<IPC::Channel> ipc_channel_; 103 std::unique_ptr<IPC::Channel> ipc_channel_;
102 104
103 base::ThreadChecker thread_checker_; 105 base::ThreadChecker thread_checker_;
104 106
105 base::WeakPtrFactory<SecurityKeyIpcClient> weak_factory_; 107 base::WeakPtrFactory<SecurityKeyIpcClient> weak_factory_;
106 108
107 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcClient); 109 DISALLOW_COPY_AND_ASSIGN(SecurityKeyIpcClient);
108 }; 110 };
109 111
110 } // namespace remoting 112 } // namespace remoting
111 113
112 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_IPC_CLIENT_H_ 114 #endif // REMOTING_HOST_SECURITY_KEY_SECURITY_KEY_IPC_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698