1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <algorithm>
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <set>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/ash_switches.h"
13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/desktop_background/desktop_background_controller.h"
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/ime/input_method_menu_item.h"
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/ime/input_method_menu_manager.h"
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/metrics/user_metrics_recorder.h"
175c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_delegate.h"
185c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "ash/session/session_state_observer.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shell_delegate.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_window_ids.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/bluetooth/bluetooth_observer.h"
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/session/logout_button_observer.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/date/clock_observer.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/ime/ime_observer.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray_accessibility.h"
3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/system/user/login_status.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/user/update_observer.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/user/user_observer.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/volume_control_delegate.h"
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/wm/lock_state_controller.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind_helpers.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h"
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
405e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/stringprintf.h"
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/sys_info.h"
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_process.h"
457dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h"
46868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/charger_replace/charger_replacement_dialog.h"
503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/chromeos/enrollment_dialog_view.h"
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/events/system_key_event_listener.h"
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/input_method/input_method_util.h"
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/login/help_app_launcher.h"
55c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/login/login_wizard.h"
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/chromeos/login/ui/login_display_host.h"
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/chromeos/login/user_flow.h"
606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/options/network_config_view.h"
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chrome/browser/chromeos/profiles/profile_helper.h"
675c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/chromeos/set_time_dialog.h"
68bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "chrome/browser/chromeos/settings/cros_settings.h"
6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/sim_dialog_delegate.h"
700529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/lifetime/application_lifetime.h"
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
74cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h"
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/ash/volume_controller_chromeos.h"
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h"
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/chrome_pages.h"
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/singleton_tabs.h"
83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/ui/tabs/tab_strip_model.h"
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/upgrade_detector.h"
87effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/common/chrome_switches.h"
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h"
901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/generated_resources.h"
911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/locale_settings.h"
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/dbus_thread_manager.h"
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/session_manager_client.h"
94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/ime/extension_ime_util.h"
95a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chromeos/ime/ime_keyboard.h"
96c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/ime/input_method_manager.h"
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/login/login_state.h"
98116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "chromeos/network/portal_detector/network_portal_detector.h"
996d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/google/core/browser/google_util.h"
100a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/cloud/cloud_policy_store.h"
1015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/user_manager/user.h"
1026e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "components/user_manager/user_manager.h"
103116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "components/user_manager/user_type.h"
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/user_metrics.h"
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/browser/web_contents.h"
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_adapter.h"
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_adapter_factory.h"
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_device.h"
11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "net/base/escape.h"
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "third_party/cros_system_api/dbus/service_constants.h"
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
114bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ui/base/l10n/time_format.h"
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos {
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The minimum session length limit that can be set.
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kSessionLengthLimitMinMs = 30 * 1000;  // 30 seconds.
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The maximum session length limit that can be set.
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000;  // 24 hours.
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
126eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kDisplaySettingsSubPageName[] = "display";
127eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kDisplayOverscanSettingsSubPageName[] = "displayOverscan";
128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime,
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const input_method::InputMethodUtil& util,
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    ash::IMEInfo* info) {
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->id = ime.id();
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->name = util.GetInputMethodLongName(ime);
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->medium_name = util.GetInputMethodMediumName(ime);
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->short_name = util.GetInputMethodShortName(ime);
136c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  info->third_party = extension_ime_util::IsExtensionIME(ime.id());
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeWindow GetNativeWindowByStatus(ash::user::LoginStatus login_status,
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          bool session_started) {
1416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  bool isUserAddingRunning = ash::Shell::GetInstance()
1426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                 ->session_state_delegate()
1436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                 ->IsInSecondaryLoginScreen();
1446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int container_id =
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (!session_started || login_status == ash::user::LOGGED_IN_NONE ||
1476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)       login_status == ash::user::LOGGED_IN_LOCKED || isUserAddingRunning)
148c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch          ? ash::kShellWindowId_LockSystemModalContainer
149c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch          : ash::kShellWindowId_SystemModalContainer;
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                  container_id);
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void BluetoothPowerFailure() {
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(sad): Show an error bubble?
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void BluetoothSetDiscoveringError() {
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  LOG(ERROR) << "BluetoothSetDiscovering failed.";
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void BluetoothDeviceConnectError(
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    device::BluetoothDevice::ConnectErrorCode error_code) {
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(sad): Do something?
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
167effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
168effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  chrome::ShowSettingsSubPageForProfile(
169effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      ProfileManager::GetActiveUserProfile(), sub_page);
1700f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
1710f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void ShowNetworkSettingsPage(const std::string& service_path) {
1733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string page = chrome::kInternetOptionsSubPage;
1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  page += "?servicePath=" + net::EscapeUrlEncodedData(service_path, true);
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("OpenInternetOptionsDialog"));
176effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(page);
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void OnAcceptMultiprofilesIntro(bool no_show_again) {
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again);
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UserAddingScreen::Get()->Start();
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
1881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    : user_profile_(NULL),
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      clock_type_(base::GetHourClockType()),
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      search_key_mapped_to_(input_method::kSearchKey),
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      screen_locked_(false),
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      have_session_start_time_(false),
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      have_session_length_limit_(false),
194a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      should_run_bluetooth_discovery_(false),
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      volume_control_delegate_(new VolumeController()),
1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_settings_observer_(CrosSettings::Get()->AddSettingsObserver(
1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          kSystemUse24HourClock,
1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
1991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                     base::Unretained(this)))),
2001320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      weak_ptr_factory_(this) {
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Register notifications on construction so that events such as
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // PROFILE_CREATED do not get missed if they happen before Initialize().
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_.reset(new content::NotificationRegistrar);
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) {
21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    registrar_->Add(this,
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    chrome::NOTIFICATION_SESSION_STARTED,
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    content::NotificationService::AllSources());
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_PROFILE_CREATED,
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_PROFILE_DESTROYED,
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
221a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
223a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  CHECK(accessibility_manager);
224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  accessibility_subscription_ = accessibility_manager->RegisterCallback(
225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged,
226a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                 base::Unretained(this)));
2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Initialize() {
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->AddObserver(this);
233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateClockType();
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothAdapterFactory::GetAdapter(
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::InitializeOnAdapterReady,
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr()));
239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      this);
24258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (LoginState::IsInitialized())
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    LoginState::Get()->AddObserver(this);
245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (CrasAudioHandler::IsInitialized())
247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CrasAudioHandler::Get()->AddAudioObserver(this);
248a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
249a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList::AddObserver(this);
2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Shutdown() {
2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device_settings_observer_.reset();
2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
255c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::InitializeOnAdapterReady(
2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_refptr<device::BluetoothAdapter> adapter) {
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_ = adapter;
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(bluetooth_adapter_.get());
2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->AddObserver(this);
2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_.reset(new PrefChangeRegistrar);
2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Init(g_browser_process->local_state());
2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateSessionStartTime();
2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateSessionLengthLimit();
2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Add(
2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kSessionStartTime,
2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionStartTime,
2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Add(
2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kSessionLengthLimit,
2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionLengthLimit,
2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* policy_connector =
2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      policy_connector->GetDeviceCloudPolicyManager();
2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (policy_manager)
2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy_manager->core()->store()->AddObserver(this);
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateEnterpriseDomain();
2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Unregister PrefChangeRegistrars.
2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_.reset();
2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset();
2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Unregister content notifications before destroying any components.
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_.reset();
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Unregister a11y status subscription.
295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  accessibility_subscription_.reset();
296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->RemoveObserver(this);
299a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this);
3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->RemoveObserver(this);
3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()
3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->session_state_delegate()
3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->RemoveSessionStateObserver(this);
3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginState::Get()->RemoveObserver(this);
3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
306a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (CrasAudioHandler::IsInitialized())
307a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CrasAudioHandler::Get()->RemoveAudioObserver(this);
308a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
309a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList::RemoveObserver(this);
310a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StopObservingAppWindowRegistry();
311a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* connector =
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      connector->GetDeviceCloudPolicyManager();
3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (policy_manager)
3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy_manager->core()->store()->RemoveObserver(this);
3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from ash::SystemTrayDelegate:
3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetTrayVisibilityOnStartup() {
3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // In case of OOBE / sign in screen tray will be shown later.
3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return LoginState::Get()->IsUserLoggedIn();
3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::user::LoginStatus SystemTrayDelegateChromeOS::GetUserLoginStatus() const {
3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All non-logged in ChromeOS specific LOGGED_IN states map to the same
3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Ash specific LOGGED_IN state.
3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!LoginState::Get()->IsUserLoggedIn())
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return ash::user::LOGGED_IN_NONE;
3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (screen_locked_)
3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return ash::user::LOGGED_IN_LOCKED;
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginState::LoggedInUserType user_type =
3365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      LoginState::Get()->GetLoggedInUserType();
3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  switch (user_type) {
3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_NONE:
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return ash::user::LOGGED_IN_NONE;
3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_REGULAR:
3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_USER;
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_OWNER:
3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_OWNER;
3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_GUEST:
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_GUEST;
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_RETAIL_MODE:
3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_RETAIL_MODE;
3485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT:
3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_PUBLIC;
3505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    case LoginState::LOGGED_IN_USER_SUPERVISED:
3515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      return ash::user::LOGGED_IN_SUPERVISED;
3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_KIOSK_APP:
3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_KIOSK_APP;
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NOTREACHED();
3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::user::LOGGED_IN_NONE;
3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
358d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ChangeProfilePicture() {
3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(
3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::UserMetricsAction("OpenChangeProfilePictureDialog"));
362effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(chrome::kChangeProfilePictureSubPage);
3635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
364c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const std::string SystemTrayDelegateChromeOS::GetEnterpriseDomain() const {
3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return enterprise_domain_;
3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const {
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetEnterpriseDomain().empty())
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE,
3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    base::UTF8ToUTF16(GetEnterpriseDomain()));
3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const {
3775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED)
3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return std::string();
3796e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  return ChromeUserManager::Get()
3806e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      ->GetSupervisedUserManager()
3816e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      ->GetManagerDisplayEmail(
3826e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          user_manager::UserManager::Get()->GetActiveUser()->email());
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16
3865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const {
3875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_SUPERVISED)
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
3896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  return ChromeUserManager::Get()
3906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      ->GetSupervisedUserManager()
3916e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      ->GetManagerDisplayName(
3926e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          user_manager::UserManager::Get()->GetActiveUser()->email());
3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
394c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage()
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const {
3971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!IsUserSupervised())
3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetStringFUTF16(
4005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      IDS_USER_IS_SUPERVISED_BY_NOTICE,
4015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      base::UTF8ToUTF16(GetSupervisedUserManager()));
4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
403eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccibool SystemTrayDelegateChromeOS::IsUserSupervised() const {
4051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser();
4061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return user && user->IsSupervised();
4071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}
4081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::SystemShouldUpgrade() const {
4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UpgradeDetector::GetInstance()->notify_upgrade();
4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
412c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::HourClockType SystemTrayDelegateChromeOS::GetHourClockType() const {
4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return clock_type_;
4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowSettings() {
418effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser("");
4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldShowSettings() {
4226e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  return ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldShowSettings() &&
4236e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)         !ash::Shell::GetInstance()
4246e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)              ->session_state_delegate()
4256e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)              ->IsInSecondaryLoginScreen();
4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDateSettings() {
4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowDateOptions"));
4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page =
4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::string(chrome::kSearchSubPage) + "#" +
4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME);
4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Everybody can change the time zone (even though it is a device setting).
434effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4375c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liuvoid SystemTrayDelegateChromeOS::ShowSetTimeDialog() {
4385c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  SetTimeDialog::ShowDialog(GetNativeWindow());
4395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}
4405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowNetworkSettings(
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& service_path) {
4436e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  bool userAddingRunning = ash::Shell::GetInstance()
4446e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                               ->session_state_delegate()
4456e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                               ->IsInSecondaryLoginScreen();
4466e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
4476e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (!LoginState::Get()->IsUserLoggedIn() || userAddingRunning)
4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShowNetworkSettingsPage(service_path);
4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowBluetoothSettings() {
4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(sad): Make this work.
4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDisplaySettings() {
4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowDisplayOptions"));
458effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(kDisplaySettingsSubPageName);
4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowChromeSlow() {
4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetPrimaryUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowSlow(displayer.browser());
4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
466eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldShowDisplayNotification() {
4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Packaged app is not counted as 'last active', so if a browser opening the
4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // display settings is in background of a packaged app, it will return true.
4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(mukai): fix this.
4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Browser* active_browser =
4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!active_browser)
4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
475ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::WebContents* active_contents =
4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      active_browser->tab_strip_model()->GetActiveWebContents();
4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!active_contents)
4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GURL visible_url = active_contents->GetLastCommittedURL();
482effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  GURL display_settings_url =
483effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      chrome::GetSettingsUrl(kDisplaySettingsSubPageName);
484effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  GURL display_overscan_url =
485effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      chrome::GetSettingsUrl(kDisplayOverscanSettingsSubPageName);
486effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  return (visible_url != display_settings_url &&
487effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch          visible_url != display_overscan_url);
4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowIMESettings() {
4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("OpenLanguageOptionsDialog"));
492effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(chrome::kLanguageOptionsSubPage);
4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowHelp() {
4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowHelpForProfile(ProfileManager::GetActiveUserProfile(),
4975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             chrome::HOST_DESKTOP_TYPE_ASH,
4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             chrome::HELP_SOURCE_MENU);
4995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowAccessibilityHelp() {
5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  accessibility::ShowAccessibilityHelp(displayer.browser());
5055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
506b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
5075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowAccessibilitySettings() {
5085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowAccessibilitySettings"));
5095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page = std::string(chrome::kSearchSubPage) + "#" +
5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         l10n_util::GetStringUTF8(
5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY);
512effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
5135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowPublicAccountInfo() {
5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowPolicy(displayer.browser());
5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void SystemTrayDelegateChromeOS::ShowSupervisedUserInfo() {
5225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(antrim): find out what should we show in this case.
5235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // http://crbug.com/229762
5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowEnterpriseInfo() {
5275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::user::LoginStatus status = GetUserLoginStatus();
5286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  bool userAddingRunning = ash::Shell::GetInstance()
5296e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                               ->session_state_delegate()
5306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                               ->IsInSecondaryLoginScreen();
5316e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
5325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (status == ash::user::LOGGED_IN_NONE ||
5336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)      status == ash::user::LOGGED_IN_LOCKED || userAddingRunning) {
5345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_refptr<chromeos::HelpAppLauncher> help_app(
5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new chromeos::HelpAppLauncher(GetNativeWindow()));
5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    help_app->ShowHelpTopic(chromeos::HelpAppLauncher::HELP_ENTERPRISE);
5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    chrome::ScopedTabbedBrowserDisplayer displayer(
5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
540f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    chrome::ShowSingletonTab(displayer.browser(),
541f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)                             GURL(chrome::kLearnMoreEnterpriseURL));
542c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
5435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
544c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowUserLogin() {
5465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell* shell = ash::Shell::GetInstance();
5475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!shell->delegate()->IsMultiProfilesEnabled())
5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Only regular users could add other users to current session.
5516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (user_manager::UserManager::Get()->GetActiveUser()->GetType() !=
552116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch      user_manager::USER_TYPE_REGULAR) {
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5566e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (static_cast<int>(
5576e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          user_manager::UserManager::Get()->GetLoggedInUsers().size()) >=
5585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers())
5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Launch sign in screen to add another user to current session.
5626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (user_manager::UserManager::Get()
5636e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          ->GetUsersAdmittedForMultiProfile()
5646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)          .size()) {
5655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Don't show dialog if any logged in user in multi-profiles session
5665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // dismissed it.
5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool show_intro = true;
5685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const user_manager::UserList logged_in_users =
5696e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        user_manager::UserManager::Get()->GetLoggedInUsers();
5705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    for (user_manager::UserList::const_iterator it = logged_in_users.begin();
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         it != logged_in_users.end();
5725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         ++it) {
5735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      show_intro &= !multi_user_util::GetProfileFromUserID(
5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         multi_user_util::GetUserIDFromEmail((*it)->email()))
5755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         ->GetPrefs()
5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         ->GetBoolean(prefs::kMultiProfileNeverShowIntro);
5775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (!show_intro)
5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        break;
5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (show_intro) {
5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Callback<void(bool)> on_accept =
5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base::Bind(&OnAcceptMultiprofilesIntro);
5835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShowMultiprofilesIntroDialog(on_accept);
5842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else {
5855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      UserAddingScreen::Get()->Start();
5862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
5872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShowSpringChargerReplacementDialog() {
5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!ChargerReplacementDialog::ShouldShowDialog())
5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
593c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ChargerReplacementDialog* dialog =
5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      new ChargerReplacementDialog(GetNativeWindow());
5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  dialog->Show();
5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
599c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsSpringChargerReplacementDialogVisible() {
6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ChargerReplacementDialog::IsDialogVisible();
6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
603c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::HasUserConfirmedSafeSpringCharger() {
6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ChargerReplacementHandler::GetChargerStatusPref() ==
6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         ChargerReplacementHandler::CONFIRM_SAFE_CHARGER;
6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
608c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShutDown() {
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown();
6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SignOut() {
6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::AttemptUserExit();
6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::RequestLockScreen() {
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(antrim) : additional logging for crbug/173178
6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LOG(WARNING) << "Requesting screen lock from AshSystemTrayDelegate";
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::RequestRestartForUpdate() {
6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We expect that UpdateEngine is in "Reboot for update" state now.
6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::NotifyAndTerminate(true /* fast path */);
6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetAvailableBluetoothDevices(
6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::BluetoothDeviceList* list) {
6305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothAdapter::DeviceList devices =
6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      bluetooth_adapter_->GetDevices();
6325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < devices.size(); ++i) {
6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothDevice* device = devices[i];
6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::BluetoothDeviceInfo info;
6355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.address = device->GetAddress();
6365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.display_name = device->GetName();
6375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.connected = device->IsConnected();
6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.connecting = device->IsConnecting();
6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.paired = device->IsPaired();
6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(info);
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() {
645e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  if (GetBluetoothDiscovering()) {
646a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LOG(WARNING) << "Already have active Bluetooth device discovery session.";
647a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
648a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
649a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Requesting new Bluetooth device discovery session.";
650a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  should_run_bluetooth_discovery_ = true;
651a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_adapter_->StartDiscoverySession(
652a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession,
653a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr()),
654a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&BluetoothSetDiscoveringError));
6555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() {
658a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  should_run_bluetooth_discovery_ = false;
659e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  if (!GetBluetoothDiscovering()) {
660a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LOG(WARNING) << "No active Bluetooth device discovery session.";
661a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
662a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
663a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Stopping Bluetooth device discovery session.";
664a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_discovery_session_->Stop(
6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError));
6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ConnectToBluetoothDevice(
6695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& address) {
6705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address);
6715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!device || device->IsConnecting() ||
6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (device->IsConnected() && device->IsPaired())) {
6735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (device->IsPaired() && !device->IsConnectable())
6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (device->IsPaired() || !device->IsPairable()) {
6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE);
6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device->Connect(NULL,
6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    base::Bind(&base::DoNothing),
6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    base::Bind(&BluetoothDeviceConnectError));
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {  // Show paring dialog for the unpaired device.
6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE);
6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    BluetoothPairingDialog* dialog =
6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new BluetoothPairingDialog(GetNativeWindow(), device);
6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // The dialog deletes itself on close.
6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    dialog->Show();
6905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsBluetoothDiscovering() {
6945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsDiscovering();
6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetCurrentIME(ash::IMEInfo* info) {
6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager* manager =
6995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      input_method::InputMethodManager::Get();
7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
70103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  input_method::InputMethodDescriptor ime =
70203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      manager->GetActiveIMEState()->GetCurrentInputMethod();
7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtractIMEInfo(ime, *util, info);
7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  info->selected = true;
7055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetAvailableIMEList(ash::IMEInfoList* list) {
7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager* manager =
7095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      input_method::InputMethodManager::Get();
7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<input_method::InputMethodDescriptors> ime_descriptors(
71203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      manager->GetActiveIMEState()->GetActiveInputMethods());
71303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  std::string current =
71403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      manager->GetActiveIMEState()->GetCurrentInputMethod().id();
7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < ime_descriptors->size(); i++) {
7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    input_method::InputMethodDescriptor& ime = ime_descriptors->at(i);
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEInfo info;
7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ExtractIMEInfo(ime, *util, &info);
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.selected = ime.id() == current;
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(info);
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetCurrentIMEProperties(
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEPropertyInfoList* list) {
726a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuItemList menu_list =
727a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      ash::ime::InputMethodMenuManager::GetInstance()->
728a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GetCurrentInputMethodMenuItemList();
729a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (size_t i = 0; i < menu_list.size(); ++i) {
7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEPropertyInfo property;
731a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.key = menu_list[i].key;
732a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.name = base::UTF8ToUTF16(menu_list[i].label);
733a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.selected = menu_list[i].is_selection_item_checked;
7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(property);
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SwitchIME(const std::string& ime_id) {
73903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  input_method::InputMethodManager::Get()
74003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      ->GetActiveIMEState()
74103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)      ->ChangeInputMethod(ime_id, false /* show_message */);
7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ActivateIMEProperty(const std::string& key) {
745a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  input_method::InputMethodManager::Get()->ActivateInputMethodMenuItem(key);
7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowNetworkConfigure(
7491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    const std::string& network_id) {
7501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  NetworkConfigView::Show(network_id, GetNativeWindow());
7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::EnrollNetwork(
7541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    const std::string& network_id) {
7551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  return enrollment::CreateDialog(network_id, GetNativeWindow());
7565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ManageBluetoothDevices() {
7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowBluetoothSettingsPage"));
7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page =
7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::string(chrome::kSearchSubPage) + "#" +
7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH);
763effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ToggleBluetooth() {
7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->SetPowered(!bluetooth_adapter_->IsPowered(),
7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Bind(&base::DoNothing),
7695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Bind(&BluetoothPowerFailure));
7705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowMobileSimDialog() {
7735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SimDialogDelegate::ShowDialog(GetNativeWindow(),
7745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                SimDialogDelegate::SIM_DIALOG_UNLOCK);
7755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
77690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowMobileSetupDialog(
7785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& service_path) {
7795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  MobileSetupDialog::Show(service_path);
7805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
781ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
7825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowOtherNetworkDialog(
7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& type) {
7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (type == shill::kTypeCellular) {
7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
7865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NetworkConfigView::ShowForType(type, GetNativeWindow());
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetBluetoothAvailable() {
7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsPresent();
7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetBluetoothEnabled() {
7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsPowered();
7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
799e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochbool SystemTrayDelegateChromeOS::GetBluetoothDiscovering() {
800e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  return (bluetooth_discovery_session_.get() &&
801e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch      bluetooth_discovery_session_->IsActive());
802e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch}
803e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ChangeProxySettings() {
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE);
8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginDisplayHostImpl::default_host()->OpenProxySettings();
8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::VolumeControlDelegate*
8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::GetVolumeControlDelegate() const {
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return volume_control_delegate_.get();
8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SetVolumeControlDelegate(
8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<ash::VolumeControlDelegate> delegate) {
8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  volume_control_delegate_.swap(delegate);
8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetSessionStartTime(
8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeTicks* session_start_time) {
8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *session_start_time = session_start_time_;
8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return have_session_start_time_;
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetSessionLengthLimit(
8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeDelta* session_length_limit) {
8275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *session_length_limit = session_length_limit_;
8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return have_session_length_limit_;
8295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int SystemTrayDelegateChromeOS::GetSystemTrayMenuWidth() {
8325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetLocalizedContentsWidthInPixels(
8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ActiveUserWasChanged() {
8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyUserUpdate();
8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
840a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsSearchKeyMappedToCapsLock() {
841a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return search_key_mapped_to_ == input_method::kCapsLockKey;
842a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
843a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
844a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochash::tray::UserAccountsDelegate*
845a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochSystemTrayDelegateChromeOS::GetUserAccountsDelegate(
846a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const std::string& user_id) {
847a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!accounts_delegates_.contains(user_id)) {
8486e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    const user_manager::User* user =
8496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)        user_manager::UserManager::Get()->FindUser(user_id);
8506e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)    Profile* user_profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
851cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    CHECK(user_profile);
852cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    accounts_delegates_.set(
853cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        user_id,
854cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        scoped_ptr<ash::tray::UserAccountsDelegate>(
855cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)            new UserAccountsDelegateChromeOS(user_profile)));
856a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
857a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return accounts_delegates_.get(user_id);
858a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
859a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
8605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() {
8615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::Shell::GetInstance()->GetPrimarySystemTray();
8625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
8655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::Shell::GetInstance()->system_tray_notifier();
8665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
8695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Stop observing the AppWindowRegistry of the current |user_profile_|.
870a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StopObservingAppWindowRegistry();
8715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_profile_ = profile;
8735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Start observing the AppWindowRegistry of the newly set |user_profile_|.
8751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this);
8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PrefService* prefs = profile->GetPrefs();
8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset(new PrefChangeRegistrar);
8795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Init(prefs);
8805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
8815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kUse24HourClock,
8825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
8835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
8845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
8855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLanguageRemapSearchKeyTo,
8865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged,
8875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
8895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kShowLogoutButtonInTray,
8905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray,
8915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
8925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
8935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLogoutDialogDurationMs,
8945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration,
8955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
8965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
897f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      prefs::kAccessibilityLargeCursorEnabled,
8985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
8995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
902f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      prefs::kAccessibilityAutoclickEnabled,
9035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kShouldAlwaysShowAccessibilityMenu,
9085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kPerformanceTracingEnabled,
9135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing,
9145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateClockType();
9175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateShowLogoutButtonInTray();
9185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateLogoutDialogDuration();
9195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdatePerformanceTracing();
9205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  search_key_mapped_to_ =
9215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
9225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
92390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) {
9255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (profile != user_profile_)
9265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
9275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset();
928a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  user_profile_ = NULL;
9295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
9305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetShouldUse24HourClockForTesting() const {
9335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ShouldUse24HourClock();
9345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldUse24HourClock() const {
9375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // On login screen and in guest mode owner default is used for
9385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // kUse24HourClock preference.
9395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const ash::user::LoginStatus status = GetUserLoginStatus();
9405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const CrosSettings* const cros_settings = CrosSettings::Get();
9415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool system_use_24_hour_clock = true;
9425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const bool system_value_found = cros_settings->GetBoolean(
9435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kSystemUse24HourClock, &system_use_24_hour_clock);
9445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if ((status == ash::user::LOGGED_IN_NONE) || !user_pref_registrar_)
9465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return (system_value_found
9475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                ? system_use_24_hour_clock
9485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                : (base::GetHourClockType() == base::k24HourClock));
9495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService::Preference* user_pref =
9515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->FindPreference(prefs::kUse24HourClock);
9525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (status == ash::user::LOGGED_IN_GUEST && user_pref->IsDefaultValue())
9535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return (system_value_found
9545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                ? system_use_24_hour_clock
9555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                : (base::GetHourClockType() == base::k24HourClock));
9565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool use_24_hour_clock = true;
9585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock);
9595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return use_24_hour_clock;
9605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateClockType() {
9635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const bool use_24_hour_clock = ShouldUse24HourClock();
9645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  clock_type_ = use_24_hour_clock ? base::k24HourClock : base::k12HourClock;
9655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyDateFormatChanged();
9665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This also works for enterprise-managed devices because they never have
9675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // local owner.
9686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  if (user_manager::UserManager::Get()->IsCurrentUserOwner())
9695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CrosSettings::Get()->SetBoolean(kSystemUse24HourClock, use_24_hour_clock);
9705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray() {
9735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyShowLoginButtonChanged(
9745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->GetBoolean(
9755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          prefs::kShowLogoutButtonInTray));
9765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration() {
9795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const int duration_ms =
9805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->GetInteger(prefs::kLogoutDialogDurationMs);
9815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyLogoutDialogDurationChanged(
9825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::TimeDelta::FromMilliseconds(duration_ms));
9835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
98458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
9855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateSessionStartTime() {
9865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService* local_state = local_state_registrar_->prefs();
9875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (local_state->HasPrefPath(prefs::kSessionStartTime)) {
9885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_start_time_ = true;
9895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_start_time_ = base::TimeTicks::FromInternalValue(
9905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        local_state->GetInt64(prefs::kSessionStartTime));
9915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
9925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_start_time_ = false;
9935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_start_time_ = base::TimeTicks();
9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifySessionStartTimeChanged();
9965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateSessionLengthLimit() {
9995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService* local_state = local_state_registrar_->prefs();
10005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (local_state->HasPrefPath(prefs::kSessionLengthLimit)) {
10015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_length_limit_ = true;
10025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_length_limit_ = base::TimeDelta::FromMilliseconds(
10035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        std::min(std::max(local_state->GetInteger(prefs::kSessionLengthLimit),
10045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                          kSessionLengthLimitMinMs),
10055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 kSessionLengthLimitMaxMs));
10065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
10075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_length_limit_ = false;
10085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_length_limit_ = base::TimeDelta();
10095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifySessionLengthLimitChanged();
10115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1013a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::StopObservingAppWindowRegistry() {
1014a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!user_profile_)
1015a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1016a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
10171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  extensions::AppWindowRegistry* registry =
10181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      extensions::AppWindowRegistry::Factory::GetForBrowserContext(
10191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          user_profile_, false);
1020a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (registry)
1021a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    registry->RemoveObserver(this);
1022a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1023a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1024a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() {
1025a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!user_profile_)
1026a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1027a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1028a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList* browser_list =
1029a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1030a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (BrowserList::const_iterator it = browser_list->begin();
1031a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       it != browser_list->end();
1032a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       ++it) {
1033a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if ((*it)->profile()->IsSameProfile(user_profile_)) {
1034a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      // The current user has at least one open browser window.
1035a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return;
1036a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
1037a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1038a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
10391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  if (!extensions::AppWindowRegistry::Get(
10401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci          user_profile_)->app_windows().empty()) {
1041a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // The current user has at least one open app window.
1042a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1043a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1044a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1045a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyLastWindowClosed();
1046a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1047a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
10485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// LoginState::Observer overrides.
10495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::LoggedInStateChanged() {
10505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // It apparently sometimes takes a while after login before the current user
10515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is recognized as the owner. Make sure that the system-wide clock setting
10525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is updated when the recognition eventually happens
10535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // (http://crbug.com/278601).
10545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
10555d1f7b1de12d16ce