Index: chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
index 4eff0dcee56747ed3be7ef09d16de36862a66f85..c4de8ae7cd9c7b10bea99e2d76ab02b5e161d088 100644 |
--- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
+++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc |
@@ -7,6 +7,7 @@ |
#include "ash/shell.h" |
#include "ash/shell_window_ids.h" |
#include "ash/system/audio/audio_observer.h" |
+#include "ash/system/bluetooth/bluetooth_observer.h" |
#include "ash/system/brightness/brightness_observer.h" |
#include "ash/system/network/network_observer.h" |
#include "ash/system/power/clock_observer.h" |
@@ -21,6 +22,8 @@ |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/chromeos/audio/audio_handler.h" |
+#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" |
+#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" |
#include "chrome/browser/chromeos/cros/cros_library.h" |
#include "chrome/browser/chromeos/cros/network_library.h" |
#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
@@ -72,6 +75,7 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
public NetworkLibrary::CellularDataPlanObserver, |
public content::NotificationObserver, |
public system::TimezoneSettings::Observer, |
+ public BluetoothAdapter::Observer, |
public SystemKeyEventListener::CapsLockObserver { |
public: |
explicit SystemTrayDelegate(ash::SystemTray* tray) |
@@ -116,6 +120,9 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, |
g_browser_process->local_state(), this); |
+ |
+ bluetooth_adapter_.reset(BluetoothAdapter::CreateDefaultAdapter()); |
+ bluetooth_adapter_->AddObserver(this); |
} |
virtual ~SystemTrayDelegate() { |
@@ -229,6 +236,21 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
NotifyScreenLockRequested(); |
} |
+ virtual ash::BluetoothDeviceList GetAvailableBluetoothDevices() OVERRIDE { |
+ BluetoothAdapter::DeviceList devices = bluetooth_adapter_->GetDevices(); |
sadrul
2012/03/20 21:40:24
Is 'GetDevice' an expensive operation? If it is, t
keybuk
2012/03/20 21:59:58
It's expensive only in that it makes a vector of p
sadrul
2012/03/20 22:02:37
Excellent!
|
+ ash::BluetoothDeviceList list; |
+ for (size_t i = 0; i < devices.size(); ++i) { |
+ BluetoothDevice* device = devices[i]; |
+ ash::BluetoothDeviceInfo info; |
+ info.address = device->address(); |
+ info.display_name = device->GetName(); |
+ info.connected = device->IsConnected(); |
+ |
+ list.push_back(info); |
+ } |
+ return list; |
+ } |
+ |
virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { |
ash::NetworkIconInfo info; |
info.image = !large ? network_icon_->GetIconAndText(&info.description) : |
@@ -379,6 +401,13 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
} |
} |
+ void NotifyRefreshBluetooth() { |
+ ash::BluetoothObserver* observer = |
+ ash::Shell::GetInstance()->tray()->bluetooth_observer(); |
+ if (observer) |
+ observer->OnBluetoothRefresh(); |
+ } |
+ |
void RefreshNetworkObserver(NetworkLibrary* crosnet) { |
const Network* network = crosnet->active_network(); |
std::string new_path = network ? network->service_path() : std::string(); |
@@ -535,6 +564,37 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
NotifyRefreshClock(); |
} |
+ // Overridden from BluetoothAdapter::Observer. |
+ virtual void AdapterPresentChanged(BluetoothAdapter* adapter, |
+ bool present) OVERRIDE { |
+ NotifyRefreshBluetooth(); |
+ } |
+ |
+ virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, |
+ bool powered) OVERRIDE { |
+ NotifyRefreshBluetooth(); |
+ } |
+ |
+ virtual void AdapterDiscoveringChanged(BluetoothAdapter* adapter, |
+ bool discovering) OVERRIDE { |
+ // Not necessary to do anything here? |
keybuk
2012/03/20 21:59:58
You may want to do cutesy flashing animations or s
sadrul
2012/03/20 22:02:37
I will leave a TODO to cutesify :)
|
+ } |
+ |
+ virtual void DeviceAdded(BluetoothAdapter* adapter, |
+ BluetoothDevice* device) OVERRIDE { |
+ NotifyRefreshBluetooth(); |
+ } |
+ |
+ virtual void DeviceChanged(BluetoothAdapter* adapter, |
+ BluetoothDevice* device) OVERRIDE { |
+ NotifyRefreshBluetooth(); |
+ } |
+ |
+ virtual void DeviceRemoved(BluetoothAdapter* adapter, |
+ BluetoothDevice* device) OVERRIDE { |
+ NotifyRefreshBluetooth(); |
+ } |
+ |
// Overridden from SystemKeyEventListener::CapsLockObserver. |
virtual void OnCapsLockChange(bool enabled) OVERRIDE { |
ash::CapsLockObserver* observer = |
@@ -555,6 +615,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, |
PowerSupplyStatus power_supply_status_; |
base::HourClockType clock_type_; |
+ scoped_ptr<BluetoothAdapter> bluetooth_adapter_; |
+ |
BooleanPrefMember accessibility_enabled_; |
DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |