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

Unified Diff: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc

Issue 8233042: Chrome OS: Attach bluetooth UI to device discovery API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address kevers@ code review comments Created 9 years, 2 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
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
diff --git a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
index 847e29a163852b853fc78a7c74b5ef3eeaa02d05..d3ab23c22ae86c816ee3edcef382e532a6f8088f 100644
--- a/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.cc
@@ -8,6 +8,7 @@
#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
#include "chrome/browser/chromeos/system/runtime_environment.h"
#include "chrome/browser/ui/webui/options/chromeos/system_settings_provider.h"
#include "chrome/common/chrome_switches.h"
@@ -23,7 +24,23 @@ BluetoothOptionsHandler::BluetoothOptionsHandler()
}
BluetoothOptionsHandler::~BluetoothOptionsHandler() {
- // TODO(kevers): Shutdown bluetooth.
+ if (!CommandLine::ForCurrentProcess()
+ ->HasSwitch(switches::kEnableBluetooth)) {
+ return;
+ }
+
+ chromeos::BluetoothManager* bluetooth_manager =
+ chromeos::BluetoothManager::GetInstance();
+ DCHECK(bluetooth_manager);
+
+ chromeos::BluetoothAdapter* default_adapter =
+ bluetooth_manager->DefaultAdapter();
+
+ if (default_adapter != NULL) {
+ default_adapter->RemoveObserver(this);
+ }
+
+ bluetooth_manager->RemoveObserver(this);
}
void BluetoothOptionsHandler::GetLocalizedValues(
@@ -52,14 +69,22 @@ void BluetoothOptionsHandler::Initialize() {
DCHECK(web_ui_);
// Bluetooth support is a work in progress. Supress the feature unless
// explicitly enabled via a command line flag.
- // TODO(kevers): Test for presence of bluetooth hardware.
if (!CommandLine::ForCurrentProcess()
->HasSwitch(switches::kEnableBluetooth)) {
return;
}
+
web_ui_->CallJavascriptFunction(
"options.SystemOptions.showBluetoothSettings");
- // TODO(kevers): Initialize bluetooth.
+
+ chromeos::BluetoothManager* bluetooth_manager =
+ chromeos::BluetoothManager::GetInstance();
+ DCHECK(bluetooth_manager);
+ bluetooth_manager->AddObserver(this);
+
+ chromeos::BluetoothAdapter* default_adapter =
+ bluetooth_manager->DefaultAdapter();
+ DefaultAdapterChanged(default_adapter);
}
void BluetoothOptionsHandler::RegisterMessages() {
@@ -88,7 +113,22 @@ void BluetoothOptionsHandler::FindDevicesCallback(
GenerateFakeDeviceList();
return;
}
- // TODO(kevers): Fetch real Bluetooth devices.
+
+ chromeos::BluetoothManager* bluetooth_manager =
+ chromeos::BluetoothManager::GetInstance();
+ DCHECK(bluetooth_manager);
+
+ chromeos::BluetoothAdapter* default_adapter =
+ bluetooth_manager->DefaultAdapter();
+
+ ValidateDefaultAdapter(default_adapter);
+
+ if (default_adapter == NULL) {
+ VLOG(1) << "FindDevicesCallback: no default adapter";
+ return;
+ }
+
+ default_adapter->StartDiscovery();
}
void BluetoothOptionsHandler::UpdateDeviceCallback(
@@ -102,6 +142,91 @@ void BluetoothOptionsHandler::DeviceNotification(
"options.SystemOptions.addBluetoothDevice", device);
}
+void BluetoothOptionsHandler::DefaultAdapterChanged(
+ chromeos::BluetoothAdapter* adapter) {
+ std::string old_default_adapter_id = default_adapter_id_;
+
+ if (adapter == NULL) {
+ default_adapter_id_.clear();
+ VLOG(2) << "DefaultAdapterChanged: no default bluetooth adapter";
+ } else {
+ default_adapter_id_ = adapter->Id();
+ VLOG(2) << "DefaultAdapterChanged: " << default_adapter_id_;
+ }
+
+ if (default_adapter_id_ == old_default_adapter_id) {
+ return;
+ }
+
+ if (adapter != NULL) {
+ adapter->AddObserver(this);
+ }
+
+ // TODO(vlaviano): Respond to adapter change.
+}
+
+void BluetoothOptionsHandler::DiscoveryStarted(const std::string& adapter_id) {
+ VLOG(2) << "Discovery started on " << adapter_id;
+}
+
+void BluetoothOptionsHandler::DiscoveryEnded(const std::string& adapter_id) {
+ VLOG(2) << "Discovery ended on " << adapter_id;
+ web_ui_->CallJavascriptFunction(
+ "options.SystemOptions.notifyBluetoothSearchComplete");
+
+ // Stop the discovery session.
+ // TODO(vlaviano): We may want to expose DeviceDisappeared, remove the
+ // "Find devices" button, and let the discovery session continue throughout
+ // the time that the page is visible rather than just doing a single discovery
+ // cycle in response to a button click.
+ chromeos::BluetoothManager* bluetooth_manager =
+ chromeos::BluetoothManager::GetInstance();
+ DCHECK(bluetooth_manager);
+
+ chromeos::BluetoothAdapter* default_adapter =
+ bluetooth_manager->DefaultAdapter();
+
+ ValidateDefaultAdapter(default_adapter);
+
+ if (default_adapter == NULL) {
+ VLOG(1) << "DiscoveryEnded: no default adapter";
+ return;
+ }
+
+ default_adapter->StopDiscovery();
+}
+
+void BluetoothOptionsHandler::DeviceFound(const std::string& adapter_id,
+ chromeos::BluetoothDevice* device) {
+ VLOG(2) << "Device found on " << adapter_id;
+ DCHECK(device);
+
+ // TODO(vlaviano): eliminate inconsistencies between the javascript rep and
+ // BluetoothDevice so that we can use BluetoothDevice::AsDictionary() here.
+ DictionaryValue device_js_rep;
+ device_js_rep.SetString("deviceName", device->GetName());
+ device_js_rep.SetString("deviceId", device->GetAddress());
+ device_js_rep.SetString("deviceType", device->GetIcon());
+ if (device->IsPaired()) {
+ device_js_rep.SetString("deviceStatus", "bluetoothDeviceConnected");
+ } else {
+ device_js_rep.SetString("deviceStatus", "bluetoothDeviceNotPaired");
+ }
+
+ web_ui_->CallJavascriptFunction(
+ "options.SystemOptions.addBluetoothDevice", device_js_rep);
+}
+
+void BluetoothOptionsHandler::ValidateDefaultAdapter(
+ chromeos::BluetoothAdapter* adapter) {
+ if ((adapter == NULL && !default_adapter_id_.empty()) ||
+ (adapter != NULL && default_adapter_id_ != adapter->Id())) {
+ VLOG(1) << "unexpected default adapter change from \""
+ << default_adapter_id_ << "\" to \"" << adapter->Id() << "\"";
+ DefaultAdapterChanged(adapter);
+ }
+}
+
void BluetoothOptionsHandler::GenerateFakeDeviceList() {
// TODO(kevers): Send notifications asynchronously simulating that the
// process of discovering bluetooth devices takes time.
@@ -125,5 +250,4 @@ void BluetoothOptionsHandler::GenerateFakeDeviceList() {
"options.SystemOptions.notifyBluetoothSearchComplete");
}
-}
-
+} // namespace chromeos
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/bluetooth_options_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698