| 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/security_key_message_handler.h" | 5 #include "remoting/host/security_key/security_key_message_handler.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 void SecurityKeyMessageHandler::HandleIpcConnectionChange( | 84 void SecurityKeyMessageHandler::HandleIpcConnectionChange( |
| 85 bool connection_established) { | 85 bool connection_established) { |
| 86 DCHECK(thread_checker_.CalledOnValidThread()); | 86 DCHECK(thread_checker_.CalledOnValidThread()); |
| 87 if (connection_established) { | 87 if (connection_established) { |
| 88 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_RESPONSE, | 88 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_RESPONSE, |
| 89 std::string(1, kConnectResponseActiveSession)); | 89 std::string(1, kConnectResponseActiveSession)); |
| 90 } else { | 90 } else { |
| 91 SendMessageWithPayload( | 91 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_RESPONSE, |
| 92 SecurityKeyMessageType::CONNECT_ERROR, | 92 std::string(1, kConnectResponseNoSession)); |
| 93 "Unknown error occurred while establishing connection."); | 93 // We expect the server to close the IPC channel in this scenario. |
| 94 expect_ipc_channel_close_ = true; |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 98 void SecurityKeyMessageHandler::HandleIpcConnectionError() { |
| 99 DCHECK(thread_checker_.CalledOnValidThread()); |
| 100 if (!expect_ipc_channel_close_) { |
| 101 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_ERROR, |
| 102 "Unknown error occurred during connection."); |
| 103 } |
| 104 } |
| 105 |
| 97 void SecurityKeyMessageHandler::HandleSecurityKeyResponse( | 106 void SecurityKeyMessageHandler::HandleSecurityKeyResponse( |
| 98 const std::string& response_data) { | 107 const std::string& response_data) { |
| 99 if (response_data.compare(kSecurityKeyConnectionError) == 0) { | 108 if (response_data.compare(kSecurityKeyConnectionError) == 0) { |
| 100 SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR, | 109 SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR, |
| 101 "An error occurred during the request."); | 110 "An error occurred during the request."); |
| 102 return; | 111 return; |
| 103 } | 112 } |
| 104 | 113 |
| 105 if (response_data.empty()) { | 114 if (response_data.empty()) { |
| 106 SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR, | 115 SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 118 if (!message_payload.empty()) { | 127 if (!message_payload.empty()) { |
| 119 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_ERROR, | 128 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_ERROR, |
| 120 "Unexpected payload data received."); | 129 "Unexpected payload data received."); |
| 121 return; | 130 return; |
| 122 } | 131 } |
| 123 | 132 |
| 124 if (ipc_client_->CheckForSecurityKeyIpcServerChannel()) { | 133 if (ipc_client_->CheckForSecurityKeyIpcServerChannel()) { |
| 125 // If we find an IPC server, then attempt to establish a connection. | 134 // If we find an IPC server, then attempt to establish a connection. |
| 126 ipc_client_->EstablishIpcConnection( | 135 ipc_client_->EstablishIpcConnection( |
| 127 base::Bind(&SecurityKeyMessageHandler::HandleIpcConnectionChange, | 136 base::Bind(&SecurityKeyMessageHandler::HandleIpcConnectionChange, |
| 128 base::Unretained(this), true), | 137 base::Unretained(this)), |
| 129 base::Bind(&SecurityKeyMessageHandler::HandleIpcConnectionChange, | 138 base::Bind(&SecurityKeyMessageHandler::HandleIpcConnectionError, |
| 130 base::Unretained(this), false)); | 139 base::Unretained(this))); |
| 131 } else { | 140 } else { |
| 132 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_RESPONSE, | 141 SendMessageWithPayload(SecurityKeyMessageType::CONNECT_RESPONSE, |
| 133 std::string(1, kConnectResponseNoSession)); | 142 std::string(1, kConnectResponseNoSession)); |
| 134 } | 143 } |
| 135 } | 144 } |
| 136 | 145 |
| 137 void SecurityKeyMessageHandler::HandleSecurityKeyRequest( | 146 void SecurityKeyMessageHandler::HandleSecurityKeyRequest( |
| 138 const std::string& message_payload) { | 147 const std::string& message_payload) { |
| 139 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
| 140 if (message_payload.empty()) { | 149 if (message_payload.empty()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 ipc_client_.reset(); | 181 ipc_client_.reset(); |
| 173 writer_.reset(); | 182 writer_.reset(); |
| 174 reader_.reset(); | 183 reader_.reset(); |
| 175 | 184 |
| 176 if (!error_callback_.is_null()) { | 185 if (!error_callback_.is_null()) { |
| 177 base::ResetAndReturn(&error_callback_).Run(); | 186 base::ResetAndReturn(&error_callback_).Run(); |
| 178 } | 187 } |
| 179 } | 188 } |
| 180 | 189 |
| 181 } // namespace remoting | 190 } // namespace remoting |
| OLD | NEW |