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

Side by Side Diff: components/arc/bluetooth/arc_bluetooth_bridge.cc

Issue 2190483003: arc: Revamp the ArcBridgeService interface (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@2785
Patch Set: One less diff line Created 4 years, 4 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 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 <fcntl.h> 7 #include <fcntl.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <iomanip> 10 #include <iomanip>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service) 64 ArcBluetoothBridge::ArcBluetoothBridge(ArcBridgeService* bridge_service)
65 : ArcService(bridge_service), binding_(this), weak_factory_(this) { 65 : ArcService(bridge_service), binding_(this), weak_factory_(this) {
66 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { 66 if (BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) {
67 VLOG(1) << "registering bluetooth adapter"; 67 VLOG(1) << "registering bluetooth adapter";
68 BluetoothAdapterFactory::GetAdapter(base::Bind( 68 BluetoothAdapterFactory::GetAdapter(base::Bind(
69 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr())); 69 &ArcBluetoothBridge::OnAdapterInitialized, weak_factory_.GetWeakPtr()));
70 } else { 70 } else {
71 VLOG(1) << "no bluetooth adapter available"; 71 VLOG(1) << "no bluetooth adapter available";
72 } 72 }
73 73
74 arc_bridge_service()->AddObserver(this); 74 arc_bridge_service()->bluetooth()->AddObserver(this);
75 } 75 }
76 76
77 ArcBluetoothBridge::~ArcBluetoothBridge() { 77 ArcBluetoothBridge::~ArcBluetoothBridge() {
78 arc_bridge_service()->RemoveObserver(this); 78 arc_bridge_service()->bluetooth()->RemoveObserver(this);
79 79
80 if (bluetooth_adapter_) 80 if (bluetooth_adapter_)
81 bluetooth_adapter_->RemoveObserver(this); 81 bluetooth_adapter_->RemoveObserver(this);
82 } 82 }
83 83
84 void ArcBluetoothBridge::OnAdapterInitialized( 84 void ArcBluetoothBridge::OnAdapterInitialized(
85 scoped_refptr<BluetoothAdapter> adapter) { 85 scoped_refptr<BluetoothAdapter> adapter) {
86 // We can downcast here because we are always running on Chrome OS, and 86 // We can downcast here because we are always running on Chrome OS, and
87 // so our adapter uses BlueZ. 87 // so our adapter uses BlueZ.
88 bluetooth_adapter_ = 88 bluetooth_adapter_ =
89 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get()); 89 static_cast<bluez::BluetoothAdapterBlueZ*>(adapter.get());
90 bluetooth_adapter_->AddObserver(this); 90 bluetooth_adapter_->AddObserver(this);
91 } 91 }
92 92
93 void ArcBluetoothBridge::OnBluetoothInstanceReady() { 93 void ArcBluetoothBridge::OnInstanceReady() {
94 mojom::BluetoothInstance* bluetooth_instance = 94 mojom::BluetoothInstance* bluetooth_instance =
95 arc_bridge_service()->bluetooth_instance(); 95 arc_bridge_service()->bluetooth()->instance();
96 if (!bluetooth_instance) { 96 if (!bluetooth_instance) {
97 LOG(ERROR) << "OnBluetoothInstanceReady called, " 97 LOG(ERROR) << "OnBluetoothInstanceReady called, "
98 << "but no bluetooth instance found"; 98 << "but no bluetooth instance found";
99 return; 99 return;
100 } 100 }
101 101 bluetooth_instance->Init(binding_.CreateInterfacePtrAndBind());
102 arc_bridge_service()->bluetooth_instance()->Init(
103 binding_.CreateInterfacePtrAndBind());
104 } 102 }
105 103
106 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter, 104 void ArcBluetoothBridge::AdapterPoweredChanged(BluetoothAdapter* adapter,
107 bool powered) { 105 bool powered) {
108 if (!HasBluetoothInstance()) 106 if (!HasBluetoothInstance())
109 return; 107 return;
110 108
111 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge 109 // TODO(smbarber): Invoke EnableAdapter or DisableAdapter via ARC bridge
112 // service. 110 // service.
113 } 111 }
114 112
115 void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter, 113 void ArcBluetoothBridge::DeviceAdded(BluetoothAdapter* adapter,
116 BluetoothDevice* device) { 114 BluetoothDevice* device) {
117 if (!HasBluetoothInstance()) 115 if (!HasBluetoothInstance())
118 return; 116 return;
119 117
120 if (device->IsConnected()) 118 if (device->IsConnected())
121 return; 119 return;
122 120
123 mojo::Array<mojom::BluetoothPropertyPtr> properties = 121 mojo::Array<mojom::BluetoothPropertyPtr> properties =
124 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); 122 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
125 123
126 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( 124 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
127 std::move(properties)); 125 std::move(properties));
128 126
129 if (!CheckBluetoothInstanceVersion(kMinBtleVersion)) 127 if (!CheckBluetoothInstanceVersion(kMinBtleVersion))
130 return; 128 return;
131 129
132 mojom::BluetoothAddressPtr addr = 130 mojom::BluetoothAddressPtr addr =
133 mojom::BluetoothAddress::From(device->GetAddress()); 131 mojom::BluetoothAddress::From(device->GetAddress());
134 int rssi = device->GetInquiryRSSI(); 132 int rssi = device->GetInquiryRSSI();
135 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = 133 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
136 GetAdvertisingData(device); 134 GetAdvertisingData(device);
137 arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( 135 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
138 std::move(addr), rssi, std::move(adv_data)); 136 std::move(addr), rssi, std::move(adv_data));
139 } 137 }
140 138
141 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter, 139 void ArcBluetoothBridge::DeviceChanged(BluetoothAdapter* adapter,
142 BluetoothDevice* device) { 140 BluetoothDevice* device) {
143 // TODO(smbarber): device properties changed; inform the container. 141 // TODO(smbarber): device properties changed; inform the container.
144 } 142 }
145 143
146 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter, 144 void ArcBluetoothBridge::DeviceAddressChanged(BluetoothAdapter* adapter,
147 BluetoothDevice* device, 145 BluetoothDevice* device,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 BluetoothDevice* device) { 195 BluetoothDevice* device) {
198 if (!HasBluetoothInstance()) 196 if (!HasBluetoothInstance())
199 return; 197 return;
200 198
201 if (!CheckBluetoothInstanceVersion(kMinBtleVersion)) 199 if (!CheckBluetoothInstanceVersion(kMinBtleVersion))
202 return; 200 return;
203 201
204 mojom::BluetoothAddressPtr addr = 202 mojom::BluetoothAddressPtr addr =
205 mojom::BluetoothAddress::From(device->GetAddress()); 203 mojom::BluetoothAddress::From(device->GetAddress());
206 204
207 arc_bridge_service()->bluetooth_instance()->OnSearchComplete( 205 arc_bridge_service()->bluetooth()->instance()->OnSearchComplete(
208 std::move(addr), mojom::BluetoothGattStatus::GATT_SUCCESS); 206 std::move(addr), mojom::BluetoothGattStatus::GATT_SUCCESS);
209 } 207 }
210 208
211 void ArcBluetoothBridge::GattDiscoveryCompleteForService( 209 void ArcBluetoothBridge::GattDiscoveryCompleteForService(
212 BluetoothAdapter* adapter, 210 BluetoothAdapter* adapter,
213 BluetoothRemoteGattService* service) { 211 BluetoothRemoteGattService* service) {
214 // Placeholder for GATT client functionality 212 // Placeholder for GATT client functionality
215 } 213 }
216 214
217 void ArcBluetoothBridge::GattServiceChanged( 215 void ArcBluetoothBridge::GattServiceChanged(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 mojom::BluetoothGattServiceID::New(); 260 mojom::BluetoothGattServiceID::New();
263 service_id->is_primary = service->IsPrimary(); 261 service_id->is_primary = service->IsPrimary();
264 service_id->id = mojom::BluetoothGattID::New(); 262 service_id->id = mojom::BluetoothGattID::New();
265 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier()); 263 service_id->id->inst_id = ConvertGattIdentifierToId(service->GetIdentifier());
266 service_id->id->uuid = mojom::BluetoothUUID::From(service->GetUUID()); 264 service_id->id->uuid = mojom::BluetoothUUID::From(service->GetUUID());
267 265
268 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New(); 266 mojom::BluetoothGattIDPtr char_id = mojom::BluetoothGattID::New();
269 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier()); 267 char_id->inst_id = ConvertGattIdentifierToId(characteristic->GetIdentifier());
270 char_id->uuid = mojom::BluetoothUUID::From(characteristic->GetUUID()); 268 char_id->uuid = mojom::BluetoothUUID::From(characteristic->GetUUID());
271 269
272 arc_bridge_service()->bluetooth_instance()->OnGattNotify( 270 arc_bridge_service()->bluetooth()->instance()->OnGattNotify(
273 std::move(address), std::move(service_id), std::move(char_id), 271 std::move(address), std::move(service_id), std::move(char_id),
274 true /* is_notify */, mojo::Array<uint8_t>::From(value)); 272 true /* is_notify */, mojo::Array<uint8_t>::From(value));
275 } 273 }
276 274
277 void ArcBluetoothBridge::GattDescriptorValueChanged( 275 void ArcBluetoothBridge::GattDescriptorValueChanged(
278 BluetoothAdapter* adapter, 276 BluetoothAdapter* adapter,
279 BluetoothRemoteGattDescriptor* descriptor, 277 BluetoothRemoteGattDescriptor* descriptor,
280 const std::vector<uint8_t>& value) { 278 const std::vector<uint8_t>& value) {
281 // Placeholder for GATT client functionality 279 // Placeholder for GATT client functionality
282 } 280 }
(...skipping 23 matching lines...) Expand all
306 } 304 }
307 305
308 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) { 306 void ArcBluetoothBridge::GetAdapterProperty(mojom::BluetoothPropertyType type) {
309 DCHECK(bluetooth_adapter_); 307 DCHECK(bluetooth_adapter_);
310 if (!HasBluetoothInstance()) 308 if (!HasBluetoothInstance())
311 return; 309 return;
312 310
313 mojo::Array<mojom::BluetoothPropertyPtr> properties = 311 mojo::Array<mojom::BluetoothPropertyPtr> properties =
314 GetAdapterProperties(type); 312 GetAdapterProperties(type);
315 313
316 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( 314 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
317 mojom::BluetoothStatus::SUCCESS, std::move(properties)); 315 mojom::BluetoothStatus::SUCCESS, std::move(properties));
318 } 316 }
319 317
320 void ArcBluetoothBridge::SetAdapterProperty( 318 void ArcBluetoothBridge::SetAdapterProperty(
321 mojom::BluetoothPropertyPtr property) { 319 mojom::BluetoothPropertyPtr property) {
322 DCHECK(bluetooth_adapter_); 320 DCHECK(bluetooth_adapter_);
323 if (!HasBluetoothInstance()) 321 if (!HasBluetoothInstance())
324 return; 322 return;
325 323
326 // TODO(smbarber): Implement SetAdapterProperty 324 // TODO(smbarber): Implement SetAdapterProperty
327 arc_bridge_service()->bluetooth_instance()->OnAdapterProperties( 325 arc_bridge_service()->bluetooth()->instance()->OnAdapterProperties(
328 mojom::BluetoothStatus::FAIL, 326 mojom::BluetoothStatus::FAIL,
329 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); 327 mojo::Array<mojom::BluetoothPropertyPtr>::New(0));
330 } 328 }
331 329
332 void ArcBluetoothBridge::GetRemoteDeviceProperty( 330 void ArcBluetoothBridge::GetRemoteDeviceProperty(
333 mojom::BluetoothAddressPtr remote_addr, 331 mojom::BluetoothAddressPtr remote_addr,
334 mojom::BluetoothPropertyType type) { 332 mojom::BluetoothPropertyType type) {
335 DCHECK(bluetooth_adapter_); 333 DCHECK(bluetooth_adapter_);
336 if (!HasBluetoothInstance()) 334 if (!HasBluetoothInstance())
337 return; 335 return;
338 336
339 std::string addr_str = remote_addr->To<std::string>(); 337 std::string addr_str = remote_addr->To<std::string>();
340 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); 338 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str);
341 339
342 mojo::Array<mojom::BluetoothPropertyPtr> properties = 340 mojo::Array<mojom::BluetoothPropertyPtr> properties =
343 GetDeviceProperties(type, device); 341 GetDeviceProperties(type, device);
344 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS; 342 mojom::BluetoothStatus status = mojom::BluetoothStatus::SUCCESS;
345 343
346 if (!device) { 344 if (!device) {
347 VLOG(1) << __func__ << ": device " << addr_str << " not available"; 345 VLOG(1) << __func__ << ": device " << addr_str << " not available";
348 status = mojom::BluetoothStatus::FAIL; 346 status = mojom::BluetoothStatus::FAIL;
349 } 347 }
350 348
351 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( 349 arc_bridge_service()->bluetooth()->instance()->OnRemoteDeviceProperties(
352 status, std::move(remote_addr), std::move(properties)); 350 status, std::move(remote_addr), std::move(properties));
353 } 351 }
354 352
355 void ArcBluetoothBridge::SetRemoteDeviceProperty( 353 void ArcBluetoothBridge::SetRemoteDeviceProperty(
356 mojom::BluetoothAddressPtr remote_addr, 354 mojom::BluetoothAddressPtr remote_addr,
357 mojom::BluetoothPropertyPtr property) { 355 mojom::BluetoothPropertyPtr property) {
358 DCHECK(bluetooth_adapter_); 356 DCHECK(bluetooth_adapter_);
359 if (!HasBluetoothInstance()) 357 if (!HasBluetoothInstance())
360 return; 358 return;
361 359
362 // TODO(smbarber): Implement SetRemoteDeviceProperty 360 // TODO(smbarber): Implement SetRemoteDeviceProperty
363 arc_bridge_service()->bluetooth_instance()->OnRemoteDeviceProperties( 361 arc_bridge_service()->bluetooth()->instance()->OnRemoteDeviceProperties(
364 mojom::BluetoothStatus::FAIL, std::move(remote_addr), 362 mojom::BluetoothStatus::FAIL, std::move(remote_addr),
365 mojo::Array<mojom::BluetoothPropertyPtr>::New(0)); 363 mojo::Array<mojom::BluetoothPropertyPtr>::New(0));
366 } 364 }
367 365
368 void ArcBluetoothBridge::GetRemoteServiceRecord( 366 void ArcBluetoothBridge::GetRemoteServiceRecord(
369 mojom::BluetoothAddressPtr remote_addr, 367 mojom::BluetoothAddressPtr remote_addr,
370 mojom::BluetoothUUIDPtr uuid) { 368 mojom::BluetoothUUIDPtr uuid) {
371 // TODO(smbarber): Implement GetRemoteServiceRecord 369 // TODO(smbarber): Implement GetRemoteServiceRecord
372 } 370 }
373 371
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 : mojom::BluetoothAdapterState::OFF); 421 : mojom::BluetoothAdapterState::OFF);
424 } 422 }
425 423
426 void ArcBluetoothBridge::OnDiscoveryStarted( 424 void ArcBluetoothBridge::OnDiscoveryStarted(
427 std::unique_ptr<BluetoothDiscoverySession> session) { 425 std::unique_ptr<BluetoothDiscoverySession> session) {
428 if (!HasBluetoothInstance()) 426 if (!HasBluetoothInstance())
429 return; 427 return;
430 428
431 discovery_session_ = std::move(session); 429 discovery_session_ = std::move(session);
432 430
433 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( 431 arc_bridge_service()->bluetooth()->instance()->OnDiscoveryStateChanged(
434 mojom::BluetoothDiscoveryState::STARTED); 432 mojom::BluetoothDiscoveryState::STARTED);
435 433
436 SendCachedDevicesFound(); 434 SendCachedDevicesFound();
437 } 435 }
438 436
439 void ArcBluetoothBridge::OnDiscoveryStopped() { 437 void ArcBluetoothBridge::OnDiscoveryStopped() {
440 if (!HasBluetoothInstance()) 438 if (!HasBluetoothInstance())
441 return; 439 return;
442 440
443 discovery_session_.reset(); 441 discovery_session_.reset();
444 442
445 arc_bridge_service()->bluetooth_instance()->OnDiscoveryStateChanged( 443 arc_bridge_service()->bluetooth()->instance()->OnDiscoveryStateChanged(
446 mojom::BluetoothDiscoveryState::STOPPED); 444 mojom::BluetoothDiscoveryState::STOPPED);
447 } 445 }
448 446
449 void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr, 447 void ArcBluetoothBridge::CreateBond(mojom::BluetoothAddressPtr addr,
450 int32_t transport) { 448 int32_t transport) {
451 std::string addr_str = addr->To<std::string>(); 449 std::string addr_str = addr->To<std::string>();
452 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str); 450 BluetoothDevice* device = bluetooth_adapter_->GetDevice(addr_str);
453 if (!device || !device->IsPairable()) { 451 if (!device || !device->IsPairable()) {
454 VLOG(1) << __func__ << ": device " << addr_str 452 VLOG(1) << __func__ << ": device " << addr_str
455 << " is no longer valid or pairable"; 453 << " is no longer valid or pairable";
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 mojom::BluetoothAddressPtr addr, 547 mojom::BluetoothAddressPtr addr,
550 bool connected) const { 548 bool connected) const {
551 if (!HasBluetoothInstance()) 549 if (!HasBluetoothInstance())
552 return; 550 return;
553 551
554 if (!CheckBluetoothInstanceVersion(kMinBtleVersion)) 552 if (!CheckBluetoothInstanceVersion(kMinBtleVersion))
555 return; 553 return;
556 554
557 DCHECK(addr); 555 DCHECK(addr);
558 556
559 arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( 557 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange(
560 std::move(addr), connected); 558 std::move(addr), connected);
561 } 559 }
562 560
563 void ArcBluetoothBridge::OnGattConnected( 561 void ArcBluetoothBridge::OnGattConnected(
564 mojom::BluetoothAddressPtr addr, 562 mojom::BluetoothAddressPtr addr,
565 std::unique_ptr<BluetoothGattConnection> connection) const { 563 std::unique_ptr<BluetoothGattConnection> connection) const {
566 OnGattConnectStateChanged(std::move(addr), true); 564 OnGattConnectStateChanged(std::move(addr), true);
567 } 565 }
568 566
569 void ArcBluetoothBridge::OnGattConnectError( 567 void ArcBluetoothBridge::OnGattConnectError(
(...skipping 10 matching lines...) Expand all
580 void ArcBluetoothBridge::ConnectLEDevice( 578 void ArcBluetoothBridge::ConnectLEDevice(
581 mojom::BluetoothAddressPtr remote_addr) { 579 mojom::BluetoothAddressPtr remote_addr) {
582 if (!HasBluetoothInstance()) 580 if (!HasBluetoothInstance())
583 return; 581 return;
584 582
585 BluetoothDevice* device = 583 BluetoothDevice* device =
586 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 584 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
587 DCHECK(device); 585 DCHECK(device);
588 586
589 if (device->IsConnected()) { 587 if (device->IsConnected()) {
590 arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( 588 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange(
591 std::move(remote_addr), true); 589 std::move(remote_addr), true);
592 return; 590 return;
593 } 591 }
594 592
595 // Also pass disconnect callback in error case 593 // Also pass disconnect callback in error case
596 // since it would be disconnected anyway. 594 // since it would be disconnected anyway.
597 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); 595 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone();
598 device->CreateGattConnection( 596 device->CreateGattConnection(
599 base::Bind(&ArcBluetoothBridge::OnGattConnected, 597 base::Bind(&ArcBluetoothBridge::OnGattConnected,
600 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), 598 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)),
601 base::Bind(&ArcBluetoothBridge::OnGattConnectError, 599 base::Bind(&ArcBluetoothBridge::OnGattConnectError,
602 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); 600 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone)));
603 } 601 }
604 602
605 void ArcBluetoothBridge::DisconnectLEDevice( 603 void ArcBluetoothBridge::DisconnectLEDevice(
606 mojom::BluetoothAddressPtr remote_addr) { 604 mojom::BluetoothAddressPtr remote_addr) {
607 if (!HasBluetoothInstance()) 605 if (!HasBluetoothInstance())
608 return; 606 return;
609 607
610 BluetoothDevice* device = 608 BluetoothDevice* device =
611 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 609 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
612 DCHECK(device); 610 DCHECK(device);
613 611
614 if (!device->IsConnected()) { 612 if (!device->IsConnected()) {
615 arc_bridge_service()->bluetooth_instance()->OnLEConnectionStateChange( 613 arc_bridge_service()->bluetooth()->instance()->OnLEConnectionStateChange(
616 std::move(remote_addr), false); 614 std::move(remote_addr), false);
617 return; 615 return;
618 } 616 }
619 617
620 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone(); 618 mojom::BluetoothAddressPtr remote_addr_clone = remote_addr.Clone();
621 device->Disconnect( 619 device->Disconnect(
622 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, 620 base::Bind(&ArcBluetoothBridge::OnGattDisconnected,
623 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)), 621 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr)),
624 base::Bind(&ArcBluetoothBridge::OnGattDisconnected, 622 base::Bind(&ArcBluetoothBridge::OnGattDisconnected,
625 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone))); 623 weak_factory_.GetWeakPtr(), base::Passed(&remote_addr_clone)));
626 } 624 }
627 625
628 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) { 626 void ArcBluetoothBridge::SearchService(mojom::BluetoothAddressPtr remote_addr) {
629 if (!HasBluetoothInstance()) 627 if (!HasBluetoothInstance())
630 return; 628 return;
631 629
632 BluetoothDevice* device = 630 BluetoothDevice* device =
633 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>()); 631 bluetooth_adapter_->GetDevice(remote_addr->To<std::string>());
634 DCHECK(device); 632 DCHECK(device);
635 633
636 // Call the callback if discovery is completed 634 // Call the callback if discovery is completed
637 if (device->IsGattServicesDiscoveryComplete()) { 635 if (device->IsGattServicesDiscoveryComplete()) {
638 arc_bridge_service()->bluetooth_instance()->OnSearchComplete( 636 arc_bridge_service()->bluetooth()->instance()->OnSearchComplete(
639 std::move(remote_addr), mojom::BluetoothGattStatus::GATT_SUCCESS); 637 std::move(remote_addr), mojom::BluetoothGattStatus::GATT_SUCCESS);
640 return; 638 return;
641 } 639 }
642 640
643 // Discard result. Will call the callback when discovery is completed. 641 // Discard result. Will call the callback when discovery is completed.
644 device->GetGattServices(); 642 device->GetGattServices();
645 } 643 }
646 644
647 void ArcBluetoothBridge::OnStartLEListenDone( 645 void ArcBluetoothBridge::OnStartLEListenDone(
648 const StartLEListenCallback& callback, 646 const StartLEListenCallback& callback,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 db.push_back(std::move(characteristic_element)); 752 db.push_back(std::move(characteristic_element));
755 753
756 for (auto descriptor : characteristic->GetDescriptors()) { 754 for (auto descriptor : characteristic->GetDescriptors()) {
757 db.push_back(CreateGattDBElement<device::BluetoothRemoteGattDescriptor>( 755 db.push_back(CreateGattDBElement<device::BluetoothRemoteGattDescriptor>(
758 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR, 756 mojom::BluetoothGattDBAttributeType::BTGATT_DB_DESCRIPTOR,
759 descriptor)); 757 descriptor));
760 } 758 }
761 } 759 }
762 } 760 }
763 761
764 arc_bridge_service()->bluetooth_instance()->OnGetGattDB( 762 arc_bridge_service()->bluetooth()->instance()->OnGetGattDB(
765 std::move(remote_addr), std::move(db)); 763 std::move(remote_addr), std::move(db));
766 } 764 }
767 765
768 // Find Gatt Service/Characteristic/Descriptor from std::vector from UUID. 766 // Find Gatt Service/Characteristic/Descriptor from std::vector from UUID.
769 template <class T> 767 template <class T>
770 T* ArcBluetoothBridge::FindGattObjectFromUuid( 768 T* ArcBluetoothBridge::FindGattObjectFromUuid(
771 const std::vector<T*> gatt_objs, 769 const std::vector<T*> gatt_objs,
772 const device::BluetoothUUID uuid) const { 770 const device::BluetoothUUID uuid) const {
773 auto it = std::find_if(gatt_objs.begin(), gatt_objs.end(), 771 auto it = std::find_if(gatt_objs.begin(), gatt_objs.end(),
774 [&](T* obj) { return obj->GetUUID() == uuid; }); 772 [&](T* obj) { return obj->GetUUID() == uuid; });
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1014 }
1017 1015
1018 void ArcBluetoothBridge::OnDiscoveryError() { 1016 void ArcBluetoothBridge::OnDiscoveryError() {
1019 LOG(WARNING) << "failed to change discovery state"; 1017 LOG(WARNING) << "failed to change discovery state";
1020 } 1018 }
1021 1019
1022 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const { 1020 void ArcBluetoothBridge::OnPairing(mojom::BluetoothAddressPtr addr) const {
1023 if (!HasBluetoothInstance()) 1021 if (!HasBluetoothInstance())
1024 return; 1022 return;
1025 1023
1026 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( 1024 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged(
1027 mojom::BluetoothStatus::SUCCESS, std::move(addr), 1025 mojom::BluetoothStatus::SUCCESS, std::move(addr),
1028 mojom::BluetoothBondState::BONDING); 1026 mojom::BluetoothBondState::BONDING);
1029 } 1027 }
1030 1028
1031 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const { 1029 void ArcBluetoothBridge::OnPairedDone(mojom::BluetoothAddressPtr addr) const {
1032 if (!HasBluetoothInstance()) 1030 if (!HasBluetoothInstance())
1033 return; 1031 return;
1034 1032
1035 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( 1033 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged(
1036 mojom::BluetoothStatus::SUCCESS, std::move(addr), 1034 mojom::BluetoothStatus::SUCCESS, std::move(addr),
1037 mojom::BluetoothBondState::BONDED); 1035 mojom::BluetoothBondState::BONDED);
1038 } 1036 }
1039 1037
1040 void ArcBluetoothBridge::OnPairedError( 1038 void ArcBluetoothBridge::OnPairedError(
1041 mojom::BluetoothAddressPtr addr, 1039 mojom::BluetoothAddressPtr addr,
1042 BluetoothDevice::ConnectErrorCode error_code) const { 1040 BluetoothDevice::ConnectErrorCode error_code) const {
1043 if (!HasBluetoothInstance()) 1041 if (!HasBluetoothInstance())
1044 return; 1042 return;
1045 1043
1046 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( 1044 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged(
1047 mojom::BluetoothStatus::FAIL, std::move(addr), 1045 mojom::BluetoothStatus::FAIL, std::move(addr),
1048 mojom::BluetoothBondState::NONE); 1046 mojom::BluetoothBondState::NONE);
1049 } 1047 }
1050 1048
1051 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const { 1049 void ArcBluetoothBridge::OnForgetDone(mojom::BluetoothAddressPtr addr) const {
1052 if (!HasBluetoothInstance()) 1050 if (!HasBluetoothInstance())
1053 return; 1051 return;
1054 1052
1055 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( 1053 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged(
1056 mojom::BluetoothStatus::SUCCESS, std::move(addr), 1054 mojom::BluetoothStatus::SUCCESS, std::move(addr),
1057 mojom::BluetoothBondState::NONE); 1055 mojom::BluetoothBondState::NONE);
1058 } 1056 }
1059 1057
1060 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const { 1058 void ArcBluetoothBridge::OnForgetError(mojom::BluetoothAddressPtr addr) const {
1061 if (!HasBluetoothInstance()) 1059 if (!HasBluetoothInstance())
1062 return; 1060 return;
1063 1061
1064 BluetoothDevice* device = 1062 BluetoothDevice* device =
1065 bluetooth_adapter_->GetDevice(addr->To<std::string>()); 1063 bluetooth_adapter_->GetDevice(addr->To<std::string>());
1066 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE; 1064 mojom::BluetoothBondState bond_state = mojom::BluetoothBondState::NONE;
1067 if (device && device->IsPaired()) { 1065 if (device && device->IsPaired()) {
1068 bond_state = mojom::BluetoothBondState::BONDED; 1066 bond_state = mojom::BluetoothBondState::BONDED;
1069 } 1067 }
1070 arc_bridge_service()->bluetooth_instance()->OnBondStateChanged( 1068 arc_bridge_service()->bluetooth()->instance()->OnBondStateChanged(
1071 mojom::BluetoothStatus::FAIL, std::move(addr), bond_state); 1069 mojom::BluetoothStatus::FAIL, std::move(addr), bond_state);
1072 } 1070 }
1073 1071
1074 mojo::Array<mojom::BluetoothPropertyPtr> 1072 mojo::Array<mojom::BluetoothPropertyPtr>
1075 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type, 1073 ArcBluetoothBridge::GetDeviceProperties(mojom::BluetoothPropertyType type,
1076 BluetoothDevice* device) const { 1074 BluetoothDevice* device) const {
1077 mojo::Array<mojom::BluetoothPropertyPtr> properties; 1075 mojo::Array<mojom::BluetoothPropertyPtr> properties;
1078 1076
1079 if (!device) { 1077 if (!device) {
1080 return properties; 1078 return properties;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 return; 1272 return;
1275 1273
1276 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); 1274 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices();
1277 for (auto device : devices) { 1275 for (auto device : devices) {
1278 if (device->IsPaired()) 1276 if (device->IsPaired())
1279 continue; 1277 continue;
1280 1278
1281 mojo::Array<mojom::BluetoothPropertyPtr> properties = 1279 mojo::Array<mojom::BluetoothPropertyPtr> properties =
1282 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); 1280 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
1283 1281
1284 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( 1282 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
1285 std::move(properties)); 1283 std::move(properties));
1286 1284
1287 if (arc_bridge_service()->bluetooth_version() >= kMinBtleVersion) { 1285 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) {
1288 mojom::BluetoothAddressPtr addr = 1286 mojom::BluetoothAddressPtr addr =
1289 mojom::BluetoothAddress::From(device->GetAddress()); 1287 mojom::BluetoothAddress::From(device->GetAddress());
1290 int rssi = device->GetInquiryRSSI(); 1288 int rssi = device->GetInquiryRSSI();
1291 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = 1289 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
1292 GetAdvertisingData(device); 1290 GetAdvertisingData(device);
1293 arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( 1291 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
1294 std::move(addr), rssi, std::move(adv_data)); 1292 std::move(addr), rssi, std::move(adv_data));
1295 } 1293 }
1296 } 1294 }
1297 } 1295 }
1298 1296
1299 bool ArcBluetoothBridge::HasBluetoothInstance() const { 1297 bool ArcBluetoothBridge::HasBluetoothInstance() const {
1300 if (!arc_bridge_service()->bluetooth_instance()) { 1298 if (!arc_bridge_service()->bluetooth()->instance()) {
1301 LOG(WARNING) << "no Bluetooth instance available"; 1299 LOG(WARNING) << "no Bluetooth instance available";
1302 return false; 1300 return false;
1303 } 1301 }
1304 1302
1305 return true; 1303 return true;
1306 } 1304 }
1307 1305
1308 void ArcBluetoothBridge::SendCachedPairedDevices() const { 1306 void ArcBluetoothBridge::SendCachedPairedDevices() const {
1309 DCHECK(bluetooth_adapter_); 1307 DCHECK(bluetooth_adapter_);
1310 if (!HasBluetoothInstance()) 1308 if (!HasBluetoothInstance())
1311 return; 1309 return;
1312 1310
1313 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); 1311 BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices();
1314 for (auto device : devices) { 1312 for (auto device : devices) {
1315 if (!device->IsPaired()) 1313 if (!device->IsPaired())
1316 continue; 1314 continue;
1317 1315
1318 mojo::Array<mojom::BluetoothPropertyPtr> properties = 1316 mojo::Array<mojom::BluetoothPropertyPtr> properties =
1319 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device); 1317 GetDeviceProperties(mojom::BluetoothPropertyType::ALL, device);
1320 1318
1321 arc_bridge_service()->bluetooth_instance()->OnDeviceFound( 1319 arc_bridge_service()->bluetooth()->instance()->OnDeviceFound(
1322 std::move(properties)); 1320 std::move(properties));
1323 1321
1324 mojom::BluetoothAddressPtr addr = 1322 mojom::BluetoothAddressPtr addr =
1325 mojom::BluetoothAddress::From(device->GetAddress()); 1323 mojom::BluetoothAddress::From(device->GetAddress());
1326 1324
1327 if (arc_bridge_service()->bluetooth_version() >= kMinBtleVersion) { 1325 if (arc_bridge_service()->bluetooth()->version() >= kMinBtleVersion) {
1328 int rssi = device->GetInquiryRSSI(); 1326 int rssi = device->GetInquiryRSSI();
1329 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data = 1327 mojo::Array<mojom::BluetoothAdvertisingDataPtr> adv_data =
1330 GetAdvertisingData(device); 1328 GetAdvertisingData(device);
1331 arc_bridge_service()->bluetooth_instance()->OnLEDeviceFound( 1329 arc_bridge_service()->bluetooth()->instance()->OnLEDeviceFound(
1332 addr->Clone(), rssi, std::move(adv_data)); 1330 addr->Clone(), rssi, std::move(adv_data));
1333 } 1331 }
1334 1332
1335 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING 1333 // OnBondStateChanged must be called with mojom::BluetoothBondState::BONDING
1336 // to 1334 // to
1337 // make sure the bond state machine on Android is ready to take the 1335 // make sure the bond state machine on Android is ready to take the
1338 // pair-done event. Otherwise the pair-done event will be dropped as an 1336 // pair-done event. Otherwise the pair-done event will be dropped as an
1339 // invalid change of paired status. 1337 // invalid change of paired status.
1340 OnPairing(addr->Clone()); 1338 OnPairing(addr->Clone());
1341 OnPairedDone(std::move(addr)); 1339 OnPairedDone(std::move(addr));
1342 } 1340 }
1343 } 1341 }
1344 1342
1345 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion( 1343 bool ArcBluetoothBridge::CheckBluetoothInstanceVersion(
1346 int32_t version_need) const { 1344 uint32_t version_need) const {
1347 int32_t version = arc_bridge_service()->bluetooth_version(); 1345 uint32_t version = arc_bridge_service()->bluetooth()->version();
1348 if (version >= version_need) 1346 if (version >= version_need)
1349 return true; 1347 return true;
1350 LOG(WARNING) << "Bluetooth instance is too old (version " << version 1348 LOG(WARNING) << "Bluetooth instance is too old (version " << version
1351 << ") need version " << version_need; 1349 << ") need version " << version_need;
1352 return false; 1350 return false;
1353 } 1351 }
1354 1352
1355 } // namespace arc 1353 } // namespace arc
OLDNEW
« no previous file with comments | « components/arc/bluetooth/arc_bluetooth_bridge.h ('k') | components/arc/clipboard/arc_clipboard_bridge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698