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

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

Issue 2596393002: Update IPC message handling for SecurityKeyIpcClient class (Closed)
Patch Set: Addressing CR Feedback Created 3 years, 12 months 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
« no previous file with comments | « no previous file | remoting/host/security_key/security_key_ipc_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/security_key_ipc_client.h" 5 #include "remoting/host/security_key/security_key_ipc_client.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 23 matching lines...) Expand all
34 if (!channel_handle_.is_valid()) { 34 if (!channel_handle_.is_valid()) {
35 channel_handle_ = mojo::edk::CreateClientHandle(named_channel_handle_); 35 channel_handle_ = mojo::edk::CreateClientHandle(named_channel_handle_);
36 } 36 }
37 return channel_handle_.is_valid(); 37 return channel_handle_.is_valid();
38 } 38 }
39 39
40 void SecurityKeyIpcClient::EstablishIpcConnection( 40 void SecurityKeyIpcClient::EstablishIpcConnection(
41 const ConnectedCallback& connected_callback, 41 const ConnectedCallback& connected_callback,
42 const base::Closure& connection_error_callback) { 42 const base::Closure& connection_error_callback) {
43 DCHECK(thread_checker_.CalledOnValidThread()); 43 DCHECK(thread_checker_.CalledOnValidThread());
44 DCHECK(!connected_callback.is_null()); 44 DCHECK(connected_callback);
45 DCHECK(!connection_error_callback.is_null()); 45 DCHECK(connection_error_callback);
46 DCHECK(!ipc_channel_); 46 DCHECK(!ipc_channel_);
47 47
48 connected_callback_ = connected_callback; 48 connected_callback_ = connected_callback;
49 connection_error_callback_ = connection_error_callback; 49 connection_error_callback_ = connection_error_callback;
50 50
51 ConnectToIpcChannel(); 51 ConnectToIpcChannel();
52 } 52 }
53 53
54 bool SecurityKeyIpcClient::SendSecurityKeyRequest( 54 bool SecurityKeyIpcClient::SendSecurityKeyRequest(
55 const std::string& request_payload, 55 const std::string& request_payload,
56 const ResponseCallback& response_callback) { 56 const ResponseCallback& response_callback) {
57 DCHECK(thread_checker_.CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
58 DCHECK(!request_payload.empty()); 58 DCHECK(!request_payload.empty());
59 DCHECK(!response_callback.is_null()); 59 DCHECK(response_callback);
60 60
61 if (!ipc_channel_) { 61 if (!ipc_channel_) {
62 LOG(ERROR) << "Request made before IPC connection was established."; 62 LOG(ERROR) << "Request made before IPC connection was established.";
63 return false; 63 return false;
64 } 64 }
65 65
66 if (!response_callback_.is_null()) { 66 if (response_callback_) {
67 LOG(ERROR) 67 LOG(ERROR)
68 << "Request made while waiting for a response to a previous request."; 68 << "Request made while waiting for a response to a previous request.";
69 return false; 69 return false;
70 } 70 }
71 71
72 response_callback_ = response_callback; 72 response_callback_ = response_callback;
73 return ipc_channel_->Send( 73 return ipc_channel_->Send(
74 new ChromotingRemoteSecurityKeyToNetworkMsg_Request(request_payload)); 74 new ChromotingRemoteSecurityKeyToNetworkMsg_Request(request_payload));
75 } 75 }
76 76
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 << peer_session_id; 124 << peer_session_id;
125 base::ResetAndReturn(&connection_error_callback_).Run(); 125 base::ResetAndReturn(&connection_error_callback_).Run();
126 return; 126 return;
127 } 127 }
128 #endif // defined(OS_WIN) 128 #endif // defined(OS_WIN)
129 } 129 }
130 130
131 void SecurityKeyIpcClient::OnChannelError() { 131 void SecurityKeyIpcClient::OnChannelError() {
132 DCHECK(thread_checker_.CalledOnValidThread()); 132 DCHECK(thread_checker_.CalledOnValidThread());
133 133
134 if (!connection_error_callback_.is_null()) { 134 if (connection_error_callback_) {
135 base::ResetAndReturn(&connection_error_callback_).Run(); 135 base::ResetAndReturn(&connection_error_callback_).Run();
136 } 136 }
137 } 137 }
138 138
139 void SecurityKeyIpcClient::OnSecurityKeyResponse( 139 void SecurityKeyIpcClient::OnSecurityKeyResponse(
140 const std::string& response_data) { 140 const std::string& response_data) {
141 DCHECK(thread_checker_.CalledOnValidThread()); 141 DCHECK(thread_checker_.CalledOnValidThread());
142 DCHECK(!connection_error_callback_.is_null());
143 142
144 if (!response_data.empty()) { 143 if (!response_data.empty()) {
145 base::ResetAndReturn(&response_callback_).Run(response_data); 144 base::ResetAndReturn(&response_callback_).Run(response_data);
146 } else { 145 } else {
147 LOG(ERROR) << "Invalid response received"; 146 LOG(ERROR) << "Invalid response received";
148 base::ResetAndReturn(&connection_error_callback_).Run(); 147 if (connection_error_callback_) {
148 base::ResetAndReturn(&connection_error_callback_).Run();
149 }
149 } 150 }
150 } 151 }
151 152
152 void SecurityKeyIpcClient::OnConnectionReady() { 153 void SecurityKeyIpcClient::OnConnectionReady() {
153 DCHECK(thread_checker_.CalledOnValidThread()); 154 DCHECK(thread_checker_.CalledOnValidThread());
154 DCHECK(!connected_callback_.is_null()); 155
156 if (!connected_callback_) {
157 LOG(ERROR) << "Unexpected ConnectionReady message received.";
158 if (connection_error_callback_) {
159 base::ResetAndReturn(&connection_error_callback_).Run();
160 }
161 return;
162 }
155 163
156 base::ResetAndReturn(&connected_callback_).Run(/*connection_usable=*/true); 164 base::ResetAndReturn(&connected_callback_).Run(/*connection_usable=*/true);
157 } 165 }
158 166
159 void SecurityKeyIpcClient::OnInvalidSession() { 167 void SecurityKeyIpcClient::OnInvalidSession() {
160 DCHECK(thread_checker_.CalledOnValidThread()); 168 DCHECK(thread_checker_.CalledOnValidThread());
161 DCHECK(!connected_callback_.is_null()); 169
170 if (!connected_callback_) {
171 LOG(ERROR) << "Unexpected InvalidSession message received.";
172 if (connection_error_callback_) {
173 base::ResetAndReturn(&connection_error_callback_).Run();
174 }
175 return;
176 }
162 177
163 base::ResetAndReturn(&connected_callback_).Run(/*connection_usable=*/false); 178 base::ResetAndReturn(&connected_callback_).Run(/*connection_usable=*/false);
164 } 179 }
165 180
166 void SecurityKeyIpcClient::ConnectToIpcChannel() { 181 void SecurityKeyIpcClient::ConnectToIpcChannel() {
167 DCHECK(thread_checker_.CalledOnValidThread()); 182 DCHECK(thread_checker_.CalledOnValidThread());
168 183
169 // Verify that any existing IPC connection has been closed. 184 // Verify that any existing IPC connection has been closed.
170 CloseIpcConnection(); 185 CloseIpcConnection();
171 186
172 if (!channel_handle_.is_valid() && !CheckForSecurityKeyIpcServerChannel()) { 187 if (!channel_handle_.is_valid() && !CheckForSecurityKeyIpcServerChannel()) {
173 if (!connection_error_callback_.is_null()) { 188 if (connection_error_callback_) {
174 base::ResetAndReturn(&connection_error_callback_).Run(); 189 base::ResetAndReturn(&connection_error_callback_).Run();
175 } 190 }
176 return; 191 return;
177 } 192 }
178 193
179 ipc_channel_ = IPC::Channel::CreateClient( 194 ipc_channel_ = IPC::Channel::CreateClient(
180 mojo::edk::ConnectToPeerProcess(std::move(channel_handle_)).release(), 195 mojo::edk::ConnectToPeerProcess(std::move(channel_handle_)).release(),
181 this); 196 this);
182 if (ipc_channel_->Connect()) { 197 if (ipc_channel_->Connect()) {
183 return; 198 return;
184 } 199 }
185 ipc_channel_.reset(); 200 ipc_channel_.reset();
186 201
187 if (!connection_error_callback_.is_null()) { 202 if (connection_error_callback_) {
188 base::ResetAndReturn(&connection_error_callback_).Run(); 203 base::ResetAndReturn(&connection_error_callback_).Run();
189 } 204 }
190 } 205 }
191 206
192 } // namespace remoting 207 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | remoting/host/security_key/security_key_ipc_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698