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

Side by Side Diff: chrome/browser/ui/ash/system_tray_delegate_chromeos.cc

Issue 627593003: Adding infrastructure for possibility of changing manager names for the supervised accounts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Weak pointers removed. Created 6 years, 2 months 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
OLDNEW
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
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/user_accounts_delegate_chromeos.h" 76 #include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h"
75 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" 77 #include "chrome/browser/ui/ash/volume_controller_chromeos.h"
76 #include "chrome/browser/ui/browser.h" 78 #include "chrome/browser/ui/browser.h"
77 #include "chrome/browser/ui/browser_finder.h" 79 #include "chrome/browser/ui/browser_finder.h"
78 #include "chrome/browser/ui/browser_list.h" 80 #include "chrome/browser/ui/browser_list.h"
79 #include "chrome/browser/ui/chrome_pages.h" 81 #include "chrome/browser/ui/chrome_pages.h"
80 #include "chrome/browser/ui/host_desktop.h" 82 #include "chrome/browser/ui/host_desktop.h"
81 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 83 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
82 #include "chrome/browser/ui/singleton_tabs.h" 84 #include "chrome/browser/ui/singleton_tabs.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 ash::Shell::GetInstance() 303 ash::Shell::GetInstance()
302 ->session_state_delegate() 304 ->session_state_delegate()
303 ->RemoveSessionStateObserver(this); 305 ->RemoveSessionStateObserver(this);
304 LoginState::Get()->RemoveObserver(this); 306 LoginState::Get()->RemoveObserver(this);
305 307
306 if (CrasAudioHandler::IsInitialized()) 308 if (CrasAudioHandler::IsInitialized())
307 CrasAudioHandler::Get()->RemoveAudioObserver(this); 309 CrasAudioHandler::Get()->RemoveAudioObserver(this);
308 310
309 BrowserList::RemoveObserver(this); 311 BrowserList::RemoveObserver(this);
310 StopObservingAppWindowRegistry(); 312 StopObservingAppWindowRegistry();
313 StopObservingCustodianInfoChanges();
311 314
312 policy::BrowserPolicyConnectorChromeOS* connector = 315 policy::BrowserPolicyConnectorChromeOS* connector =
313 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 316 g_browser_process->platform_part()->browser_policy_connector_chromeos();
314 policy::DeviceCloudPolicyManagerChromeOS* policy_manager = 317 policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
315 connector->GetDeviceCloudPolicyManager(); 318 connector->GetDeviceCloudPolicyManager();
316 if (policy_manager) 319 if (policy_manager)
317 policy_manager->core()->store()->RemoveObserver(this); 320 policy_manager->core()->store()->RemoveObserver(this);
318 } 321 }
319 322
320 // Overridden from ash::SystemTrayDelegate: 323 // Overridden from ash::SystemTrayDelegate:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 370 }
368 371
369 const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const { 372 const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const {
370 if (GetEnterpriseDomain().empty()) 373 if (GetEnterpriseDomain().empty())
371 return base::string16(); 374 return base::string16();
372 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE, 375 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE,
373 base::UTF8ToUTF16(GetEnterpriseDomain())); 376 base::UTF8ToUTF16(GetEnterpriseDomain()));
374 } 377 }
375 378
376 const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const { 379 const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const {
377 if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED) 380 if (!IsUserSupervised())
378 return std::string(); 381 return std::string();
379 return ChromeUserManager::Get() 382 return SupervisedUserServiceFactory::GetForProfile(user_profile_)->
380 ->GetSupervisedUserManager() 383 GetCustodianEmailAddress();
381 ->GetManagerDisplayEmail(
382 user_manager::UserManager::Get()->GetActiveUser()->email());
383 } 384 }
384 385
385 const base::string16 386 const base::string16
386 SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const { 387 SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const {
387 if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED) 388 if (!IsUserSupervised())
388 return base::string16(); 389 return base::string16();
389 return ChromeUserManager::Get() 390 return base::UTF8ToUTF16(SupervisedUserServiceFactory::GetForProfile(
390 ->GetSupervisedUserManager() 391 user_profile_)->GetCustodianName());
391 ->GetManagerDisplayName(
392 user_manager::UserManager::Get()->GetActiveUser()->email());
393 } 392 }
394 393
395 const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage() 394 const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage()
396 const { 395 const {
397 if (!IsUserSupervised()) 396 if (!IsUserSupervised())
398 return base::string16(); 397 return base::string16();
398 std::string user_manager_name = GetSupervisedUserManager();
399 LOG_IF(WARNING, user_manager_name.empty()) <<
400 "Returning incomplete supervised user message as manager not known yet.";
399 return l10n_util::GetStringFUTF16( 401 return l10n_util::GetStringFUTF16(
400 IDS_USER_IS_SUPERVISED_BY_NOTICE, 402 IDS_USER_IS_SUPERVISED_BY_NOTICE,
401 base::UTF8ToUTF16(GetSupervisedUserManager())); 403 base::UTF8ToUTF16(user_manager_name));
402 } 404 }
403 405
404 bool SystemTrayDelegateChromeOS::IsUserSupervised() const { 406 bool SystemTrayDelegateChromeOS::IsUserSupervised() const {
405 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser(); 407 user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser();
406 return user && user->IsSupervised(); 408 return user && user->IsSupervised();
407 } 409 }
408 410
409 bool SystemTrayDelegateChromeOS::SystemShouldUpgrade() const { 411 bool SystemTrayDelegateChromeOS::SystemShouldUpgrade() const {
410 return UpgradeDetector::GetInstance()->notify_upgrade(); 412 return UpgradeDetector::GetInstance()->notify_upgrade();
411 } 413 }
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 } 864 }
863 865
864 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() { 866 ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
865 return ash::Shell::GetInstance()->system_tray_notifier(); 867 return ash::Shell::GetInstance()->system_tray_notifier();
866 } 868 }
867 869
868 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) { 870 void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
869 // Stop observing the AppWindowRegistry of the current |user_profile_|. 871 // Stop observing the AppWindowRegistry of the current |user_profile_|.
870 StopObservingAppWindowRegistry(); 872 StopObservingAppWindowRegistry();
871 873
874 // Stop observing custodian info changes of the current |user_profile_|.
875 StopObservingCustodianInfoChanges();
876
872 user_profile_ = profile; 877 user_profile_ = profile;
873 878
874 // Start observing the AppWindowRegistry of the newly set |user_profile_|. 879 // Start observing the AppWindowRegistry of the newly set |user_profile_|.
875 extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this); 880 extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this);
876 881
882 // Start observing custodian info changes of the newly set |user_profile_|.
883 SupervisedUserServiceFactory::GetForProfile(profile)->AddObserver(this);
884
877 PrefService* prefs = profile->GetPrefs(); 885 PrefService* prefs = profile->GetPrefs();
878 user_pref_registrar_.reset(new PrefChangeRegistrar); 886 user_pref_registrar_.reset(new PrefChangeRegistrar);
879 user_pref_registrar_->Init(prefs); 887 user_pref_registrar_->Init(prefs);
880 user_pref_registrar_->Add( 888 user_pref_registrar_->Add(
881 prefs::kUse24HourClock, 889 prefs::kUse24HourClock,
882 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType, 890 base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
883 base::Unretained(this))); 891 base::Unretained(this)));
884 user_pref_registrar_->Add( 892 user_pref_registrar_->Add(
885 prefs::kLanguageRemapSearchKeyTo, 893 prefs::kLanguageRemapSearchKeyTo,
886 base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged, 894 base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged,
(...skipping 23 matching lines...) Expand all
910 ash::A11Y_NOTIFICATION_NONE)); 918 ash::A11Y_NOTIFICATION_NONE));
911 user_pref_registrar_->Add( 919 user_pref_registrar_->Add(
912 prefs::kPerformanceTracingEnabled, 920 prefs::kPerformanceTracingEnabled,
913 base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing, 921 base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing,
914 base::Unretained(this))); 922 base::Unretained(this)));
915 923
916 UpdateClockType(); 924 UpdateClockType();
917 UpdateShowLogoutButtonInTray(); 925 UpdateShowLogoutButtonInTray();
918 UpdateLogoutDialogDuration(); 926 UpdateLogoutDialogDuration();
919 UpdatePerformanceTracing(); 927 UpdatePerformanceTracing();
928 OnCustodianInfoChanged();
920 search_key_mapped_to_ = 929 search_key_mapped_to_ =
921 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo); 930 profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
922 } 931 }
923 932
924 bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) { 933 bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) {
925 if (profile != user_profile_) 934 if (profile != user_profile_)
926 return false; 935 return false;
927 user_pref_registrar_.reset(); 936 user_pref_registrar_.reset();
928 user_profile_ = NULL; 937 user_profile_ = NULL;
929 return true; 938 return true;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 if (!user_profile_) 1023 if (!user_profile_)
1015 return; 1024 return;
1016 1025
1017 extensions::AppWindowRegistry* registry = 1026 extensions::AppWindowRegistry* registry =
1018 extensions::AppWindowRegistry::Factory::GetForBrowserContext( 1027 extensions::AppWindowRegistry::Factory::GetForBrowserContext(
1019 user_profile_, false); 1028 user_profile_, false);
1020 if (registry) 1029 if (registry)
1021 registry->RemoveObserver(this); 1030 registry->RemoveObserver(this);
1022 } 1031 }
1023 1032
1033 void SystemTrayDelegateChromeOS::StopObservingCustodianInfoChanges() {
1034 if (!user_profile_)
1035 return;
1036
1037 SupervisedUserService* service = SupervisedUserServiceFactory::GetForProfile(
1038 user_profile_);
1039 if (service)
1040 service->RemoveObserver(this);
1041 }
1042
1024 void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() { 1043 void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() {
1025 if (!user_profile_) 1044 if (!user_profile_)
1026 return; 1045 return;
1027 1046
1028 BrowserList* browser_list = 1047 BrowserList* browser_list =
1029 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 1048 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1030 for (BrowserList::const_iterator it = browser_list->begin(); 1049 for (BrowserList::const_iterator it = browser_list->begin();
1031 it != browser_list->end(); 1050 it != browser_list->end();
1032 ++it) { 1051 ++it) {
1033 if ((*it)->profile()->IsSameProfile(user_profile_)) { 1052 if ((*it)->profile()->IsSameProfile(user_profile_)) {
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) { 1301 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) {
1283 NotifyIfLastWindowClosed(); 1302 NotifyIfLastWindowClosed();
1284 } 1303 }
1285 1304
1286 // Overridden from extensions::AppWindowRegistry::Observer. 1305 // Overridden from extensions::AppWindowRegistry::Observer.
1287 void SystemTrayDelegateChromeOS::OnAppWindowRemoved( 1306 void SystemTrayDelegateChromeOS::OnAppWindowRemoved(
1288 extensions::AppWindow* app_window) { 1307 extensions::AppWindow* app_window) {
1289 NotifyIfLastWindowClosed(); 1308 NotifyIfLastWindowClosed();
1290 } 1309 }
1291 1310
1311 // Overridden from SupervisedUserServiceObserver.
1312 void SystemTrayDelegateChromeOS::OnCustodianInfoChanged() {
1313 FOR_EACH_OBSERVER(
1314 ash::CustodianInfoTrayObserver, custodian_info_changed_observers_,
1315 OnCustodianInfoChanged());
1316 }
1317
1318 void SystemTrayDelegateChromeOS::AddObserver(
Daniel Erat 2014/10/07 16:16:00 please move this and RemoveObserver so they match
merkulova 2014/10/08 09:19:37 Done.
1319 ash::CustodianInfoTrayObserver* observer) {
1320 custodian_info_changed_observers_.AddObserver(observer);
1321 }
1322
1323 void SystemTrayDelegateChromeOS::RemoveObserver(
1324 ash::CustodianInfoTrayObserver* observer) {
1325 custodian_info_changed_observers_.RemoveObserver(observer);
1326 }
1327
1292 void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged( 1328 void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged(
1293 const AccessibilityStatusEventDetails& details) { 1329 const AccessibilityStatusEventDetails& details) {
1294 if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN) 1330 if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN)
1295 accessibility_subscription_.reset(); 1331 accessibility_subscription_.reset();
1296 else 1332 else
1297 OnAccessibilityModeChanged(details.notify); 1333 OnAccessibilityModeChanged(details.notify);
1298 } 1334 }
1299 1335
1300 ash::SystemTrayDelegate* CreateSystemTrayDelegate() { 1336 ash::SystemTrayDelegate* CreateSystemTrayDelegate() {
1301 return new SystemTrayDelegateChromeOS(); 1337 return new SystemTrayDelegateChromeOS();
1302 } 1338 }
1303 1339
1304 } // namespace chromeos 1340 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698