| 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/remote_security_key_message_reader.h" | 5 #include "remoting/host/security_key/remote_security_key_message_reader.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 std::string message_data(total_message_size_bytes, '\0'); | 89 std::string message_data(total_message_size_bytes, '\0'); |
| 90 read_result = read_stream_.ReadAtCurrentPos(string_as_array(&message_data), | 90 read_result = read_stream_.ReadAtCurrentPos(string_as_array(&message_data), |
| 91 total_message_size_bytes); | 91 total_message_size_bytes); |
| 92 // The static cast is safe as we know the value is smaller than max int. | 92 // The static cast is safe as we know the value is smaller than max int. |
| 93 if (read_result != static_cast<int>(total_message_size_bytes)) { | 93 if (read_result != static_cast<int>(total_message_size_bytes)) { |
| 94 LOG(ERROR) << "Failed to read message: " << read_result; | 94 LOG(ERROR) << "Failed to read message: " << read_result; |
| 95 NotifyError(); | 95 NotifyError(); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 | 98 |
| 99 scoped_ptr<SecurityKeyMessage> message(new SecurityKeyMessage()); | 99 std::unique_ptr<SecurityKeyMessage> message(new SecurityKeyMessage()); |
| 100 if (!message->ParseMessage(message_data)) { | 100 if (!message->ParseMessage(message_data)) { |
| 101 LOG(ERROR) << "Invalid message data received."; | 101 LOG(ERROR) << "Invalid message data received."; |
| 102 NotifyError(); | 102 NotifyError(); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Notify callback of the new message received. | 106 // Notify callback of the new message received. |
| 107 main_task_runner_->PostTask( | 107 main_task_runner_->PostTask( |
| 108 FROM_HERE, | 108 FROM_HERE, |
| 109 base::Bind(&RemoteSecurityKeyMessageReader::InvokeMessageCallback, | 109 base::Bind(&RemoteSecurityKeyMessageReader::InvokeMessageCallback, |
| 110 weak_factory_.GetWeakPtr(), base::Passed(&message))); | 110 weak_factory_.GetWeakPtr(), base::Passed(&message))); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void RemoteSecurityKeyMessageReader::NotifyError() { | 114 void RemoteSecurityKeyMessageReader::NotifyError() { |
| 115 DCHECK(read_task_runner_->RunsTasksOnCurrentThread()); | 115 DCHECK(read_task_runner_->RunsTasksOnCurrentThread()); |
| 116 | 116 |
| 117 main_task_runner_->PostTask( | 117 main_task_runner_->PostTask( |
| 118 FROM_HERE, | 118 FROM_HERE, |
| 119 base::Bind(&RemoteSecurityKeyMessageReader::InvokeErrorCallback, | 119 base::Bind(&RemoteSecurityKeyMessageReader::InvokeErrorCallback, |
| 120 weak_factory_.GetWeakPtr())); | 120 weak_factory_.GetWeakPtr())); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void RemoteSecurityKeyMessageReader::InvokeMessageCallback( | 123 void RemoteSecurityKeyMessageReader::InvokeMessageCallback( |
| 124 scoped_ptr<SecurityKeyMessage> message) { | 124 std::unique_ptr<SecurityKeyMessage> message) { |
| 125 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); | 125 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); |
| 126 message_callback_.Run(std::move(message)); | 126 message_callback_.Run(std::move(message)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void RemoteSecurityKeyMessageReader::InvokeErrorCallback() { | 129 void RemoteSecurityKeyMessageReader::InvokeErrorCallback() { |
| 130 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); | 130 DCHECK(main_task_runner_->RunsTasksOnCurrentThread()); |
| 131 error_callback_.Run(); | 131 error_callback_.Run(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace remoting | 134 } // namespace remoting |
| OLD | NEW |