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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 ash::Shell::GetInstance() | 304 ash::Shell::GetInstance() |
303 ->session_state_delegate() | 305 ->session_state_delegate() |
304 ->RemoveSessionStateObserver(this); | 306 ->RemoveSessionStateObserver(this); |
305 LoginState::Get()->RemoveObserver(this); | 307 LoginState::Get()->RemoveObserver(this); |
306 | 308 |
307 if (CrasAudioHandler::IsInitialized()) | 309 if (CrasAudioHandler::IsInitialized()) |
308 CrasAudioHandler::Get()->RemoveAudioObserver(this); | 310 CrasAudioHandler::Get()->RemoveAudioObserver(this); |
309 | 311 |
310 BrowserList::RemoveObserver(this); | 312 BrowserList::RemoveObserver(this); |
311 StopObservingAppWindowRegistry(); | 313 StopObservingAppWindowRegistry(); |
314 StopObservingCustodianInfoChanges(); | |
312 | 315 |
313 policy::BrowserPolicyConnectorChromeOS* connector = | 316 policy::BrowserPolicyConnectorChromeOS* connector = |
314 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 317 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
315 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = | 318 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = |
316 connector->GetDeviceCloudPolicyManager(); | 319 connector->GetDeviceCloudPolicyManager(); |
317 if (policy_manager) | 320 if (policy_manager) |
318 policy_manager->core()->store()->RemoveObserver(this); | 321 policy_manager->core()->store()->RemoveObserver(this); |
319 } | 322 } |
320 | 323 |
321 // Overridden from ash::SystemTrayDelegate: | 324 // Overridden from ash::SystemTrayDelegate: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 } | 371 } |
369 | 372 |
370 const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const { | 373 const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const { |
371 if (GetEnterpriseDomain().empty()) | 374 if (GetEnterpriseDomain().empty()) |
372 return base::string16(); | 375 return base::string16(); |
373 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE, | 376 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE, |
374 base::UTF8ToUTF16(GetEnterpriseDomain())); | 377 base::UTF8ToUTF16(GetEnterpriseDomain())); |
375 } | 378 } |
376 | 379 |
377 const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const { | 380 const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const { |
378 if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED) | 381 if (!IsUserSupervised()) |
379 return std::string(); | 382 return std::string(); |
380 return ChromeUserManager::Get() | 383 return SupervisedUserServiceFactory::GetForProfile(user_profile_)-> |
381 ->GetSupervisedUserManager() | 384 GetCustodianEmailAddress(); |
382 ->GetManagerDisplayEmail( | |
383 user_manager::UserManager::Get()->GetActiveUser()->email()); | |
384 } | 385 } |
385 | 386 |
386 const base::string16 | 387 const base::string16 |
387 SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const { | 388 SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const { |
388 if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED) | 389 if (!IsUserSupervised()) |
389 return base::string16(); | 390 return base::string16(); |
390 return ChromeUserManager::Get() | 391 return base::UTF8ToUTF16(SupervisedUserServiceFactory::GetForProfile( |
391 ->GetSupervisedUserManager() | 392 user_profile_)->GetCustodianName()); |
392 ->GetManagerDisplayName( | |
393 user_manager::UserManager::Get()->GetActiveUser()->email()); | |
394 } | 393 } |
395 | 394 |
396 const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage() | 395 const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage() |
397 const { | 396 const { |
398 if (!IsUserSupervised()) | 397 if (!IsUserSupervised()) |
399 return base::string16(); | 398 return base::string16(); |
399 std::string user_manager_name = GetSupervisedUserManager(); | |
400 LOG_IF(WARNING, user_manager_name.empty()) << | |
401 "Returning incomplete supervised user message as manager not known yet."; | |
400 return l10n_util::GetStringFUTF16( | 402 return l10n_util::GetStringFUTF16( |
401 IDS_USER_IS_SUPERVISED_BY_NOTICE, | 403 IDS_USER_IS_SUPERVISED_BY_NOTICE, |
402 base::UTF8ToUTF16(GetSupervisedUserManager())); | 404 base::UTF8ToUTF16(user_manager_name)); |
403 } | 405 } |
404 | 406 |
405 bool SystemTrayDelegateChromeOS::IsUserSupervised() const { | 407 bool SystemTrayDelegateChromeOS::IsUserSupervised() const { |
406 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser(); | 408 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser(); |
407 return user && user->IsSupervised(); | 409 return user && user->IsSupervised(); |
408 } | 410 } |
409 | 411 |
410 void SystemTrayDelegateChromeOS::GetSystemUpdateInfo( | 412 void SystemTrayDelegateChromeOS::GetSystemUpdateInfo( |
411 ash::UpdateInfo* info) const { | 413 ash::UpdateInfo* info) const { |
412 GetUpdateInfo(UpgradeDetector::GetInstance(), info); | 414 GetUpdateInfo(UpgradeDetector::GetInstance(), info); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 Profile* user_profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 854 Profile* user_profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
853 CHECK(user_profile); | 855 CHECK(user_profile); |
854 accounts_delegates_.set( | 856 accounts_delegates_.set( |
855 user_id, | 857 user_id, |
856 scoped_ptr<ash::tray::UserAccountsDelegate>( | 858 scoped_ptr<ash::tray::UserAccountsDelegate>( |
857 new UserAccountsDelegateChromeOS(user_profile))); | 859 new UserAccountsDelegateChromeOS(user_profile))); |
858 } | 860 } |
859 return accounts_delegates_.get(user_id); | 861 return accounts_delegates_.get(user_id); |
860 } | 862 } |
861 | 863 |
864 void SystemTrayDelegateChromeOS::AddCustodianInfoTrayObserver( | |
865 ash::CustodianInfoTrayObserver* observer) { | |
866 custodian_info_changed_observers_.AddObserver(observer); | |
867 } | |
868 | |
869 void SystemTrayDelegateChromeOS::RemoveCustodianInfoTrayObserver( | |
870 ash::CustodianInfoTrayObserver* observer) { | |
871 custodian_info_changed_observers_.RemoveObserver(observer); | |
872 } | |
873 | |
862 ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() { | 874 ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() { |
863 return ash::Shell::GetInstance()->GetPrimarySystemTray(); | 875 return ash::Shell::GetInstance()->GetPrimarySystemTray(); |
864 } | 876 } |
865 | 877 |
866 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() { | 878 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() { |
867 return ash::Shell::GetInstance()->system_tray_notifier(); | 879 return ash::Shell::GetInstance()->system_tray_notifier(); |
868 } | 880 } |
869 | 881 |
870 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) { | 882 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) { |
871 // Stop observing the AppWindowRegistry of the current |user_profile_|. | 883 // Stop observing the AppWindowRegistry of the current |user_profile_|. |
872 StopObservingAppWindowRegistry(); | 884 StopObservingAppWindowRegistry(); |
873 | 885 |
886 // Stop observing custodian info changes of the current |user_profile_|. | |
887 StopObservingCustodianInfoChanges(); | |
888 | |
874 user_profile_ = profile; | 889 user_profile_ = profile; |
875 | 890 |
876 // Start observing the AppWindowRegistry of the newly set |user_profile_|. | 891 // Start observing the AppWindowRegistry of the newly set |user_profile_|. |
877 extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this); | 892 extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this); |
878 | 893 |
894 // Start observing custodian info changes of the newly set |user_profile_|. | |
895 SupervisedUserServiceFactory::GetForProfile(profile)->AddObserver(this); | |
896 | |
879 PrefService* prefs = profile->GetPrefs(); | 897 PrefService* prefs = profile->GetPrefs(); |
880 user_pref_registrar_.reset(new PrefChangeRegistrar); | 898 user_pref_registrar_.reset(new PrefChangeRegistrar); |
881 user_pref_registrar_->Init(prefs); | 899 user_pref_registrar_->Init(prefs); |
882 user_pref_registrar_->Add( | 900 user_pref_registrar_->Add( |
883 prefs::kUse24HourClock, | 901 prefs::kUse24HourClock, |
884 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, | 902 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, |
885 base::Unretained(this))); | 903 base::Unretained(this))); |
886 user_pref_registrar_->Add( | 904 user_pref_registrar_->Add( |
887 prefs::kLanguageRemapSearchKeyTo, | 905 prefs::kLanguageRemapSearchKeyTo, |
888 base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged, | 906 base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged, |
(...skipping 23 matching lines...) Expand all Loading... | |
912 ash::A11Y_NOTIFICATION_NONE)); | 930 ash::A11Y_NOTIFICATION_NONE)); |
913 user_pref_registrar_->Add( | 931 user_pref_registrar_->Add( |
914 prefs::kPerformanceTracingEnabled, | 932 prefs::kPerformanceTracingEnabled, |
915 base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing, | 933 base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing, |
916 base::Unretained(this))); | 934 base::Unretained(this))); |
917 | 935 |
918 UpdateClockType(); | 936 UpdateClockType(); |
919 UpdateShowLogoutButtonInTray(); | 937 UpdateShowLogoutButtonInTray(); |
920 UpdateLogoutDialogDuration(); | 938 UpdateLogoutDialogDuration(); |
921 UpdatePerformanceTracing(); | 939 UpdatePerformanceTracing(); |
940 OnCustodianInfoChanged(); | |
922 search_key_mapped_to_ = | 941 search_key_mapped_to_ = |
923 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo); | 942 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo); |
924 } | 943 } |
925 | 944 |
926 bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) { | 945 bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) { |
927 if (profile != user_profile_) | 946 if (profile != user_profile_) |
928 return false; | 947 return false; |
929 user_pref_registrar_.reset(); | 948 user_pref_registrar_.reset(); |
930 user_profile_ = NULL; | 949 user_profile_ = NULL; |
931 return true; | 950 return true; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 if (!user_profile_) | 1035 if (!user_profile_) |
1017 return; | 1036 return; |
1018 | 1037 |
1019 extensions::AppWindowRegistry* registry = | 1038 extensions::AppWindowRegistry* registry = |
1020 extensions::AppWindowRegistry::Factory::GetForBrowserContext( | 1039 extensions::AppWindowRegistry::Factory::GetForBrowserContext( |
1021 user_profile_, false); | 1040 user_profile_, false); |
1022 if (registry) | 1041 if (registry) |
1023 registry->RemoveObserver(this); | 1042 registry->RemoveObserver(this); |
1024 } | 1043 } |
1025 | 1044 |
1045 void SystemTrayDelegateChromeOS::StopObservingCustodianInfoChanges() { | |
1046 if (!user_profile_) | |
1047 return; | |
1048 | |
1049 SupervisedUserService* service = SupervisedUserServiceFactory::GetForProfile( | |
1050 user_profile_); | |
1051 if (service) | |
1052 service->RemoveObserver(this); | |
1053 } | |
1054 | |
1026 void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() { | 1055 void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() { |
1027 if (!user_profile_) | 1056 if (!user_profile_) |
1028 return; | 1057 return; |
1029 | 1058 |
1030 BrowserList* browser_list = | 1059 BrowserList* browser_list = |
1031 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 1060 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
1032 for (BrowserList::const_iterator it = browser_list->begin(); | 1061 for (BrowserList::const_iterator it = browser_list->begin(); |
1033 it != browser_list->end(); | 1062 it != browser_list->end(); |
1034 ++it) { | 1063 ++it) { |
1035 if ((*it)->profile()->IsSameProfile(user_profile_)) { | 1064 if ((*it)->profile()->IsSameProfile(user_profile_)) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1264 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) { | 1293 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) { |
1265 NotifyIfLastWindowClosed(); | 1294 NotifyIfLastWindowClosed(); |
1266 } | 1295 } |
1267 | 1296 |
1268 // Overridden from extensions::AppWindowRegistry::Observer. | 1297 // Overridden from extensions::AppWindowRegistry::Observer. |
1269 void SystemTrayDelegateChromeOS::OnAppWindowRemoved( | 1298 void SystemTrayDelegateChromeOS::OnAppWindowRemoved( |
1270 extensions::AppWindow* app_window) { | 1299 extensions::AppWindow* app_window) { |
1271 NotifyIfLastWindowClosed(); | 1300 NotifyIfLastWindowClosed(); |
1272 } | 1301 } |
1273 | 1302 |
1303 // Overridden from SupervisedUserServiceObserver. | |
Daniel Erat
2014/10/08 14:10:46
don't need to fix it here, but chrome typically do
| |
1304 void SystemTrayDelegateChromeOS::OnCustodianInfoChanged() { | |
1305 FOR_EACH_OBSERVER( | |
1306 ash::CustodianInfoTrayObserver, custodian_info_changed_observers_, | |
1307 OnCustodianInfoChanged()); | |
1308 } | |
1309 | |
1274 void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged( | 1310 void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged( |
1275 const AccessibilityStatusEventDetails& details) { | 1311 const AccessibilityStatusEventDetails& details) { |
1276 if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN) | 1312 if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN) |
1277 accessibility_subscription_.reset(); | 1313 accessibility_subscription_.reset(); |
1278 else | 1314 else |
1279 OnAccessibilityModeChanged(details.notify); | 1315 OnAccessibilityModeChanged(details.notify); |
1280 } | 1316 } |
1281 | 1317 |
1282 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { | 1318 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { |
1283 return new SystemTrayDelegateChromeOS(); | 1319 return new SystemTrayDelegateChromeOS(); |
1284 } | 1320 } |
1285 | 1321 |
1286 } // namespace chromeos | 1322 } // namespace chromeos |
OLD | NEW |