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

Side by Side Diff: chrome/browser/chromeos/bluetooth/bluetooth_device.cc

Issue 10546010: Implement support for the OOB Pairing APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/bluetooth/bluetooth_device.h" 5 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/string16.h" 14 #include "base/string16.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" 18 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
19 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h" 19 #include "chrome/browser/chromeos/bluetooth/bluetooth_service_record.h"
20 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h" 20 #include "chrome/browser/chromeos/bluetooth/bluetooth_socket.h"
21 #include "chromeos/dbus/bluetooth_adapter_client.h" 21 #include "chromeos/dbus/bluetooth_adapter_client.h"
22 #include "chromeos/dbus/bluetooth_agent_service_provider.h" 22 #include "chromeos/dbus/bluetooth_agent_service_provider.h"
23 #include "chromeos/dbus/bluetooth_device_client.h" 23 #include "chromeos/dbus/bluetooth_device_client.h"
24 #include "chromeos/dbus/bluetooth_input_client.h" 24 #include "chromeos/dbus/bluetooth_input_client.h"
25 #include "chromeos/dbus/bluetooth_out_of_band_client.h"
25 #include "chromeos/dbus/dbus_thread_manager.h" 26 #include "chromeos/dbus/dbus_thread_manager.h"
26 #include "chromeos/dbus/introspectable_client.h" 27 #include "chromeos/dbus/introspectable_client.h"
27 #include "dbus/bus.h" 28 #include "dbus/bus.h"
28 #include "dbus/object_path.h" 29 #include "dbus/object_path.h"
29 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
30 #include "third_party/cros_system_api/dbus/service_constants.h" 31 #include "third_party/cros_system_api/dbus/service_constants.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 33
33 namespace chromeos { 34 namespace chromeos {
34 35
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 BluetoothSocket::CreateBluetoothSocket(service_record)); 545 BluetoothSocket::CreateBluetoothSocket(service_record));
545 if (socket.get() != NULL) { 546 if (socket.get() != NULL) {
546 callback.Run(socket); 547 callback.Run(socket);
547 return; 548 return;
548 } 549 }
549 } 550 }
550 } 551 }
551 callback.Run(NULL); 552 callback.Run(NULL);
552 } 553 }
553 554
555 void BluetoothDevice::OnRemoteDataCallback(const base::Closure& callback,
556 const ErrorCallback& error_callback,
557 bool success) {
558 if (success)
559 callback.Run();
560 else
561 error_callback.Run();
562 }
563
554 void BluetoothDevice::ConnectToService(const std::string& service_uuid, 564 void BluetoothDevice::ConnectToService(const std::string& service_uuid,
555 const SocketCallback& callback) { 565 const SocketCallback& callback) {
556 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 566 DBusThreadManager::Get()->GetBluetoothDeviceClient()->
557 DiscoverServices( 567 DiscoverServices(
558 object_path_, 568 object_path_,
559 service_uuid, 569 service_uuid,
560 base::Bind(&BluetoothDevice::ConnectToMatchingService, 570 base::Bind(&BluetoothDevice::ConnectToMatchingService,
561 weak_ptr_factory_.GetWeakPtr(), 571 weak_ptr_factory_.GetWeakPtr(),
562 service_uuid, 572 service_uuid,
563 callback)); 573 callback));
564 } 574 }
565 575
576 void BluetoothDevice::SetOutOfBandPairingData(
577 const chromeos::BluetoothOutOfBandPairingData& data,
578 const base::Closure& callback,
579 const ErrorCallback& error_callback) {
580 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
581 AddRemoteData(
582 object_path_,
583 address(),
584 data,
585 base::Bind(&BluetoothDevice::OnRemoteDataCallback,
586 weak_ptr_factory_.GetWeakPtr(),
587 callback,
588 error_callback));
589 }
590
591 void BluetoothDevice::ClearOutOfBandPairingData(
592 const base::Closure& callback,
593 const ErrorCallback& error_callback) {
594 DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
595 RemoveRemoteData(
596 object_path_,
597 address(),
598 base::Bind(&BluetoothDevice::OnRemoteDataCallback,
599 weak_ptr_factory_.GetWeakPtr(),
600 callback,
601 error_callback));
602 }
603
566 void BluetoothDevice::ForgetCallback(const ErrorCallback& error_callback, 604 void BluetoothDevice::ForgetCallback(const ErrorCallback& error_callback,
567 const dbus::ObjectPath& adapter_path, 605 const dbus::ObjectPath& adapter_path,
568 bool success) { 606 bool success) {
569 // It's quite normal that this path never gets called on success; we use a 607 // It's quite normal that this path never gets called on success; we use a
570 // weak pointer, and bluetoothd might send the DeviceRemoved signal before 608 // weak pointer, and bluetoothd might send the DeviceRemoved signal before
571 // the method reply, in which case this object is deleted and the 609 // the method reply, in which case this object is deleted and the
572 // callback never takes place. Therefore don't do anything here for the 610 // callback never takes place. Therefore don't do anything here for the
573 // success case. 611 // success case.
574 if (!success) { 612 if (!success) {
575 LOG(WARNING) << "Forget failed: " << address_; 613 LOG(WARNING) << "Forget failed: " << address_;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 // static 732 // static
695 BluetoothDevice* BluetoothDevice::CreateUnbound( 733 BluetoothDevice* BluetoothDevice::CreateUnbound(
696 BluetoothAdapter* adapter, 734 BluetoothAdapter* adapter,
697 const BluetoothDeviceClient::Properties* properties) { 735 const BluetoothDeviceClient::Properties* properties) {
698 BluetoothDevice* device = new BluetoothDevice(adapter); 736 BluetoothDevice* device = new BluetoothDevice(adapter);
699 device->Update(properties, false); 737 device->Update(properties, false);
700 return device; 738 return device;
701 } 739 }
702 740
703 } // namespace chromeos 741 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/bluetooth/bluetooth_device.h ('k') | chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698