Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 | 81 |
| 82 // Send it. | 82 // Send it. |
| 83 pending_message_ = message.Pass(); | 83 pending_message_ = message.Pass(); |
| 84 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); | 84 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); |
| 85 socket_->Send(buffer, | 85 socket_->Send(buffer, |
| 86 message_length, | 86 message_length, |
| 87 base::Bind(&BluetoothConnection::OnSend, weak_this), | 87 base::Bind(&BluetoothConnection::OnSend, weak_this), |
| 88 base::Bind(&BluetoothConnection::OnSendError, weak_this)); | 88 base::Bind(&BluetoothConnection::OnSendError, weak_this)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void BluetoothConnection::DeviceChanged(device::BluetoothAdapter* adapter, | |
| 92 device::BluetoothDevice* device) { | |
| 93 DCHECK_EQ(adapter, adapter_.get()); | |
| 94 if (device->GetAddress() == remote_device().bluetooth_address && | |
| 95 IsConnected() && !device->IsConnected()) { | |
| 96 PA_LOG(INFO) << "Device disconnected..."; | |
| 97 Disconnect(); | |
| 98 } | |
| 99 } | |
| 100 | |
| 91 void BluetoothConnection::DeviceRemoved(device::BluetoothAdapter* adapter, | 101 void BluetoothConnection::DeviceRemoved(device::BluetoothAdapter* adapter, |
| 92 device::BluetoothDevice* device) { | 102 device::BluetoothDevice* device) { |
| 93 DCHECK_EQ(adapter, adapter_.get()); | 103 DCHECK_EQ(adapter, adapter_.get()); |
| 94 if (device->GetAddress() != remote_device().bluetooth_address) | 104 if (device->GetAddress() != remote_device().bluetooth_address) |
| 95 return; | 105 return; |
| 96 | 106 |
| 97 DCHECK_NE(status(), DISCONNECTED); | 107 DCHECK_NE(status(), DISCONNECTED); |
| 98 PA_LOG(INFO) << "Device disconnected..."; | 108 PA_LOG(INFO) << "Device disconnected..."; |
| 99 Disconnect(); | 109 Disconnect(); |
|
sacomoto
2015/09/24 11:34:24
nit: Please check if |IsConnected()| before callin
Tim Song
2015/09/28 22:20:38
Done.
| |
| 100 } | 110 } |
| 101 | 111 |
| 102 void BluetoothConnection::StartReceive() { | 112 void BluetoothConnection::StartReceive() { |
| 103 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); | 113 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); |
| 104 socket_->Receive(kReceiveBufferSizeBytes, | 114 socket_->Receive(kReceiveBufferSizeBytes, |
| 105 base::Bind(&BluetoothConnection::OnReceive, weak_this), | 115 base::Bind(&BluetoothConnection::OnReceive, weak_this), |
| 106 base::Bind(&BluetoothConnection::OnReceiveError, weak_this)); | 116 base::Bind(&BluetoothConnection::OnReceiveError, weak_this)); |
| 107 } | 117 } |
| 108 | 118 |
| 109 void BluetoothConnection::OnAdapterInitialized( | 119 void BluetoothConnection::OnAdapterInitialized( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; | 194 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; |
| 185 | 195 |
| 186 // Post a task to delay the read until the socket is available, as | 196 // Post a task to delay the read until the socket is available, as |
| 187 // calling StartReceive at this point would error with ERR_IO_PENDING. | 197 // calling StartReceive at this point would error with ERR_IO_PENDING. |
| 188 base::ThreadTaskRunnerHandle::Get()->PostTask( | 198 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 189 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, | 199 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, |
| 190 weak_ptr_factory_.GetWeakPtr())); | 200 weak_ptr_factory_.GetWeakPtr())); |
| 191 } | 201 } |
| 192 | 202 |
| 193 } // namespace proximity_auth | 203 } // namespace proximity_auth |
| OLD | NEW |