Chromium Code Reviews| Index: components/arc/bluetooth/arc_bluetooth_bridge.cc |
| diff --git a/components/arc/bluetooth/arc_bluetooth_bridge.cc b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| index 7d11d2036d55a8a0f68fea9da1253e607b1853e3..ca4ce61fe1221e9326a09210f0d732ac3153343d 100644 |
| --- a/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| +++ b/components/arc/bluetooth/arc_bluetooth_bridge.cc |
| @@ -184,12 +184,25 @@ uint16_t GetUUID16(const BluetoothUUID& uuid) { |
| return std::stoi(uuid.canonical_value().substr(4, 4), nullptr, 16); |
| } |
| +mojo::Array<arc::mojom::BluetoothPropertyPtr> GetDiscoveryTimeoutProperty( |
| + uint32_t timeout) { |
| + arc::mojom::BluetoothPropertyPtr property = |
| + arc::mojom::BluetoothProperty::New(); |
| + property->set_discovery_timeout(timeout); |
| + mojo::Array<arc::mojom::BluetoothPropertyPtr> properties; |
| + properties.push_back(std::move(property)); |
| + return properties; |
| +} |
| + |
| } // namespace |
| namespace arc { |
| ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) |
| - : ArcService(bridge_service), binding_(this), weak_factory_(this) { |
| + : ArcService(bridge_service), |
| + binding_(this), |
| + discoverable_off_timer_(true, false), |
|
Luis Héctor Chávez
2016/09/01 19:28:15
it looks like you can use base::OneShotTimer inste
puthik_chromium
2016/09/01 20:42:24
Done.
|
| + weak_factory_(this) { |
| if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
| VLOG(1) << "Registering bluetooth adapter."; |
| BluetoothAdapterFactory::GetAdapter(base::Bind( |
| @@ -618,16 +631,84 @@ void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { |
| mojom::BluetoothStatus::SUCCESS, std::move(properties)); |
| } |
| +void ArcBluetoothBridge::OnSetDiscoverable(bool discoverable, |
| + bool success, |
| + uint32_t timeout) { |
| + if (!success) { |
|
Luis Héctor Chávez
2016/09/01 19:28:15
nit:
DCHECK(CalledOnValidThread());
if (!HasBluet
puthik_chromium
2016/09/01 20:42:24
Done.
|
| + arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( |
| + mojom::BluetoothStatus::FAIL, |
| + mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); |
| + return; |
| + } |
| + |
| + arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( |
| + mojom::BluetoothStatus::SUCCESS, GetDiscoveryTimeoutProperty(timeout)); |
| + |
| + if (discoverable && timeout > 0) { |
| + discoverable_off_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromSeconds(timeout), |
| + base::Bind(&ArcBluetoothBridge::SetDiscoverable, |
| + weak_factory_.GetWeakPtr(), false, 0)); |
| + } |
| +} |
| + |
| +// Set discoverable state to on / off. |
| +// In case of turning on, start timer to turn it back off in |timeout| seconds. |
| +void ArcBluetoothBridge::SetDiscoverable(bool discoverable, uint32_t timeout) { |
| + DCHECK(bluetooth_adapter_); |
| + DCHECK(CalledOnValidThread()); |
| + DCHECK(!discoverable || timeout == 0); |
| + |
| + bool current = bluetooth_adapter_->IsDiscoverable(); |
|
Luis Héctor Chávez
2016/09/01 19:28:15
nit: currently_discoverable.
puthik_chromium
2016/09/01 20:42:24
Done.
|
| + |
| + if (!discoverable && !current) |
| + return; |
| + |
| + if (discoverable && current) { |
| + if (base::TimeDelta::FromSeconds(timeout) > |
| + discoverable_off_timer_.GetCurrentDelay()) { |
| + // Restart discoverable_off_timer_ if new timeout is greater |
| + OnSetDiscoverable(true, true, timeout); |
| + } else { |
| + // Just send message to Chrome is new timeout is lower. |
|
Luis Héctor Chávez
2016/09/01 19:28:15
nit: "Android if"? this also needs to be gated upo
puthik_chromium
2016/09/01 20:42:24
Done.
|
| + arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( |
| + mojom::BluetoothStatus::SUCCESS, |
| + GetDiscoveryTimeoutProperty(timeout)); |
| + } |
| + return; |
| + } |
| + |
| + bluetooth_adapter_->SetDiscoverable( |
| + discoverable, |
| + base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, |
| + weak_factory_.GetWeakPtr(), discoverable, true, timeout), |
| + base::Bind(&ArcBluetoothBridge::OnSetDiscoverable, |
| + weak_factory_.GetWeakPtr(), discoverable, false, timeout)); |
| +} |
| + |
| void ArcBluetoothBridge::SetAdapterProperty( |
| mojom::BluetoothPropertyPtr property) { |
| DCHECK(bluetooth_adapter_); |
| if (!HasBluetoothInstance()) |
| return; |
| - // TODO(smbarber): Implement SetAdapterProperty |
| - arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( |
| - mojom::BluetoothStatus::FAIL, |
| - mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); |
| + if (property->is_discovery_timeout()) { |
| + uint32_t discovery_timeout = property->get_discovery_timeout(); |
| + mojo::Array<mojom::BluetoothPropertyPtr> success_result; |
| + success_result.push_back(std::move(property)); |
| + if (discovery_timeout > 0) { |
| + SetDiscoverable(true, discovery_timeout); |
| + } else { |
| + arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( |
| + mojom::BluetoothStatus::PARM_INVALID, |
| + mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); |
| + } |
| + } else { |
| + // TODO(puthik) Implement other case. |
| + arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties( |
| + mojom::BluetoothStatus::UNSUPPORTED, |
| + mojo::Array<arc::mojom::BluetoothPropertyPtr>::New(0)); |
| + } |
| } |
| void ArcBluetoothBridge::GetRemoteDeviceProperty( |