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

Unified Diff: chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc

Issue 9694054: bluetooth: implement device pairing support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc
diff --git a/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc b/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc
index 3f9d530c56a3e8b1bdfd030f4cefe5919a0deb99..c55905bfb4f45a6f2b8ba315b186e2f8af29d7ed 100644
--- a/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc
+++ b/chrome/browser/ui/webui/options2/chromeos/bluetooth_options_handler2.cc
@@ -27,12 +27,30 @@ const int kUpdateDeviceAddressIndex = 0;
const int kUpdateDeviceCommandIndex = 1;
const int kUpdateDevicePasskeyIndex = 2;
+// |UpdateDeviceCallback| provides a command value of one of the following
+// constants that indicates what update it is providing to us.
+const std::string kConnectCommand = "connect";
+const std::string kCancelCommand = "cancel";
+const std::string kAcceptCommand = "accept";
+const std::string kRejectCommand = "reject";
+const std::string kDisconnectCommand = "disconnect";
+const std::string kForgetCommand = "forget";
+
+// |SendDeviceNotification| may include a pairing parameter whose value
+// is one of the following constants instructing the UI to perform a certain
+// action.
+const std::string kEnterPinCode = "bluetoothEnterPinCode";
+const std::string kEnterPasskey = "bluetoothEnterPasskey";
+const std::string kRemotePinCode = "bluetoothRemotePinCode";
+const std::string kRemotePasskey = "bluetoothRemotePasskey";
+const std::string kConfirmPasskey = "bluetoothConfirmPasskey";
+
} // namespace
namespace chromeos {
namespace options2 {
-BluetoothOptionsHandler::BluetoothOptionsHandler() {
+BluetoothOptionsHandler::BluetoothOptionsHandler() : weak_ptr_factory_(this) {
}
BluetoothOptionsHandler::~BluetoothOptionsHandler() {
@@ -190,33 +208,77 @@ void BluetoothOptionsHandler::EnableChangeCallback(
adapter_->SetPowered(bluetooth_enabled,
base::Bind(&BluetoothOptionsHandler::ErrorCallback,
- base::Unretained(this)));
+ weak_ptr_factory_.GetWeakPtr()));
}
void BluetoothOptionsHandler::FindDevicesCallback(
const ListValue* args) {
adapter_->SetDiscovering(true,
base::Bind(&BluetoothOptionsHandler::ErrorCallback,
- base::Unretained(this)));
+ weak_ptr_factory_.GetWeakPtr()));
}
void BluetoothOptionsHandler::UpdateDeviceCallback(
const ListValue* args) {
- // TODO(kevers): Trigger connect/disconnect.
- int size = args->GetSize();
std::string address;
- std::string command;
args->GetString(kUpdateDeviceAddressIndex, &address);
+
+ BluetoothDevice* device = adapter_->GetDevice(address);
+ if (!device)
+ return;
+
+ std::string command;
args->GetString(kUpdateDeviceCommandIndex, &command);
- if (size > kUpdateDevicePasskeyIndex) {
- // Passkey confirmation as part of the pairing process.
- std::string passkey;
- args->GetString(kUpdateDevicePasskeyIndex, &passkey);
- DVLOG(1) << "UpdateDeviceCallback: " << address << ": " << command
- << " [" << passkey << "]";
+
+ if (command == kConnectCommand) {
+ int size = args->GetSize();
+ if (size > kUpdateDevicePasskeyIndex) {
+ // PIN code or Passkey entry during the pairing process.
+ // TODO(keybuk, kevers): disambiguate PIN (string) vs. Passkey (integer)
+ std::string pincode;
+ args->GetString(kUpdateDevicePasskeyIndex, &pincode);
+ DVLOG(1) << "PIN code supplied: " << address << ": " << pincode;
+
+ device->SetPinCode(pincode);
+
+ } else {
+ // Connection request.
+ DVLOG(1) << "Connect: " << address;
+ if (device->WasDiscovered()) {
+ device->PairAndConnect(
+ this, base::Bind(&BluetoothOptionsHandler::ErrorCallback,
+ weak_ptr_factory_.GetWeakPtr()));
+ } else {
+ device->Connect(base::Bind(&BluetoothOptionsHandler::ErrorCallback,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+ }
+
+ } else if (command == kCancelCommand) {
+ // Cancel pairing.
+ DVLOG(1) << "Cancel pairing: " << address;
+ device->CancelPairing();
+
+ } else if (command == kAcceptCommand) {
+ // Confirm displayed Passkey.
+ DVLOG(1) << "Confirm pairing: " << address;
+ device->ConfirmPairing();
+
+ } else if (command == kRejectCommand) {
+ // Reject displayed Passkey.
+ DVLOG(1) << "Reject pairing: " << address;
+ device->RejectPairing();
+
+ } else if (command == kDisconnectCommand) {
+ // TODO(keybuk): implement
+ DVLOG(1) << "Disconnect device: " << address;
+
+ } else if (command == kForgetCommand) {
+ // TODO(keybuk): implement
+ DVLOG(1) << "Forget device: " << address;
+
} else {
- // Initiating a device connection or disconnecting
- DVLOG(1) << "UpdateDeviceCallback: " << address << ": " << command;
+ LOG(WARNING) << "Unknown updateBluetoothDevice command: " << command;
}
}
@@ -224,7 +286,7 @@ void BluetoothOptionsHandler::StopDiscoveryCallback(
const ListValue* args) {
adapter_->SetDiscovering(false,
base::Bind(&BluetoothOptionsHandler::ErrorCallback,
- base::Unretained(this)));
+ weak_ptr_factory_.GetWeakPtr()));
}
void BluetoothOptionsHandler::GetPairedDevicesCallback(
@@ -253,52 +315,50 @@ void BluetoothOptionsHandler::SendDeviceNotification(
js_properties);
}
-void BluetoothOptionsHandler::DisplayPinCode(
- const BluetoothDevice* device,
- const std::string& pincode) {
+void BluetoothOptionsHandler::RequestPinCode(BluetoothDevice* device) {
DictionaryValue params;
- params.SetString("pairing", "bluetoothRemotePinCode");
- params.SetString("pincode", pincode);
+ params.SetString("pairing", kEnterPinCode);
SendDeviceNotification(device, &params);
}
-void BluetoothOptionsHandler::DisplayPasskey(
- const BluetoothDevice* device,
- int passkey,
- int entered) {
+void BluetoothOptionsHandler::RequestPasskey(BluetoothDevice* device) {
DictionaryValue params;
- params.SetString("pairing", "bluetoothRemotePasskey");
- params.SetInteger("passkey", passkey);
- params.SetInteger("entered", entered);
+ params.SetString("pairing", kEnterPasskey);
SendDeviceNotification(device, &params);
}
-void BluetoothOptionsHandler::RequestPinCode(
- const BluetoothDevice* device) {
+void BluetoothOptionsHandler::DisplayPinCode(BluetoothDevice* device,
+ const std::string& pincode) {
DictionaryValue params;
- params.SetString("pairing", "bluetoothEnterPinCode");
+ params.SetString("pairing", kRemotePinCode);
+ params.SetString("pincode", pincode);
SendDeviceNotification(device, &params);
}
-void BluetoothOptionsHandler::RequestPasskey(
- const BluetoothDevice* device) {
+void BluetoothOptionsHandler::DisplayPasskey(BluetoothDevice* device,
+ uint32 passkey) {
DictionaryValue params;
- params.SetString("pairing", "bluetoothEnterPasskey");
+ params.SetString("pairing", kRemotePasskey);
+ params.SetInteger("passkey", passkey);
SendDeviceNotification(device, &params);
}
-void BluetoothOptionsHandler::RequestConfirmation(
- const BluetoothDevice* device,
- int passkey) {
+void BluetoothOptionsHandler::ConfirmPasskey(BluetoothDevice* device,
+ uint32 passkey) {
DictionaryValue params;
- params.SetString("pairing", "bluetoothConfirmPasskey");
+ params.SetString("pairing", kConfirmPasskey);
params.SetInteger("passkey", passkey);
SendDeviceNotification(device, &params);
}
+void BluetoothOptionsHandler::DismissDisplayOrConfirm() {
+ // TODO(kevers): please fill this in
+}
+
void BluetoothOptionsHandler::ReportError(
const BluetoothDevice* device,
ConnectionError error) {
+ // TODO(keybuk): not called from anywhere
std::string errorCode;
switch (error) {
case DEVICE_NOT_FOUND:

Powered by Google App Engine
This is Rietveld 408576698