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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
12 #include "ash/ash_switches.h"
13 #include "ash/desktop_background/desktop_background_controller.h"
14 #include "ash/display/display_manager.h"
15 #include "ash/metrics/user_metrics_recorder.h"
16 #include "ash/session/session_state_delegate.h"
17 #include "ash/session/session_state_observer.h"
18 #include "ash/shell.h"
19 #include "ash/shell_delegate.h"
20 #include "ash/shell_window_ids.h"
21 #include "ash/system/bluetooth/bluetooth_observer.h"
22 #include "ash/system/chromeos/session/logout_button_observer.h"
23 #include "ash/system/chromeos/shutdown_policy_observer.h"
24 #include "ash/system/date/clock_observer.h"
25 #include "ash/system/ime/ime_observer.h"
26 #include "ash/system/tray/system_tray.h"
27 #include "ash/system/tray/system_tray_delegate.h"
28 #include "ash/system/tray/system_tray_notifier.h"
29 #include "ash/system/tray_accessibility.h"
30 #include "ash/system/user/login_status.h"
31 #include "ash/system/user/update_observer.h"
32 #include "ash/system/user/user_observer.h"
33 #include "ash/volume_control_delegate.h"
34 #include "ash/wm/lock_state_controller.h"
35 #include "base/bind_helpers.h"
36 #include "base/callback.h"
37 #include "base/logging.h"
38 #include "base/memory/weak_ptr.h"
39 #include "base/prefs/pref_service.h"
40 #include "base/strings/stringprintf.h"
41 #include "base/strings/utf_string_conversions.h"
42 #include "base/sys_info.h"
43 #include "base/time/time.h"
44 #include "chrome/browser/browser_process.h"
45 #include "chrome/browser/chrome_notification_types.h"
46 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
47 #include "chrome/browser/chromeos/accessibility/magnification_manager.h"
48 #include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
49 #include "chrome/browser/chromeos/events/system_key_event_listener.h"
50 #include "chrome/browser/chromeos/input_method/input_method_switch_recorder.h"
51 #include "chrome/browser/chromeos/input_method/input_method_util.h"
52 #include "chrome/browser/chromeos/login/help_app_launcher.h"
53 #include "chrome/browser/chromeos/login/login_wizard.h"
54 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
55 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
56 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
57 #include "chrome/browser/chromeos/login/user_flow.h"
58 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
59 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
60 #include "chrome/browser/chromeos/options/network_config_view.h"
61 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
62 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
63 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
64 #include "chrome/browser/chromeos/profiles/profile_helper.h"
65 #include "chrome/browser/chromeos/set_time_dialog.h"
66 #include "chrome/browser/chromeos/settings/cros_settings.h"
67 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
68 #include "chrome/browser/lifetime/application_lifetime.h"
69 #include "chrome/browser/profiles/profile_manager.h"
70 #include "chrome/browser/supervised_user/supervised_user_service.h"
71 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
72 #include "chrome/browser/ui/ash/cast_config_delegate_chromeos.h"
73 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
74 #include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h"
75 #include "chrome/browser/ui/ash/system_tray_delegate_utils.h"
76 #include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h"
77 #include "chrome/browser/ui/ash/volume_controller_chromeos.h"
78 #include "chrome/browser/ui/ash/vpn_delegate_chromeos.h"
79 #include "chrome/browser/ui/browser.h"
80 #include "chrome/browser/ui/browser_finder.h"
81 #include "chrome/browser/ui/browser_list.h"
82 #include "chrome/browser/ui/chrome_pages.h"
83 #include "chrome/browser/ui/host_desktop.h"
84 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
85 #include "chrome/browser/ui/singleton_tabs.h"
86 #include "chrome/browser/ui/tabs/tab_strip_model.h"
87 #include "chrome/browser/upgrade_detector.h"
88 #include "chrome/common/chrome_switches.h"
89 #include "chrome/common/pref_names.h"
90 #include "chrome/common/url_constants.h"
91 #include "chrome/grit/generated_resources.h"
92 #include "chrome/grit/locale_settings.h"
93 #include "chromeos/dbus/dbus_thread_manager.h"
94 #include "chromeos/dbus/session_manager_client.h"
95 #include "chromeos/login/login_state.h"
96 #include "chromeos/network/portal_detector/network_portal_detector.h"
97 #include "components/google/core/browser/google_util.h"
98 #include "components/policy/core/common/cloud/cloud_policy_store.h"
99 #include "components/user_manager/user.h"
100 #include "components/user_manager/user_manager.h"
101 #include "components/user_manager/user_type.h"
102 #include "content/public/browser/notification_observer.h"
103 #include "content/public/browser/notification_service.h"
104 #include "content/public/browser/user_metrics.h"
105 #include "content/public/browser/web_contents.h"
106 #include "device/bluetooth/bluetooth_adapter.h"
107 #include "device/bluetooth/bluetooth_adapter_factory.h"
108 #include "device/bluetooth/bluetooth_device.h"
109 #include "net/base/escape.h"
110 #include "third_party/cros_system_api/dbus/service_constants.h"
111 #include "ui/base/ime/chromeos/extension_ime_util.h"
112 #include "ui/base/ime/chromeos/ime_keyboard.h"
113 #include "ui/base/ime/chromeos/input_method_manager.h"
114 #include "ui/base/l10n/l10n_util.h"
115 #include "ui/base/l10n/time_format.h"
116 #include "ui/chromeos/ime/input_method_menu_item.h"
117 #include "ui/chromeos/ime/input_method_menu_manager.h"
119 #if defined(ENABLE_SUPERVISED_USERS)
120 #include "chrome/browser/supervised_user/supervised_user_service.h"
121 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
128 // The minimum session length limit that can be set.
129 const int kSessionLengthLimitMinMs
= 30 * 1000; // 30 seconds.
131 // The maximum session length limit that can be set.
132 const int kSessionLengthLimitMaxMs
= 24 * 60 * 60 * 1000; // 24 hours.
134 const char kDisplaySettingsSubPageName
[] = "display";
135 const char kDisplayOverscanSettingsSubPageName
[] = "displayOverscan";
137 void ExtractIMEInfo(const input_method::InputMethodDescriptor
& ime
,
138 const input_method::InputMethodUtil
& util
,
139 ash::IMEInfo
* info
) {
141 info
->name
= util
.GetInputMethodLongName(ime
);
142 info
->medium_name
= util
.GetInputMethodMediumName(ime
);
143 info
->short_name
= util
.GetInputMethodShortName(ime
);
144 info
->third_party
= extension_ime_util::IsExtensionIME(ime
.id());
147 gfx::NativeWindow
GetNativeWindowByStatus(ash::user::LoginStatus login_status
,
148 bool session_started
) {
149 bool isUserAddingRunning
= ash::Shell::GetInstance()
150 ->session_state_delegate()
151 ->IsInSecondaryLoginScreen();
154 (!session_started
|| login_status
== ash::user::LOGGED_IN_NONE
||
155 login_status
== ash::user::LOGGED_IN_LOCKED
|| isUserAddingRunning
)
156 ? ash::kShellWindowId_LockSystemModalContainer
157 : ash::kShellWindowId_SystemModalContainer
;
158 return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
162 void BluetoothSetDiscoveringError() {
163 LOG(ERROR
) << "BluetoothSetDiscovering failed.";
166 void BluetoothDeviceConnectError(
167 device::BluetoothDevice::ConnectErrorCode error_code
) {
170 void ShowSettingsSubPageForActiveUser(const std::string
& sub_page
) {
171 chrome::ShowSettingsSubPageForProfile(
172 ProfileManager::GetActiveUserProfile(), sub_page
);
175 void OnAcceptMultiprofilesIntro(bool no_show_again
) {
176 PrefService
* prefs
= ProfileManager::GetActiveUserProfile()->GetPrefs();
177 prefs
->SetBoolean(prefs::kMultiProfileNeverShowIntro
, no_show_again
);
178 UserAddingScreen::Get()->Start();
183 SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
184 : user_profile_(NULL
),
185 clock_type_(base::GetHourClockType()),
186 search_key_mapped_to_(input_method::kSearchKey
),
187 screen_locked_(false),
188 have_session_start_time_(false),
189 have_session_length_limit_(false),
190 should_run_bluetooth_discovery_(false),
191 session_started_(false),
192 cast_config_delegate_(new CastConfigDelegateChromeos()),
193 networking_config_delegate_(new NetworkingConfigDelegateChromeos()),
194 volume_control_delegate_(new VolumeController()),
195 vpn_delegate_(new VPNDelegateChromeOS
),
196 weak_ptr_factory_(this) {
197 // Register notifications on construction so that events such as
198 // PROFILE_CREATED do not get missed if they happen before Initialize().
199 registrar_
.reset(new content::NotificationRegistrar
);
200 registrar_
->Add(this,
201 chrome::NOTIFICATION_UPGRADE_RECOMMENDED
,
202 content::NotificationService::AllSources());
203 registrar_
->Add(this,
204 chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
,
205 content::NotificationService::AllSources());
206 if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE
) {
207 registrar_
->Add(this,
208 chrome::NOTIFICATION_SESSION_STARTED
,
209 content::NotificationService::AllSources());
211 registrar_
->Add(this,
212 chrome::NOTIFICATION_PROFILE_CREATED
,
213 content::NotificationService::AllSources());
214 registrar_
->Add(this,
215 chrome::NOTIFICATION_PROFILE_DESTROYED
,
216 content::NotificationService::AllSources());
218 AccessibilityManager
* accessibility_manager
= AccessibilityManager::Get();
219 CHECK(accessibility_manager
);
220 accessibility_subscription_
= accessibility_manager
->RegisterCallback(
221 base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged
,
222 base::Unretained(this)));
224 user_manager::UserManager::Get()->AddSessionStateObserver(this);
225 shutdown_policy_handler_
.reset(
226 new ShutdownPolicyHandler(CrosSettings::Get(), this));
229 void SystemTrayDelegateChromeOS::Initialize() {
230 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
232 input_method::InputMethodManager::Get()->AddObserver(this);
233 ui::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
235 g_browser_process
->platform_part()->GetSystemClock()->AddObserver(this);
237 OnSystemClockChanged(g_browser_process
->platform_part()->GetSystemClock());
239 device::BluetoothAdapterFactory::GetAdapter(
240 base::Bind(&SystemTrayDelegateChromeOS::InitializeOnAdapterReady
,
241 weak_ptr_factory_
.GetWeakPtr()));
243 ash::Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(
246 if (CrasAudioHandler::IsInitialized())
247 CrasAudioHandler::Get()->AddAudioObserver(this);
249 BrowserList::AddObserver(this);
252 void SystemTrayDelegateChromeOS::Shutdown() {
255 void SystemTrayDelegateChromeOS::InitializeOnAdapterReady(
256 scoped_refptr
<device::BluetoothAdapter
> adapter
) {
257 bluetooth_adapter_
= adapter
;
258 CHECK(bluetooth_adapter_
.get());
259 bluetooth_adapter_
->AddObserver(this);
261 local_state_registrar_
.reset(new PrefChangeRegistrar
);
262 local_state_registrar_
->Init(g_browser_process
->local_state());
264 UpdateSessionStartTime();
265 UpdateSessionLengthLimit();
267 local_state_registrar_
->Add(
268 prefs::kSessionStartTime
,
269 base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionStartTime
,
270 base::Unretained(this)));
271 local_state_registrar_
->Add(
272 prefs::kSessionLengthLimit
,
273 base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionLengthLimit
,
274 base::Unretained(this)));
276 policy::BrowserPolicyConnectorChromeOS
* policy_connector
=
277 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
278 policy::DeviceCloudPolicyManagerChromeOS
* policy_manager
=
279 policy_connector
->GetDeviceCloudPolicyManager();
281 policy_manager
->core()->store()->AddObserver(this);
282 UpdateEnterpriseDomain();
285 SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
286 // Unregister PrefChangeRegistrars.
287 local_state_registrar_
.reset();
288 user_pref_registrar_
.reset();
290 // Unregister content notifications before destroying any components.
293 // Unregister a11y status subscription.
294 accessibility_subscription_
.reset();
296 g_browser_process
->platform_part()->GetSystemClock()->RemoveObserver(this);
297 DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
298 input_method::InputMethodManager::Get()->RemoveObserver(this);
299 ui::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this);
300 bluetooth_adapter_
->RemoveObserver(this);
301 ash::Shell::GetInstance()
302 ->session_state_delegate()
303 ->RemoveSessionStateObserver(this);
305 if (CrasAudioHandler::IsInitialized())
306 CrasAudioHandler::Get()->RemoveAudioObserver(this);
308 BrowserList::RemoveObserver(this);
309 StopObservingAppWindowRegistry();
310 StopObservingCustodianInfoChanges();
312 policy::BrowserPolicyConnectorChromeOS
* connector
=
313 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
314 policy::DeviceCloudPolicyManagerChromeOS
* policy_manager
=
315 connector
->GetDeviceCloudPolicyManager();
317 policy_manager
->core()->store()->RemoveObserver(this);
319 user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
322 // Overridden from ash::SystemTrayDelegate:
323 bool SystemTrayDelegateChromeOS::GetTrayVisibilityOnStartup() {
324 // In case of OOBE / sign in screen tray will be shown later.
325 return LoginState::Get()->IsUserLoggedIn();
328 ash::user::LoginStatus
SystemTrayDelegateChromeOS::GetUserLoginStatus() const {
329 // All non-logged in ChromeOS specific LOGGED_IN states map to the same
330 // Ash specific LOGGED_IN state.
331 if (!LoginState::Get()->IsUserLoggedIn())
332 return ash::user::LOGGED_IN_NONE
;
335 return ash::user::LOGGED_IN_LOCKED
;
337 LoginState::LoggedInUserType user_type
=
338 LoginState::Get()->GetLoggedInUserType();
340 case LoginState::LOGGED_IN_USER_NONE
:
341 return ash::user::LOGGED_IN_NONE
;
342 case LoginState::LOGGED_IN_USER_REGULAR
:
343 return ash::user::LOGGED_IN_USER
;
344 case LoginState::LOGGED_IN_USER_OWNER
:
345 return ash::user::LOGGED_IN_OWNER
;
346 case LoginState::LOGGED_IN_USER_GUEST
:
347 return ash::user::LOGGED_IN_GUEST
;
348 case LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT
:
349 return ash::user::LOGGED_IN_PUBLIC
;
350 case LoginState::LOGGED_IN_USER_SUPERVISED
:
351 return ash::user::LOGGED_IN_SUPERVISED
;
352 case LoginState::LOGGED_IN_USER_KIOSK_APP
:
353 return ash::user::LOGGED_IN_KIOSK_APP
;
356 return ash::user::LOGGED_IN_NONE
;
359 void SystemTrayDelegateChromeOS::ChangeProfilePicture() {
360 content::RecordAction(
361 base::UserMetricsAction("OpenChangeProfilePictureDialog"));
362 ShowSettingsSubPageForActiveUser(chrome::kChangeProfilePictureSubPage
);
365 std::string
SystemTrayDelegateChromeOS::GetEnterpriseDomain() const {
366 return enterprise_domain_
;
369 const base::string16
SystemTrayDelegateChromeOS::GetEnterpriseMessage() const {
370 if (GetEnterpriseDomain().empty())
371 return base::string16();
372 return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE
,
373 base::UTF8ToUTF16(GetEnterpriseDomain()));
376 const std::string
SystemTrayDelegateChromeOS::GetSupervisedUserManager() const {
377 if (!IsUserSupervised())
378 return std::string();
379 return SupervisedUserServiceFactory::GetForProfile(user_profile_
)->
380 GetCustodianEmailAddress();
384 SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const {
385 if (!IsUserSupervised())
386 return base::string16();
387 return base::UTF8ToUTF16(SupervisedUserServiceFactory::GetForProfile(
388 user_profile_
)->GetCustodianName());
391 const base::string16
SystemTrayDelegateChromeOS::GetSupervisedUserMessage()
393 if (!IsUserSupervised())
394 return base::string16();
396 return GetChildUserMessage();
397 return GetLegacySupervisedUserMessage();
400 bool SystemTrayDelegateChromeOS::IsUserSupervised() const {
401 user_manager::User
* user
= user_manager::UserManager::Get()->GetActiveUser();
402 return user
&& user
->IsSupervised();
405 bool SystemTrayDelegateChromeOS::IsUserChild() const {
406 return user_manager::UserManager::Get()->IsLoggedInAsChildUser();
409 void SystemTrayDelegateChromeOS::GetSystemUpdateInfo(
410 ash::UpdateInfo
* info
) const {
411 GetUpdateInfo(UpgradeDetector::GetInstance(), info
);
414 base::HourClockType
SystemTrayDelegateChromeOS::GetHourClockType() const {
418 void SystemTrayDelegateChromeOS::ShowSettings() {
419 ShowSettingsSubPageForActiveUser("");
422 bool SystemTrayDelegateChromeOS::ShouldShowSettings() {
423 return ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldShowSettings() &&
424 !ash::Shell::GetInstance()
425 ->session_state_delegate()
426 ->IsInSecondaryLoginScreen();
429 void SystemTrayDelegateChromeOS::ShowDateSettings() {
430 content::RecordAction(base::UserMetricsAction("ShowDateOptions"));
431 std::string sub_page
=
432 std::string(chrome::kSearchSubPage
) + "#" +
433 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME
);
434 // Everybody can change the time zone (even though it is a device setting).
435 ShowSettingsSubPageForActiveUser(sub_page
);
438 void SystemTrayDelegateChromeOS::ShowSetTimeDialog() {
439 SetTimeDialog::ShowDialog(GetNativeWindow());
442 void SystemTrayDelegateChromeOS::ShowNetworkSettingsForGuid(
443 const std::string
& guid
) {
444 bool userAddingRunning
= ash::Shell::GetInstance()
445 ->session_state_delegate()
446 ->IsInSecondaryLoginScreen();
448 if (!LoginState::Get()->IsUserLoggedIn() || userAddingRunning
)
450 std::string page
= chrome::kInternetOptionsSubPage
;
452 page
+= "?guid=" + net::EscapeUrlEncodedData(guid
, true);
453 content::RecordAction(base::UserMetricsAction("OpenInternetOptionsDialog"));
454 ShowSettingsSubPageForActiveUser(page
);
457 void SystemTrayDelegateChromeOS::ShowDisplaySettings() {
458 // TODO(michaelpg): Allow display settings to be shown when they are updated
459 // to work for 3+ displays. See issue 467195.
460 if (ash::Shell::GetInstance()->display_manager()->num_connected_displays() >
464 content::RecordAction(base::UserMetricsAction("ShowDisplayOptions"));
465 ShowSettingsSubPageForActiveUser(kDisplaySettingsSubPageName
);
468 void SystemTrayDelegateChromeOS::ShowChromeSlow() {
469 chrome::ScopedTabbedBrowserDisplayer
displayer(
470 ProfileManager::GetPrimaryUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH
);
471 chrome::ShowSlow(displayer
.browser());
474 bool SystemTrayDelegateChromeOS::ShouldShowDisplayNotification() {
475 // Packaged app is not counted as 'last active', so if a browser opening the
476 // display settings is in background of a packaged app, it will return true.
477 // TODO(mukai): fix this.
478 Browser
* active_browser
=
479 chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH
);
483 content::WebContents
* active_contents
=
484 active_browser
->tab_strip_model()->GetActiveWebContents();
485 if (!active_contents
)
488 GURL visible_url
= active_contents
->GetLastCommittedURL();
489 return !(chrome::IsSettingsSubPage(visible_url
,
490 kDisplaySettingsSubPageName
) ||
491 chrome::IsSettingsSubPage(visible_url
,
492 kDisplayOverscanSettingsSubPageName
));
495 void SystemTrayDelegateChromeOS::ShowIMESettings() {
496 content::RecordAction(base::UserMetricsAction("OpenLanguageOptionsDialog"));
497 ShowSettingsSubPageForActiveUser(chrome::kLanguageOptionsSubPage
);
500 void SystemTrayDelegateChromeOS::ShowHelp() {
501 chrome::ShowHelpForProfile(ProfileManager::GetActiveUserProfile(),
502 chrome::HOST_DESKTOP_TYPE_ASH
,
503 chrome::HELP_SOURCE_MENU
);
506 void SystemTrayDelegateChromeOS::ShowAccessibilityHelp() {
507 chrome::ScopedTabbedBrowserDisplayer
displayer(
508 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH
);
509 accessibility::ShowAccessibilityHelp(displayer
.browser());
512 void SystemTrayDelegateChromeOS::ShowAccessibilitySettings() {
513 content::RecordAction(base::UserMetricsAction("ShowAccessibilitySettings"));
514 std::string sub_page
= std::string(chrome::kSearchSubPage
) + "#" +
515 l10n_util::GetStringUTF8(
516 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY
);
517 ShowSettingsSubPageForActiveUser(sub_page
);
520 void SystemTrayDelegateChromeOS::ShowPublicAccountInfo() {
521 chrome::ScopedTabbedBrowserDisplayer
displayer(
522 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH
);
523 chrome::ShowPolicy(displayer
.browser());
526 void SystemTrayDelegateChromeOS::ShowSupervisedUserInfo() {
527 // TODO(antrim): find out what should we show in this case.
528 // http://crbug.com/229762
531 void SystemTrayDelegateChromeOS::ShowEnterpriseInfo() {
532 ash::user::LoginStatus status
= GetUserLoginStatus();
533 bool userAddingRunning
= ash::Shell::GetInstance()
534 ->session_state_delegate()
535 ->IsInSecondaryLoginScreen();
537 if (status
== ash::user::LOGGED_IN_NONE
||
538 status
== ash::user::LOGGED_IN_LOCKED
|| userAddingRunning
) {
539 scoped_refptr
<chromeos::HelpAppLauncher
> help_app(
540 new chromeos::HelpAppLauncher(GetNativeWindow()));
541 help_app
->ShowHelpTopic(chromeos::HelpAppLauncher::HELP_ENTERPRISE
);
543 chrome::ScopedTabbedBrowserDisplayer
displayer(
544 ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH
);
545 chrome::ShowSingletonTab(displayer
.browser(),
546 GURL(chrome::kLearnMoreEnterpriseURL
));
550 void SystemTrayDelegateChromeOS::ShowUserLogin() {
551 ash::Shell
* shell
= ash::Shell::GetInstance();
552 if (!shell
->delegate()->IsMultiProfilesEnabled())
555 // Only regular non-supervised users could add other users to current session.
556 if (user_manager::UserManager::Get()->GetActiveUser()->GetType() !=
557 user_manager::USER_TYPE_REGULAR
) {
561 if (static_cast<int>(
562 user_manager::UserManager::Get()->GetLoggedInUsers().size()) >=
563 shell
->session_state_delegate()->GetMaximumNumberOfLoggedInUsers())
566 // Launch sign in screen to add another user to current session.
567 if (user_manager::UserManager::Get()
568 ->GetUsersAllowedForMultiProfile()
570 // Don't show dialog if any logged in user in multi-profiles session
572 bool show_intro
= true;
573 const user_manager::UserList logged_in_users
=
574 user_manager::UserManager::Get()->GetLoggedInUsers();
575 for (user_manager::UserList::const_iterator it
= logged_in_users
.begin();
576 it
!= logged_in_users
.end();
578 show_intro
&= !multi_user_util::GetProfileFromUserID(
579 multi_user_util::GetUserIDFromEmail((*it
)->email()))
581 ->GetBoolean(prefs::kMultiProfileNeverShowIntro
);
586 base::Callback
<void(bool)> on_accept
=
587 base::Bind(&OnAcceptMultiprofilesIntro
);
588 ShowMultiprofilesIntroDialog(on_accept
);
590 UserAddingScreen::Get()->Start();
595 void SystemTrayDelegateChromeOS::SignOut() {
596 chrome::AttemptUserExit();
599 void SystemTrayDelegateChromeOS::RequestLockScreen() {
600 // TODO(antrim) : additional logging for crbug/173178
601 LOG(WARNING
) << "Requesting screen lock from AshSystemTrayDelegate";
602 DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
605 void SystemTrayDelegateChromeOS::RequestRestartForUpdate() {
606 // We expect that UpdateEngine is in "Reboot for update" state now.
607 chrome::NotifyAndTerminate(true /* fast path */);
610 void SystemTrayDelegateChromeOS::GetAvailableBluetoothDevices(
611 ash::BluetoothDeviceList
* list
) {
612 device::BluetoothAdapter::DeviceList devices
=
613 bluetooth_adapter_
->GetDevices();
614 for (size_t i
= 0; i
< devices
.size(); ++i
) {
615 device::BluetoothDevice
* device
= devices
[i
];
616 ash::BluetoothDeviceInfo info
;
617 info
.address
= device
->GetAddress();
618 info
.display_name
= device
->GetName();
619 info
.connected
= device
->IsConnected();
620 info
.connecting
= device
->IsConnecting();
621 info
.paired
= device
->IsPaired();
622 list
->push_back(info
);
626 void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() {
627 if (GetBluetoothDiscovering()) {
628 LOG(WARNING
) << "Already have active Bluetooth device discovery session.";
631 VLOG(1) << "Requesting new Bluetooth device discovery session.";
632 should_run_bluetooth_discovery_
= true;
633 bluetooth_adapter_
->StartDiscoverySession(
634 base::Bind(&SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession
,
635 weak_ptr_factory_
.GetWeakPtr()),
636 base::Bind(&BluetoothSetDiscoveringError
));
639 void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() {
640 should_run_bluetooth_discovery_
= false;
641 if (!GetBluetoothDiscovering()) {
642 LOG(WARNING
) << "No active Bluetooth device discovery session.";
645 VLOG(1) << "Stopping Bluetooth device discovery session.";
646 bluetooth_discovery_session_
->Stop(
647 base::Bind(&base::DoNothing
), base::Bind(&BluetoothSetDiscoveringError
));
650 void SystemTrayDelegateChromeOS::ConnectToBluetoothDevice(
651 const std::string
& address
) {
652 device::BluetoothDevice
* device
= bluetooth_adapter_
->GetDevice(address
);
653 if (!device
|| device
->IsConnecting() ||
654 (device
->IsConnected() && device
->IsPaired())) {
657 if (device
->IsPaired() && !device
->IsConnectable())
659 if (device
->IsPaired() || !device
->IsPairable()) {
660 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
661 ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE
);
662 device
->Connect(NULL
,
663 base::Bind(&base::DoNothing
),
664 base::Bind(&BluetoothDeviceConnectError
));
665 } else { // Show paring dialog for the unpaired device.
666 ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
667 ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE
);
668 BluetoothPairingDialog
* dialog
=
669 new BluetoothPairingDialog(GetNativeWindow(), device
);
670 // The dialog deletes itself on close.
675 bool SystemTrayDelegateChromeOS::IsBluetoothDiscovering() {
676 return bluetooth_adapter_
->IsDiscovering();
679 void SystemTrayDelegateChromeOS::GetCurrentIME(ash::IMEInfo
* info
) {
680 input_method::InputMethodManager
* manager
=
681 input_method::InputMethodManager::Get();
682 input_method::InputMethodUtil
* util
= manager
->GetInputMethodUtil();
683 input_method::InputMethodDescriptor ime
=
684 manager
->GetActiveIMEState()->GetCurrentInputMethod();
685 ExtractIMEInfo(ime
, *util
, info
);
686 info
->selected
= true;
689 void SystemTrayDelegateChromeOS::GetAvailableIMEList(ash::IMEInfoList
* list
) {
690 input_method::InputMethodManager
* manager
=
691 input_method::InputMethodManager::Get();
692 input_method::InputMethodUtil
* util
= manager
->GetInputMethodUtil();
693 scoped_ptr
<input_method::InputMethodDescriptors
> ime_descriptors(
694 manager
->GetActiveIMEState()->GetActiveInputMethods());
695 std::string current
=
696 manager
->GetActiveIMEState()->GetCurrentInputMethod().id();
697 for (size_t i
= 0; i
< ime_descriptors
->size(); i
++) {
698 input_method::InputMethodDescriptor
& ime
= ime_descriptors
->at(i
);
700 ExtractIMEInfo(ime
, *util
, &info
);
701 info
.selected
= ime
.id() == current
;
702 list
->push_back(info
);
706 void SystemTrayDelegateChromeOS::GetCurrentIMEProperties(
707 ash::IMEPropertyInfoList
* list
) {
708 ui::ime::InputMethodMenuItemList menu_list
=
709 ui::ime::InputMethodMenuManager::GetInstance()->
710 GetCurrentInputMethodMenuItemList();
711 for (size_t i
= 0; i
< menu_list
.size(); ++i
) {
712 ash::IMEPropertyInfo property
;
713 property
.key
= menu_list
[i
].key
;
714 property
.name
= base::UTF8ToUTF16(menu_list
[i
].label
);
715 property
.selected
= menu_list
[i
].is_selection_item_checked
;
716 list
->push_back(property
);
720 void SystemTrayDelegateChromeOS::SwitchIME(const std::string
& ime_id
) {
721 input_method::InputMethodManager::Get()
722 ->GetActiveIMEState()
723 ->ChangeInputMethod(ime_id
, false /* show_message */);
724 input_method::InputMethodSwitchRecorder::Get()->RecordSwitch(
725 true /* by_tray_menu */);
728 void SystemTrayDelegateChromeOS::ActivateIMEProperty(const std::string
& key
) {
729 input_method::InputMethodManager::Get()->ActivateInputMethodMenuItem(key
);
732 void SystemTrayDelegateChromeOS::ManageBluetoothDevices() {
733 content::RecordAction(base::UserMetricsAction("ShowBluetoothSettingsPage"));
734 std::string sub_page
=
735 std::string(chrome::kSearchSubPage
) + "#" +
736 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH
);
737 ShowSettingsSubPageForActiveUser(sub_page
);
740 void SystemTrayDelegateChromeOS::ToggleBluetooth() {
741 bluetooth_adapter_
->SetPowered(!bluetooth_adapter_
->IsPowered(),
742 base::Bind(&base::DoNothing
),
743 base::Bind(&base::DoNothing
));
746 void SystemTrayDelegateChromeOS::ShowOtherNetworkDialog(
747 const std::string
& type
) {
748 if (type
== shill::kTypeCellular
) {
749 ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
752 NetworkConfigView::ShowForType(type
, GetNativeWindow());
755 bool SystemTrayDelegateChromeOS::GetBluetoothAvailable() {
756 return bluetooth_adapter_
->IsPresent();
759 bool SystemTrayDelegateChromeOS::GetBluetoothEnabled() {
760 return bluetooth_adapter_
->IsPowered();
763 bool SystemTrayDelegateChromeOS::GetBluetoothDiscovering() {
764 return (bluetooth_discovery_session_
.get() &&
765 bluetooth_discovery_session_
->IsActive());
768 void SystemTrayDelegateChromeOS::ChangeProxySettings() {
769 CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE
);
770 LoginDisplayHostImpl::default_host()->OpenProxySettings();
773 ash::CastConfigDelegate
* SystemTrayDelegateChromeOS::GetCastConfigDelegate()
775 return cast_config_delegate_
.get();
778 ash::NetworkingConfigDelegate
*
779 SystemTrayDelegateChromeOS::GetNetworkingConfigDelegate() const {
780 return networking_config_delegate_
.get();
783 ash::VolumeControlDelegate
*
784 SystemTrayDelegateChromeOS::GetVolumeControlDelegate() const {
785 return volume_control_delegate_
.get();
788 void SystemTrayDelegateChromeOS::SetVolumeControlDelegate(
789 scoped_ptr
<ash::VolumeControlDelegate
> delegate
) {
790 volume_control_delegate_
.swap(delegate
);
793 bool SystemTrayDelegateChromeOS::GetSessionStartTime(
794 base::TimeTicks
* session_start_time
) {
795 *session_start_time
= session_start_time_
;
796 return have_session_start_time_
;
799 bool SystemTrayDelegateChromeOS::GetSessionLengthLimit(
800 base::TimeDelta
* session_length_limit
) {
801 *session_length_limit
= session_length_limit_
;
802 return have_session_length_limit_
;
805 int SystemTrayDelegateChromeOS::GetSystemTrayMenuWidth() {
806 return l10n_util::GetLocalizedContentsWidthInPixels(
807 IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS
);
810 void SystemTrayDelegateChromeOS::ActiveUserWasChanged() {
811 SetProfile(ProfileManager::GetActiveUserProfile());
812 GetSystemTrayNotifier()->NotifyUserUpdate();
815 bool SystemTrayDelegateChromeOS::IsSearchKeyMappedToCapsLock() {
816 return search_key_mapped_to_
== input_method::kCapsLockKey
;
819 ash::tray::UserAccountsDelegate
*
820 SystemTrayDelegateChromeOS::GetUserAccountsDelegate(
821 const std::string
& user_id
) {
822 if (!accounts_delegates_
.contains(user_id
)) {
823 const user_manager::User
* user
=
824 user_manager::UserManager::Get()->FindUser(user_id
);
825 Profile
* user_profile
= ProfileHelper::Get()->GetProfileByUserUnsafe(user
);
827 accounts_delegates_
.set(
829 scoped_ptr
<ash::tray::UserAccountsDelegate
>(
830 new UserAccountsDelegateChromeOS(user_profile
)));
832 return accounts_delegates_
.get(user_id
);
835 void SystemTrayDelegateChromeOS::AddCustodianInfoTrayObserver(
836 ash::CustodianInfoTrayObserver
* observer
) {
837 custodian_info_changed_observers_
.AddObserver(observer
);
840 void SystemTrayDelegateChromeOS::RemoveCustodianInfoTrayObserver(
841 ash::CustodianInfoTrayObserver
* observer
) {
842 custodian_info_changed_observers_
.RemoveObserver(observer
);
845 void SystemTrayDelegateChromeOS::AddShutdownPolicyObserver(
846 ash::ShutdownPolicyObserver
* observer
) {
847 shutdown_policy_observers_
.AddObserver(observer
);
850 void SystemTrayDelegateChromeOS::RemoveShutdownPolicyObserver(
851 ash::ShutdownPolicyObserver
* observer
) {
852 shutdown_policy_observers_
.RemoveObserver(observer
);
855 void SystemTrayDelegateChromeOS::ShouldRebootOnShutdown(
856 const ash::RebootOnShutdownCallback
& callback
) {
857 shutdown_policy_handler_
->CheckIfRebootOnShutdown(callback
);
860 ash::VPNDelegate
* SystemTrayDelegateChromeOS::GetVPNDelegate() const {
861 return vpn_delegate_
.get();
864 void SystemTrayDelegateChromeOS::UserAddedToSession(
865 const user_manager::User
* active_user
) {
868 void SystemTrayDelegateChromeOS::ActiveUserChanged(
869 const user_manager::User
* /* active_user */) {
872 void SystemTrayDelegateChromeOS::UserChangedChildStatus(
873 user_manager::User
* user
) {
874 Profile
* user_profile
= ProfileHelper::Get()->GetProfileByUser(user
);
876 // Returned user_profile might be NULL on restoring Users on browser start.
877 // At some point profile is not yet fully initiated.
878 if (session_started_
&&
879 user_profile
!= NULL
&&
880 user_profile_
== user_profile
) {
881 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
882 GetUserLoginStatus());
886 ash::SystemTray
* SystemTrayDelegateChromeOS::GetPrimarySystemTray() {
887 return ash::Shell::GetInstance()->GetPrimarySystemTray();
890 ash::SystemTrayNotifier
* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
891 return ash::Shell::GetInstance()->system_tray_notifier();
894 void SystemTrayDelegateChromeOS::SetProfile(Profile
* profile
) {
895 // Stop observing the AppWindowRegistry of the current |user_profile_|.
896 StopObservingAppWindowRegistry();
898 // Stop observing custodian info changes of the current |user_profile_|.
899 StopObservingCustodianInfoChanges();
901 user_profile_
= profile
;
903 // Start observing the AppWindowRegistry of the newly set |user_profile_|.
904 extensions::AppWindowRegistry::Get(user_profile_
)->AddObserver(this);
906 // Start observing custodian info changes of the newly set |user_profile_|.
907 SupervisedUserServiceFactory::GetForProfile(profile
)->AddObserver(this);
909 PrefService
* prefs
= profile
->GetPrefs();
910 user_pref_registrar_
.reset(new PrefChangeRegistrar
);
911 user_pref_registrar_
->Init(prefs
);
912 user_pref_registrar_
->Add(
913 prefs::kLanguageRemapSearchKeyTo
,
914 base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged
,
915 base::Unretained(this)));
916 user_pref_registrar_
->Add(
917 prefs::kShowLogoutButtonInTray
,
918 base::Bind(&SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray
,
919 base::Unretained(this)));
920 user_pref_registrar_
->Add(
921 prefs::kLogoutDialogDurationMs
,
922 base::Bind(&SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration
,
923 base::Unretained(this)));
924 user_pref_registrar_
->Add(
925 prefs::kAccessibilityLargeCursorEnabled
,
926 base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged
,
927 base::Unretained(this),
928 ui::A11Y_NOTIFICATION_NONE
));
929 user_pref_registrar_
->Add(
930 prefs::kAccessibilityAutoclickEnabled
,
931 base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged
,
932 base::Unretained(this),
933 ui::A11Y_NOTIFICATION_NONE
));
934 user_pref_registrar_
->Add(
935 prefs::kShouldAlwaysShowAccessibilityMenu
,
936 base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged
,
937 base::Unretained(this),
938 ui::A11Y_NOTIFICATION_NONE
));
939 user_pref_registrar_
->Add(
940 prefs::kPerformanceTracingEnabled
,
941 base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing
,
942 base::Unretained(this)));
944 UpdateShowLogoutButtonInTray();
945 UpdateLogoutDialogDuration();
946 UpdatePerformanceTracing();
947 OnCustodianInfoChanged();
948 search_key_mapped_to_
=
949 profile
->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo
);
952 bool SystemTrayDelegateChromeOS::UnsetProfile(Profile
* profile
) {
953 if (profile
!= user_profile_
)
955 user_pref_registrar_
.reset();
956 user_profile_
= NULL
;
960 bool SystemTrayDelegateChromeOS::GetShouldUse24HourClockForTesting() const {
961 return g_browser_process
->platform_part()
963 ->ShouldUse24HourClock();
966 void SystemTrayDelegateChromeOS::OnSystemClockChanged(
967 system::SystemClock
* system_clock
) {
968 const bool use_24_hour_clock
= system_clock
->ShouldUse24HourClock();
969 clock_type_
= use_24_hour_clock
? base::k24HourClock
: base::k12HourClock
;
970 GetSystemTrayNotifier()->NotifyDateFormatChanged();
973 void SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray() {
974 GetSystemTrayNotifier()->NotifyShowLoginButtonChanged(
975 user_pref_registrar_
->prefs()->GetBoolean(
976 prefs::kShowLogoutButtonInTray
));
979 void SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration() {
980 const int duration_ms
=
981 user_pref_registrar_
->prefs()->GetInteger(prefs::kLogoutDialogDurationMs
);
982 GetSystemTrayNotifier()->NotifyLogoutDialogDurationChanged(
983 base::TimeDelta::FromMilliseconds(duration_ms
));
986 void SystemTrayDelegateChromeOS::UpdateSessionStartTime() {
987 const PrefService
* local_state
= local_state_registrar_
->prefs();
988 if (local_state
->HasPrefPath(prefs::kSessionStartTime
)) {
989 have_session_start_time_
= true;
990 session_start_time_
= base::TimeTicks::FromInternalValue(
991 local_state
->GetInt64(prefs::kSessionStartTime
));
993 have_session_start_time_
= false;
994 session_start_time_
= base::TimeTicks();
996 GetSystemTrayNotifier()->NotifySessionStartTimeChanged();
999 void SystemTrayDelegateChromeOS::UpdateSessionLengthLimit() {
1000 const PrefService
* local_state
= local_state_registrar_
->prefs();
1001 if (local_state
->HasPrefPath(prefs::kSessionLengthLimit
)) {
1002 have_session_length_limit_
= true;
1003 session_length_limit_
= base::TimeDelta::FromMilliseconds(
1004 std::min(std::max(local_state
->GetInteger(prefs::kSessionLengthLimit
),
1005 kSessionLengthLimitMinMs
),
1006 kSessionLengthLimitMaxMs
));
1008 have_session_length_limit_
= false;
1009 session_length_limit_
= base::TimeDelta();
1011 GetSystemTrayNotifier()->NotifySessionLengthLimitChanged();
1014 void SystemTrayDelegateChromeOS::StopObservingAppWindowRegistry() {
1018 extensions::AppWindowRegistry
* registry
=
1019 extensions::AppWindowRegistry::Factory::GetForBrowserContext(
1020 user_profile_
, false);
1022 registry
->RemoveObserver(this);
1025 void SystemTrayDelegateChromeOS::StopObservingCustodianInfoChanges() {
1029 SupervisedUserService
* service
= SupervisedUserServiceFactory::GetForProfile(
1032 service
->RemoveObserver(this);
1035 void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() {
1039 BrowserList
* browser_list
=
1040 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH
);
1041 for (BrowserList::const_iterator it
= browser_list
->begin();
1042 it
!= browser_list
->end();
1044 if ((*it
)->profile()->IsSameProfile(user_profile_
)) {
1045 // The current user has at least one open browser window.
1050 if (!extensions::AppWindowRegistry::Get(
1051 user_profile_
)->app_windows().empty()) {
1052 // The current user has at least one open app window.
1056 GetSystemTrayNotifier()->NotifyLastWindowClosed();
1059 // Overridden from SessionManagerClient::Observer.
1060 void SystemTrayDelegateChromeOS::ScreenIsLocked() {
1061 screen_locked_
= true;
1062 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
1065 void SystemTrayDelegateChromeOS::ScreenIsUnlocked() {
1066 screen_locked_
= false;
1067 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
1070 gfx::NativeWindow
SystemTrayDelegateChromeOS::GetNativeWindow() const {
1071 bool session_started
= ash::Shell::GetInstance()
1072 ->session_state_delegate()
1073 ->IsActiveUserSessionStarted();
1074 return GetNativeWindowByStatus(GetUserLoginStatus(), session_started
);
1077 // content::NotificationObserver implementation.
1078 void SystemTrayDelegateChromeOS::Observe(
1080 const content::NotificationSource
& source
,
1081 const content::NotificationDetails
& details
) {
1083 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED
: {
1084 ash::UpdateInfo info
;
1085 GetUpdateInfo(content::Source
<UpgradeDetector
>(source
).ptr(), &info
);
1086 GetSystemTrayNotifier()->NotifyUpdateRecommended(info
);
1089 case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED
: {
1090 // This notification is also sent on login screen when user avatar
1091 // is loaded from file.
1092 if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE
) {
1093 GetSystemTrayNotifier()->NotifyUserUpdate();
1097 case chrome::NOTIFICATION_PROFILE_CREATED
: {
1098 SetProfile(content::Source
<Profile
>(source
).ptr());
1099 registrar_
->Remove(this,
1100 chrome::NOTIFICATION_PROFILE_CREATED
,
1101 content::NotificationService::AllSources());
1104 case chrome::NOTIFICATION_PROFILE_DESTROYED
: {
1105 if (UnsetProfile(content::Source
<Profile
>(source
).ptr())) {
1106 registrar_
->Remove(this,
1107 chrome::NOTIFICATION_PROFILE_DESTROYED
,
1108 content::NotificationService::AllSources());
1112 case chrome::NOTIFICATION_SESSION_STARTED
: {
1113 session_started_
= true;
1114 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
1115 GetUserLoginStatus());
1116 SetProfile(ProfileManager::GetActiveUserProfile());
1124 void SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged() {
1125 search_key_mapped_to_
= user_pref_registrar_
->prefs()->GetInteger(
1126 prefs::kLanguageRemapSearchKeyTo
);
1129 void SystemTrayDelegateChromeOS::OnAccessibilityModeChanged(
1130 ui::AccessibilityNotificationVisibility notify
) {
1131 GetSystemTrayNotifier()->NotifyAccessibilityModeChanged(notify
);
1134 void SystemTrayDelegateChromeOS::UpdatePerformanceTracing() {
1135 if (!user_pref_registrar_
)
1137 bool value
= user_pref_registrar_
->prefs()->GetBoolean(
1138 prefs::kPerformanceTracingEnabled
);
1139 GetSystemTrayNotifier()->NotifyTracingModeChanged(value
);
1142 // Overridden from InputMethodManager::Observer.
1143 void SystemTrayDelegateChromeOS::InputMethodChanged(
1144 input_method::InputMethodManager
* manager
,
1145 Profile
* /* profile */,
1146 bool show_message
) {
1147 GetSystemTrayNotifier()->NotifyRefreshIME();
1150 // Overridden from InputMethodMenuManager::Observer.
1151 void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged(
1152 ui::ime::InputMethodMenuManager
* manager
) {
1153 GetSystemTrayNotifier()->NotifyRefreshIME();
1156 // Overridden from CrasAudioHandler::AudioObserver.
1157 void SystemTrayDelegateChromeOS::OnOutputNodeVolumeChanged(uint64_t node_id
,
1159 GetSystemTrayNotifier()->NotifyAudioOutputVolumeChanged(node_id
, volume
);
1162 void SystemTrayDelegateChromeOS::OnOutputMuteChanged(bool mute_on
,
1163 bool system_adjust
) {
1164 GetSystemTrayNotifier()->NotifyAudioOutputMuteChanged(mute_on
, system_adjust
);
1167 void SystemTrayDelegateChromeOS::OnInputNodeGainChanged(uint64_t /* node_id */,
1171 void SystemTrayDelegateChromeOS::OnInputMuteChanged(bool /* mute_on */) {
1174 void SystemTrayDelegateChromeOS::OnAudioNodesChanged() {
1175 GetSystemTrayNotifier()->NotifyAudioNodesChanged();
1178 void SystemTrayDelegateChromeOS::OnActiveOutputNodeChanged() {
1179 GetSystemTrayNotifier()->NotifyAudioActiveOutputNodeChanged();
1182 void SystemTrayDelegateChromeOS::OnActiveInputNodeChanged() {
1183 GetSystemTrayNotifier()->NotifyAudioActiveInputNodeChanged();
1186 // Overridden from BluetoothAdapter::Observer.
1187 void SystemTrayDelegateChromeOS::AdapterPresentChanged(
1188 device::BluetoothAdapter
* adapter
,
1190 GetSystemTrayNotifier()->NotifyRefreshBluetooth();
1193 void SystemTrayDelegateChromeOS::AdapterPoweredChanged(
1194 device::BluetoothAdapter
* adapter
,
1196 GetSystemTrayNotifier()->NotifyRefreshBluetooth();
1199 void SystemTrayDelegateChromeOS::AdapterDiscoveringChanged(
1200 device::BluetoothAdapter
* adapter
,
1202 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
1205 void SystemTrayDelegateChromeOS::DeviceAdded(device::BluetoothAdapter
* adapter
,
1206 device::BluetoothDevice
* device
) {
1207 GetSystemTrayNotifier()->NotifyRefreshBluetooth();
1210 void SystemTrayDelegateChromeOS::DeviceChanged(
1211 device::BluetoothAdapter
* adapter
,
1212 device::BluetoothDevice
* device
) {
1213 GetSystemTrayNotifier()->NotifyRefreshBluetooth();
1216 void SystemTrayDelegateChromeOS::DeviceRemoved(
1217 device::BluetoothAdapter
* adapter
,
1218 device::BluetoothDevice
* device
) {
1219 GetSystemTrayNotifier()->NotifyRefreshBluetooth();
1222 void SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession(
1223 scoped_ptr
<device::BluetoothDiscoverySession
> discovery_session
) {
1224 // If the discovery session was returned after a request to stop discovery
1225 // (e.g. the user dismissed the Bluetooth detailed view before the call
1226 // returned), don't claim the discovery session and let it clean up.
1227 if (!should_run_bluetooth_discovery_
)
1229 VLOG(1) << "Claiming new Bluetooth device discovery session.";
1230 bluetooth_discovery_session_
= discovery_session
.Pass();
1231 GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
1234 void SystemTrayDelegateChromeOS::UpdateEnterpriseDomain() {
1235 policy::BrowserPolicyConnectorChromeOS
* connector
=
1236 g_browser_process
->platform_part()->browser_policy_connector_chromeos();
1237 std::string enterprise_domain
= connector
->GetEnterpriseDomain();
1238 if (enterprise_domain_
!= enterprise_domain
) {
1239 enterprise_domain_
= enterprise_domain
;
1240 GetSystemTrayNotifier()->NotifyEnterpriseDomainChanged();
1244 // Overridden from CloudPolicyStore::Observer
1245 void SystemTrayDelegateChromeOS::OnStoreLoaded(
1246 policy::CloudPolicyStore
* store
) {
1247 UpdateEnterpriseDomain();
1250 void SystemTrayDelegateChromeOS::OnStoreError(policy::CloudPolicyStore
* store
) {
1251 UpdateEnterpriseDomain();
1254 // Overridden from ash::SessionStateObserver
1255 void SystemTrayDelegateChromeOS::UserAddedToSession(
1256 const std::string
& user_id
) {
1257 GetSystemTrayNotifier()->NotifyUserAddedToSession();
1260 void SystemTrayDelegateChromeOS::ActiveUserChanged(
1261 const std::string
& /* user_id */) {
1264 // Overridden from chrome::BrowserListObserver.
1265 void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser
* browser
) {
1266 NotifyIfLastWindowClosed();
1269 // Overridden from extensions::AppWindowRegistry::Observer.
1270 void SystemTrayDelegateChromeOS::OnAppWindowRemoved(
1271 extensions::AppWindow
* app_window
) {
1272 NotifyIfLastWindowClosed();
1275 // Overridden from SupervisedUserServiceObserver.
1276 void SystemTrayDelegateChromeOS::OnCustodianInfoChanged() {
1278 ash::CustodianInfoTrayObserver
, custodian_info_changed_observers_
,
1279 OnCustodianInfoChanged());
1282 void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged(
1283 const AccessibilityStatusEventDetails
& details
) {
1284 if (details
.notification_type
== ACCESSIBILITY_MANAGER_SHUTDOWN
)
1285 accessibility_subscription_
.reset();
1287 OnAccessibilityModeChanged(details
.notify
);
1290 void SystemTrayDelegateChromeOS::OnShutdownPolicyChanged(
1291 bool reboot_on_shutdown
) {
1292 // Notify all observers.
1293 FOR_EACH_OBSERVER(ash::ShutdownPolicyObserver
, shutdown_policy_observers_
,
1294 OnShutdownPolicyChanged(reboot_on_shutdown
));
1297 const base::string16
1298 SystemTrayDelegateChromeOS::GetLegacySupervisedUserMessage() const {
1299 std::string user_manager_name
= GetSupervisedUserManager();
1300 return l10n_util::GetStringFUTF16(
1301 IDS_USER_IS_SUPERVISED_BY_NOTICE
,
1302 base::UTF8ToUTF16(user_manager_name
));
1305 const base::string16
1306 SystemTrayDelegateChromeOS::GetChildUserMessage() const {
1307 #if defined(ENABLE_SUPERVISED_USERS)
1308 SupervisedUserService
* service
=
1309 SupervisedUserServiceFactory::GetForProfile(user_profile_
);
1310 base::string16 first_custodian
=
1311 base::UTF8ToUTF16(service
->GetCustodianEmailAddress());
1312 base::string16 second_custodian
=
1313 base::UTF8ToUTF16(service
->GetSecondCustodianEmailAddress());
1314 LOG_IF(WARNING
, first_custodian
.empty()) <<
1315 "Returning incomplete child user message as manager not known yet.";
1316 if (second_custodian
.empty()) {
1317 return l10n_util::GetStringFUTF16(
1318 IDS_CHILD_USER_IS_MANAGED_BY_ONE_PARENT_NOTICE
, first_custodian
);
1320 return l10n_util::GetStringFUTF16(
1321 IDS_CHILD_USER_IS_MANAGED_BY_TWO_PARENTS_NOTICE
,
1327 LOG(WARNING
) << "SystemTrayDelegateChromeOS::GetChildUserMessage call while "
1328 << "ENABLE_SUPERVISED_USERS undefined.";
1329 return base::string16();
1332 ash::SystemTrayDelegate
* CreateSystemTrayDelegate() {
1333 return new SystemTrayDelegateChromeOS();
1336 } // namespace chromeos