OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/ash/system_tray_delegate_chromeos.h" | 5 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 63 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
64 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 64 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
65 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" | 65 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" |
66 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 66 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
67 #include "chrome/browser/chromeos/set_time_dialog.h" | 67 #include "chrome/browser/chromeos/set_time_dialog.h" |
68 #include "chrome/browser/chromeos/settings/cros_settings.h" | 68 #include "chrome/browser/chromeos/settings/cros_settings.h" |
69 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 69 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
70 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" | 70 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" |
71 #include "chrome/browser/lifetime/application_lifetime.h" | 71 #include "chrome/browser/lifetime/application_lifetime.h" |
72 #include "chrome/browser/profiles/profile_manager.h" | 72 #include "chrome/browser/profiles/profile_manager.h" |
| 73 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 74 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
73 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 75 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
74 #include "chrome/browser/ui/ash/system_tray_delegate_utils.h" | 76 #include "chrome/browser/ui/ash/system_tray_delegate_utils.h" |
75 #include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h" | 77 #include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h" |
76 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" | 78 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" |
77 #include "chrome/browser/ui/browser.h" | 79 #include "chrome/browser/ui/browser.h" |
78 #include "chrome/browser/ui/browser_finder.h" | 80 #include "chrome/browser/ui/browser_finder.h" |
79 #include "chrome/browser/ui/browser_list.h" | 81 #include "chrome/browser/ui/browser_list.h" |
80 #include "chrome/browser/ui/chrome_pages.h" | 82 #include "chrome/browser/ui/chrome_pages.h" |
81 #include "chrome/browser/ui/host_desktop.h" | 83 #include "chrome/browser/ui/host_desktop.h" |
82 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 84 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 ash::Shell::GetInstance() | 307 ash::Shell::GetInstance() |
306 ->session_state_delegate() | 308 ->session_state_delegate() |
307 ->RemoveSessionStateObserver(this); | 309 ->RemoveSessionStateObserver(this); |
308 LoginState::Get()->RemoveObserver(this); | 310 LoginState::Get()->RemoveObserver(this); |
309 | 311 |
310 if (CrasAudioHandler::IsInitialized()) | 312 if (CrasAudioHandler::IsInitialized()) |
311 CrasAudioHandler::Get()->RemoveAudioObserver(this); | 313 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
312 | 314 |
313 BrowserList::RemoveObserver(this); | 315 BrowserList::RemoveObserver(this); |
314 StopObservingAppWindowRegistry(); | 316 StopObservingAppWindowRegistry(); |
| 317 StopObservingCustodianInfoChanges(); |
315 | 318 |
316 policy::BrowserPolicyConnectorChromeOS* connector = | 319 policy::BrowserPolicyConnectorChromeOS* connector = |
317 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 320 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
318 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | 321 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
319 connector->GetDeviceCloudPolicyManager(); | 322 connector->GetDeviceCloudPolicyManager(); |
320 if (policy_manager) | 323 if (policy_manager) |
321 policy_manager->core()->store()->RemoveObserver(this); | 324 policy_manager->core()->store()->RemoveObserver(this); |
322 | 325 |
323 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); | 326 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
324 } | 327 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 376 } |
374 | 377 |
375 const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const { | 378 const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const { |
376 if (GetEnterpriseDomain().empty()) | 379 if (GetEnterpriseDomain().empty()) |
377 return base::string16(); | 380 return base::string16(); |
378 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE, | 381 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE, |
379 base::UTF8ToUTF16(GetEnterpriseDomain())); | 382 base::UTF8ToUTF16(GetEnterpriseDomain())); |
380 } | 383 } |
381 | 384 |
382 const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const { | 385 const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const { |
383 if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED) | 386 if (!IsUserSupervised()) |
384 return std::string(); | 387 return std::string(); |
385 return ChromeUserManager::Get() | 388 return SupervisedUserServiceFactory::GetForProfile(user_profile_)-> |
386 ->GetSupervisedUserManager() | 389 GetCustodianEmailAddress(); |
387 ->GetManagerDisplayEmail( | |
388 user_manager::UserManager::Get()->GetActiveUser()->email()); | |
389 } | 390 } |
390 | 391 |
391 const base::string16 | 392 const base::string16 |
392 SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const { | 393 SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const { |
393 if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED) | 394 if (!IsUserSupervised()) |
394 return base::string16(); | 395 return base::string16(); |
395 return ChromeUserManager::Get() | 396 return base::UTF8ToUTF16(SupervisedUserServiceFactory::GetForProfile( |
396 ->GetSupervisedUserManager() | 397 user_profile_)->GetCustodianName()); |
397 ->GetManagerDisplayName( | |
398 user_manager::UserManager::Get()->GetActiveUser()->email()); | |
399 } | 398 } |
400 | 399 |
401 const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage() | 400 const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage() |
402 const { | 401 const { |
403 if (!IsUserSupervised()) | 402 if (!IsUserSupervised()) |
404 return base::string16(); | 403 return base::string16(); |
| 404 std::string user_manager_name = GetSupervisedUserManager(); |
| 405 LOG_IF(WARNING, user_manager_name.empty()) << |
| 406 "Returning incomplete supervised user message as manager not known yet."; |
405 return l10n_util::GetStringFUTF16( | 407 return l10n_util::GetStringFUTF16( |
406 IDS_USER_IS_SUPERVISED_BY_NOTICE, | 408 IDS_USER_IS_SUPERVISED_BY_NOTICE, |
407 base::UTF8ToUTF16(GetSupervisedUserManager())); | 409 base::UTF8ToUTF16(user_manager_name)); |
408 } | 410 } |
409 | 411 |
410 bool SystemTrayDelegateChromeOS::IsUserSupervised() const { | 412 bool SystemTrayDelegateChromeOS::IsUserSupervised() const { |
411 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser(); | 413 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser(); |
412 return user && user->IsSupervised(); | 414 return user && user->IsSupervised(); |
413 } | 415 } |
414 | 416 |
415 void SystemTrayDelegateChromeOS::GetSystemUpdateInfo( | 417 void SystemTrayDelegateChromeOS::GetSystemUpdateInfo( |
416 ash::UpdateInfo* info) const { | 418 ash::UpdateInfo* info) const { |
417 GetUpdateInfo(UpgradeDetector::GetInstance(), info); | 419 GetUpdateInfo(UpgradeDetector::GetInstance(), info); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 Profile* user_profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 859 Profile* user_profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
858 CHECK(user_profile); | 860 CHECK(user_profile); |
859 accounts_delegates_.set( | 861 accounts_delegates_.set( |
860 user_id, | 862 user_id, |
861 scoped_ptr<ash::tray::UserAccountsDelegate>( | 863 scoped_ptr<ash::tray::UserAccountsDelegate>( |
862 new UserAccountsDelegateChromeOS(user_profile))); | 864 new UserAccountsDelegateChromeOS(user_profile))); |
863 } | 865 } |
864 return accounts_delegates_.get(user_id); | 866 return accounts_delegates_.get(user_id); |
865 } | 867 } |
866 | 868 |
| 869 void SystemTrayDelegateChromeOS::AddCustodianInfoTrayObserver( |
| 870 ash::CustodianInfoTrayObserver* observer) { |
| 871 custodian_info_changed_observers_.AddObserver(observer); |
| 872 } |
| 873 |
| 874 void SystemTrayDelegateChromeOS::RemoveCustodianInfoTrayObserver( |
| 875 ash::CustodianInfoTrayObserver* observer) { |
| 876 custodian_info_changed_observers_.RemoveObserver(observer); |
| 877 } |
| 878 |
867 void SystemTrayDelegateChromeOS::UserAddedToSession( | 879 void SystemTrayDelegateChromeOS::UserAddedToSession( |
868 const user_manager::User* active_user) { | 880 const user_manager::User* active_user) { |
869 } | 881 } |
870 | 882 |
871 void SystemTrayDelegateChromeOS::UserChangedSupervisedStatus( | 883 void SystemTrayDelegateChromeOS::UserChangedSupervisedStatus( |
872 user_manager::User* user) { | 884 user_manager::User* user) { |
873 Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(user); | 885 Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(user); |
874 DCHECK(user_profile); | 886 DCHECK(user_profile); |
875 | 887 |
876 if (session_started_ && user_profile_ == user_profile) { | 888 if (session_started_ && user_profile_ == user_profile) { |
877 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( | 889 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( |
878 GetUserLoginStatus()); | 890 GetUserLoginStatus()); |
879 } | 891 } |
880 } | 892 } |
881 | 893 |
882 ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() { | 894 ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() { |
883 return ash::Shell::GetInstance()->GetPrimarySystemTray(); | 895 return ash::Shell::GetInstance()->GetPrimarySystemTray(); |
884 } | 896 } |
885 | 897 |
886 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() { | 898 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() { |
887 return ash::Shell::GetInstance()->system_tray_notifier(); | 899 return ash::Shell::GetInstance()->system_tray_notifier(); |
888 } | 900 } |
889 | 901 |
890 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) { | 902 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) { |
891 // Stop observing the AppWindowRegistry of the current |user_profile_|. | 903 // Stop observing the AppWindowRegistry of the current |user_profile_|. |
892 StopObservingAppWindowRegistry(); | 904 StopObservingAppWindowRegistry(); |
893 | 905 |
| 906 // Stop observing custodian info changes of the current |user_profile_|. |
| 907 StopObservingCustodianInfoChanges(); |
| 908 |
894 user_profile_ = profile; | 909 user_profile_ = profile; |
895 | 910 |
896 // Start observing the AppWindowRegistry of the newly set |user_profile_|. | 911 // Start observing the AppWindowRegistry of the newly set |user_profile_|. |
897 extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this); | 912 extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this); |
898 | 913 |
| 914 // Start observing custodian info changes of the newly set |user_profile_|. |
| 915 SupervisedUserServiceFactory::GetForProfile(profile)->AddObserver(this); |
| 916 |
899 PrefService* prefs = profile->GetPrefs(); | 917 PrefService* prefs = profile->GetPrefs(); |
900 user_pref_registrar_.reset(new PrefChangeRegistrar); | 918 user_pref_registrar_.reset(new PrefChangeRegistrar); |
901 user_pref_registrar_->Init(prefs); | 919 user_pref_registrar_->Init(prefs); |
902 user_pref_registrar_->Add( | 920 user_pref_registrar_->Add( |
903 prefs::kUse24HourClock, | 921 prefs::kUse24HourClock, |
904 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, | 922 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, |
905 base::Unretained(this))); | 923 base::Unretained(this))); |
906 user_pref_registrar_->Add( | 924 user_pref_registrar_->Add( |
907 prefs::kLanguageRemapSearchKeyTo, | 925 prefs::kLanguageRemapSearchKeyTo, |
908 base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged, | 926 base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged, |
(...skipping 23 matching lines...) Expand all Loading... |
932 ash::A11Y_NOTIFICATION_NONE)); | 950 ash::A11Y_NOTIFICATION_NONE)); |
933 user_pref_registrar_->Add( | 951 user_pref_registrar_->Add( |
934 prefs::kPerformanceTracingEnabled, | 952 prefs::kPerformanceTracingEnabled, |
935 base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing, | 953 base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing, |
936 base::Unretained(this))); | 954 base::Unretained(this))); |
937 | 955 |
938 UpdateClockType(); | 956 UpdateClockType(); |
939 UpdateShowLogoutButtonInTray(); | 957 UpdateShowLogoutButtonInTray(); |
940 UpdateLogoutDialogDuration(); | 958 UpdateLogoutDialogDuration(); |
941 UpdatePerformanceTracing(); | 959 UpdatePerformanceTracing(); |
| 960 OnCustodianInfoChanged(); |
942 search_key_mapped_to_ = | 961 search_key_mapped_to_ = |
943 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo); | 962 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo); |
944 } | 963 } |
945 | 964 |
946 bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) { | 965 bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) { |
947 if (profile != user_profile_) | 966 if (profile != user_profile_) |
948 return false; | 967 return false; |
949 user_pref_registrar_.reset(); | 968 user_pref_registrar_.reset(); |
950 user_profile_ = NULL; | 969 user_profile_ = NULL; |
951 return true; | 970 return true; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 if (!user_profile_) | 1055 if (!user_profile_) |
1037 return; | 1056 return; |
1038 | 1057 |
1039 extensions::AppWindowRegistry* registry = | 1058 extensions::AppWindowRegistry* registry = |
1040 extensions::AppWindowRegistry::Factory::GetForBrowserContext( | 1059 extensions::AppWindowRegistry::Factory::GetForBrowserContext( |
1041 user_profile_, false); | 1060 user_profile_, false); |
1042 if (registry) | 1061 if (registry) |
1043 registry->RemoveObserver(this); | 1062 registry->RemoveObserver(this); |
1044 } | 1063 } |
1045 | 1064 |
| 1065 void SystemTrayDelegateChromeOS::StopObservingCustodianInfoChanges() { |
| 1066 if (!user_profile_) |
| 1067 return; |
| 1068 |
| 1069 SupervisedUserService* service = SupervisedUserServiceFactory::GetForProfile( |
| 1070 user_profile_); |
| 1071 if (service) |
| 1072 service->RemoveObserver(this); |
| 1073 } |
| 1074 |
1046 void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() { | 1075 void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() { |
1047 if (!user_profile_) | 1076 if (!user_profile_) |
1048 return; | 1077 return; |
1049 | 1078 |
1050 BrowserList* browser_list = | 1079 BrowserList* browser_list = |
1051 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 1080 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
1052 for (BrowserList::const_iterator it = browser_list->begin(); | 1081 for (BrowserList::const_iterator it = browser_list->begin(); |
1053 it != browser_list->end(); | 1082 it != browser_list->end(); |
1054 ++it) { | 1083 ++it) { |
1055 if ((*it)->profile()->IsSameProfile(user_profile_)) { | 1084 if ((*it)->profile()->IsSameProfile(user_profile_)) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1285 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) { | 1314 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) { |
1286 NotifyIfLastWindowClosed(); | 1315 NotifyIfLastWindowClosed(); |
1287 } | 1316 } |
1288 | 1317 |
1289 // Overridden from extensions::AppWindowRegistry::Observer. | 1318 // Overridden from extensions::AppWindowRegistry::Observer. |
1290 void SystemTrayDelegateChromeOS::OnAppWindowRemoved( | 1319 void SystemTrayDelegateChromeOS::OnAppWindowRemoved( |
1291 extensions::AppWindow* app_window) { | 1320 extensions::AppWindow* app_window) { |
1292 NotifyIfLastWindowClosed(); | 1321 NotifyIfLastWindowClosed(); |
1293 } | 1322 } |
1294 | 1323 |
| 1324 // Overridden from SupervisedUserServiceObserver. |
| 1325 void SystemTrayDelegateChromeOS::OnCustodianInfoChanged() { |
| 1326 FOR_EACH_OBSERVER( |
| 1327 ash::CustodianInfoTrayObserver, custodian_info_changed_observers_, |
| 1328 OnCustodianInfoChanged()); |
| 1329 } |
| 1330 |
1295 void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged( | 1331 void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged( |
1296 const AccessibilityStatusEventDetails& details) { | 1332 const AccessibilityStatusEventDetails& details) { |
1297 if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN) | 1333 if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN) |
1298 accessibility_subscription_.reset(); | 1334 accessibility_subscription_.reset(); |
1299 else | 1335 else |
1300 OnAccessibilityModeChanged(details.notify); | 1336 OnAccessibilityModeChanged(details.notify); |
1301 } | 1337 } |
1302 | 1338 |
1303 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { | 1339 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { |
1304 return new SystemTrayDelegateChromeOS(); | 1340 return new SystemTrayDelegateChromeOS(); |
1305 } | 1341 } |
1306 | 1342 |
1307 } // namespace chromeos | 1343 } // namespace chromeos |
OLD | NEW |