OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/proximity_auth/bluetooth_connection.h" | 5 #include "components/proximity_auth/bluetooth_connection.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/location.h" | 10 #include "base/location.h" |
9 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
12 #include "components/proximity_auth/logging/logging.h" | 14 #include "components/proximity_auth/logging/logging.h" |
13 #include "components/proximity_auth/remote_device.h" | 15 #include "components/proximity_auth/remote_device.h" |
14 #include "components/proximity_auth/wire_message.h" | 16 #include "components/proximity_auth/wire_message.h" |
15 #include "device/bluetooth/bluetooth_adapter_factory.h" | 17 #include "device/bluetooth/bluetooth_adapter_factory.h" |
16 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 void BluetoothConnection::SendMessageImpl(scoped_ptr<WireMessage> message) { | 75 void BluetoothConnection::SendMessageImpl(scoped_ptr<WireMessage> message) { |
74 DCHECK_EQ(status(), CONNECTED); | 76 DCHECK_EQ(status(), CONNECTED); |
75 | 77 |
76 // Serialize the message. | 78 // Serialize the message. |
77 std::string serialized_message = message->Serialize(); | 79 std::string serialized_message = message->Serialize(); |
78 int message_length = base::checked_cast<int>(serialized_message.size()); | 80 int message_length = base::checked_cast<int>(serialized_message.size()); |
79 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(message_length); | 81 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(message_length); |
80 memcpy(buffer->data(), serialized_message.c_str(), message_length); | 82 memcpy(buffer->data(), serialized_message.c_str(), message_length); |
81 | 83 |
82 // Send it. | 84 // Send it. |
83 pending_message_ = message.Pass(); | 85 pending_message_ = std::move(message); |
84 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); | 86 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); |
85 socket_->Send(buffer, | 87 socket_->Send(buffer, |
86 message_length, | 88 message_length, |
87 base::Bind(&BluetoothConnection::OnSend, weak_this), | 89 base::Bind(&BluetoothConnection::OnSend, weak_this), |
88 base::Bind(&BluetoothConnection::OnSendError, weak_this)); | 90 base::Bind(&BluetoothConnection::OnSendError, weak_this)); |
89 } | 91 } |
90 | 92 |
91 void BluetoothConnection::DeviceChanged(device::BluetoothAdapter* adapter, | 93 void BluetoothConnection::DeviceChanged(device::BluetoothAdapter* adapter, |
92 device::BluetoothDevice* device) { | 94 device::BluetoothDevice* device) { |
93 DCHECK_EQ(adapter, adapter_.get()); | 95 DCHECK_EQ(adapter, adapter_.get()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; | 197 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; |
196 | 198 |
197 // Post a task to delay the read until the socket is available, as | 199 // Post a task to delay the read until the socket is available, as |
198 // calling StartReceive at this point would error with ERR_IO_PENDING. | 200 // calling StartReceive at this point would error with ERR_IO_PENDING. |
199 base::ThreadTaskRunnerHandle::Get()->PostTask( | 201 base::ThreadTaskRunnerHandle::Get()->PostTask( |
200 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, | 202 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, |
201 weak_ptr_factory_.GetWeakPtr())); | 203 weak_ptr_factory_.GetWeakPtr())); |
202 } | 204 } |
203 | 205 |
204 } // namespace proximity_auth | 206 } // namespace proximity_auth |
OLD | NEW |