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

Side by Side Diff: chrome/browser/chromeos/system/ash_system_tray_delegate.cc

Issue 11293249: Remove PrefObserver usage, batch 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bluetooth/bluetooth_observer.h"
11 #include "ash/system/brightness/brightness_observer.h" 11 #include "ash/system/brightness/brightness_observer.h"
12 #include "ash/system/chromeos/network/network_observer.h" 12 #include "ash/system/chromeos/network/network_observer.h"
13 #include "ash/system/date/clock_observer.h" 13 #include "ash/system/date/clock_observer.h"
14 #include "ash/system/drive/drive_observer.h" 14 #include "ash/system/drive/drive_observer.h"
15 #include "ash/system/ime/ime_observer.h" 15 #include "ash/system/ime/ime_observer.h"
16 #include "ash/system/logout_button/logout_button_observer.h" 16 #include "ash/system/logout_button/logout_button_observer.h"
17 #include "ash/system/power/power_status_observer.h" 17 #include "ash/system/power/power_status_observer.h"
18 #include "ash/system/tray/system_tray.h" 18 #include "ash/system/tray/system_tray.h"
19 #include "ash/system/tray/system_tray_delegate.h" 19 #include "ash/system/tray/system_tray_delegate.h"
20 #include "ash/system/tray_accessibility.h" 20 #include "ash/system/tray_accessibility.h"
21 #include "ash/system/tray_caps_lock.h" 21 #include "ash/system/tray_caps_lock.h"
22 #include "ash/system/user/update_observer.h" 22 #include "ash/system/user/update_observer.h"
23 #include "ash/system/user/user_observer.h" 23 #include "ash/system/user/user_observer.h"
24 #include "ash/volume_control_delegate.h" 24 #include "ash/volume_control_delegate.h"
25 #include "base/bind_helpers.h" 25 #include "base/bind_helpers.h"
26 #include "base/callback.h" 26 #include "base/callback.h"
27 #include "base/chromeos/chromeos_version.h" 27 #include "base/chromeos/chromeos_version.h"
28 #include "base/logging.h" 28 #include "base/logging.h"
29 #include "base/memory/weak_ptr.h" 29 #include "base/memory/weak_ptr.h"
30 #include "base/prefs/public/pref_observer.h"
31 #include "base/utf_string_conversions.h" 30 #include "base/utf_string_conversions.h"
32 #include "chrome/browser/browser_process.h" 31 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 32 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
34 #include "chrome/browser/chromeos/audio/audio_handler.h" 33 #include "chrome/browser/chromeos/audio/audio_handler.h"
35 #include "chrome/browser/chromeos/cros/cros_library.h" 34 #include "chrome/browser/chromeos/cros/cros_library.h"
36 #include "chrome/browser/chromeos/cros/network_library.h" 35 #include "chrome/browser/chromeos/cros/network_library.h"
37 #include "chrome/browser/chromeos/drive/drive_system_service.h" 36 #include "chrome/browser/chromeos/drive/drive_system_service.h"
38 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 37 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
39 #include "chrome/browser/chromeos/input_method/input_method_util.h" 38 #include "chrome/browser/chromeos/input_method/input_method_util.h"
40 #include "chrome/browser/chromeos/input_method/xkeyboard.h" 39 #include "chrome/browser/chromeos/input_method/xkeyboard.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 145
147 class SystemTrayDelegate : public ash::SystemTrayDelegate, 146 class SystemTrayDelegate : public ash::SystemTrayDelegate,
148 public AudioHandler::VolumeObserver, 147 public AudioHandler::VolumeObserver,
149 public PowerManagerClient::Observer, 148 public PowerManagerClient::Observer,
150 public SessionManagerClient::Observer, 149 public SessionManagerClient::Observer,
151 public NetworkMenuIcon::Delegate, 150 public NetworkMenuIcon::Delegate,
152 public NetworkMenu::Delegate, 151 public NetworkMenu::Delegate,
153 public NetworkLibrary::NetworkManagerObserver, 152 public NetworkLibrary::NetworkManagerObserver,
154 public NetworkLibrary::NetworkObserver, 153 public NetworkLibrary::NetworkObserver,
155 public NetworkLibrary::CellularDataPlanObserver, 154 public NetworkLibrary::CellularDataPlanObserver,
156 public PrefObserver,
157 public google_apis::DriveServiceObserver, 155 public google_apis::DriveServiceObserver,
158 public content::NotificationObserver, 156 public content::NotificationObserver,
159 public input_method::InputMethodManager::Observer, 157 public input_method::InputMethodManager::Observer,
160 public system::TimezoneSettings::Observer, 158 public system::TimezoneSettings::Observer,
161 public device::BluetoothAdapter::Observer, 159 public device::BluetoothAdapter::Observer,
162 public SystemKeyEventListener::CapsLockObserver, 160 public SystemKeyEventListener::CapsLockObserver,
163 public ash::NetworkTrayDelegate { 161 public ash::NetworkTrayDelegate {
164 public: 162 public:
165 SystemTrayDelegate() 163 SystemTrayDelegate()
166 : ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( 164 : ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 OnNetworkManagerChanged(crosnet); 209 OnNetworkManagerChanged(crosnet);
212 crosnet->AddCellularDataPlanObserver(this); 210 crosnet->AddCellularDataPlanObserver(this);
213 211
214 input_method::InputMethodManager::GetInstance()->AddObserver(this); 212 input_method::InputMethodManager::GetInstance()->AddObserver(this);
215 213
216 system::TimezoneSettings::GetInstance()->AddObserver(this); 214 system::TimezoneSettings::GetInstance()->AddObserver(this);
217 215
218 if (SystemKeyEventListener::GetInstance()) 216 if (SystemKeyEventListener::GetInstance())
219 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this); 217 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this);
220 218
221 accessibility_enabled_.Init(prefs::kSpokenFeedbackEnabled, 219 accessibility_enabled_.Init(
222 g_browser_process->local_state(), this); 220 prefs::kSpokenFeedbackEnabled,
221 g_browser_process->local_state(),
222 base::Bind(&SystemTrayDelegate::OnPreferenceChanged,
223 base::Unretained(this)));
223 224
224 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT); 225 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT);
225 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK); 226 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK);
226 227
227 bluetooth_adapter_ = device::BluetoothAdapterFactory::DefaultAdapter(); 228 bluetooth_adapter_ = device::BluetoothAdapterFactory::DefaultAdapter();
228 bluetooth_adapter_->AddObserver(this); 229 bluetooth_adapter_->AddObserver(this);
229 } 230 }
230 231
231 virtual ~SystemTrayDelegate() { 232 virtual ~SystemTrayDelegate() {
232 AudioHandler* audiohandler = AudioHandler::GetInstance(); 233 AudioHandler* audiohandler = AudioHandler::GetInstance();
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 Browser* GetAppropriateBrowser() { 746 Browser* GetAppropriateBrowser() {
746 return browser::FindOrCreateTabbedBrowser( 747 return browser::FindOrCreateTabbedBrowser(
747 ProfileManager::GetDefaultProfileOrOffTheRecord(), 748 ProfileManager::GetDefaultProfileOrOffTheRecord(),
748 chrome::HOST_DESKTOP_TYPE_ASH); 749 chrome::HOST_DESKTOP_TYPE_ASH);
749 } 750 }
750 751
751 void SetProfile(Profile* profile) { 752 void SetProfile(Profile* profile) {
752 PrefService* prefs = profile->GetPrefs(); 753 PrefService* prefs = profile->GetPrefs();
753 pref_registrar_.reset(new PrefChangeRegistrar); 754 pref_registrar_.reset(new PrefChangeRegistrar);
754 pref_registrar_->Init(prefs); 755 pref_registrar_->Init(prefs);
755 pref_registrar_->Add(prefs::kUse24HourClock, this); 756 pref_registrar_->Add(prefs::kUse24HourClock,
Mattias Nissler (ping if slow) 2012/11/13 14:11:31 nit: I'd put a linebreak here as well for consiste
Jói 2012/11/13 14:22:38 Done.
756 pref_registrar_->Add(prefs::kLanguageRemapSearchKeyTo, this); 757 base::Bind(&SystemTrayDelegate::UpdateClockType,
757 pref_registrar_->Add(prefs::kShowLogoutButtonInTray, this); 758 base::Unretained(this)));
758 UpdateClockType(prefs); 759 pref_registrar_->Add(
759 UpdateShowLogoutButtonInTray(prefs); 760 prefs::kLanguageRemapSearchKeyTo,
761 base::Bind(&SystemTrayDelegate::OnLanguageRemapSearchKeyToChanged,
762 base::Unretained(this)));
763 pref_registrar_->Add(
764 prefs::kShowLogoutButtonInTray,
765 base::Bind(&SystemTrayDelegate::UpdateShowLogoutButtonInTray,
766 base::Unretained(this)));
767 UpdateClockType();
768 UpdateShowLogoutButtonInTray();
760 search_key_mapped_to_ = 769 search_key_mapped_to_ =
761 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo); 770 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
762 } 771 }
763 772
764 void ObserveGDataUpdates() { 773 void ObserveGDataUpdates() {
765 DriveSystemService* system_service = FindDriveSystemService(); 774 DriveSystemService* system_service = FindDriveSystemService();
766 if (!system_service) 775 if (!system_service)
767 return; 776 return;
768 777
769 system_service->drive_service()->AddObserver(this); 778 system_service->drive_service()->AddObserver(this);
770 } 779 }
771 780
772 void UpdateClockType(PrefServiceBase* service) { 781 void UpdateClockType() {
773 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? 782 clock_type_ = pref_registrar_->prefs()->GetBoolean(prefs::kUse24HourClock) ?
774 base::k24HourClock : base::k12HourClock; 783 base::k24HourClock : base::k12HourClock;
775 ash::ClockObserver* observer = GetSystemTray()->clock_observer(); 784 ash::ClockObserver* observer = GetSystemTray()->clock_observer();
776 if (observer) 785 if (observer)
777 observer->OnDateFormatChanged(); 786 observer->OnDateFormatChanged();
778 } 787 }
779 788
780 void UpdateShowLogoutButtonInTray(PrefServiceBase* service) { 789 void UpdateShowLogoutButtonInTray() {
781 ash::LogoutButtonObserver* observer = 790 ash::LogoutButtonObserver* observer =
782 GetSystemTray()->logout_button_observer(); 791 GetSystemTray()->logout_button_observer();
783 if (observer) { 792 if (observer) {
784 observer->OnShowLogoutButtonInTrayChanged( 793 observer->OnShowLogoutButtonInTrayChanged(
785 service->GetBoolean(prefs::kShowLogoutButtonInTray)); 794 pref_registrar_->prefs()->GetBoolean(prefs::kShowLogoutButtonInTray));
786 } 795 }
787 } 796 }
788 797
789 void NotifyRefreshClock() { 798 void NotifyRefreshClock() {
790 ash::ClockObserver* observer = GetSystemTray()->clock_observer(); 799 ash::ClockObserver* observer = GetSystemTray()->clock_observer();
791 if (observer) 800 if (observer)
792 observer->Refresh(); 801 observer->Refresh();
793 } 802 }
794 803
795 void NotifyRefreshNetwork() { 804 void NotifyRefreshNetwork() {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( 1135 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
1127 GetUserLoginStatus()); 1136 GetUserLoginStatus());
1128 SetProfile(ProfileManager::GetDefaultProfile()); 1137 SetProfile(ProfileManager::GetDefaultProfile());
1129 break; 1138 break;
1130 } 1139 }
1131 default: 1140 default:
1132 NOTREACHED(); 1141 NOTREACHED();
1133 } 1142 }
1134 } 1143 }
1135 1144
1136 virtual void OnPreferenceChanged(PrefServiceBase* service, 1145 void OnLanguageRemapSearchKeyToChanged() {
1137 const std::string& pref) OVERRIDE { 1146 search_key_mapped_to_ = pref_registrar_->prefs()->GetInteger(
1138 if (pref == prefs::kUse24HourClock) { 1147 prefs::kLanguageRemapSearchKeyTo);
1139 UpdateClockType(service); 1148 }
1140 } else if (pref == prefs::kLanguageRemapSearchKeyTo) { 1149
1141 search_key_mapped_to_ = 1150 void OnSpokenFeedbackEnabledChanged() {
1142 service->GetInteger(prefs::kLanguageRemapSearchKeyTo); 1151 ash::AccessibilityObserver* observer =
1143 } else if (pref == prefs::kSpokenFeedbackEnabled) { 1152 GetSystemTray()->accessibility_observer();
1144 ash::AccessibilityObserver* observer = 1153 if (observer) {
1145 GetSystemTray()->accessibility_observer(); 1154 observer->OnAccessibilityModeChanged(
1146 if (observer) { 1155 accessibility_enabled_->prefs()->GetBoolean(
1147 observer->OnAccessibilityModeChanged( 1156 prefs::kSpokenFeedbackEnabled));
1148 service->GetBoolean(prefs::kSpokenFeedbackEnabled));
1149 }
1150 } else if (pref == prefs::kShowLogoutButtonInTray) {
1151 UpdateShowLogoutButtonInTray(service);
1152 } else {
1153 NOTREACHED();
1154 } 1157 }
1155 } 1158 }
1156 1159
1157 // Overridden from InputMethodManager::Observer. 1160 // Overridden from InputMethodManager::Observer.
1158 virtual void InputMethodChanged( 1161 virtual void InputMethodChanged(
1159 input_method::InputMethodManager* manager, bool show_message) OVERRIDE { 1162 input_method::InputMethodManager* manager, bool show_message) OVERRIDE {
1160 NotifyRefreshIME(show_message); 1163 NotifyRefreshIME(show_message);
1161 } 1164 }
1162 1165
1163 virtual void InputMethodPropertyChanged( 1166 virtual void InputMethodPropertyChanged(
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); 1330 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate);
1328 }; 1331 };
1329 1332
1330 } // namespace 1333 } // namespace
1331 1334
1332 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { 1335 ash::SystemTrayDelegate* CreateSystemTrayDelegate() {
1333 return new chromeos::SystemTrayDelegate(); 1336 return new chromeos::SystemTrayDelegate();
1334 } 1337 }
1335 1338
1336 } // namespace chromeos 1339 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698