Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(844)

Side by Side Diff: components/proximity_auth/bluetooth_connection.cc

Issue 1359043005: Fix BluetoothConnection to disconnect when the underlying device disconnects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proximity_auth_system2
Patch Set: fix test Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 status() != DISCONNECTED && !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 if (status() != DISCONNECTED)
110 Disconnect();
100 } 111 }
101 112
102 void BluetoothConnection::StartReceive() { 113 void BluetoothConnection::StartReceive() {
103 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr(); 114 base::WeakPtr<BluetoothConnection> weak_this = weak_ptr_factory_.GetWeakPtr();
104 socket_->Receive(kReceiveBufferSizeBytes, 115 socket_->Receive(kReceiveBufferSizeBytes,
105 base::Bind(&BluetoothConnection::OnReceive, weak_this), 116 base::Bind(&BluetoothConnection::OnReceive, weak_this),
106 base::Bind(&BluetoothConnection::OnReceiveError, weak_this)); 117 base::Bind(&BluetoothConnection::OnReceiveError, weak_this));
107 } 118 }
108 119
109 void BluetoothConnection::OnAdapterInitialized( 120 void BluetoothConnection::OnAdapterInitialized(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 PA_LOG(WARNING) << "Error receiving bytes: " << error_message; 195 PA_LOG(WARNING) << "Error receiving bytes: " << error_message;
185 196
186 // Post a task to delay the read until the socket is available, as 197 // 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. 198 // calling StartReceive at this point would error with ERR_IO_PENDING.
188 base::ThreadTaskRunnerHandle::Get()->PostTask( 199 base::ThreadTaskRunnerHandle::Get()->PostTask(
189 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive, 200 FROM_HERE, base::Bind(&BluetoothConnection::StartReceive,
190 weak_ptr_factory_.GetWeakPtr())); 201 weak_ptr_factory_.GetWeakPtr()));
191 } 202 }
192 203
193 } // namespace proximity_auth 204 } // namespace proximity_auth
OLDNEW
« no previous file with comments | « components/proximity_auth/bluetooth_connection.h ('k') | components/proximity_auth/bluetooth_connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698