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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 bool IsGattOffsetValid(int offset) { | 172 bool IsGattOffsetValid(int offset) { |
| 173 return 0 <= offset && offset < kMaxGattAttributeLength; | 173 return 0 <= offset && offset < kMaxGattAttributeLength; |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace | 176 } // namespace |
| 177 | 177 |
| 178 namespace arc { | 178 namespace arc { |
| 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()) { | |
| 183 VLOG(1) << "registering bluetooth adapter"; | |
| 184 BluetoothAdapterFactory::GetAdapter(base::Bind( | |
| 185 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); | |
| 186 } else { | |
| 187 VLOG(1) << "no bluetooth adapter available"; | |
| 188 } | |
| 189 | |
| 190 arc_bridge_service()->bluetooth()->AddObserver(this); | 182 arc_bridge_service()->bluetooth()->AddObserver(this); |
| 191 } | 183 } |
| 192 | 184 |
| 193 ArcBluetoothBridge::~ArcBluetoothBridge() { | 185 ArcBluetoothBridge::~ArcBluetoothBridge() { |
| 194 DCHECK(CalledOnValidThread()); | 186 DCHECK(CalledOnValidThread()); |
| 195 | 187 |
| 196 arc_bridge_service()->bluetooth()->RemoveObserver(this); | 188 arc_bridge_service()->bluetooth()->RemoveObserver(this); |
| 197 | 189 |
| 198 if (bluetooth_adapter_) | 190 if (bluetooth_adapter_) |
| 199 bluetooth_adapter_->RemoveObserver(this); | 191 bluetooth_adapter_->RemoveObserver(this); |
| 200 } | 192 } |
| 201 | 193 |
| 202 void ArcBluetoothBridge::OnAdapterInitialized( | 194 void ArcBluetoothBridge::OnAdapterInitialized( |
| 203 scoped_refptr<BluetoothAdapter> adapter) { | 195 scoped_refptr<BluetoothAdapter> adapter) { |
| 204 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
| 205 | 197 |
| 206 // We can downcast here because we are always running on Chrome OS, and | 198 // We can downcast here because we are always running on Chrome OS, and |
| 207 // so our adapter uses BlueZ. | 199 // so our adapter uses BlueZ. |
| 208 bluetooth_adapter_ = | 200 bluetooth_adapter_ = |
| 209 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get()); | 201 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get()); |
| 210 bluetooth_adapter_->AddObserver(this); | 202 bluetooth_adapter_->AddObserver(this); |
| 203 bluetooth_observer_flag_ = true; | |
| 211 } | 204 } |
| 212 | 205 |
| 213 void ArcBluetoothBridge::OnInstanceReady() { | 206 void ArcBluetoothBridge::OnInstanceReady() { |
| 214 mojom::BluetoothInstance* bluetooth_instance = | 207 mojom::BluetoothInstance* bluetooth_instance = |
| 215 arc_bridge_service()->bluetooth()->instance(); | 208 arc_bridge_service()->bluetooth()->instance(); |
| 216 if (!bluetooth_instance) { | 209 if (!bluetooth_instance) { |
| 217 LOG(ERROR) << "OnBluetoothInstanceReady called, " | 210 LOG(ERROR) << "OnBluetoothInstanceReady called, " |
| 218 << "but no bluetooth instance found"; | 211 << "but no bluetooth instance found"; |
| 219 return; | 212 return; |
| 220 } | 213 } |
| 221 bluetooth_instance->Init(binding_.CreateInterfacePtrAndBind()); | 214 bluetooth_instance->Init(binding_.CreateInterfacePtrAndBind()); |
| 215 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | |
| 216 VLOG(1) << "registering bluetooth adapter"; | |
|
rkc
2016/08/08 21:08:12
VLOG(1) << "Registering Bluetooth adapter.";
puthik_chromium
2016/08/08 21:40:25
Done.
| |
| 217 BluetoothAdapterFactory::GetAdapter(base::Bind( | |
| 218 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); | |
| 219 } else { | |
| 220 VLOG(1) << "no bluetooth adapter available"; | |
|
rkc
2016/08/08 21:08:12
VLOG(1) << "No Bluetooth adapter available.";
puthik_chromium
2016/08/08 21:40:25
Done.
| |
| 221 } | |
| 222 } | |
| 223 | |
| 224 void ArcBluetoothBridge::OnInstanceClosed() { | |
| 225 if (bluetooth_observer_flag_ && bluetooth_adapter_) | |
| 226 bluetooth_adapter_->RemoveObserver(this); | |
|
rkc
2016/08/08 21:08:12
You don't need the bluetooth_observer_flag_ flag.
puthik_chromium
2016/08/08 21:40:25
The flag is used to see that we should register ob
| |
| 227 bluetooth_observer_flag_ = false; | |
| 222 } | 228 } |
| 223 | 229 |
| 224 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, | 230 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, |
| 225 bool powered) { | 231 bool powered) { |
| 226 if (!HasBluetoothInstance()) | 232 if (!HasBluetoothInstance()) |
| 227 return; | 233 return; |
| 228 | 234 |
| 229 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge | 235 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge |
| 230 // service. | 236 // service. |
| 231 } | 237 } |
| (...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1640 LOG(WARNING) << "Bluetooth instance is too old (version " << version | 1646 LOG(WARNING) << "Bluetooth instance is too old (version " << version |
| 1641 << ") need version " << version_need; | 1647 << ") need version " << version_need; |
| 1642 return false; | 1648 return false; |
| 1643 } | 1649 } |
| 1644 | 1650 |
| 1645 bool ArcBluetoothBridge::CalledOnValidThread() { | 1651 bool ArcBluetoothBridge::CalledOnValidThread() { |
| 1646 return thread_checker_.CalledOnValidThread(); | 1652 return thread_checker_.CalledOnValidThread(); |
| 1647 } | 1653 } |
| 1648 | 1654 |
| 1649 } // namespace arc | 1655 } // namespace arc |
| OLD | NEW |