OLD | NEW |
---|---|
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/system/ash_system_tray_delegate.h" | 5 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/system/audio/audio_observer.h" | 9 #include "ash/system/audio/audio_observer.h" |
10 #include "ash/system/bluetooth/bluetooth_observer.h" | |
10 #include "ash/system/brightness/brightness_observer.h" | 11 #include "ash/system/brightness/brightness_observer.h" |
11 #include "ash/system/network/network_observer.h" | 12 #include "ash/system/network/network_observer.h" |
12 #include "ash/system/power/clock_observer.h" | 13 #include "ash/system/power/clock_observer.h" |
13 #include "ash/system/power/power_status_observer.h" | 14 #include "ash/system/power/power_status_observer.h" |
14 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
15 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
16 #include "ash/system/tray_accessibility.h" | 17 #include "ash/system/tray_accessibility.h" |
17 #include "ash/system/tray_caps_lock.h" | 18 #include "ash/system/tray_caps_lock.h" |
18 #include "ash/system/user/update_observer.h" | 19 #include "ash/system/user/update_observer.h" |
19 #include "ash/system/user/user_observer.h" | 20 #include "ash/system/user/user_observer.h" |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
21 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
23 #include "chrome/browser/chromeos/audio/audio_handler.h" | 24 #include "chrome/browser/chromeos/audio/audio_handler.h" |
25 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" | |
26 #include "chrome/browser/chromeos/bluetooth/bluetooth_device.h" | |
24 #include "chrome/browser/chromeos/cros/cros_library.h" | 27 #include "chrome/browser/chromeos/cros/cros_library.h" |
25 #include "chrome/browser/chromeos/cros/network_library.h" | 28 #include "chrome/browser/chromeos/cros/network_library.h" |
26 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 29 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
27 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 30 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
28 #include "chrome/browser/chromeos/input_method/input_method_manager.h" | 31 #include "chrome/browser/chromeos/input_method/input_method_manager.h" |
29 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 32 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
30 #include "chrome/browser/chromeos/login/base_login_display_host.h" | 33 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
31 #include "chrome/browser/chromeos/login/login_display_host.h" | 34 #include "chrome/browser/chromeos/login/login_display_host.h" |
32 #include "chrome/browser/chromeos/login/user.h" | 35 #include "chrome/browser/chromeos/login/user.h" |
33 #include "chrome/browser/chromeos/login/user_manager.h" | 36 #include "chrome/browser/chromeos/login/user_manager.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 68 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
66 public AudioHandler::VolumeObserver, | 69 public AudioHandler::VolumeObserver, |
67 public PowerManagerClient::Observer, | 70 public PowerManagerClient::Observer, |
68 public NetworkMenuIcon::Delegate, | 71 public NetworkMenuIcon::Delegate, |
69 public NetworkMenu::Delegate, | 72 public NetworkMenu::Delegate, |
70 public NetworkLibrary::NetworkManagerObserver, | 73 public NetworkLibrary::NetworkManagerObserver, |
71 public NetworkLibrary::NetworkObserver, | 74 public NetworkLibrary::NetworkObserver, |
72 public NetworkLibrary::CellularDataPlanObserver, | 75 public NetworkLibrary::CellularDataPlanObserver, |
73 public content::NotificationObserver, | 76 public content::NotificationObserver, |
74 public system::TimezoneSettings::Observer, | 77 public system::TimezoneSettings::Observer, |
78 public BluetoothAdapter::Observer, | |
75 public SystemKeyEventListener::CapsLockObserver { | 79 public SystemKeyEventListener::CapsLockObserver { |
76 public: | 80 public: |
77 explicit SystemTrayDelegate(ash::SystemTray* tray) | 81 explicit SystemTrayDelegate(ash::SystemTray* tray) |
78 : tray_(tray), | 82 : tray_(tray), |
79 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( | 83 network_icon_(ALLOW_THIS_IN_INITIALIZER_LIST( |
80 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), | 84 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), |
81 network_icon_large_(ALLOW_THIS_IN_INITIALIZER_LIST( | 85 network_icon_large_(ALLOW_THIS_IN_INITIALIZER_LIST( |
82 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), | 86 new NetworkMenuIcon(this, NetworkMenuIcon::MENU_MODE))), |
83 network_menu_(ALLOW_THIS_IN_INITIALIZER_LIST(new NetworkMenu(this))), | 87 network_menu_(ALLOW_THIS_IN_INITIALIZER_LIST(new NetworkMenu(this))), |
84 clock_type_(base::k24HourClock) { | 88 clock_type_(base::k24HourClock) { |
(...skipping 24 matching lines...) Expand all Loading... | |
109 registrar_.Add(this, | 113 registrar_.Add(this, |
110 chrome::NOTIFICATION_SESSION_STARTED, | 114 chrome::NOTIFICATION_SESSION_STARTED, |
111 content::NotificationService::AllSources()); | 115 content::NotificationService::AllSources()); |
112 | 116 |
113 SetProfile(ProfileManager::GetDefaultProfile()); | 117 SetProfile(ProfileManager::GetDefaultProfile()); |
114 | 118 |
115 network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE); | 119 network_icon_large_->SetResourceSize(NetworkMenuIcon::SIZE_LARGE); |
116 | 120 |
117 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, | 121 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, |
118 g_browser_process->local_state(), this); | 122 g_browser_process->local_state(), this); |
123 | |
124 bluetooth_adapter_.reset(BluetoothAdapter::CreateDefaultAdapter()); | |
125 bluetooth_adapter_->AddObserver(this); | |
119 } | 126 } |
120 | 127 |
121 virtual ~SystemTrayDelegate() { | 128 virtual ~SystemTrayDelegate() { |
122 AudioHandler* audiohandler = AudioHandler::GetInstance(); | 129 AudioHandler* audiohandler = AudioHandler::GetInstance(); |
123 if (audiohandler) | 130 if (audiohandler) |
124 audiohandler->RemoveVolumeObserver(this); | 131 audiohandler->RemoveVolumeObserver(this); |
125 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 132 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
126 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | 133 system::TimezoneSettings::GetInstance()->RemoveObserver(this); |
127 if (SystemKeyEventListener::GetInstance()) | 134 if (SystemKeyEventListener::GetInstance()) |
128 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); | 135 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 | 229 |
223 virtual void SignOut() OVERRIDE { | 230 virtual void SignOut() OVERRIDE { |
224 BrowserList::AttemptUserExit(); | 231 BrowserList::AttemptUserExit(); |
225 } | 232 } |
226 | 233 |
227 virtual void RequestLockScreen() OVERRIDE { | 234 virtual void RequestLockScreen() OVERRIDE { |
228 DBusThreadManager::Get()->GetPowerManagerClient()-> | 235 DBusThreadManager::Get()->GetPowerManagerClient()-> |
229 NotifyScreenLockRequested(); | 236 NotifyScreenLockRequested(); |
230 } | 237 } |
231 | 238 |
239 virtual ash::BluetoothDeviceList GetAvailableBluetoothDevices() OVERRIDE { | |
240 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!
| |
241 ash::BluetoothDeviceList list; | |
242 for (size_t i = 0; i < devices.size(); ++i) { | |
243 BluetoothDevice* device = devices[i]; | |
244 ash::BluetoothDeviceInfo info; | |
245 info.address = device->address(); | |
246 info.display_name = device->GetName(); | |
247 info.connected = device->IsConnected(); | |
248 | |
249 list.push_back(info); | |
250 } | |
251 return list; | |
252 } | |
253 | |
232 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { | 254 virtual ash::NetworkIconInfo GetMostRelevantNetworkIcon(bool large) OVERRIDE { |
233 ash::NetworkIconInfo info; | 255 ash::NetworkIconInfo info; |
234 info.image = !large ? network_icon_->GetIconAndText(&info.description) : | 256 info.image = !large ? network_icon_->GetIconAndText(&info.description) : |
235 network_icon_large_->GetIconAndText(&info.description); | 257 network_icon_large_->GetIconAndText(&info.description); |
236 return info; | 258 return info; |
237 } | 259 } |
238 | 260 |
239 virtual void GetAvailableNetworks( | 261 virtual void GetAvailableNetworks( |
240 std::vector<ash::NetworkIconInfo>* list) OVERRIDE { | 262 std::vector<ash::NetworkIconInfo>* list) OVERRIDE { |
241 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); | 263 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
372 void NotifyRefreshNetwork() { | 394 void NotifyRefreshNetwork() { |
373 ash::NetworkObserver* observer = | 395 ash::NetworkObserver* observer = |
374 ash::Shell::GetInstance()->tray()->network_observer(); | 396 ash::Shell::GetInstance()->tray()->network_observer(); |
375 if (observer) { | 397 if (observer) { |
376 ash::NetworkIconInfo info; | 398 ash::NetworkIconInfo info; |
377 info.image = network_icon_->GetIconAndText(&info.description); | 399 info.image = network_icon_->GetIconAndText(&info.description); |
378 observer->OnNetworkRefresh(info); | 400 observer->OnNetworkRefresh(info); |
379 } | 401 } |
380 } | 402 } |
381 | 403 |
404 void NotifyRefreshBluetooth() { | |
405 ash::BluetoothObserver* observer = | |
406 ash::Shell::GetInstance()->tray()->bluetooth_observer(); | |
407 if (observer) | |
408 observer->OnBluetoothRefresh(); | |
409 } | |
410 | |
382 void RefreshNetworkObserver(NetworkLibrary* crosnet) { | 411 void RefreshNetworkObserver(NetworkLibrary* crosnet) { |
383 const Network* network = crosnet->active_network(); | 412 const Network* network = crosnet->active_network(); |
384 std::string new_path = network ? network->service_path() : std::string(); | 413 std::string new_path = network ? network->service_path() : std::string(); |
385 if (active_network_path_ != new_path) { | 414 if (active_network_path_ != new_path) { |
386 if (!active_network_path_.empty()) | 415 if (!active_network_path_.empty()) |
387 crosnet->RemoveNetworkObserver(active_network_path_, this); | 416 crosnet->RemoveNetworkObserver(active_network_path_, this); |
388 if (!new_path.empty()) | 417 if (!new_path.empty()) |
389 crosnet->AddNetworkObserver(new_path, this); | 418 crosnet->AddNetworkObserver(new_path, this); |
390 active_network_path_ = new_path; | 419 active_network_path_ = new_path; |
391 } | 420 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
528 default: | 557 default: |
529 NOTREACHED(); | 558 NOTREACHED(); |
530 } | 559 } |
531 } | 560 } |
532 | 561 |
533 // Overridden from system::TimezoneSettings::Observer. | 562 // Overridden from system::TimezoneSettings::Observer. |
534 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { | 563 virtual void TimezoneChanged(const icu::TimeZone& timezone) OVERRIDE { |
535 NotifyRefreshClock(); | 564 NotifyRefreshClock(); |
536 } | 565 } |
537 | 566 |
567 // Overridden from BluetoothAdapter::Observer. | |
568 virtual void AdapterPresentChanged(BluetoothAdapter* adapter, | |
569 bool present) OVERRIDE { | |
570 NotifyRefreshBluetooth(); | |
571 } | |
572 | |
573 virtual void AdapterPoweredChanged(BluetoothAdapter* adapter, | |
574 bool powered) OVERRIDE { | |
575 NotifyRefreshBluetooth(); | |
576 } | |
577 | |
578 virtual void AdapterDiscoveringChanged(BluetoothAdapter* adapter, | |
579 bool discovering) OVERRIDE { | |
580 // 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 :)
| |
581 } | |
582 | |
583 virtual void DeviceAdded(BluetoothAdapter* adapter, | |
584 BluetoothDevice* device) OVERRIDE { | |
585 NotifyRefreshBluetooth(); | |
586 } | |
587 | |
588 virtual void DeviceChanged(BluetoothAdapter* adapter, | |
589 BluetoothDevice* device) OVERRIDE { | |
590 NotifyRefreshBluetooth(); | |
591 } | |
592 | |
593 virtual void DeviceRemoved(BluetoothAdapter* adapter, | |
594 BluetoothDevice* device) OVERRIDE { | |
595 NotifyRefreshBluetooth(); | |
596 } | |
597 | |
538 // Overridden from SystemKeyEventListener::CapsLockObserver. | 598 // Overridden from SystemKeyEventListener::CapsLockObserver. |
539 virtual void OnCapsLockChange(bool enabled) OVERRIDE { | 599 virtual void OnCapsLockChange(bool enabled) OVERRIDE { |
540 ash::CapsLockObserver* observer = | 600 ash::CapsLockObserver* observer = |
541 ash::Shell::GetInstance()->tray()->caps_lock_observer(); | 601 ash::Shell::GetInstance()->tray()->caps_lock_observer(); |
542 if (observer) | 602 if (observer) |
543 observer->OnCapsLockChanged(enabled); | 603 observer->OnCapsLockChanged(enabled); |
544 } | 604 } |
545 | 605 |
546 ash::SystemTray* tray_; | 606 ash::SystemTray* tray_; |
547 scoped_ptr<NetworkMenuIcon> network_icon_; | 607 scoped_ptr<NetworkMenuIcon> network_icon_; |
548 scoped_ptr<NetworkMenuIcon> network_icon_large_; | 608 scoped_ptr<NetworkMenuIcon> network_icon_large_; |
549 scoped_ptr<NetworkMenu> network_menu_; | 609 scoped_ptr<NetworkMenu> network_menu_; |
550 content::NotificationRegistrar registrar_; | 610 content::NotificationRegistrar registrar_; |
551 scoped_ptr<PrefChangeRegistrar> pref_registrar_; | 611 scoped_ptr<PrefChangeRegistrar> pref_registrar_; |
552 std::string cellular_device_path_; | 612 std::string cellular_device_path_; |
553 std::string active_network_path_; | 613 std::string active_network_path_; |
554 scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_; | 614 scoped_ptr<LoginHtmlDialog> proxy_settings_dialog_; |
555 PowerSupplyStatus power_supply_status_; | 615 PowerSupplyStatus power_supply_status_; |
556 base::HourClockType clock_type_; | 616 base::HourClockType clock_type_; |
557 | 617 |
618 scoped_ptr<BluetoothAdapter> bluetooth_adapter_; | |
619 | |
558 BooleanPrefMember accessibility_enabled_; | 620 BooleanPrefMember accessibility_enabled_; |
559 | 621 |
560 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 622 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
561 }; | 623 }; |
562 | 624 |
563 } // namespace | 625 } // namespace |
564 | 626 |
565 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 627 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
566 return new chromeos::SystemTrayDelegate(tray); | 628 return new chromeos::SystemTrayDelegate(tray); |
567 } | 629 } |
568 | 630 |
569 } // namespace chromeos | 631 } // namespace chromeos |
OLD | NEW |