| Index: remoting/host/security_key/security_key_message_handler.cc
|
| diff --git a/remoting/host/security_key/remote_security_key_message_handler.cc b/remoting/host/security_key/security_key_message_handler.cc
|
| similarity index 50%
|
| rename from remoting/host/security_key/remote_security_key_message_handler.cc
|
| rename to remoting/host/security_key/security_key_message_handler.cc
|
| index 2840627ed452e4ef1b7da208e468f08ab92cdd10..1617f89d30457aa96fc4c9b9ea85588f781a06d5 100644
|
| --- a/remoting/host/security_key/remote_security_key_message_handler.cc
|
| +++ b/remoting/host/security_key/security_key_message_handler.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "remoting/host/security_key/remote_security_key_message_handler.h"
|
| +#include "remoting/host/security_key/security_key_message_handler.h"
|
|
|
| #include <cstdint>
|
| #include <string>
|
| @@ -11,21 +11,21 @@
|
| #include "base/bind.h"
|
| #include "base/callback.h"
|
| #include "base/callback_helpers.h"
|
| -#include "remoting/host/security_key/remote_security_key_ipc_client.h"
|
| -#include "remoting/host/security_key/remote_security_key_ipc_constants.h"
|
| -#include "remoting/host/security_key/remote_security_key_message_reader_impl.h"
|
| -#include "remoting/host/security_key/remote_security_key_message_writer_impl.h"
|
| +#include "remoting/host/security_key/security_key_ipc_client.h"
|
| +#include "remoting/host/security_key/security_key_ipc_constants.h"
|
| +#include "remoting/host/security_key/security_key_message_reader_impl.h"
|
| +#include "remoting/host/security_key/security_key_message_writer_impl.h"
|
|
|
| namespace remoting {
|
|
|
| -RemoteSecurityKeyMessageHandler::RemoteSecurityKeyMessageHandler() {}
|
| +SecurityKeyMessageHandler::SecurityKeyMessageHandler() {}
|
|
|
| -RemoteSecurityKeyMessageHandler::~RemoteSecurityKeyMessageHandler() {}
|
| +SecurityKeyMessageHandler::~SecurityKeyMessageHandler() {}
|
|
|
| -void RemoteSecurityKeyMessageHandler::Start(
|
| +void SecurityKeyMessageHandler::Start(
|
| base::File message_read_stream,
|
| base::File message_write_stream,
|
| - std::unique_ptr<RemoteSecurityKeyIpcClient> ipc_client,
|
| + std::unique_ptr<SecurityKeyIpcClient> ipc_client,
|
| const base::Closure& error_callback) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| DCHECK(message_read_stream.IsValid());
|
| @@ -36,89 +36,87 @@ void RemoteSecurityKeyMessageHandler::Start(
|
|
|
| if (!reader_) {
|
| reader_.reset(
|
| - new RemoteSecurityKeyMessageReaderImpl(std::move(message_read_stream)));
|
| + new SecurityKeyMessageReaderImpl(std::move(message_read_stream)));
|
| }
|
|
|
| if (!writer_) {
|
| - writer_.reset(new RemoteSecurityKeyMessageWriterImpl(
|
| - std::move(message_write_stream)));
|
| + writer_.reset(
|
| + new SecurityKeyMessageWriterImpl(std::move(message_write_stream)));
|
| }
|
|
|
| ipc_client_ = std::move(ipc_client);
|
| error_callback_ = error_callback;
|
|
|
| reader_->Start(
|
| - base::Bind(
|
| - &RemoteSecurityKeyMessageHandler::ProcessRemoteSecurityKeyMessage,
|
| - base::Unretained(this)),
|
| - base::Bind(&RemoteSecurityKeyMessageHandler::OnError,
|
| - base::Unretained(this)));
|
| + base::Bind(&SecurityKeyMessageHandler::ProcessSecurityKeyMessage,
|
| + base::Unretained(this)),
|
| + base::Bind(&SecurityKeyMessageHandler::OnError, base::Unretained(this)));
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::SetRemoteSecurityKeyMessageReaderForTest(
|
| - std::unique_ptr<RemoteSecurityKeyMessageReader> reader) {
|
| +void SecurityKeyMessageHandler::SetSecurityKeyMessageReaderForTest(
|
| + std::unique_ptr<SecurityKeyMessageReader> reader) {
|
| DCHECK(!reader_);
|
| reader_ = std::move(reader);
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::SetRemoteSecurityKeyMessageWriterForTest(
|
| - std::unique_ptr<RemoteSecurityKeyMessageWriter> writer) {
|
| +void SecurityKeyMessageHandler::SetSecurityKeyMessageWriterForTest(
|
| + std::unique_ptr<SecurityKeyMessageWriter> writer) {
|
| DCHECK(!writer_);
|
| writer_ = std::move(writer);
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::ProcessRemoteSecurityKeyMessage(
|
| +void SecurityKeyMessageHandler::ProcessSecurityKeyMessage(
|
| std::unique_ptr<SecurityKeyMessage> message) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
|
|
| - RemoteSecurityKeyMessageType message_type = message->type();
|
| - if (message_type == RemoteSecurityKeyMessageType::CONNECT) {
|
| + SecurityKeyMessageType message_type = message->type();
|
| + if (message_type == SecurityKeyMessageType::CONNECT) {
|
| HandleConnectRequest(message->payload());
|
| - } else if (message_type == RemoteSecurityKeyMessageType::REQUEST) {
|
| + } else if (message_type == SecurityKeyMessageType::REQUEST) {
|
| HandleSecurityKeyRequest(message->payload());
|
| } else {
|
| LOG(ERROR) << "Unknown message type: "
|
| << static_cast<uint8_t>(message_type);
|
| - SendMessage(RemoteSecurityKeyMessageType::UNKNOWN_COMMAND);
|
| + SendMessage(SecurityKeyMessageType::UNKNOWN_COMMAND);
|
| }
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::HandleIpcConnectionChange(
|
| +void SecurityKeyMessageHandler::HandleIpcConnectionChange(
|
| bool connection_established) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| if (connection_established) {
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::CONNECT_RESPONSE,
|
| + SendMessageWithPayload(SecurityKeyMessageType::CONNECT_RESPONSE,
|
| std::string(1, kConnectResponseActiveSession));
|
| } else {
|
| SendMessageWithPayload(
|
| - RemoteSecurityKeyMessageType::CONNECT_ERROR,
|
| + SecurityKeyMessageType::CONNECT_ERROR,
|
| "Unknown error occurred while establishing connection.");
|
| }
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::HandleSecurityKeyResponse(
|
| +void SecurityKeyMessageHandler::HandleSecurityKeyResponse(
|
| const std::string& response_data) {
|
| - if (response_data.compare(kRemoteSecurityKeyConnectionError) == 0) {
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + if (response_data.compare(kSecurityKeyConnectionError) == 0) {
|
| + SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR,
|
| "An error occurred during the request.");
|
| return;
|
| }
|
|
|
| if (response_data.empty()) {
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR,
|
| "Invalid client response received.");
|
| return;
|
| }
|
|
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::REQUEST_RESPONSE,
|
| + SendMessageWithPayload(SecurityKeyMessageType::REQUEST_RESPONSE,
|
| response_data);
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::HandleConnectRequest(
|
| +void SecurityKeyMessageHandler::HandleConnectRequest(
|
| const std::string& message_payload) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| if (!message_payload.empty()) {
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::CONNECT_ERROR,
|
| + SendMessageWithPayload(SecurityKeyMessageType::CONNECT_ERROR,
|
| "Unexpected payload data received.");
|
| return;
|
| }
|
| @@ -126,51 +124,50 @@ void RemoteSecurityKeyMessageHandler::HandleConnectRequest(
|
| if (ipc_client_->WaitForSecurityKeyIpcServerChannel()) {
|
| // If we find an IPC server, then attempt to establish a connection.
|
| ipc_client_->EstablishIpcConnection(
|
| - base::Bind(&RemoteSecurityKeyMessageHandler::HandleIpcConnectionChange,
|
| + base::Bind(&SecurityKeyMessageHandler::HandleIpcConnectionChange,
|
| base::Unretained(this), true),
|
| - base::Bind(&RemoteSecurityKeyMessageHandler::HandleIpcConnectionChange,
|
| + base::Bind(&SecurityKeyMessageHandler::HandleIpcConnectionChange,
|
| base::Unretained(this), false));
|
| } else {
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::CONNECT_RESPONSE,
|
| + SendMessageWithPayload(SecurityKeyMessageType::CONNECT_RESPONSE,
|
| std::string(1, kConnectResponseNoSession));
|
| }
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::HandleSecurityKeyRequest(
|
| +void SecurityKeyMessageHandler::HandleSecurityKeyRequest(
|
| const std::string& message_payload) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| if (message_payload.empty()) {
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR,
|
| "Request sent without request data.");
|
| return;
|
| }
|
|
|
| if (!ipc_client_->SendSecurityKeyRequest(
|
| message_payload,
|
| - base::Bind(
|
| - &RemoteSecurityKeyMessageHandler::HandleSecurityKeyResponse,
|
| - base::Unretained(this)))) {
|
| - SendMessageWithPayload(RemoteSecurityKeyMessageType::REQUEST_ERROR,
|
| + base::Bind(&SecurityKeyMessageHandler::HandleSecurityKeyResponse,
|
| + base::Unretained(this)))) {
|
| + SendMessageWithPayload(SecurityKeyMessageType::REQUEST_ERROR,
|
| "Failed to send request data.");
|
| }
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::SendMessage(
|
| - RemoteSecurityKeyMessageType message_type) {
|
| +void SecurityKeyMessageHandler::SendMessage(
|
| + SecurityKeyMessageType message_type) {
|
| if (!writer_->WriteMessage(message_type)) {
|
| OnError();
|
| }
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::SendMessageWithPayload(
|
| - RemoteSecurityKeyMessageType message_type,
|
| +void SecurityKeyMessageHandler::SendMessageWithPayload(
|
| + SecurityKeyMessageType message_type,
|
| const std::string& message_payload) {
|
| if (!writer_->WriteMessageWithPayload(message_type, message_payload)) {
|
| OnError();
|
| }
|
| }
|
|
|
| -void RemoteSecurityKeyMessageHandler::OnError() {
|
| +void SecurityKeyMessageHandler::OnError() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| ipc_client_.reset();
|
| writer_.reset();
|
|
|