Chromium Code Reviews| 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 "components/arc/bluetooth/arc_bluetooth_bridge.h" | 5 #include "components/arc/bluetooth/arc_bluetooth_bridge.h" |
| 6 | 6 |
| 7 #include <bluetooth/bluetooth.h> | 7 #include <bluetooth/bluetooth.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 | 179 |
| 180 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) | 180 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) |
| 181 : ArcService(bridge_service), binding_(this), weak_factory_(this) { | 181 : ArcService(bridge_service), binding_(this), weak_factory_(this) { |
| 182 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | 182 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
| 183 VLOG(1) << "registering bluetooth adapter"; | 183 VLOG(1) << "registering bluetooth adapter"; |
| 184 BluetoothAdapterFactory::GetAdapter(base::Bind( | 184 BluetoothAdapterFactory::GetAdapter(base::Bind( |
| 185 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); | 185 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); |
| 186 } else { | 186 } else { |
| 187 VLOG(1) << "no bluetooth adapter available"; | 187 VLOG(1) << "no bluetooth adapter available"; |
| 188 } | 188 } |
| 189 | |
| 190 arc_bridge_service()->bluetooth()->AddObserver(this); | 189 arc_bridge_service()->bluetooth()->AddObserver(this); |
| 191 } | 190 } |
| 192 | 191 |
| 193 ArcBluetoothBridge::~ArcBluetoothBridge() { | 192 ArcBluetoothBridge::~ArcBluetoothBridge() { |
| 194 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 195 | 194 |
| 196 arc_bridge_service()->bluetooth()->RemoveObserver(this); | 195 arc_bridge_service()->bluetooth()->RemoveObserver(this); |
| 197 | 196 |
| 198 if (bluetooth_adapter_) | 197 if (bluetooth_adapter_) |
| 199 bluetooth_adapter_->RemoveObserver(this); | 198 bluetooth_adapter_->RemoveObserver(this); |
| 200 } | 199 } |
| 201 | 200 |
| 202 void ArcBluetoothBridge::OnAdapterInitialized( | 201 void ArcBluetoothBridge::OnAdapterInitialized( |
| 203 scoped_refptr<BluetoothAdapter> adapter) { | 202 scoped_refptr<BluetoothAdapter> adapter) { |
| 204 DCHECK(CalledOnValidThread()); | 203 DCHECK(CalledOnValidThread()); |
| 205 | 204 |
| 206 // We can downcast here because we are always running on Chrome OS, and | 205 // We can downcast here because we are always running on Chrome OS, and |
| 207 // so our adapter uses BlueZ. | 206 // so our adapter uses BlueZ. |
| 208 bluetooth_adapter_ = | 207 bluetooth_adapter_ = |
| 209 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get()); | 208 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get()); |
| 210 bluetooth_adapter_->AddObserver(this); | 209 |
| 210 // Arc instance is ready before Bluetooth adapter. | |
| 211 // We should register ourself to bluetooth observer here. | |
|
Luis Héctor Chávez
2016/08/08 21:12:03
nit: s/ourself/ourselves/. Same below.
puthik_chromium
2016/08/08 21:40:25
Done.
| |
| 212 if (!bluetooth_observer_flag_ && | |
| 213 arc_bridge_service()->bluetooth()->instance()) { | |
| 214 bluetooth_observer_flag_ = true; | |
| 215 bluetooth_adapter_->AddObserver(this); | |
| 216 } | |
| 211 } | 217 } |
| 212 | 218 |
| 213 void ArcBluetoothBridge::OnInstanceReady() { | 219 void ArcBluetoothBridge::OnInstanceReady() { |
| 214 mojom::BluetoothInstance* bluetooth_instance = | 220 mojom::BluetoothInstance* bluetooth_instance = |
| 215 arc_bridge_service()->bluetooth()->instance(); | 221 arc_bridge_service()->bluetooth()->instance(); |
| 216 if (!bluetooth_instance) { | 222 if (!bluetooth_instance) { |
| 217 LOG(ERROR) << "OnBluetoothInstanceReady called, " | 223 LOG(ERROR) << "OnBluetoothInstanceReady called, " |
| 218 << "but no bluetooth instance found"; | 224 << "but no bluetooth instance found"; |
| 219 return; | 225 return; |
| 220 } | 226 } |
| 221 bluetooth_instance->Init(binding_.CreateInterfacePtrAndBind()); | 227 |
|
rkc
2016/08/08 21:16:15
Where are we doing this now?
puthik_chromium
2016/08/08 21:40:25
My error. Fixed
| |
| 228 // Bluetooth adapter is ready before Arc instance. | |
| 229 // We should register ourself to bluetooth observer here. | |
| 230 if (!bluetooth_observer_flag_ && bluetooth_adapter_) { | |
| 231 bluetooth_observer_flag_ = true; | |
| 232 bluetooth_adapter_->AddObserver(this); | |
| 233 } | |
| 234 } | |
| 235 | |
| 236 void ArcBluetoothBridge::OnInstanceClosed() { | |
| 237 if (bluetooth_observer_flag_ && bluetooth_adapter_) | |
|
Luis Héctor Chávez
2016/08/08 21:12:03
If you remove the flag like rkc@ suggested, maybe
rkc
2016/08/08 21:16:15
+1
puthik_chromium
2016/08/08 21:40:25
I changed to code to hold make bluetooth_adapter_
| |
| 238 bluetooth_adapter_->RemoveObserver(this); | |
| 239 bluetooth_observer_flag_ = false; | |
| 222 } | 240 } |
| 223 | 241 |
| 224 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, | 242 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, |
| 225 bool powered) { | 243 bool powered) { |
| 226 if (!HasBluetoothInstance()) | 244 if (!HasBluetoothInstance()) |
| 227 return; | 245 return; |
| 228 | 246 |
| 229 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge | 247 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge |
| 230 // service. | 248 // service. |
| 231 } | 249 } |
| (...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1640 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1658 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1641 << ") need version " << version_need; | 1659 << ") need version " << version_need; |
| 1642 return false; | 1660 return false; |
| 1643 } | 1661 } |
| 1644 | 1662 |
| 1645 bool ArcBluetoothBridge::CalledOnValidThread() { | 1663 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 1646 return thread_checker_.CalledOnValidThread(); | 1664 return thread_checker_.CalledOnValidThread(); |
| 1647 } | 1665 } |
| 1648 | 1666 |
| 1649 } // namespace arc | 1667 } // namespace arc |
| OLD | NEW |