| 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> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "components/cryptauth/remote_device.h" |
| 14 #include "components/proximity_auth/logging/logging.h" | 15 #include "components/proximity_auth/logging/logging.h" |
| 15 #include "components/proximity_auth/remote_device.h" | |
| 16 #include "components/proximity_auth/wire_message.h" | 16 #include "components/proximity_auth/wire_message.h" |
| 17 #include "device/bluetooth/bluetooth_adapter_factory.h" | 17 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 18 #include "device/bluetooth/bluetooth_device.h" | 18 #include "device/bluetooth/bluetooth_device.h" |
| 19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 20 | 20 |
| 21 namespace proximity_auth { | 21 namespace proximity_auth { |
| 22 namespace { | 22 namespace { |
| 23 const int kReceiveBufferSizeBytes = 1024; | 23 const int kReceiveBufferSizeBytes = 1024; |
| 24 } | 24 } |
| 25 | 25 |
| 26 BluetoothConnection::BluetoothConnection(const RemoteDevice& remote_device, | 26 BluetoothConnection::BluetoothConnection( |
| 27 const device::BluetoothUUID& uuid) | 27 const cryptauth::RemoteDevice& remote_device, |
| 28 : Connection(remote_device), uuid_(uuid), weak_ptr_factory_(this) { | 28 const device::BluetoothUUID& uuid) |
| 29 } | 29 : Connection(remote_device), uuid_(uuid), weak_ptr_factory_(this) {} |
| 30 | 30 |
| 31 BluetoothConnection::~BluetoothConnection() { | 31 BluetoothConnection::~BluetoothConnection() { |
| 32 if (status() != DISCONNECTED) | 32 if (status() != DISCONNECTED) |
| 33 Disconnect(); | 33 Disconnect(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void BluetoothConnection::Connect() { | 36 void BluetoothConnection::Connect() { |
| 37 if (status() != DISCONNECTED) { | 37 if (status() != DISCONNECTED) { |
| 38 PA_LOG(WARNING) | 38 PA_LOG(WARNING) |
| 39 << "Ignoring attempt to connect a non-disconnected connection."; | 39 << "Ignoring attempt to connect a non-disconnected connection."; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; | 198 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; |
| 199 | 199 |
| 200 // Post a task to delay the read until the socket is available, as | 200 // Post a task to delay the read until the socket is available, as |
| 201 // calling StartReceive at this point would error with ERR_IO_PENDING. | 201 // calling StartReceive at this point would error with ERR_IO_PENDING. |
| 202 base::ThreadTaskRunnerHandle::Get()->PostTask( | 202 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 203 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, | 203 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, |
| 204 weak_ptr_factory_.GetWeakPtr())); | 204 weak_ptr_factory_.GetWeakPtr())); |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace proximity_auth | 207 } // namespace proximity_auth |
| OLD | NEW |