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

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

Issue 11568036: Add countdown when session time is limited (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed. Created 8 years 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
« no previous file with comments | « ash/system/tray/test_system_tray_delegate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm>
8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/shell_delegate.h" 10 #include "ash/shell_delegate.h"
9 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
10 #include "ash/system/audio/audio_observer.h" 12 #include "ash/system/audio/audio_observer.h"
11 #include "ash/system/bluetooth/bluetooth_observer.h" 13 #include "ash/system/bluetooth/bluetooth_observer.h"
12 #include "ash/system/brightness/brightness_observer.h" 14 #include "ash/system/brightness/brightness_observer.h"
13 #include "ash/system/chromeos/network/network_observer.h" 15 #include "ash/system/chromeos/network/network_observer.h"
14 #include "ash/system/date/clock_observer.h" 16 #include "ash/system/date/clock_observer.h"
15 #include "ash/system/drive/drive_observer.h" 17 #include "ash/system/drive/drive_observer.h"
16 #include "ash/system/ime/ime_observer.h" 18 #include "ash/system/ime/ime_observer.h"
17 #include "ash/system/logout_button/logout_button_observer.h" 19 #include "ash/system/logout_button/logout_button_observer.h"
18 #include "ash/system/power/power_status_observer.h" 20 #include "ash/system/power/power_status_observer.h"
19 #include "ash/system/tray/system_tray.h" 21 #include "ash/system/tray/system_tray.h"
20 #include "ash/system/tray/system_tray_delegate.h" 22 #include "ash/system/tray/system_tray_delegate.h"
21 #include "ash/system/tray/system_tray_notifier.h" 23 #include "ash/system/tray/system_tray_notifier.h"
22 #include "ash/system/tray_accessibility.h" 24 #include "ash/system/tray_accessibility.h"
23 #include "ash/system/tray_caps_lock.h" 25 #include "ash/system/tray_caps_lock.h"
24 #include "ash/system/user/update_observer.h" 26 #include "ash/system/user/update_observer.h"
25 #include "ash/system/user/user_observer.h" 27 #include "ash/system/user/user_observer.h"
26 #include "ash/volume_control_delegate.h" 28 #include "ash/volume_control_delegate.h"
27 #include "ash/wm/session_state_controller.h" 29 #include "ash/wm/session_state_controller.h"
28 #include "base/bind_helpers.h" 30 #include "base/bind_helpers.h"
29 #include "base/callback.h" 31 #include "base/callback.h"
30 #include "base/chromeos/chromeos_version.h" 32 #include "base/chromeos/chromeos_version.h"
31 #include "base/command_line.h" 33 #include "base/command_line.h"
32 #include "base/logging.h" 34 #include "base/logging.h"
33 #include "base/memory/weak_ptr.h" 35 #include "base/memory/weak_ptr.h"
36 #include "base/prefs/public/pref_service_base.h"
37 #include "base/time.h"
34 #include "base/utf_string_conversions.h" 38 #include "base/utf_string_conversions.h"
35 #include "chrome/browser/browser_process.h" 39 #include "chrome/browser/browser_process.h"
36 #include "chrome/browser/chromeos/accessibility/accessibility_util.h" 40 #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
37 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" 41 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
38 #include "chrome/browser/chromeos/audio/audio_handler.h" 42 #include "chrome/browser/chromeos/audio/audio_handler.h"
39 #include "chrome/browser/chromeos/cros/cros_library.h" 43 #include "chrome/browser/chromeos/cros/cros_library.h"
40 #include "chrome/browser/chromeos/cros/network_library.h" 44 #include "chrome/browser/chromeos/cros/network_library.h"
41 #include "chrome/browser/chromeos/drive/drive_system_service.h" 45 #include "chrome/browser/chromeos/drive/drive_system_service.h"
42 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 46 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
43 #include "chrome/browser/chromeos/input_method/input_method_manager.h" 47 #include "chrome/browser/chromeos/input_method/input_method_manager.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 #include "grit/generated_resources.h" 90 #include "grit/generated_resources.h"
87 #include "ui/base/l10n/l10n_util.h" 91 #include "ui/base/l10n/l10n_util.h"
88 92
89 using drive::DriveSystemService; 93 using drive::DriveSystemService;
90 using drive::DriveSystemServiceFactory; 94 using drive::DriveSystemServiceFactory;
91 95
92 namespace chromeos { 96 namespace chromeos {
93 97
94 namespace { 98 namespace {
95 99
100 // The minimum session length limit that can be set.
101 const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds.
102
103 // The maximum session length limit that can be set.
104 const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours.
105
96 // Time delay for rechecking gdata operation when we suspect that there will 106 // Time delay for rechecking gdata operation when we suspect that there will
97 // be no upcoming activity notifications that need to be pushed to UI. 107 // be no upcoming activity notifications that need to be pushed to UI.
98 const int kGDataOperationRecheckDelayMs = 5000; 108 const int kGDataOperationRecheckDelayMs = 5000;
99 109
100 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network, 110 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network,
101 NetworkMenu* network_menu) { 111 NetworkMenu* network_menu) {
102 ash::NetworkIconInfo info; 112 ash::NetworkIconInfo info;
103 info.name = UTF8ToUTF16(network->name()); 113 info.name = UTF8ToUTF16(network->name());
104 info.image = NetworkMenuIcon::GetImage(network, NetworkMenuIcon::COLOR_DARK); 114 info.image = NetworkMenuIcon::GetImage(network, NetworkMenuIcon::COLOR_DARK);
105 info.service_path = network->service_path(); 115 info.service_path = network->service_path();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this); 244 SystemKeyEventListener::GetInstance()->AddCapsLockObserver(this);
235 245
236 if (chromeos::MagnificationManager::Get()) 246 if (chromeos::MagnificationManager::Get())
237 chromeos::MagnificationManager::Get()->AddObserver(this); 247 chromeos::MagnificationManager::Get()->AddObserver(this);
238 248
239 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT); 249 network_icon_->SetResourceColorTheme(NetworkMenuIcon::COLOR_LIGHT);
240 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK); 250 network_icon_dark_->SetResourceColorTheme(NetworkMenuIcon::COLOR_DARK);
241 251
242 bluetooth_adapter_ = device::BluetoothAdapterFactory::DefaultAdapter(); 252 bluetooth_adapter_ = device::BluetoothAdapterFactory::DefaultAdapter();
243 bluetooth_adapter_->AddObserver(this); 253 bluetooth_adapter_->AddObserver(this);
254
255 local_state_registrar_.Init(g_browser_process->local_state());
256
257 UpdateSessionStartTime();
258 UpdateSessionLengthLimit();
259
260 local_state_registrar_.Add(
261 prefs::kSessionStartTime,
262 base::Bind(&SystemTrayDelegate::UpdateSessionStartTime,
263 base::Unretained(this)));
264 local_state_registrar_.Add(
265 prefs::kSessionLengthLimit,
266 base::Bind(&SystemTrayDelegate::UpdateSessionLengthLimit,
267 base::Unretained(this)));
244 } 268 }
245 269
246 virtual ~SystemTrayDelegate() { 270 virtual ~SystemTrayDelegate() {
247 AudioHandler* audiohandler = AudioHandler::GetInstance(); 271 AudioHandler* audiohandler = AudioHandler::GetInstance();
248 if (audiohandler) 272 if (audiohandler)
249 audiohandler->RemoveVolumeObserver(this); 273 audiohandler->RemoveVolumeObserver(this);
250 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this); 274 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
251 DBusThreadManager::Get()->GetRootPowerManagerClient()->RemoveObserver(this); 275 DBusThreadManager::Get()->GetRootPowerManagerClient()->RemoveObserver(this);
252 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 276 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
253 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary(); 277 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 virtual ash::VolumeControlDelegate* GetVolumeControlDelegate() const OVERRIDE 789 virtual ash::VolumeControlDelegate* GetVolumeControlDelegate() const OVERRIDE
766 { 790 {
767 return volume_control_delegate_.get(); 791 return volume_control_delegate_.get();
768 } 792 }
769 793
770 virtual void SetVolumeControlDelegate( 794 virtual void SetVolumeControlDelegate(
771 scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE { 795 scoped_ptr<ash::VolumeControlDelegate> delegate) OVERRIDE {
772 volume_control_delegate_.swap(delegate); 796 volume_control_delegate_.swap(delegate);
773 } 797 }
774 798
799 virtual base::Time GetSessionStartTime() OVERRIDE {
800 return session_start_time_;
801 }
802
803 virtual base::TimeDelta GetSessionLengthLimit() OVERRIDE {
804 return session_length_limit_;
805 }
806
775 private: 807 private:
776 ash::SystemTray* GetPrimarySystemTray() { 808 ash::SystemTray* GetPrimarySystemTray() {
777 return ash::Shell::GetInstance()->GetPrimarySystemTray(); 809 return ash::Shell::GetInstance()->GetPrimarySystemTray();
778 } 810 }
779 811
780 ash::SystemTrayNotifier* GetSystemTrayNotifier() { 812 ash::SystemTrayNotifier* GetSystemTrayNotifier() {
781 return ash::Shell::GetInstance()->system_tray_notifier(); 813 return ash::Shell::GetInstance()->system_tray_notifier();
782 } 814 }
783 815
784 // Returns the last active browser. If there is no such browser, creates a new 816 // Returns the last active browser. If there is no such browser, creates a new
785 // browser window with an empty tab and returns it. 817 // browser window with an empty tab and returns it.
786 Browser* GetAppropriateBrowser() { 818 Browser* GetAppropriateBrowser() {
787 return browser::FindOrCreateTabbedBrowser( 819 return browser::FindOrCreateTabbedBrowser(
788 ProfileManager::GetDefaultProfileOrOffTheRecord(), 820 ProfileManager::GetDefaultProfileOrOffTheRecord(),
789 chrome::HOST_DESKTOP_TYPE_ASH); 821 chrome::HOST_DESKTOP_TYPE_ASH);
790 } 822 }
791 823
792 void SetProfile(Profile* profile) { 824 void SetProfile(Profile* profile) {
793 PrefService* prefs = profile->GetPrefs(); 825 PrefService* prefs = profile->GetPrefs();
794 pref_registrar_.reset(new PrefChangeRegistrar); 826 user_pref_registrar_.reset(new PrefChangeRegistrar);
795 pref_registrar_->Init(prefs); 827 user_pref_registrar_->Init(prefs);
796 pref_registrar_->Add( 828 user_pref_registrar_->Add(
797 prefs::kUse24HourClock, 829 prefs::kUse24HourClock,
798 base::Bind(&SystemTrayDelegate::UpdateClockType, 830 base::Bind(&SystemTrayDelegate::UpdateClockType,
799 base::Unretained(this))); 831 base::Unretained(this)));
800 pref_registrar_->Add( 832 user_pref_registrar_->Add(
801 prefs::kLanguageRemapSearchKeyTo, 833 prefs::kLanguageRemapSearchKeyTo,
802 base::Bind(&SystemTrayDelegate::OnLanguageRemapSearchKeyToChanged, 834 base::Bind(&SystemTrayDelegate::OnLanguageRemapSearchKeyToChanged,
803 base::Unretained(this))); 835 base::Unretained(this)));
804 pref_registrar_->Add( 836 user_pref_registrar_->Add(
805 prefs::kShowLogoutButtonInTray, 837 prefs::kShowLogoutButtonInTray,
806 base::Bind(&SystemTrayDelegate::UpdateShowLogoutButtonInTray, 838 base::Bind(&SystemTrayDelegate::UpdateShowLogoutButtonInTray,
807 base::Unretained(this))); 839 base::Unretained(this)));
808 pref_registrar_->Add( 840 user_pref_registrar_->Add(
809 prefs::kShouldAlwaysShowAccessibilityMenu, 841 prefs::kShouldAlwaysShowAccessibilityMenu,
810 base::Bind(&SystemTrayDelegate::OnAccessibilityModeChanged, 842 base::Bind(&SystemTrayDelegate::OnAccessibilityModeChanged,
811 base::Unretained(this), 843 base::Unretained(this),
812 ash::A11Y_NOTIFICATION_NONE)); 844 ash::A11Y_NOTIFICATION_NONE));
813 845
814 UpdateClockType(); 846 UpdateClockType();
815 UpdateShowLogoutButtonInTray(); 847 UpdateShowLogoutButtonInTray();
816 search_key_mapped_to_ = 848 search_key_mapped_to_ =
817 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo); 849 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
818 } 850 }
819 851
820 void ObserveGDataUpdates() { 852 void ObserveGDataUpdates() {
821 DriveSystemService* system_service = FindDriveSystemService(); 853 DriveSystemService* system_service = FindDriveSystemService();
822 if (!system_service) 854 if (!system_service)
823 return; 855 return;
824 856
825 system_service->drive_service()->AddObserver(this); 857 system_service->drive_service()->AddObserver(this);
826 } 858 }
827 859
828 void UpdateClockType() { 860 void UpdateClockType() {
829 clock_type_ = pref_registrar_->prefs()->GetBoolean(prefs::kUse24HourClock) ? 861 clock_type_ =
830 base::k24HourClock : base::k12HourClock; 862 user_pref_registrar_->prefs()->GetBoolean(prefs::kUse24HourClock) ?
863 base::k24HourClock : base::k12HourClock;
831 GetSystemTrayNotifier()->NotifyDateFormatChanged(); 864 GetSystemTrayNotifier()->NotifyDateFormatChanged();
832 } 865 }
833 866
834 void UpdateShowLogoutButtonInTray() { 867 void UpdateShowLogoutButtonInTray() {
835 GetSystemTrayNotifier()->NotifyShowLoginButtonChanged( 868 GetSystemTrayNotifier()->NotifyShowLoginButtonChanged(
836 pref_registrar_->prefs()->GetBoolean(prefs::kShowLogoutButtonInTray)); 869 user_pref_registrar_->prefs()->GetBoolean(
870 prefs::kShowLogoutButtonInTray));
871 }
872
873 void UpdateSessionStartTime() {
874 session_start_time_ = base::Time::FromInternalValue(
875 local_state_registrar_.prefs()->GetInt64(prefs::kSessionStartTime));
876 GetSystemTrayNotifier()->NotifySessionStartTimeChanged(session_start_time_);
877 }
878
879 void UpdateSessionLengthLimit() {
880 const PrefServiceBase::Preference* session_length_limit_pref =
881 local_state_registrar_.prefs()->
882 FindPreference(prefs::kSessionLengthLimit);
883 int limit;
884 if (session_length_limit_pref->IsDefaultValue() ||
885 !session_length_limit_pref->GetValue()->GetAsInteger(&limit)) {
886 session_length_limit_ = base::TimeDelta();
887 } else {
888 session_length_limit_ = base::TimeDelta::FromMilliseconds(
889 std::min(std::max(limit, kSessionLengthLimitMinMs),
890 kSessionLengthLimitMaxMs));
891 }
892 GetSystemTrayNotifier()->NotifySessionLengthLimitChanged(
893 session_length_limit_);
837 } 894 }
838 895
839 void NotifyRefreshNetwork() { 896 void NotifyRefreshNetwork() {
840 chromeos::NetworkLibrary* crosnet = 897 chromeos::NetworkLibrary* crosnet =
841 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 898 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
842 const Network* network = crosnet->connected_network(); 899 const Network* network = crosnet->connected_network();
843 ash::NetworkIconInfo info; 900 ash::NetworkIconInfo info;
844 if (network) { 901 if (network) {
845 info.name = network->type() == TYPE_ETHERNET ? 902 info.name = network->type() == TYPE_ETHERNET ?
846 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET) : 903 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET) :
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 details).ptr(); 1135 details).ptr();
1079 OnAccessibilityModeChanged(accessibility_status->notify); 1136 OnAccessibilityModeChanged(accessibility_status->notify);
1080 break; 1137 break;
1081 } 1138 }
1082 default: 1139 default:
1083 NOTREACHED(); 1140 NOTREACHED();
1084 } 1141 }
1085 } 1142 }
1086 1143
1087 void OnLanguageRemapSearchKeyToChanged() { 1144 void OnLanguageRemapSearchKeyToChanged() {
1088 search_key_mapped_to_ = pref_registrar_->prefs()->GetInteger( 1145 search_key_mapped_to_ = user_pref_registrar_->prefs()->GetInteger(
1089 prefs::kLanguageRemapSearchKeyTo); 1146 prefs::kLanguageRemapSearchKeyTo);
1090 } 1147 }
1091 1148
1092 void OnAccessibilityModeChanged( 1149 void OnAccessibilityModeChanged(
1093 ash::AccessibilityNotificationVisibility notify) { 1150 ash::AccessibilityNotificationVisibility notify) {
1094 GetSystemTrayNotifier()->NotifyAccessibilityModeChanged(notify); 1151 GetSystemTrayNotifier()->NotifyAccessibilityModeChanged(notify);
1095 } 1152 }
1096 1153
1097 // Overridden from InputMethodManager::Observer. 1154 // Overridden from InputMethodManager::Observer.
1098 virtual void InputMethodChanged( 1155 virtual void InputMethodChanged(
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 // Overridden from MagnificationObserver 1297 // Overridden from MagnificationObserver
1241 void OnMagnifierTypeChanged(ash::MagnifierType new_type) { 1298 void OnMagnifierTypeChanged(ash::MagnifierType new_type) {
1242 OnAccessibilityModeChanged(ash::A11Y_NOTIFICATION_NONE); 1299 OnAccessibilityModeChanged(ash::A11Y_NOTIFICATION_NONE);
1243 } 1300 }
1244 1301
1245 scoped_ptr<base::WeakPtrFactory<SystemTrayDelegate> > ui_weak_ptr_factory_; 1302 scoped_ptr<base::WeakPtrFactory<SystemTrayDelegate> > ui_weak_ptr_factory_;
1246 scoped_ptr<NetworkMenuIcon> network_icon_; 1303 scoped_ptr<NetworkMenuIcon> network_icon_;
1247 scoped_ptr<NetworkMenuIcon> network_icon_dark_; 1304 scoped_ptr<NetworkMenuIcon> network_icon_dark_;
1248 scoped_ptr<NetworkMenu> network_menu_; 1305 scoped_ptr<NetworkMenu> network_menu_;
1249 content::NotificationRegistrar registrar_; 1306 content::NotificationRegistrar registrar_;
1250 scoped_ptr<PrefChangeRegistrar> pref_registrar_; 1307 PrefChangeRegistrar local_state_registrar_;
1308 scoped_ptr<PrefChangeRegistrar> user_pref_registrar_;
1251 std::string cellular_device_path_; 1309 std::string cellular_device_path_;
1252 std::string active_network_path_; 1310 std::string active_network_path_;
1253 PowerSupplyStatus power_supply_status_; 1311 PowerSupplyStatus power_supply_status_;
1254 base::HourClockType clock_type_; 1312 base::HourClockType clock_type_;
1255 int search_key_mapped_to_; 1313 int search_key_mapped_to_;
1256 bool screen_locked_; 1314 bool screen_locked_;
1315 base::Time session_start_time_;
1316 base::TimeDelta session_length_limit_;
1257 1317
1258 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; 1318 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
1259 1319
1260 scoped_ptr<DataPromoNotification> data_promo_notification_; 1320 scoped_ptr<DataPromoNotification> data_promo_notification_;
1261 1321
1262 scoped_ptr<ash::VolumeControlDelegate> volume_control_delegate_; 1322 scoped_ptr<ash::VolumeControlDelegate> volume_control_delegate_;
1263 1323
1264 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); 1324 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate);
1265 }; 1325 };
1266 1326
1267 } // namespace 1327 } // namespace
1268 1328
1269 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { 1329 ash::SystemTrayDelegate* CreateSystemTrayDelegate() {
1270 return new chromeos::SystemTrayDelegate(); 1330 return new chromeos::SystemTrayDelegate();
1271 } 1331 }
1272 1332
1273 } // namespace chromeos 1333 } // namespace chromeos
OLDNEW
« no previous file with comments | « ash/system/tray/test_system_tray_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698