system_tray_delegate_chromeos.cc revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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"
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/session_state_delegate.h"
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/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/drive/drive_observer.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/ime/ime_observer.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray_accessibility.h"
3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/system/user/login_status.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/user/update_observer.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/user/user_observer.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/volume_control_delegate.h"
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/wm/lock_state_controller.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind_helpers.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h"
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
415e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/stringprintf.h"
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/sys_info.h"
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_process.h"
467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h"
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/charger_replace/charger_replacement_dialog.h"
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/drive/drive_integration_service.h"
52868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/drive/job_list.h"
533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/chromeos/enrollment_dialog_view.h"
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/events/system_key_event_listener.h"
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/input_method/input_method_util.h"
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/login/help_app_launcher.h"
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/login/login_display_host.h"
59c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/login/login_display_host_impl.h"
60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/login/login_wizard.h"
618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/chromeos/login/supervised_user_manager.h"
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/login/user.h"
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/login/user_adding_screen.h"
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/login/user_manager.h"
65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/chromeos/net/network_portal_detector.h"
6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/options/network_config_view.h"
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
70bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "chrome/browser/chromeos/settings/cros_settings.h"
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/sim_dialog_delegate.h"
720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch#include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/drive/drive_service_interface.h"
74ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/feedback/tracing_manager.h"
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/google/google_util.h"
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/lifetime/application_lifetime.h"
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
79a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chrome/browser/ui/ash/stub_user_accounts_delegate.h"
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/ash/volume_controller_chromeos.h"
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h"
83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/chrome_pages.h"
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/singleton_tabs.h"
88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/ui/tabs/tab_strip_model.h"
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/upgrade_detector.h"
92effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/common/chrome_switches.h"
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h"
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/dbus_thread_manager.h"
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/session_manager_client.h"
97c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/ime/extension_ime_util.h"
98a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chromeos/ime/ime_keyboard.h"
99c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/ime/input_method_manager.h"
100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/login/login_state.h"
101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/cloud/cloud_policy_store.h"
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/user_metrics.h"
105eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/browser/web_contents.h"
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_adapter.h"
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_adapter_factory.h"
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_device.h"
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "grit/ash_strings.h"
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/generated_resources.h"
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "grit/locale_settings.h"
11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "net/base/escape.h"
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "third_party/cros_system_api/dbus/service_constants.h"
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
115bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ui/base/l10n/time_format.h"
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using drive::DriveIntegrationService;
11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using drive::DriveIntegrationServiceFactory;
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos {
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The minimum session length limit that can be set.
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kSessionLengthLimitMinMs = 30 * 1000;  // 30 seconds.
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The maximum session length limit that can be set.
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000;  // 24 hours.
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
130eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kDisplaySettingsSubPageName[] = "display";
131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kDisplayOverscanSettingsSubPageName[] = "displayOverscan";
132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
133f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The URL for the Google Drive settings page.
134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char kDriveSettingsPageURL[] = "https://drive.google.com";
135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime,
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const input_method::InputMethodUtil& util,
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    ash::IMEInfo* info) {
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->id = ime.id();
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->name = util.GetInputMethodLongName(ime);
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->medium_name = util.GetInputMethodMediumName(ime);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->short_name = util.GetInputMethodShortName(ime);
143c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  info->third_party = extension_ime_util::IsExtensionIME(ime.id());
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeWindow GetNativeWindowByStatus(ash::user::LoginStatus login_status,
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          bool session_started) {
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int container_id =
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (!session_started || login_status == ash::user::LOGGED_IN_NONE ||
150c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch       login_status == ash::user::LOGGED_IN_LOCKED)
151c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch          ? ash::kShellWindowId_LockSystemModalContainer
152c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch          : ash::kShellWindowId_SystemModalContainer;
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                  container_id);
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
157c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Converts drive::JobInfo to ash::DriveOperationStatus.
158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// If the job is not of type that ash tray is interested, returns false.
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool ConvertToDriveOperationStatus(const drive::JobInfo& info,
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                   ash::DriveOperationStatus* status) {
161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (info.job_type == drive::TYPE_DOWNLOAD_FILE) {
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->type = ash::DriveOperationStatus::OPERATION_DOWNLOAD;
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  } else if (info.job_type == drive::TYPE_UPLOAD_NEW_FILE ||
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             info.job_type == drive::TYPE_UPLOAD_EXISTING_FILE) {
165c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->type = ash::DriveOperationStatus::OPERATION_UPLOAD;
166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  } else {
167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (info.state == drive::STATE_NONE)
171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->state = ash::DriveOperationStatus::OPERATION_NOT_STARTED;
172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  else
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->state = ash::DriveOperationStatus::OPERATION_IN_PROGRESS;
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  status->id = info.job_id;
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  status->file_path = info.file_path;
177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  status->progress = info.num_total_bytes == 0 ? 0.0 :
178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      static_cast<double>(info.num_completed_bytes) /
179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          static_cast<double>(info.num_total_bytes);
180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Converts drive::JobInfo that has finished in |error| state
184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// to ash::DriveOperationStatus.
185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// If the job is not of type that ash tray is interested, returns false.
186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool ConvertToFinishedDriveOperationStatus(const drive::JobInfo& info,
187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                           drive::FileError error,
188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                           ash::DriveOperationStatus* status) {
189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!ConvertToDriveOperationStatus(info, status))
190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  status->state = (error == drive::FILE_ERROR_OK)
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                      ? ash::DriveOperationStatus::OPERATION_COMPLETED
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                      : ash::DriveOperationStatus::OPERATION_FAILED;
194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Converts a list of drive::JobInfo to a list of ash::DriveOperationStatusList.
198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ash::DriveOperationStatusList ConvertToDriveStatusList(
199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const std::vector<drive::JobInfo>& list) {
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ash::DriveOperationStatusList results;
201c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < list.size(); ++i) {
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ash::DriveOperationStatus status;
203c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (ConvertToDriveOperationStatus(list[i], &status))
204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      results.push_back(status);
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return results;
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void BluetoothPowerFailure() {
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(sad): Show an error bubble?
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void BluetoothSetDiscoveringError() {
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  LOG(ERROR) << "BluetoothSetDiscovering failed.";
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void BluetoothDeviceConnectError(
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    device::BluetoothDevice::ConnectErrorCode error_code) {
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(sad): Do something?
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
222effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
223effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  chrome::ShowSettingsSubPageForProfile(
224effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      ProfileManager::GetActiveUserProfile(), sub_page);
2250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
2260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void ShowNetworkSettingsPage(const std::string& service_path) {
2283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string page = chrome::kInternetOptionsSubPage;
2294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  page += "?servicePath=" + net::EscapeUrlEncodedData(service_path, true);
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("OpenInternetOptionsDialog"));
231effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(page);
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void OnAcceptMultiprofilesIntro(bool no_show_again) {
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again);
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UserAddingScreen::Get()->Start();
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : weak_ptr_factory_(this),
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_profile_(NULL),
2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      clock_type_(base::GetHourClockType()),
2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      search_key_mapped_to_(input_method::kSearchKey),
2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      screen_locked_(false),
2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      have_session_start_time_(false),
2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      have_session_length_limit_(false),
250a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      should_run_bluetooth_discovery_(false),
2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      volume_control_delegate_(new VolumeController()),
2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_settings_observer_(CrosSettings::Get()->AddSettingsObserver(
2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          kSystemUse24HourClock,
2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     base::Unretained(this)))) {
2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Register notifications on construction so that events such as
2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // PROFILE_CREATED do not get missed if they happen before Initialize().
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_.reset(new content::NotificationRegistrar);
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) {
26690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    registrar_->Add(this,
2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    chrome::NOTIFICATION_SESSION_STARTED,
2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    content::NotificationService::AllSources());
2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_PROFILE_CREATED,
2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_PROFILE_DESTROYED,
2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
276a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  CHECK(accessibility_manager);
279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  accessibility_subscription_ = accessibility_manager->RegisterCallback(
280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged,
281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                 base::Unretained(this)));
2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Initialize() {
2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->AddObserver(this);
288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateClockType();
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothAdapterFactory::GetAdapter(
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::InitializeOnAdapterReady,
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr()));
294868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(
2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      this);
29758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (LoginState::IsInitialized())
2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    LoginState::Get()->AddObserver(this);
300a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (CrasAudioHandler::IsInitialized())
302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CrasAudioHandler::Get()->AddAudioObserver(this);
303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
304a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList::AddObserver(this);
3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Shutdown() {
3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device_settings_observer_.reset();
3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
310c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::InitializeOnAdapterReady(
3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_refptr<device::BluetoothAdapter> adapter) {
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_ = adapter;
3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(bluetooth_adapter_.get());
3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->AddObserver(this);
3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_.reset(new PrefChangeRegistrar);
3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Init(g_browser_process->local_state());
3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateSessionStartTime();
3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateSessionLengthLimit();
3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Add(
3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kSessionStartTime,
3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionStartTime,
3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Add(
3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kSessionLengthLimit,
3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionLengthLimit,
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* policy_connector =
3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      policy_connector->GetDeviceCloudPolicyManager();
3365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (policy_manager)
3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy_manager->core()->store()->AddObserver(this);
3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateEnterpriseDomain();
3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Unregister PrefChangeRegistrars.
3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_.reset();
3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset();
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
346a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Unregister content notifications before destroying any components.
3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_.reset();
3485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
349a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Unregister a11y status subscription.
350a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  accessibility_subscription_.reset();
351a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->RemoveObserver(this);
354a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this);
3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->RemoveObserver(this);
3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()
3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->session_state_delegate()
3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->RemoveSessionStateObserver(this);
3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginState::Get()->RemoveObserver(this);
3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
361a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (CrasAudioHandler::IsInitialized())
362a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CrasAudioHandler::Get()->RemoveAudioObserver(this);
363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
364a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList::RemoveObserver(this);
365a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StopObservingAppWindowRegistry();
366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Stop observing Drive operations.
3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UnobserveDriveUpdates();
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* connector =
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      connector->GetDeviceCloudPolicyManager();
3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (policy_manager)
3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy_manager->core()->store()->RemoveObserver(this);
3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from ash::SystemTrayDelegate:
3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetTrayVisibilityOnStartup() {
3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // In case of OOBE / sign in screen tray will be shown later.
3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return LoginState::Get()->IsUserLoggedIn();
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::user::LoginStatus SystemTrayDelegateChromeOS::GetUserLoginStatus() const {
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All non-logged in ChromeOS specific LOGGED_IN states map to the same
3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Ash specific LOGGED_IN state.
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!LoginState::Get()->IsUserLoggedIn())
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return ash::user::LOGGED_IN_NONE;
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (screen_locked_)
3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return ash::user::LOGGED_IN_LOCKED;
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginState::LoggedInUserType user_type =
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      LoginState::Get()->GetLoggedInUserType();
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  switch (user_type) {
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_NONE:
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return ash::user::LOGGED_IN_NONE;
3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_REGULAR:
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_USER;
4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_OWNER:
4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_OWNER;
4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_GUEST:
4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_GUEST;
4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_RETAIL_MODE:
4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_RETAIL_MODE;
4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT:
4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_PUBLIC;
4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_LOCALLY_MANAGED:
4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_LOCALLY_MANAGED;
4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_KIOSK_APP:
4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_KIOSK_APP;
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NOTREACHED();
4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::user::LOGGED_IN_NONE;
4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
416d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ChangeProfilePicture() {
4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(
4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::UserMetricsAction("OpenChangeProfilePictureDialog"));
420effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(chrome::kChangeProfilePictureSubPage);
4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
422c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const std::string SystemTrayDelegateChromeOS::GetEnterpriseDomain() const {
4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return enterprise_domain_;
4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const {
4285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetEnterpriseDomain().empty())
4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE,
4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    base::UTF8ToUTF16(GetEnterpriseDomain()));
4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const std::string SystemTrayDelegateChromeOS::GetLocallyManagedUserManager()
4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const {
4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_LOCALLY_MANAGED)
4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return std::string();
4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UserManager::Get()->GetSupervisedUserManager()->GetManagerDisplayEmail(
4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chromeos::UserManager::Get()->GetActiveUser()->email());
4405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16
4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::GetLocallyManagedUserManagerName() const {
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_LOCALLY_MANAGED)
4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UserManager::Get()->GetSupervisedUserManager()->GetManagerDisplayName(
4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chromeos::UserManager::Get()->GetActiveUser()->email());
4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
449c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16 SystemTrayDelegateChromeOS::GetLocallyManagedUserMessage()
4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const {
4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_LOCALLY_MANAGED)
4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetStringFUTF16(
4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      IDS_USER_IS_LOCALLY_MANAGED_BY_NOTICE,
4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::UTF8ToUTF16(GetLocallyManagedUserManager()));
4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
458eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::SystemShouldUpgrade() const {
4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UpgradeDetector::GetInstance()->notify_upgrade();
4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
462c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::HourClockType SystemTrayDelegateChromeOS::GetHourClockType() const {
4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return clock_type_;
4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowSettings() {
468effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser("");
4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldShowSettings() {
4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UserManager::Get()->GetCurrentUserFlow()->ShouldShowSettings();
4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDateSettings() {
4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowDateOptions"));
4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page =
4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::string(chrome::kSearchSubPage) + "#" +
4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME);
4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Everybody can change the time zone (even though it is a device setting).
481effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowNetworkSettings(
4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& service_path) {
4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!LoginState::Get()->IsUserLoggedIn())
4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShowNetworkSettingsPage(service_path);
4895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowBluetoothSettings() {
4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(sad): Make this work.
4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDisplaySettings() {
4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowDisplayOptions"));
497effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(kDisplaySettingsSubPageName);
4985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowChromeSlow() {
5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetPrimaryUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowSlow(displayer.browser());
5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
505eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldShowDisplayNotification() {
5075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Packaged app is not counted as 'last active', so if a browser opening the
5085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // display settings is in background of a packaged app, it will return true.
5095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(mukai): fix this.
5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Browser* active_browser =
5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!active_browser)
5135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
514ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::WebContents* active_contents =
5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      active_browser->tab_strip_model()->GetActiveWebContents();
5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!active_contents)
5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
5195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GURL visible_url = active_contents->GetLastCommittedURL();
521effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  GURL display_settings_url =
522effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      chrome::GetSettingsUrl(kDisplaySettingsSubPageName);
523effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  GURL display_overscan_url =
524effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      chrome::GetSettingsUrl(kDisplayOverscanSettingsSubPageName);
525effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  return (visible_url != display_settings_url &&
526effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch          visible_url != display_overscan_url);
5275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDriveSettings() {
5305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(tengs): Open the drive-specific settings page once we put it in.
5315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // For now just show Google Drive main page.
5325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowSingletonTabOverwritingNTP(
5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      displayer.browser(),
5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chrome::GetSingletonTabNavigateParams(displayer.browser(),
5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                            GURL(kDriveSettingsPageURL)));
5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowIMESettings() {
5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("OpenLanguageOptionsDialog"));
542effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(chrome::kLanguageOptionsSubPage);
5435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowHelp() {
5465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowHelpForProfile(ProfileManager::GetActiveUserProfile(),
5475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             chrome::HOST_DESKTOP_TYPE_ASH,
5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             chrome::HELP_SOURCE_MENU);
5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowAccessibilityHelp() {
5525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  accessibility::ShowAccessibilityHelp(displayer.browser());
5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
556b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowAccessibilitySettings() {
5585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowAccessibilitySettings"));
5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page = std::string(chrome::kSearchSubPage) + "#" +
5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         l10n_util::GetStringUTF8(
5615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY);
562effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
5635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowPublicAccountInfo() {
5665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowPolicy(displayer.browser());
5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowLocallyManagedUserInfo() {
5725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(antrim): find out what should we show in this case.
5735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // http://crbug.com/229762
5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowEnterpriseInfo() {
5775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::user::LoginStatus status = GetUserLoginStatus();
5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (status == ash::user::LOGGED_IN_NONE ||
5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      status == ash::user::LOGGED_IN_LOCKED) {
5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_refptr<chromeos::HelpAppLauncher> help_app(
5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new chromeos::HelpAppLauncher(GetNativeWindow()));
5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    help_app->ShowHelpTopic(chromeos::HelpAppLauncher::HELP_ENTERPRISE);
5835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
5845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GURL url(google_util::StringAppendGoogleLocaleParam(
5855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        chrome::kLearnMoreEnterpriseURL));
5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    chrome::ScopedTabbedBrowserDisplayer displayer(
5875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    chrome::ShowSingletonTab(displayer.browser(), url);
589c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
591c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowUserLogin() {
5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell* shell = ash::Shell::GetInstance();
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!shell->delegate()->IsMultiProfilesEnabled())
5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Only regular users could add other users to current session.
5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (UserManager::Get()->GetActiveUser()->GetType() !=
5995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      User::USER_TYPE_REGULAR) {
6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (static_cast<int>(UserManager::Get()->GetLoggedInUsers().size()) >=
6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers())
6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Launch sign in screen to add another user to current session.
6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (UserManager::Get()->GetUsersAdmittedForMultiProfile().size()) {
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Don't show dialog if any logged in user in multi-profiles session
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // dismissed it.
6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool show_intro = true;
6125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers();
6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    for (UserList::const_iterator it = logged_in_users.begin();
6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         it != logged_in_users.end();
6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         ++it) {
6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      show_intro &= !multi_user_util::GetProfileFromUserID(
6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         multi_user_util::GetUserIDFromEmail((*it)->email()))
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         ->GetPrefs()
6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         ->GetBoolean(prefs::kMultiProfileNeverShowIntro);
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (!show_intro)
6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        break;
6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
6235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (show_intro) {
6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Callback<void(bool)> on_accept =
6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base::Bind(&OnAcceptMultiprofilesIntro);
6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShowMultiprofilesIntroDialog(on_accept);
6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else {
6285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      UserAddingScreen::Get()->Start();
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShowSpringChargerReplacementDialog() {
6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!ChargerReplacementDialog::ShouldShowDialog())
6355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
636c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ChargerReplacementDialog* dialog =
6385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      new ChargerReplacementDialog(GetNativeWindow());
6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  dialog->Show();
6405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
642c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsSpringChargerReplacementDialogVisible() {
6445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ChargerReplacementDialog::IsDialogVisible();
6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
646c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::HasUserConfirmedSafeSpringCharger() {
6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ChargerReplacementHandler::GetChargerStatusPref() ==
6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         ChargerReplacementHandler::CONFIRM_SAFE_CHARGER;
6505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
651c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShutDown() {
6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown();
6545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SignOut() {
6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::AttemptUserExit();
6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::RequestLockScreen() {
6615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(antrim) : additional logging for crbug/173178
6625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LOG(WARNING) << "Requesting screen lock from AshSystemTrayDelegate";
6635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::RequestRestartForUpdate() {
6675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We expect that UpdateEngine is in "Reboot for update" state now.
6685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::NotifyAndTerminate(true /* fast path */);
6695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetAvailableBluetoothDevices(
6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::BluetoothDeviceList* list) {
6735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothAdapter::DeviceList devices =
6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      bluetooth_adapter_->GetDevices();
6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < devices.size(); ++i) {
6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothDevice* device = devices[i];
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::BluetoothDeviceInfo info;
6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.address = device->GetAddress();
6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.display_name = device->GetName();
6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.connected = device->IsConnected();
6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.connecting = device->IsConnecting();
6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.paired = device->IsPaired();
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(info);
6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() {
688e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  if (GetBluetoothDiscovering()) {
689a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LOG(WARNING) << "Already have active Bluetooth device discovery session.";
690a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
691a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
692a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Requesting new Bluetooth device discovery session.";
693a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  should_run_bluetooth_discovery_ = true;
694a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_adapter_->StartDiscoverySession(
695a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession,
696a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr()),
697a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&BluetoothSetDiscoveringError));
6985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() {
701a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  should_run_bluetooth_discovery_ = false;
702e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  if (!GetBluetoothDiscovering()) {
703a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LOG(WARNING) << "No active Bluetooth device discovery session.";
704a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
705a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
706a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Stopping Bluetooth device discovery session.";
707a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_discovery_session_->Stop(
7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError));
7095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ConnectToBluetoothDevice(
7125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& address) {
7135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address);
7145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!device || device->IsConnecting() ||
7155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (device->IsConnected() && device->IsPaired())) {
7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (device->IsPaired() && !device->IsConnectable())
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (device->IsPaired() || !device->IsPairable()) {
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE);
7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device->Connect(NULL,
7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    base::Bind(&base::DoNothing),
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    base::Bind(&BluetoothDeviceConnectError));
7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {  // Show paring dialog for the unpaired device.
7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE);
7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    BluetoothPairingDialog* dialog =
7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new BluetoothPairingDialog(GetNativeWindow(), device);
7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // The dialog deletes itself on close.
7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    dialog->Show();
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsBluetoothDiscovering() {
7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsDiscovering();
7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetCurrentIME(ash::IMEInfo* info) {
7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager* manager =
7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      input_method::InputMethodManager::Get();
7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodDescriptor ime = manager->GetCurrentInputMethod();
7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtractIMEInfo(ime, *util, info);
7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  info->selected = true;
7475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetAvailableIMEList(ash::IMEInfoList* list) {
7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager* manager =
7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      input_method::InputMethodManager::Get();
7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<input_method::InputMethodDescriptors> ime_descriptors(
7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      manager->GetActiveInputMethods());
7555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string current = manager->GetCurrentInputMethod().id();
7565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < ime_descriptors->size(); i++) {
7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    input_method::InputMethodDescriptor& ime = ime_descriptors->at(i);
7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEInfo info;
7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ExtractIMEInfo(ime, *util, &info);
7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.selected = ime.id() == current;
7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(info);
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetCurrentIMEProperties(
7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEPropertyInfoList* list) {
767a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuItemList menu_list =
768a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      ash::ime::InputMethodMenuManager::GetInstance()->
769a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GetCurrentInputMethodMenuItemList();
770a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (size_t i = 0; i < menu_list.size(); ++i) {
7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEPropertyInfo property;
772a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.key = menu_list[i].key;
773a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.name = base::UTF8ToUTF16(menu_list[i].label);
774a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.selected = menu_list[i].is_selection_item_checked;
7755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(property);
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SwitchIME(const std::string& ime_id) {
7805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->ChangeInputMethod(ime_id);
7815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ActivateIMEProperty(const std::string& key) {
784a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  input_method::InputMethodManager::Get()->ActivateInputMethodMenuItem(key);
7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::CancelDriveOperation(int32 operation_id) {
7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!integration_service)
7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  integration_service->job_list()->CancelJob(operation_id);
7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetDriveOperationStatusList(
7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::DriveOperationStatusList* list) {
7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!integration_service)
7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *list = ConvertToDriveStatusList(
8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      integration_service->job_list()->GetJobInfoList());
8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowNetworkConfigure(
8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& network_id,
8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    gfx::NativeWindow parent_window) {
8085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NetworkConfigView::Show(network_id, parent_window);
8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::EnrollNetwork(
8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& network_id,
8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    gfx::NativeWindow parent_window) {
8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return enrollment::CreateDialog(network_id, parent_window);
8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ManageBluetoothDevices() {
8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowBluetoothSettingsPage"));
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page =
8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::string(chrome::kSearchSubPage) + "#" +
8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH);
822effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ToggleBluetooth() {
8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->SetPowered(!bluetooth_adapter_->IsPowered(),
8275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Bind(&base::DoNothing),
8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Bind(&BluetoothPowerFailure));
8295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowMobileSimDialog() {
8325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SimDialogDelegate::ShowDialog(GetNativeWindow(),
8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                SimDialogDelegate::SIM_DIALOG_UNLOCK);
8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
83590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowMobileSetupDialog(
8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& service_path) {
8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  MobileSetupDialog::Show(service_path);
8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
840ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
8415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowOtherNetworkDialog(
8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& type) {
8435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (type == shill::kTypeCellular) {
8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
8455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NetworkConfigView::ShowForType(type, GetNativeWindow());
8485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetBluetoothAvailable() {
8515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsPresent();
8525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetBluetoothEnabled() {
8555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsPowered();
8565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
858e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochbool SystemTrayDelegateChromeOS::GetBluetoothDiscovering() {
859e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  return (bluetooth_discovery_session_.get() &&
860e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch      bluetooth_discovery_session_->IsActive());
861e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch}
862e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
8635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ChangeProxySettings() {
8645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE);
8655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginDisplayHostImpl::default_host()->OpenProxySettings();
8665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::VolumeControlDelegate*
8695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::GetVolumeControlDelegate() const {
8705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return volume_control_delegate_.get();
8715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SetVolumeControlDelegate(
8745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<ash::VolumeControlDelegate> delegate) {
8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  volume_control_delegate_.swap(delegate);
8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetSessionStartTime(
8795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeTicks* session_start_time) {
8805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *session_start_time = session_start_time_;
8815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return have_session_start_time_;
8825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetSessionLengthLimit(
8855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeDelta* session_length_limit) {
8865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *session_length_limit = session_length_limit_;
8875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return have_session_length_limit_;
8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int SystemTrayDelegateChromeOS::GetSystemTrayMenuWidth() {
8915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetLocalizedContentsWidthInPixels(
8925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
8935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ActiveUserWasChanged() {
8965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyUserUpdate();
8975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
899a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsNetworkBehindCaptivePortal(
900a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const std::string& service_path) const {
901a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NetworkPortalDetector::CaptivePortalState state =
902a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      NetworkPortalDetector::Get()->GetCaptivePortalState(service_path);
903a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
904a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
905a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
906a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsSearchKeyMappedToCapsLock() {
907a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return search_key_mapped_to_ == input_method::kCapsLockKey;
908a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
909a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
910a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochash::tray::UserAccountsDelegate*
911a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochSystemTrayDelegateChromeOS::GetUserAccountsDelegate(
912a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const std::string& user_id) {
913a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!accounts_delegates_.contains(user_id)) {
914a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    // TODO(dzhioev): replace stub with real implementation.
915a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    accounts_delegates_.set(user_id,
916a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                            scoped_ptr<ash::tray::UserAccountsDelegate>(
917a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                new StubUserAccountsDelegate(user_id)));
918a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
919a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("secondary_account1@gmail.com");
920a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
921a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("very_long_account_name_for_user@gmail.com");
922a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
923a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("secondary_account2@gmail.com");
924a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
925a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("very_very_very_long_account_name_for_user@gmail.com");
926a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
927a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return accounts_delegates_.get(user_id);
928a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
929a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
9305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() {
9315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::Shell::GetInstance()->GetPrimarySystemTray();
9325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
9355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::Shell::GetInstance()->system_tray_notifier();
9365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
939a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Stop observing the Drive integration status and the AppWindowRegistry of
940a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the current |user_profile_|.
9415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UnobserveDriveUpdates();
942a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StopObservingAppWindowRegistry();
9435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_profile_ = profile;
9455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
946a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Start observing the Drive integration status and the AppWindowRegistry of
947a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the newly set |user_profile_|.
9485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ObserveDriveUpdates();
949a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  apps::AppWindowRegistry::Get(user_profile_)->AddObserver(this);
9505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PrefService* prefs = profile->GetPrefs();
9525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset(new PrefChangeRegistrar);
9535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Init(prefs);
9545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kUse24HourClock,
9565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
9575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLanguageRemapSearchKeyTo,
9605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged,
9615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kShowLogoutButtonInTray,
9645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray,
9655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLogoutDialogDurationMs,
9685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration,
9695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLargeCursorEnabled,
9725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kAutoclickEnabled,
9775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kShouldAlwaysShowAccessibilityMenu,
9825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kPerformanceTracingEnabled,
9875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing,
9885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateClockType();
9915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateShowLogoutButtonInTray();
9925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateLogoutDialogDuration();
9935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdatePerformanceTracing();
9945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  search_key_mapped_to_ =
9955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
9965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
99790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
9985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) {
9995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (profile != user_profile_)
10005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
10015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset();
1002a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  user_profile_ = NULL;
10035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
10045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ObserveDriveUpdates() {
10075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
10085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (integration_service)
10095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    integration_service->job_list()->AddObserver(this);
10105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
10125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UnobserveDriveUpdates() {
10135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
10145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (integration_service)
10155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    integration_service->job_list()->RemoveObserver(this);
10165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1017bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
10185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetShouldUse24HourClockForTesting() const {
10195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ShouldUse24HourClock();
10205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldUse24HourClock() const {
10235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // On login screen and in guest mode owner default is used for
10245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // kUse24HourClock preference.
10255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const ash::user::LoginStatus status = GetUserLoginStatus();
10265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const CrosSettings* const cros_settings = CrosSettings::Get();
10275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool system_use_24_hour_clock = true;
10285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const bool system_value_found = cros_settings->GetBoolean(
10295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kSystemUse24HourClock, &system_use_24_hour_clock);
10305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if ((status == ash::user::LOGGED_IN_NONE) || !user_pref_registrar_)
10325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return (system_value_found
10335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                ? system_use_24_hour_clock
10345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                : (base::GetHourClockType() == base::k24HourClock));
10355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService::Preference* user_pref =
10375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->FindPreference(prefs::kUse24HourClock);
10385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (status == ash::user::LOGGED_IN_GUEST && user_pref->IsDefaultValue())
10395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return (system_value_found
10405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                ? system_use_24_hour_clock
10415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                : (base::GetHourClockType() == base::k24HourClock));
10425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool use_24_hour_clock = true;
10445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock);
10455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return use_24_hour_clock;
10465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateClockType() {
10495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const bool use_24_hour_clock = ShouldUse24HourClock();
10505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  clock_type_ = use_24_hour_clock ? base::k24HourClock : base::k12HourClock;
10515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyDateFormatChanged();
10525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This also works for enterprise-managed devices because they never have
10535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // local owner.
10545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (chromeos::UserManager::Get()->IsCurrentUserOwner())
10555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CrosSettings::Get()->SetBoolean(kSystemUse24HourClock, use_24_hour_clock);
10565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray() {
10595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyShowLoginButtonChanged(
10605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->GetBoolean(
10615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          prefs::kShowLogoutButtonInTray));
10625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration() {
10655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const int duration_ms =
10665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->GetInteger(prefs::kLogoutDialogDurationMs);
10675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyLogoutDialogDurationChanged(
10685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::TimeDelta::FromMilliseconds(duration_ms));
10695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
107058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
10715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateSessionStartTime() {
10725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService* local_state = local_state_registrar_->prefs();
10735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (local_state->HasPrefPath(prefs::kSessionStartTime)) {
10745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_start_time_ = true;
10755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_start_time_ = base::TimeTicks::FromInternalValue(
10765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        local_state->GetInt64(prefs::kSessionStartTime));
10775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
10785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_start_time_ = false;
10795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_start_time_ = base::TimeTicks();
10805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifySessionStartTimeChanged();
10825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateSessionLengthLimit() {
10855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService* local_state = local_state_registrar_->prefs();
10865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (local_state->HasPrefPath(prefs::kSessionLengthLimit)) {
10875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_length_limit_ = true;
10885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_length_limit_ = base::TimeDelta::FromMilliseconds(
10895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        std::min(std::max(local_state->GetInteger(prefs::kSessionLengthLimit),
10905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                          kSessionLengthLimitMinMs),
10915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 kSessionLengthLimitMaxMs));
10925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
10935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_length_limit_ = false;
10945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_length_limit_ = base::TimeDelta();
10955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifySessionLengthLimitChanged();
10975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1099a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::StopObservingAppWindowRegistry() {
1100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!user_profile_)
1101a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  apps::AppWindowRegistry* registry =
1104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      apps::AppWindowRegistry::Factory::GetForBrowserContext(user_profile_,
1105a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                                             false);
1106a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (registry)
1107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    registry->RemoveObserver(this);
1108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() {
1111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!user_profile_)
1112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList* browser_list =
1115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (BrowserList::const_iterator it = browser_list->begin();
1117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       it != browser_list->end();
1118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       ++it) {
1119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if ((*it)->profile()->IsSameProfile(user_profile_)) {
1120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      // The current user has at least one open browser window.
1121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return;
1122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
1123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!apps::AppWindowRegistry::Get(user_profile_)->app_windows().empty()) {
1126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // The current user has at least one open app window.
1127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyLastWindowClosed();
1131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// LoginState::Observer overrides.
11345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::LoggedInStateChanged() {
11355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // It apparently sometimes takes a while after login before the current user
11365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is recognized as the owner. Make sure that the system-wide clock setting
11375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is updated when the recognition eventually happens
11385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // (http://crbug.com/278601).
11395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
11405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Note that it isn't safe to blindly call UpdateClockType() from this
11415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // method, as LoggedInStateChanged() is also called before the logged-in
11425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // user's profile has actually been loaded (http://crbug.com/317745). The
11435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // system tray's time format is updated at login via SetProfile().
11445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (chromeos::UserManager::Get()->IsCurrentUserOwner()) {
11455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CrosSettings::Get()->SetBoolean(kSystemUse24HourClock,
11465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    ShouldUse24HourClock());
11475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
11485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from SessionManagerClient::Observer.
11515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ScreenIsLocked() {
11525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  screen_locked_ = true;
11535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
11545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ScreenIsUnlocked() {
11575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  screen_locked_ = false;
11585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
11595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeWindow SystemTrayDelegateChromeOS::GetNativeWindow() const {
11625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool session_started = ash::Shell::GetInstance()
11635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             ->session_state_delegate()
11645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             ->IsActiveUserSessionStarted();
11655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return GetNativeWindowByStatus(GetUserLoginStatus(), session_started);
11665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// content::NotificationObserver implementation.
11695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Observe(
11705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int type,
11715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const content::NotificationSource& source,
11725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const content::NotificationDetails& details) {
11735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  switch (type) {
11745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
11755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      UpgradeDetector* detector =
11765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          content::Source<UpgradeDetector>(source).ptr();
11775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ash::UpdateObserver::UpdateSeverity severity =
11785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          ash::UpdateObserver::UPDATE_NORMAL;
11795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      switch (detector->upgrade_notification_stage()) {
11805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
11815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_SEVERE_RED;
11825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
11835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
11855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE;
11865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
11875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
11895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_LOW_GREEN;
11905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
11915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
11935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        default:
11945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_NORMAL;
11955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
11965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
11975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetSystemTrayNotifier()->NotifyUpdateRecommended(severity);
11985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
11995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: {
12015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // This notification is also sent on login screen when user avatar
12025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // is loaded from file.
12035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) {
12045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetSystemTrayNotifier()->NotifyUserUpdate();
12055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
12065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_PROFILE_CREATED: {
12095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      SetProfile(content::Source<Profile>(source).ptr());
12105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      registrar_->Remove(this,
12115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         chrome::NOTIFICATION_PROFILE_CREATED,
12125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         content::NotificationService::AllSources());
12135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_PROFILE_DESTROYED: {
12165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (UnsetProfile(content::Source<Profile>(source).ptr())) {
121790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        registrar_->Remove(this,
12185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           chrome::NOTIFICATION_PROFILE_DESTROYED,
121990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                           content::NotificationService::AllSources());
12202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
12215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
12235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_SESSION_STARTED: {
12245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
12255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          GetUserLoginStatus());
12265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      SetProfile(ProfileManager::GetActiveUserProfile());
12275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    default:
12305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NOTREACHED();
12315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
12325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged() {
12355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  search_key_mapped_to_ = user_pref_registrar_->prefs()->GetInteger(
12365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLanguageRemapSearchKeyTo);
12375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAccessibilityModeChanged(
12405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::AccessibilityNotificationVisibility notify) {
12415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAccessibilityModeChanged(notify);
12425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdatePerformanceTracing() {
12455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!user_pref_registrar_)
12465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
12475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool value = user_pref_registrar_->prefs()->GetBoolean(
12485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kPerformanceTracingEnabled);
12495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyTracingModeChanged(value);
12505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from InputMethodManager::Observer.
12535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::InputMethodChanged(
12545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    input_method::InputMethodManager* manager,
12555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool show_message) {
1256a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshIME();
1257a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1258a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1259a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from InputMethodMenuManager::Observer.
1260a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged(
1261a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ash::ime::InputMethodMenuManager* manager) {
1262a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshIME();
1263a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1264a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1265a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from CrasAudioHandler::AudioObserver.
1266a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnOutputVolumeChanged() {
1267a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioOutputVolumeChanged();
1268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1269a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnOutputMuteChanged() {
1271a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioOutputMuteChanged();
1272a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1273a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1274a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnInputGainChanged() {
1275a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1276a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnInputMuteChanged() {
12785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAudioNodesChanged() {
1281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioNodesChanged();
1282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1284a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnActiveOutputNodeChanged() {
1285a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioActiveOutputNodeChanged();
1286a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1287a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnActiveInputNodeChanged() {
1289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioActiveInputNodeChanged();
12905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// drive::JobListObserver overrides.
12935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnJobAdded(const drive::JobInfo& job_info) {
12945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  OnJobUpdated(job_info);
12955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnJobDone(const drive::JobInfo& job_info,
12985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                           drive::FileError error) {
12995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::DriveOperationStatus status;
13005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (ConvertToFinishedDriveOperationStatus(job_info, error, &status))
13015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GetSystemTrayNotifier()->NotifyDriveJobUpdated(status);
13025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnJobUpdated(const drive::JobInfo& job_info) {
13055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::DriveOperationStatus status;
13065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (ConvertToDriveOperationStatus(job_info, &status))
13075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GetSystemTrayNotifier()->NotifyDriveJobUpdated(status);
13085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DriveIntegrationService*
13115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::FindDriveIntegrationService() {
13125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return user_profile_
13135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             ? DriveIntegrationServiceFactory::FindForProfile(user_profile_)
13145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             : NULL;
13155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from BluetoothAdapter::Observer.
13185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::AdapterPresentChanged(
13195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool present) {
13215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::AdapterPoweredChanged(
13255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool powered) {
13275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::AdapterDiscoveringChanged(
13315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool discovering) {
13335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
13345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::DeviceAdded(device::BluetoothAdapter* adapter,
13375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                             device::BluetoothDevice* device) {
13385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::DeviceChanged(
13425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothDevice* device) {
13445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::DeviceRemoved(
13485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothDevice* device) {
13505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1353a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession(
1354a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
1355a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // If the discovery session was returned after a request to stop discovery
1356a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // (e.g. the user dismissed the Bluetooth detailed view before the call
1357a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // returned), don't claim the discovery session and let it clean up.
1358a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!should_run_bluetooth_discovery_)
1359a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1360a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Claiming new Bluetooth device discovery session.";
1361a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_discovery_session_ = discovery_session.Pass();
1362e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
13635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1364868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
13655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateEnterpriseDomain() {
13665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* connector =
13675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
13685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string enterprise_domain = connector->GetEnterpriseDomain();
13695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (enterprise_domain_ != enterprise_domain) {
13705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    enterprise_domain_ = enterprise_domain;
13715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GetSystemTrayNotifier()->NotifyEnterpriseDomainChanged();
13724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
13735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
13755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from CloudPolicyStore::Observer
13765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnStoreLoaded(
13775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy::CloudPolicyStore* store) {
13785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateEnterpriseDomain();
13795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
13815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnStoreError(policy::CloudPolicyStore* store) {
13825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateEnterpriseDomain();
13835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from ash::SessionStateObserver
13865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UserAddedToSession(
13875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& user_id) {
13885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyUserAddedToSession();
13895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1391a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from chrome::BrowserListObserver.
1392a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) {
1393a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NotifyIfLastWindowClosed();
1394a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1395a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1396a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from apps::AppWindowRegistry::Observer.
1397a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAppWindowAdded(apps::AppWindow* app_window) {
1398a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1399a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1400a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAppWindowIconChanged(
1401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    apps::AppWindow* app_window) {}
1402a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1403a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAppWindowRemoved(
1404a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    apps::AppWindow* app_window) {
1405a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NotifyIfLastWindowClosed();
1406a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1407a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1408a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged(
1409a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const AccessibilityStatusEventDetails& details) {
1410a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN)
1411a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    accessibility_subscription_.reset();
1412a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  else
1413a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    OnAccessibilityModeChanged(details.notify);
1414a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1415a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
14165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ash::SystemTrayDelegate* CreateSystemTrayDelegate() {
14175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return new SystemTrayDelegateChromeOS();
14185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace chromeos
1421