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

Side by Side Diff: remoting/host/security_key/fake_security_key_ipc_server.cc

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 #include "remoting/host/security_key/fake_security_key_ipc_server.h" 5 #include "remoting/host/security_key/fake_security_key_ipc_server.h"
6 6
7 #include <cstdint> 7 #include <cstdint>
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/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "ipc/ipc_channel.h" 14 #include "ipc/ipc_channel.h"
15 #include "ipc/ipc_message.h" 15 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_message_macros.h" 16 #include "ipc/ipc_message_macros.h"
17 #include "mojo/edk/embedder/embedder.h"
18 #include "mojo/edk/embedder/named_platform_handle.h"
19 #include "mojo/edk/embedder/named_platform_handle_utils.h"
17 #include "remoting/host/chromoting_messages.h" 20 #include "remoting/host/chromoting_messages.h"
18 #include "remoting/host/security_key/security_key_auth_handler.h" 21 #include "remoting/host/security_key/security_key_auth_handler.h"
19 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
20 23
21 namespace remoting { 24 namespace remoting {
22 25
23 FakeSecurityKeyIpcServer::FakeSecurityKeyIpcServer( 26 FakeSecurityKeyIpcServer::FakeSecurityKeyIpcServer(
24 int connection_id, 27 int connection_id,
25 ClientSessionDetails* client_session_details, 28 ClientSessionDetails* client_session_details,
26 base::TimeDelta initial_connect_timeout, 29 base::TimeDelta initial_connect_timeout,
27 const SecurityKeyAuthHandler::SendMessageCallback& send_message_callback, 30 const SecurityKeyAuthHandler::SendMessageCallback& send_message_callback,
31 const base::Closure& connect_callback,
28 const base::Closure& channel_closed_callback) 32 const base::Closure& channel_closed_callback)
29 : connection_id_(connection_id), 33 : connection_id_(connection_id),
30 send_message_callback_(send_message_callback), 34 send_message_callback_(send_message_callback),
35 connect_callback_(connect_callback),
31 channel_closed_callback_(channel_closed_callback), 36 channel_closed_callback_(channel_closed_callback),
32 weak_factory_(this) {} 37 weak_factory_(this) {}
33 38
34 FakeSecurityKeyIpcServer::~FakeSecurityKeyIpcServer() {} 39 FakeSecurityKeyIpcServer::~FakeSecurityKeyIpcServer() {}
35 40
36 void FakeSecurityKeyIpcServer::SendRequest(const std::string& message_data) { 41 void FakeSecurityKeyIpcServer::SendRequest(const std::string& message_data) {
37 send_message_callback_.Run(connection_id_, message_data); 42 send_message_callback_.Run(connection_id_, message_data);
38 } 43 }
39 44
40 void FakeSecurityKeyIpcServer::CloseChannel() { 45 void FakeSecurityKeyIpcServer::CloseChannel() {
(...skipping 10 matching lines...) Expand all
51 IPC_BEGIN_MESSAGE_MAP(FakeSecurityKeyIpcServer, message) 56 IPC_BEGIN_MESSAGE_MAP(FakeSecurityKeyIpcServer, message)
52 IPC_MESSAGE_HANDLER(ChromotingRemoteSecurityKeyToNetworkMsg_Request, 57 IPC_MESSAGE_HANDLER(ChromotingRemoteSecurityKeyToNetworkMsg_Request,
53 SendRequest) 58 SendRequest)
54 IPC_MESSAGE_UNHANDLED(handled = false) 59 IPC_MESSAGE_UNHANDLED(handled = false)
55 IPC_END_MESSAGE_MAP() 60 IPC_END_MESSAGE_MAP()
56 61
57 EXPECT_TRUE(handled); 62 EXPECT_TRUE(handled);
58 return handled; 63 return handled;
59 } 64 }
60 65
61 void FakeSecurityKeyIpcServer::OnChannelConnected(int32_t peer_pid) {} 66 void FakeSecurityKeyIpcServer::OnChannelConnected(int32_t peer_pid) {
67 connect_callback_.Run();
68 }
62 69
63 void FakeSecurityKeyIpcServer::OnChannelError() {} 70 bool FakeSecurityKeyIpcServer::CreateChannel(
64 71 const mojo::edk::NamedPlatformHandle& channel_handle,
65 bool FakeSecurityKeyIpcServer::CreateChannel(const std::string& channel_name, 72 base::TimeDelta request_timeout) {
66 base::TimeDelta request_timeout) { 73 mojo::edk::CreateServerHandleOptions options;
67 channel_name_ = channel_name; 74 #if defined(OS_WIN)
68 75 options.enforce_uniqueness = false;
69 ipc_channel_ = 76 #endif
70 IPC::Channel::CreateNamedServer(IPC::ChannelHandle(channel_name_), this); 77 ipc_channel_ = IPC::Channel::CreateServer(
78 mojo::edk::ConnectToPeerProcess(
79 mojo::edk::CreateServerHandle(channel_handle, options))
80 .release(),
81 this);
71 EXPECT_NE(nullptr, ipc_channel_); 82 EXPECT_NE(nullptr, ipc_channel_);
72 return ipc_channel_->Connect(); 83 return ipc_channel_->Connect();
73 } 84 }
74 85
75 bool FakeSecurityKeyIpcServer::SendResponse(const std::string& message_data) { 86 bool FakeSecurityKeyIpcServer::SendResponse(const std::string& message_data) {
76 last_message_received_ = message_data; 87 last_message_received_ = message_data;
77 88
78 // This class works in two modes: one in which the test wants the IPC channel 89 // This class works in two modes: one in which the test wants the IPC channel
79 // to be created and used for notification and the second mode where the test 90 // to be created and used for notification and the second mode where the test
80 // wants to notified of a response via a callback. If a callback is set then 91 // wants to notified of a response via a callback. If a callback is set then
(...skipping 13 matching lines...) Expand all
94 105
95 FakeSecurityKeyIpcServerFactory::~FakeSecurityKeyIpcServerFactory() { 106 FakeSecurityKeyIpcServerFactory::~FakeSecurityKeyIpcServerFactory() {
96 SecurityKeyIpcServer::SetFactoryForTest(nullptr); 107 SecurityKeyIpcServer::SetFactoryForTest(nullptr);
97 } 108 }
98 109
99 std::unique_ptr<SecurityKeyIpcServer> FakeSecurityKeyIpcServerFactory::Create( 110 std::unique_ptr<SecurityKeyIpcServer> FakeSecurityKeyIpcServerFactory::Create(
100 int connection_id, 111 int connection_id,
101 ClientSessionDetails* client_session_details, 112 ClientSessionDetails* client_session_details,
102 base::TimeDelta initial_connect_timeout, 113 base::TimeDelta initial_connect_timeout,
103 const SecurityKeyAuthHandler::SendMessageCallback& send_message_callback, 114 const SecurityKeyAuthHandler::SendMessageCallback& send_message_callback,
115 const base::Closure& connect_callback,
104 const base::Closure& done_callback) { 116 const base::Closure& done_callback) {
105 std::unique_ptr<FakeSecurityKeyIpcServer> fake_ipc_server( 117 auto fake_ipc_server = base::MakeUnique<FakeSecurityKeyIpcServer>(
106 new FakeSecurityKeyIpcServer(connection_id, client_session_details, 118 connection_id, client_session_details, initial_connect_timeout,
107 initial_connect_timeout, 119 send_message_callback, connect_callback, done_callback);
108 send_message_callback, done_callback));
109 120
110 ipc_server_map_[connection_id] = fake_ipc_server->AsWeakPtr(); 121 ipc_server_map_[connection_id] = fake_ipc_server->AsWeakPtr();
111 122
112 return base::WrapUnique(fake_ipc_server.release()); 123 return fake_ipc_server;
113 } 124 }
114 125
115 base::WeakPtr<FakeSecurityKeyIpcServer> 126 base::WeakPtr<FakeSecurityKeyIpcServer>
116 FakeSecurityKeyIpcServerFactory::GetIpcServerObject(int connection_id) { 127 FakeSecurityKeyIpcServerFactory::GetIpcServerObject(int connection_id) {
117 return ipc_server_map_[connection_id]; 128 return ipc_server_map_[connection_id];
118 } 129 }
119 130
120 } // namespace remoting 131 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/security_key/fake_security_key_ipc_server.h ('k') | remoting/host/security_key/remote_security_key_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698