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

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: rebase after separate bluetooth core code commit 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..55561475ce21de3e782982da67337960e801f0b6 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,25 @@ BluetoothOptionsHandler::BluetoothOptionsHandler()
}
BluetoothOptionsHandler::~BluetoothOptionsHandler() {
- // TODO(kevers): Shutdown bluetooth.
+ VLOG(1) << "BluetoothOptionsHandler dtor";
kevers 2011/10/27 16:14:43 Do we intend to keep this comment in the final rel
Vince Laviano 2011/10/27 20:15:54 Removed.
+
+ 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(
@@ -57,9 +76,19 @@ void BluetoothOptionsHandler::Initialize() {
->HasSwitch(switches::kEnableBluetooth)) {
return;
}
+ VLOG(1) << "Initialize";
kevers 2011/10/27 16:14:43 Message appears to be too generic.
Vince Laviano 2011/10/27 20:15:54 Removed.
+
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 +117,29 @@ 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();
+
+ if ((default_adapter == NULL && !default_adapter_id_.empty()) ||
+ (default_adapter != NULL &&
+ default_adapter_id_ != default_adapter->Id())) {
+ LOG(WARNING) << "unexpected default adapter change from \""
kevers 2011/10/27 16:14:43 Seems to be a developing trend to migrate away fro
Vince Laviano 2011/10/27 20:15:54 Done.
+ << default_adapter_id_ << "\" to \"" << default_adapter->Id()
+ << "\"";
+ DefaultAdapterChanged(default_adapter);
+ }
+
+ if (default_adapter == NULL) {
+ LOG(WARNING) << "FindDevicesCallback: no default adapter";
+ return;
+ }
+
+ default_adapter->StartDiscovery();
}
void BluetoothOptionsHandler::UpdateDeviceCallback(
@@ -102,6 +153,88 @@ 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();
+ LOG(INFO) << "DefaultAdapterChanged: no default bluetooth adapter";
kevers 2011/10/27 16:14:43 VLOG(2)?
Vince Laviano 2011/10/27 20:15:54 Done.
+ } else {
+ default_adapter_id_ = adapter->Id();
+ LOG(INFO) << "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(1) << "Discovery started on " << adapter_id;
+}
+
+void BluetoothOptionsHandler::DiscoveryEnded(const std::string& adapter_id) {
+ VLOG(1) << "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();
+
+ if ((default_adapter == NULL && !default_adapter_id_.empty()) ||
kevers 2011/10/27 16:14:43 Lines 200-207 appear to duplicate lines 128-135.
Vince Laviano 2011/10/27 20:15:54 Done.
+ (default_adapter != NULL &&
+ default_adapter_id_ != default_adapter->Id())) {
+ LOG(WARNING) << "unexpected default adapter change from \""
+ << default_adapter_id_ << "\" to \"" << default_adapter->Id()
+ << "\"";
+ DefaultAdapterChanged(default_adapter);
+ }
+
+ if (default_adapter == NULL) {
+ LOG(WARNING) << "DiscoveryEnded: no default adapter";
+ return;
+ }
+
+ default_adapter->StopDiscovery();
+}
+
+void BluetoothOptionsHandler::DeviceFound(const std::string& adapter_id,
+ chromeos::BluetoothDevice* device) {
+ VLOG(1) << "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::GenerateFakeDeviceList() {
// TODO(kevers): Send notifications asynchronously simulating that the
// process of discovering bluetooth devices takes time.
@@ -125,5 +258,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