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